aboutsummaryrefslogtreecommitdiff
path: root/slirp/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'slirp/socket.c')
-rw-r--r--slirp/socket.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/slirp/socket.c b/slirp/socket.c
index f7b212fba8..d8fbe89a74 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -41,7 +41,7 @@ solookup(struct socket *head, struct in_addr laddr, u_int lport,
* insque() it into the correct linked-list
*/
struct socket *
-socreate(void)
+socreate(Slirp *slirp)
{
struct socket *so;
@@ -50,6 +50,7 @@ socreate(void)
memset(so, 0, sizeof(struct socket));
so->so_state = SS_NOFDREF;
so->s = -1;
+ so->slirp = slirp;
}
return(so);
}
@@ -60,15 +61,17 @@ socreate(void)
void
sofree(struct socket *so)
{
+ Slirp *slirp = so->slirp;
+
if (so->so_emu==EMU_RSH && so->extra) {
sofree(so->extra);
so->extra=NULL;
}
- if (so == tcp_last_so)
- tcp_last_so = &tcb;
- else if (so == udp_last_so)
- udp_last_so = &udb;
-
+ if (so == slirp->tcp_last_so) {
+ slirp->tcp_last_so = &slirp->tcb;
+ } else if (so == slirp->udp_last_so) {
+ slirp->udp_last_so = &slirp->udb;
+ }
m_free(so->so_m);
if(so->so_next && so->so_prev)
@@ -473,7 +476,10 @@ sorecvfrom(struct socket *so)
int n;
#endif
- if (!(m = m_get())) return;
+ m = m_get(so->slirp);
+ if (!m) {
+ return;
+ }
m->m_data += IF_MAXLINKHDR;
/*
@@ -533,6 +539,7 @@ sorecvfrom(struct socket *so)
int
sosendto(struct socket *so, struct mbuf *m)
{
+ Slirp *slirp = so->slirp;
int ret;
struct sockaddr_in addr;
@@ -541,10 +548,10 @@ sosendto(struct socket *so, struct mbuf *m)
DEBUG_ARG("m = %lx", (long)m);
addr.sin_family = AF_INET;
- if ((so->so_faddr.s_addr & vnetwork_mask.s_addr) ==
- vnetwork_addr.s_addr) {
+ if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) ==
+ slirp->vnetwork_addr.s_addr) {
/* It's an alias */
- if (so->so_faddr.s_addr == vnameserver_addr.s_addr) {
+ if (so->so_faddr.s_addr == slirp->vnameserver_addr.s_addr) {
addr.sin_addr = dns_addr;
} else {
addr.sin_addr = loopback_addr;
@@ -576,7 +583,8 @@ sosendto(struct socket *so, struct mbuf *m)
* Listen for incoming TCP connections
*/
struct socket *
-tcp_listen(u_int32_t haddr, u_int hport, u_int32_t laddr, u_int lport, int flags)
+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;
@@ -590,7 +598,8 @@ tcp_listen(u_int32_t haddr, u_int hport, u_int32_t laddr, u_int lport, int flags
DEBUG_ARG("lport = %d", lport);
DEBUG_ARG("flags = %x", flags);
- if ((so = socreate()) == NULL) {
+ so = socreate(slirp);
+ if (!so) {
return NULL;
}
@@ -599,7 +608,7 @@ tcp_listen(u_int32_t haddr, u_int hport, u_int32_t laddr, u_int lport, int flags
free(so);
return NULL;
}
- insque(so,&tcb);
+ insque(so, &slirp->tcb);
/*
* SS_FACCEPTONCE sockets must time out.
@@ -637,7 +646,7 @@ tcp_listen(u_int32_t haddr, u_int hport, u_int32_t laddr, u_int lport, int flags
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 = vhost_addr;
+ so->so_faddr = slirp->vhost_addr;
else
so->so_faddr = addr.sin_addr;