tcp_listen(Slirp *slirp, u_int32_t haddr, u_int hport, u_int32_t laddr,

           u_int lport, int flags)

{

	struct sockaddr_in addr;

	struct socket *so;

	int s, opt = 1;

	socklen_t addrlen = sizeof(addr);



	DEBUG_CALL("tcp_listen");

	DEBUG_ARG("haddr = %x", haddr);

	DEBUG_ARG("hport = %d", hport);

	DEBUG_ARG("laddr = %x", laddr);

	DEBUG_ARG("lport = %d", lport);

	DEBUG_ARG("flags = %x", flags);



	so = socreate(slirp);

	if (!so) {

	  return NULL;

	}



	/* Don't tcp_attach... we don't need so_snd nor so_rcv */

	if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) {

		free(so);

		return NULL;

	}

	insque(so, &slirp->tcb);



	/*

	 * SS_FACCEPTONCE sockets must time out.

	 */

	if (flags & SS_FACCEPTONCE)

	   so->so_tcpcb->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT*2;



	so->so_state &= SS_PERSISTENT_MASK;

	so->so_state |= (SS_FACCEPTCONN | flags);

	so->so_lport = lport; /* Kept in network format */

	so->so_laddr.s_addr = laddr; /* Ditto */



	addr.sin_family = AF_INET;

	addr.sin_addr.s_addr = haddr;

	addr.sin_port = hport;



	if (((s = socket(AF_INET,SOCK_STREAM,0)) < 0) ||

	    (setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)) < 0) ||

	    (bind(s,(struct sockaddr *)&addr, sizeof(addr)) < 0) ||

	    (listen(s,1) < 0)) {

		int tmperrno = errno; /* Don't clobber the real reason we failed */



		close(s);

		sofree(so);

		/* Restore the real errno */

#ifdef _WIN32

		WSASetLastError(tmperrno);

#else

		errno = tmperrno;

#endif

		return NULL;

	}

	setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));



	getsockname(s,(struct sockaddr *)&addr,&addrlen);

	so->so_fport = addr.sin_port;

	if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr)

	   so->so_faddr = slirp->vhost_addr;

	else

	   so->so_faddr = addr.sin_addr;



	so->s = s;

	return so;

}

tcp_listen(Slirp *slirp, u_int32_t haddr, u_int hport, u_int32_t laddr,

           u_int lport, int flags)

