aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2016-04-28 18:53:08 +0200
committerPeter Maydell <peter.maydell@linaro.org>2016-04-28 18:12:08 +0100
commit7105c50e90ed17940c5bc20d016c6cfaf2d37a6d (patch)
tree648e1f07b7991a1b1a27cf6beed9a56022b8a896
parent32e771c31225ba6183cf7efb70b8d876dd7589b1 (diff)
downloadslirp-7105c50e90ed17940c5bc20d016c6cfaf2d37a6d.zip
slirp-7105c50e90ed17940c5bc20d016c6cfaf2d37a6d.tar.gz
slirp-7105c50e90ed17940c5bc20d016c6cfaf2d37a6d.tar.bz2
slirp: fix guest network access with darwin hostv2.6.0-rc5v2.6.0-rc4v2.6.0
On Darwin, connect, sendto and friends want the exact size of the sockaddr, not more (and in particular, not sizeof(struct sockaddr_storaget)) This commit adds the sockaddr_size helper to be used when passing a sockaddr size to such function, and makes use of it int sendto and connect calls. Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Reviewed-by: John Arbuckle <programmingkidx@gmail.com> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--ip_icmp.c2
-rw-r--r--socket.c2
-rw-r--r--socket.h12
-rw-r--r--tcp_subr.c2
4 files changed, 15 insertions, 3 deletions
diff --git a/ip_icmp.c b/ip_icmp.c
index 917aeae..88cde36 100644
--- a/ip_icmp.c
+++ b/ip_icmp.c
@@ -188,7 +188,7 @@ void icmp_input(struct mbuf *m, int hlen)
sotranslate_out(so, &addr);
if (sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0,
- (struct sockaddr *)&addr, sizeof(addr)) == -1) {
+ (struct sockaddr *)&addr, sockaddr_size(&addr)) == -1) {
DEBUG_MISC((dfd, "icmp_input udp sendto tx errno = %d-%s\n",
errno, strerror(errno)));
icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0,
diff --git a/socket.c b/socket.c
index f3b460d..ee76941 100644
--- a/socket.c
+++ b/socket.c
@@ -635,7 +635,7 @@ int sosendto(struct socket *so, struct mbuf *m)
/* Don't care what port we get */
ret = sendto(so->s, m->m_data, m->m_len, 0, (struct sockaddr *)&addr,
- sizeof(addr));
+ sockaddr_size(&addr));
if (ret < 0)
return -1;
diff --git a/socket.h b/socket.h
index 41b54c8..f48370f 100644
--- a/socket.h
+++ b/socket.h
@@ -127,6 +127,18 @@ static inline int sockaddr_equal(struct sockaddr_storage *a,
return 0;
}
+static inline socklen_t sockaddr_size(struct sockaddr_storage *a)
+{
+ switch (a->ss_family) {
+ case AF_INET:
+ return sizeof(struct sockaddr_in);
+ case AF_INET6:
+ return sizeof(struct sockaddr_in6);
+ default:
+ g_assert_not_reached();
+ }
+}
+
struct socket *solookup(struct socket **, struct socket *,
struct sockaddr_storage *, struct sockaddr_storage *);
struct socket *socreate(Slirp *);
diff --git a/tcp_subr.c b/tcp_subr.c
index 270e362..2a82c35 100644
--- a/tcp_subr.c
+++ b/tcp_subr.c
@@ -411,7 +411,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)
sotranslate_out(so, &addr);
/* We don't care what port we get */
- ret = connect(s, (struct sockaddr *)&addr, sizeof(addr));
+ ret = connect(s, (struct sockaddr *)&addr, sockaddr_size(&addr));
/*
* If it's not in progress, it failed, so we just return 0,