2 * Copyright (c) 1995 Danny Gasparovski.
4 * Please read the file COPYRIGHT for the
5 * terms and conditions of the copyright.
8 #include "qemu/osdep.h"
9 #include "qemu-common.h"
13 #include <sys/filio.h>
16 static void sofcantrcvmore(struct socket
*so
);
17 static void sofcantsendmore(struct socket
*so
);
19 struct socket
*solookup(struct socket
**last
, struct socket
*head
,
20 struct sockaddr_storage
*lhost
, struct sockaddr_storage
*fhost
)
22 struct socket
*so
= *last
;
25 if (so
!= head
&& sockaddr_equal(&(so
->lhost
.ss
), lhost
)
26 && (!fhost
|| sockaddr_equal(&so
->fhost
.ss
, fhost
))) {
30 for (so
= head
->so_next
; so
!= head
; so
= so
->so_next
) {
31 if (sockaddr_equal(&(so
->lhost
.ss
), lhost
)
32 && (!fhost
|| sockaddr_equal(&so
->fhost
.ss
, fhost
))) {
38 return (struct socket
*)NULL
;
42 * Create a new socket, initialise the fields
43 * It is the responsibility of the caller to
44 * insque() it into the correct linked-list
47 socreate(Slirp
*slirp
)
51 so
= (struct socket
*)malloc(sizeof(struct socket
));
53 memset(so
, 0, sizeof(struct socket
));
54 so
->so_state
= SS_NOFDREF
;
63 * remque and free a socket, clobber cache
66 sofree(struct socket
*so
)
68 Slirp
*slirp
= so
->slirp
;
70 if (so
->so_emu
==EMU_RSH
&& so
->extra
) {
74 if (so
== slirp
->tcp_last_so
) {
75 slirp
->tcp_last_so
= &slirp
->tcb
;
76 } else if (so
== slirp
->udp_last_so
) {
77 slirp
->udp_last_so
= &slirp
->udb
;
78 } else if (so
== slirp
->icmp_last_so
) {
79 slirp
->icmp_last_so
= &slirp
->icmp
;
83 if(so
->so_next
&& so
->so_prev
)
84 remque(so
); /* crashes if so is not in a queue */
89 size_t sopreprbuf(struct socket
*so
, struct iovec
*iov
, int *np
)
92 struct sbuf
*sb
= &so
->so_snd
;
93 int len
= sb
->sb_datalen
- sb
->sb_cc
;
94 int mss
= so
->so_tcpcb
->t_maxseg
;
96 DEBUG_CALL("sopreprbuf");
97 DEBUG_ARG("so = %p", so
);
102 iov
[0].iov_base
= sb
->sb_wptr
;
103 iov
[1].iov_base
= NULL
;
105 if (sb
->sb_wptr
< sb
->sb_rptr
) {
106 iov
[0].iov_len
= sb
->sb_rptr
- sb
->sb_wptr
;
107 /* Should never succeed, but... */
108 if (iov
[0].iov_len
> len
)
109 iov
[0].iov_len
= len
;
110 if (iov
[0].iov_len
> mss
)
111 iov
[0].iov_len
-= iov
[0].iov_len
%mss
;
114 iov
[0].iov_len
= (sb
->sb_data
+ sb
->sb_datalen
) - sb
->sb_wptr
;
115 /* Should never succeed, but... */
116 if (iov
[0].iov_len
> len
) iov
[0].iov_len
= len
;
117 len
-= iov
[0].iov_len
;
119 iov
[1].iov_base
= sb
->sb_data
;
120 iov
[1].iov_len
= sb
->sb_rptr
- sb
->sb_data
;
121 if(iov
[1].iov_len
> len
)
122 iov
[1].iov_len
= len
;
123 total
= iov
[0].iov_len
+ iov
[1].iov_len
;
126 if (iov
[1].iov_len
> lss
) {
127 iov
[1].iov_len
-= lss
;
130 lss
-= iov
[1].iov_len
;
131 iov
[0].iov_len
-= lss
;
137 if (iov
[0].iov_len
> mss
)
138 iov
[0].iov_len
-= iov
[0].iov_len
%mss
;
145 return iov
[0].iov_len
+ (n
- 1) * iov
[1].iov_len
;
149 * Read from so's socket into sb_snd, updating all relevant sbuf fields
150 * NOTE: This will only be called if it is select()ed for reading, so
151 * a read() of 0 (or less) means it's disconnected
154 soread(struct socket
*so
)
157 struct sbuf
*sb
= &so
->so_snd
;
160 DEBUG_CALL("soread");
161 DEBUG_ARG("so = %p", so
);
164 * No need to check if there's enough room to read.
165 * soread wouldn't have been called if there weren't
167 sopreprbuf(so
, iov
, &n
);
170 nn
= readv(so
->s
, (struct iovec
*)iov
, n
);
171 DEBUG_MISC((dfd
, " ... read nn = %d bytes\n", nn
));
173 nn
= qemu_recv(so
->s
, iov
[0].iov_base
, iov
[0].iov_len
,0);
176 if (nn
< 0 && (errno
== EINTR
|| errno
== EAGAIN
))
179 DEBUG_MISC((dfd
, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn
, errno
,strerror(errno
)));
181 tcp_sockclosed(sototcpcb(so
));
188 * If there was no error, try and read the second time round
189 * We read again if n = 2 (ie, there's another part of the buffer)
190 * and we read as much as we could in the first read
191 * We don't test for <= 0 this time, because there legitimately
192 * might not be any more data (since the socket is non-blocking),
193 * a close will be detected on next iteration.
194 * A return of -1 wont (shouldn't) happen, since it didn't happen above
196 if (n
== 2 && nn
== iov
[0].iov_len
) {
198 ret
= qemu_recv(so
->s
, iov
[1].iov_base
, iov
[1].iov_len
,0);
203 DEBUG_MISC((dfd
, " ... read nn = %d bytes\n", nn
));
209 if (sb
->sb_wptr
>= (sb
->sb_data
+ sb
->sb_datalen
))
210 sb
->sb_wptr
-= sb
->sb_datalen
;
214 int soreadbuf(struct socket
*so
, const char *buf
, int size
)
216 int n
, nn
, copy
= size
;
217 struct sbuf
*sb
= &so
->so_snd
;
220 DEBUG_CALL("soreadbuf");
221 DEBUG_ARG("so = %p", so
);
224 * No need to check if there's enough room to read.
225 * soread wouldn't have been called if there weren't
227 if (sopreprbuf(so
, iov
, &n
) < size
)
230 nn
= MIN(iov
[0].iov_len
, copy
);
231 memcpy(iov
[0].iov_base
, buf
, nn
);
239 memcpy(iov
[1].iov_base
, buf
, copy
);
245 if (sb
->sb_wptr
>= (sb
->sb_data
+ sb
->sb_datalen
))
246 sb
->sb_wptr
-= sb
->sb_datalen
;
251 tcp_sockclosed(sototcpcb(so
));
252 fprintf(stderr
, "soreadbuf buffer to small");
259 * When the socket is created, we set it SO_OOBINLINE,
260 * so when OOB data arrives, we soread() it and everything
261 * in the send buffer is sent as urgent data
264 sorecvoob(struct socket
*so
)
266 struct tcpcb
*tp
= sototcpcb(so
);
268 DEBUG_CALL("sorecvoob");
269 DEBUG_ARG("so = %p", so
);
272 * We take a guess at how much urgent data has arrived.
273 * In most situations, when urgent data arrives, the next
274 * read() should get all the urgent data. This guess will
275 * be wrong however if more data arrives just after the
276 * urgent data, or the read() doesn't return all the
280 tp
->snd_up
= tp
->snd_una
+ so
->so_snd
.sb_cc
;
288 * There's a lot duplicated code here, but...
291 sosendoob(struct socket
*so
)
293 struct sbuf
*sb
= &so
->so_rcv
;
294 char buff
[2048]; /* XXX Shouldn't be sending more oob data than this */
298 DEBUG_CALL("sosendoob");
299 DEBUG_ARG("so = %p", so
);
300 DEBUG_ARG("sb->sb_cc = %d", sb
->sb_cc
);
302 if (so
->so_urgc
> 2048)
303 so
->so_urgc
= 2048; /* XXXX */
305 if (sb
->sb_rptr
< sb
->sb_wptr
) {
306 /* We can send it directly */
307 n
= slirp_send(so
, sb
->sb_rptr
, so
->so_urgc
, (MSG_OOB
)); /* |MSG_DONTWAIT)); */
310 DEBUG_MISC((dfd
, " --- sent %d bytes urgent data, %d urgent bytes left\n", n
, so
->so_urgc
));
313 * Since there's no sendv or sendtov like writev,
314 * we must copy all data to a linear buffer then
317 len
= (sb
->sb_data
+ sb
->sb_datalen
) - sb
->sb_rptr
;
318 if (len
> so
->so_urgc
) len
= so
->so_urgc
;
319 memcpy(buff
, sb
->sb_rptr
, len
);
322 n
= sb
->sb_wptr
- sb
->sb_data
;
323 if (n
> so
->so_urgc
) n
= so
->so_urgc
;
324 memcpy((buff
+ len
), sb
->sb_data
, n
);
328 n
= slirp_send(so
, buff
, len
, (MSG_OOB
)); /* |MSG_DONTWAIT)); */
331 DEBUG_ERROR((dfd
, "Didn't send all data urgently XXXXX\n"));
333 DEBUG_MISC((dfd
, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n
, so
->so_urgc
));
338 if (sb
->sb_rptr
>= (sb
->sb_data
+ sb
->sb_datalen
))
339 sb
->sb_rptr
-= sb
->sb_datalen
;
345 * Write data from so_rcv to so's socket,
346 * updating all sbuf field as necessary
349 sowrite(struct socket
*so
)
352 struct sbuf
*sb
= &so
->so_rcv
;
356 DEBUG_CALL("sowrite");
357 DEBUG_ARG("so = %p", so
);
366 * No need to check if there's something to write,
367 * sowrite wouldn't have been called otherwise
370 iov
[0].iov_base
= sb
->sb_rptr
;
371 iov
[1].iov_base
= NULL
;
373 if (sb
->sb_rptr
< sb
->sb_wptr
) {
374 iov
[0].iov_len
= sb
->sb_wptr
- sb
->sb_rptr
;
375 /* Should never succeed, but... */
376 if (iov
[0].iov_len
> len
) iov
[0].iov_len
= len
;
379 iov
[0].iov_len
= (sb
->sb_data
+ sb
->sb_datalen
) - sb
->sb_rptr
;
380 if (iov
[0].iov_len
> len
) iov
[0].iov_len
= len
;
381 len
-= iov
[0].iov_len
;
383 iov
[1].iov_base
= sb
->sb_data
;
384 iov
[1].iov_len
= sb
->sb_wptr
- sb
->sb_data
;
385 if (iov
[1].iov_len
> len
) iov
[1].iov_len
= len
;
390 /* Check if there's urgent data to send, and if so, send it */
393 nn
= writev(so
->s
, (const struct iovec
*)iov
, n
);
395 DEBUG_MISC((dfd
, " ... wrote nn = %d bytes\n", nn
));
397 nn
= slirp_send(so
, iov
[0].iov_base
, iov
[0].iov_len
,0);
399 /* This should never happen, but people tell me it does *shrug* */
400 if (nn
< 0 && (errno
== EAGAIN
|| errno
== EINTR
))
404 DEBUG_MISC((dfd
, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",
405 so
->so_state
, errno
));
407 tcp_sockclosed(sototcpcb(so
));
412 if (n
== 2 && nn
== iov
[0].iov_len
) {
414 ret
= slirp_send(so
, iov
[1].iov_base
, iov
[1].iov_len
,0);
418 DEBUG_MISC((dfd
, " ... wrote nn = %d bytes\n", nn
));
424 if (sb
->sb_rptr
>= (sb
->sb_data
+ sb
->sb_datalen
))
425 sb
->sb_rptr
-= sb
->sb_datalen
;
428 * If in DRAIN mode, and there's no more data, set
431 if ((so
->so_state
& SS_FWDRAIN
) && sb
->sb_cc
== 0)
438 * recvfrom() a UDP socket
441 sorecvfrom(struct socket
*so
)
443 struct sockaddr_storage addr
;
444 struct sockaddr_storage saddr
, daddr
;
445 socklen_t addrlen
= sizeof(struct sockaddr_storage
);
447 DEBUG_CALL("sorecvfrom");
448 DEBUG_ARG("so = %p", so
);
450 if (so
->so_type
== IPPROTO_ICMP
) { /* This is a "ping" reply */
454 len
= recvfrom(so
->s
, buff
, 256, 0,
455 (struct sockaddr
*)&addr
, &addrlen
);
456 /* XXX Check if reply is "correct"? */
458 if(len
== -1 || len
== 0) {
459 u_char code
=ICMP_UNREACH_PORT
;
461 if(errno
== EHOSTUNREACH
) code
=ICMP_UNREACH_HOST
;
462 else if(errno
== ENETUNREACH
) code
=ICMP_UNREACH_NET
;
464 DEBUG_MISC((dfd
," udp icmp rx errno = %d-%s\n",
465 errno
,strerror(errno
)));
466 icmp_send_error(so
->so_m
, ICMP_UNREACH
, code
, 0, strerror(errno
));
468 icmp_reflect(so
->so_m
);
469 so
->so_m
= NULL
; /* Don't m_free() it again! */
471 /* No need for this socket anymore, udp_detach it */
473 } else { /* A "normal" UDP packet */
482 m
= m_get(so
->slirp
);
486 switch (so
->so_ffamily
) {
488 m
->m_data
+= IF_MAXLINKHDR
+ sizeof(struct udpiphdr
);
491 m
->m_data
+= IF_MAXLINKHDR
+ sizeof(struct ip6
)
492 + sizeof(struct udphdr
);
495 g_assert_not_reached();
500 * XXX Shouldn't FIONREAD packets destined for port 53,
501 * but I don't know the max packet size for DNS lookups
504 /* if (so->so_fport != htons(53)) { */
505 ioctlsocket(so
->s
, FIONREAD
, &n
);
508 n
= (m
->m_data
- m
->m_dat
) + m
->m_len
+ n
+ 1;
514 m
->m_len
= recvfrom(so
->s
, m
->m_data
, len
, 0,
515 (struct sockaddr
*)&addr
, &addrlen
);
516 DEBUG_MISC((dfd
, " did recvfrom %d, errno = %d-%s\n",
517 m
->m_len
, errno
,strerror(errno
)));
519 /* Report error as ICMP */
520 switch (so
->so_lfamily
) {
523 code
= ICMP_UNREACH_PORT
;
525 if (errno
== EHOSTUNREACH
) {
526 code
= ICMP_UNREACH_HOST
;
527 } else if (errno
== ENETUNREACH
) {
528 code
= ICMP_UNREACH_NET
;
531 DEBUG_MISC((dfd
, " rx error, tx icmp ICMP_UNREACH:%i\n", code
));
532 icmp_send_error(so
->so_m
, ICMP_UNREACH
, code
, 0, strerror(errno
));
535 code
= ICMP6_UNREACH_PORT
;
537 if (errno
== EHOSTUNREACH
) {
538 code
= ICMP6_UNREACH_ADDRESS
;
539 } else if (errno
== ENETUNREACH
) {
540 code
= ICMP6_UNREACH_NO_ROUTE
;
543 DEBUG_MISC((dfd
, " rx error, tx icmp6 ICMP_UNREACH:%i\n", code
));
544 icmp6_send_error(so
->so_m
, ICMP6_UNREACH
, code
);
547 g_assert_not_reached();
553 * Hack: domain name lookup will be used the most for UDP,
554 * and since they'll only be used once there's no need
555 * for the 4 minute (or whatever) timeout... So we time them
556 * out much quicker (10 seconds for now...)
559 if (so
->so_fport
== htons(53))
560 so
->so_expire
= curtime
+ SO_EXPIREFAST
;
562 so
->so_expire
= curtime
+ SO_EXPIRE
;
566 * If this packet was destined for CTL_ADDR,
567 * make it look like that's where it came from
570 sotranslate_in(so
, &saddr
);
571 daddr
= so
->lhost
.ss
;
573 switch (so
->so_ffamily
) {
575 udp_output(so
, m
, (struct sockaddr_in
*) &saddr
,
576 (struct sockaddr_in
*) &daddr
,
580 udp6_output(so
, m
, (struct sockaddr_in6
*) &saddr
,
581 (struct sockaddr_in6
*) &daddr
);
584 g_assert_not_reached();
588 } /* if ping packet */
595 sosendto(struct socket
*so
, struct mbuf
*m
)
598 struct sockaddr_storage addr
;
600 DEBUG_CALL("sosendto");
601 DEBUG_ARG("so = %p", so
);
602 DEBUG_ARG("m = %p", m
);
605 DEBUG_CALL(" sendto()ing)");
606 sotranslate_out(so
, &addr
);
608 /* Don't care what port we get */
609 ret
= sendto(so
->s
, m
->m_data
, m
->m_len
, 0,
610 (struct sockaddr
*)&addr
, sizeof(addr
));
615 * Kill the socket if there's no reply in 4 minutes,
616 * but only if it's an expirable socket
619 so
->so_expire
= curtime
+ SO_EXPIRE
;
620 so
->so_state
&= SS_PERSISTENT_MASK
;
621 so
->so_state
|= SS_ISFCONNECTED
; /* So that it gets select()ed */
626 * Listen for incoming TCP connections
629 tcp_listen(Slirp
*slirp
, uint32_t haddr
, u_int hport
, uint32_t laddr
,
630 u_int lport
, int flags
)
632 struct sockaddr_in addr
;
635 socklen_t addrlen
= sizeof(addr
);
636 memset(&addr
, 0, addrlen
);
638 DEBUG_CALL("tcp_listen");
639 DEBUG_ARG("haddr = %x", haddr
);
640 DEBUG_ARG("hport = %d", hport
);
641 DEBUG_ARG("laddr = %x", laddr
);
642 DEBUG_ARG("lport = %d", lport
);
643 DEBUG_ARG("flags = %x", flags
);
645 so
= socreate(slirp
);
650 /* Don't tcp_attach... we don't need so_snd nor so_rcv */
651 if ((so
->so_tcpcb
= tcp_newtcpcb(so
)) == NULL
) {
655 insque(so
, &slirp
->tcb
);
658 * SS_FACCEPTONCE sockets must time out.
660 if (flags
& SS_FACCEPTONCE
)
661 so
->so_tcpcb
->t_timer
[TCPT_KEEP
] = TCPTV_KEEP_INIT
*2;
663 so
->so_state
&= SS_PERSISTENT_MASK
;
664 so
->so_state
|= (SS_FACCEPTCONN
| flags
);
665 so
->so_lfamily
= AF_INET
;
666 so
->so_lport
= lport
; /* Kept in network format */
667 so
->so_laddr
.s_addr
= laddr
; /* Ditto */
669 addr
.sin_family
= AF_INET
;
670 addr
.sin_addr
.s_addr
= haddr
;
671 addr
.sin_port
= hport
;
673 if (((s
= qemu_socket(AF_INET
,SOCK_STREAM
,0)) < 0) ||
674 (socket_set_fast_reuse(s
) < 0) ||
675 (bind(s
,(struct sockaddr
*)&addr
, sizeof(addr
)) < 0) ||
677 int tmperrno
= errno
; /* Don't clobber the real reason we failed */
681 /* Restore the real errno */
683 WSASetLastError(tmperrno
);
689 qemu_setsockopt(s
, SOL_SOCKET
, SO_OOBINLINE
, &opt
, sizeof(int));
691 getsockname(s
,(struct sockaddr
*)&addr
,&addrlen
);
692 so
->so_ffamily
= AF_INET
;
693 so
->so_fport
= addr
.sin_port
;
694 if (addr
.sin_addr
.s_addr
== 0 || addr
.sin_addr
.s_addr
== loopback_addr
.s_addr
)
695 so
->so_faddr
= slirp
->vhost_addr
;
697 so
->so_faddr
= addr
.sin_addr
;
704 * Various session state calls
705 * XXX Should be #define's
706 * The socket state stuff needs work, these often get call 2 or 3
707 * times each when only 1 was needed
710 soisfconnecting(struct socket
*so
)
712 so
->so_state
&= ~(SS_NOFDREF
|SS_ISFCONNECTED
|SS_FCANTRCVMORE
|
713 SS_FCANTSENDMORE
|SS_FWDRAIN
);
714 so
->so_state
|= SS_ISFCONNECTING
; /* Clobber other states */
718 soisfconnected(struct socket
*so
)
720 so
->so_state
&= ~(SS_ISFCONNECTING
|SS_FWDRAIN
|SS_NOFDREF
);
721 so
->so_state
|= SS_ISFCONNECTED
; /* Clobber other states */
725 sofcantrcvmore(struct socket
*so
)
727 if ((so
->so_state
& SS_NOFDREF
) == 0) {
730 so
->so_state
&= ~(SS_ISFCONNECTING
);
731 if (so
->so_state
& SS_FCANTSENDMORE
) {
732 so
->so_state
&= SS_PERSISTENT_MASK
;
733 so
->so_state
|= SS_NOFDREF
; /* Don't select it */
735 so
->so_state
|= SS_FCANTRCVMORE
;
740 sofcantsendmore(struct socket
*so
)
742 if ((so
->so_state
& SS_NOFDREF
) == 0) {
743 shutdown(so
->s
,1); /* send FIN to fhost */
745 so
->so_state
&= ~(SS_ISFCONNECTING
);
746 if (so
->so_state
& SS_FCANTRCVMORE
) {
747 so
->so_state
&= SS_PERSISTENT_MASK
;
748 so
->so_state
|= SS_NOFDREF
; /* as above */
750 so
->so_state
|= SS_FCANTSENDMORE
;
755 * Set write drain mode
756 * Set CANTSENDMORE once all data has been write()n
759 sofwdrain(struct socket
*so
)
761 if (so
->so_rcv
.sb_cc
)
762 so
->so_state
|= SS_FWDRAIN
;
768 * Translate addr in host addr when it is a virtual address
770 void sotranslate_out(struct socket
*so
, struct sockaddr_storage
*addr
)
772 Slirp
*slirp
= so
->slirp
;
773 struct sockaddr_in
*sin
= (struct sockaddr_in
*)addr
;
774 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)addr
;
776 switch (addr
->ss_family
) {
778 if ((so
->so_faddr
.s_addr
& slirp
->vnetwork_mask
.s_addr
) ==
779 slirp
->vnetwork_addr
.s_addr
) {
781 if (so
->so_faddr
.s_addr
== slirp
->vnameserver_addr
.s_addr
) {
782 if (get_dns_addr(&sin
->sin_addr
) < 0) {
783 sin
->sin_addr
= loopback_addr
;
786 sin
->sin_addr
= loopback_addr
;
790 DEBUG_MISC((dfd
, " addr.sin_port=%d, "
791 "addr.sin_addr.s_addr=%.16s\n",
792 ntohs(sin
->sin_port
), inet_ntoa(sin
->sin_addr
)));
796 if (in6_equal_net(&so
->so_faddr6
, &slirp
->vprefix_addr6
,
797 slirp
->vprefix_len
)) {
798 if (in6_equal(&so
->so_faddr6
, &slirp
->vnameserver_addr6
)) {
799 /*if (get_dns_addr(&addr) < 0) {*/ /* TODO */
800 sin6
->sin6_addr
= in6addr_loopback
;
803 sin6
->sin6_addr
= in6addr_loopback
;
813 void sotranslate_in(struct socket
*so
, struct sockaddr_storage
*addr
)
815 Slirp
*slirp
= so
->slirp
;
816 struct sockaddr_in
*sin
= (struct sockaddr_in
*)addr
;
817 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)addr
;
819 switch (addr
->ss_family
) {
821 if ((so
->so_faddr
.s_addr
& slirp
->vnetwork_mask
.s_addr
) ==
822 slirp
->vnetwork_addr
.s_addr
) {
823 uint32_t inv_mask
= ~slirp
->vnetwork_mask
.s_addr
;
825 if ((so
->so_faddr
.s_addr
& inv_mask
) == inv_mask
) {
826 sin
->sin_addr
= slirp
->vhost_addr
;
827 } else if (sin
->sin_addr
.s_addr
== loopback_addr
.s_addr
||
828 so
->so_faddr
.s_addr
!= slirp
->vhost_addr
.s_addr
) {
829 sin
->sin_addr
= so
->so_faddr
;
835 if (in6_equal_net(&so
->so_faddr6
, &slirp
->vprefix_addr6
,
836 slirp
->vprefix_len
)) {
837 if (in6_equal(&sin6
->sin6_addr
, &in6addr_loopback
)
838 || !in6_equal(&so
->so_faddr6
, &slirp
->vhost_addr6
)) {
839 sin6
->sin6_addr
= so
->so_faddr6
;
850 * Translate connections from localhost to the real hostname
852 void sotranslate_accept(struct socket
*so
)
854 Slirp
*slirp
= so
->slirp
;
856 switch (so
->so_ffamily
) {
858 if (so
->so_faddr
.s_addr
== INADDR_ANY
||
859 (so
->so_faddr
.s_addr
& loopback_mask
) ==
860 (loopback_addr
.s_addr
& loopback_mask
)) {
861 so
->so_faddr
= slirp
->vhost_addr
;
866 if (in6_equal(&so
->so_faddr6
, &in6addr_any
) ||
867 in6_equal(&so
->so_faddr6
, &in6addr_loopback
)) {
868 so
->so_faddr6
= slirp
->vhost_addr6
;