{

	struct sockaddr_in addr;

	struct socket *so;

	int s, opt = 1;

	socklen_t addrlen = sizeof(addr);



	DEBUG_CALL("tcp_listen");

	DEBUG_ARG("haddr = %x", haddr);

	DEBUG_ARG("hport = %d", hport);

	DEBUG_ARG("laddr = %x", laddr);

	DEBUG_ARG("lport = %d", lport);

	DEBUG_ARG("flags = %x", flags);



	so = socreate(slirp);

	if (!so) {

	  return NULL;

	}



	

	if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) {

		free(so);

		return NULL;

	}

	insque(so, &slirp->tcb);



	





	if (flags & SS_FACCEPTONCE)

	   so->so_tcpcb->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT*2;



	so->so_state &= SS_PERSISTENT_MASK;

	so->so_state |= (SS_FACCEPTCONN | flags);

	so->so_lport = lport; 

	so->so_laddr.s_addr = laddr; 



	addr.sin_family = AF_INET;

	addr.sin_addr.s_addr = haddr;

	addr.sin_port = hport;



	if (((s = socket(AF_INET,SOCK_STREAM,0)) < 0) ||

	    (setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)) < 0) ||

	    (bind(s,(struct sockaddr *)&addr, sizeof(addr)) < 0) ||

	    (listen(s,1) < 0)) {

		int tmperrno = errno; 



		close(s);

		sofree(so);

		

#ifdef _WIN32

		WSASetLastError(tmperrno);

#else

		errno = tmperrno;

#endif

		return NULL;

	}

	setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));



	getsockname(s,(struct sockaddr *)&addr,&addrlen);

	so->so_fport = addr.sin_port;

	if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr)

	   so->so_faddr = slirp->vhost_addr;

	else

	   so->so_faddr = addr.sin_addr;



	so->s = s;

	return so;

}

	if (((s = socket(AF_INET,SOCK_STREAM,0)) < 0) ||
FUNC_0(Slirp *VAR_0, u_int32_t VAR_1, u_int VAR_2, u_int32_t VAR_3,

           u_int VAR_4, int VAR_5)

{

	struct sockaddr_in VAR_6;

	struct socket *VAR_7;

	int VAR_8, VAR_9 = 1;

	socklen_t addrlen = sizeof(VAR_6);



	DEBUG_CALL("FUNC_0");

	DEBUG_ARG("VAR_1 = %x", VAR_1);

	DEBUG_ARG("VAR_2 = %d", VAR_2);

	DEBUG_ARG("VAR_3 = %x", VAR_3);

	DEBUG_ARG("VAR_4 = %d", VAR_4);

	DEBUG_ARG("VAR_5 = %x", VAR_5);



	VAR_7 = socreate(VAR_0);

	if (!VAR_7) {

	  return NULL;

	}



	

	if ((VAR_7->so_tcpcb = tcp_newtcpcb(VAR_7)) == NULL) {

		free(VAR_7);

		return NULL;

	}

	insque(VAR_7, &VAR_0->tcb);



	





	if (VAR_5 & SS_FACCEPTONCE)

	   VAR_7->so_tcpcb->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT*2;



	VAR_7->so_state &= SS_PERSISTENT_MASK;

	VAR_7->so_state |= (SS_FACCEPTCONN | VAR_5);

	VAR_7->so_lport = VAR_4; 

	VAR_7->so_laddr.s_addr = VAR_3; 



	VAR_6.sin_family = AF_INET;

	VAR_6.sin_addr.s_addr = VAR_1;

	VAR_6.sin_port = VAR_2;



	if (((VAR_8 = socket(AF_INET,SOCK_STREAM,0)) < 0) ||

	    (setsockopt(VAR_8,SOL_SOCKET,SO_REUSEADDR,(char *)&VAR_9,sizeof(int)) < 0) ||

	    (bind(VAR_8,(struct sockaddr *)&VAR_6, sizeof(VAR_6)) < 0) ||

	    (listen(VAR_8,1) < 0)) {

		int VAR_10 = errno; 



		close(VAR_8);

		sofree(VAR_7);

		

#ifdef _WIN32

		WSASetLastError(VAR_10);

#else

		errno = VAR_10;

#endif

		return NULL;

	}

	setsockopt(VAR_8,SOL_SOCKET,SO_OOBINLINE,(char *)&VAR_9,sizeof(int));



	getsockname(VAR_8,(struct sockaddr *)&VAR_6,&addrlen);

	VAR_7->so_fport = VAR_6.sin_port;

	if (VAR_6.sin_addr.s_addr == 0 || VAR_6.sin_addr.s_addr == loopback_addr.s_addr)

	   VAR_7->so_faddr = VAR_0->vhost_addr;

	else

	   VAR_7->so_faddr = VAR_6.sin_addr;



	VAR_7->VAR_8 = VAR_8;

	return VAR_7;

}

FUNC_0(Slirp *VAR_0, u_int32_t VAR_1, u_int VAR_2, u_int32_t VAR_3,
u_int VAR_4, int VAR_5)
{ struct sockaddr_in VAR_6; struct socket *VAR_7; int VAR_8, VAR_9 = 1; socklen_t addrlen = sizeof(VAR_6); DEBUG_CALL("FUNC_0"); DEBUG_ARG("VAR_1 = %x", VAR_1); DEBUG_ARG("VAR_2 = %d", VAR_2); DEBUG_ARG("VAR_3 = %x", VAR_3); DEBUG_ARG("VAR_4 = %d", VAR_4); DEBUG_ARG("VAR_5 = %x", VAR_5); VAR_7 = socreate(VAR_0); if (!VAR_7) { return NULL; } if ((VAR_7->so_tcpcb = tcp_newtcpcb(VAR_7)) == NULL) { free(VAR_7); return NULL; } insque(VAR_7, &VAR_0->tcb); if (VAR_5 & SS_FACCEPTONCE)
VAR_7->so_tcpcb->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT*2; VAR_7->so_state &= SS_PERSISTENT_MASK; VAR_7->so_state |= (SS_FACCEPTCONN | VAR_5); VAR_7->so_lport = VAR_4; VAR_7->so_laddr.s_addr = VAR_3; VAR_6.sin_family = AF_INET; VAR_6.sin_addr.s_addr = VAR_1; VAR_6.sin_port = VAR_2; if (((VAR_8 = socket(AF_INET,SOCK_STREAM,0)) < 0) ||
(setsockopt(VAR_8,SOL_SOCKET,SO_REUSEADDR,(char *)&VAR_9,sizeof(int)) < 0) ||
(bind(VAR_8,(struct sockaddr *)&VAR_6, sizeof(VAR_6)) < 0) ||
(listen(VAR_8,1) < 0)) { int VAR_10 = errno; close(VAR_8); sofree(VAR_7); #ifdef _WIN32
WSASetLastError(VAR_10); #else
errno = VAR_10; #endif
return NULL; } setsockopt(VAR_8,SOL_SOCKET,SO_OOBINLINE,(char *)&VAR_9,sizeof(int)); getsockname(VAR_8,(struct sockaddr *)&VAR_6,&addrlen); VAR_7->so_fport = VAR_6.sin_port; if (VAR_6.sin_addr.s_addr == 0 || VAR_6.sin_addr.s_addr == loopback_addr.s_addr)
VAR_7->so_faddr = VAR_0->vhost_addr; else
VAR_7->so_faddr = VAR_6.sin_addr; VAR_7->VAR_8 = VAR_8; return VAR_7; }