diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-09-18 21:11:01 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-09-18 21:13:17 +0200 |
commit | 23db43abdb5740287bbb7cbf5cc99eb22e121298 (patch) | |
tree | 935a274ed43629d210ad27a5c95110b110bd7252 /src/tcp_subr.c | |
parent | 14e75d1c6d1509259be070725c5128abf340275f (diff) | |
download | slirp-23db43abdb5740287bbb7cbf5cc99eb22e121298.zip slirp-23db43abdb5740287bbb7cbf5cc99eb22e121298.tar.gz slirp-23db43abdb5740287bbb7cbf5cc99eb22e121298.tar.bz2 |
Use the exact sockaddr size in getnameinfo call
On NetBSD, the sockaddr size passed to getnameinfo must match the
family.
(reworked from the patch suggestion from Yorick Hardy)
Fixes #52
Diffstat (limited to 'src/tcp_subr.c')
-rw-r--r-- | src/tcp_subr.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/tcp_subr.c b/src/tcp_subr.c index 600cfa1..7c63f49 100644 --- a/src/tcp_subr.c +++ b/src/tcp_subr.c @@ -464,7 +464,7 @@ void tcp_connect(struct socket *inso) Slirp *slirp = inso->slirp; struct socket *so; struct sockaddr_storage addr; - socklen_t addrlen = sizeof(struct sockaddr_storage); + socklen_t addrlen; struct tcpcb *tp; int s, opt, ret; /* AF_INET6 addresses are bigger than AF_INET, so this is big enough. */ @@ -473,7 +473,17 @@ void tcp_connect(struct socket *inso) DEBUG_CALL("tcp_connect"); DEBUG_ARG("inso = %p", inso); - ret = getnameinfo((const struct sockaddr *) &inso->lhost.ss, sizeof(inso->lhost.ss), addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST|NI_NUMERICSERV); + switch (inso->lhost.ss.ss_family) { + case AF_INET: + addrlen = sizeof(struct sockaddr_in); + break; + case AF_INET6: + addrlen = sizeof(struct sockaddr_in6); + break; + default: + g_assert_not_reached(); + } + ret = getnameinfo((const struct sockaddr *) &inso->lhost.ss, addrlen, addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST|NI_NUMERICSERV); g_assert(ret == 0); DEBUG_ARG("ip = [%s]:%s", addrstr, portstr); DEBUG_ARG("so_state = 0x%x", inso->so_state); @@ -494,6 +504,7 @@ void tcp_connect(struct socket *inso) * us again until the guest address is available. */ DEBUG_MISC(" guest address not available yet"); + addrlen = sizeof(addr); s = accept(inso->s, (struct sockaddr *)&addr, &addrlen); if (s >= 0) { close(s); @@ -518,6 +529,7 @@ void tcp_connect(struct socket *inso) tcp_mss(sototcpcb(so), 0); + addrlen = sizeof(addr); s = accept(inso->s, (struct sockaddr *)&addr, &addrlen); if (s < 0) { tcp_close(sototcpcb(so)); /* This will sofree() as well */ |