提交 0d48dfed 编写于 作者: S Samuel Thibault 提交者: Peter Maydell

slirp: fix guest network access with darwin host

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: NSamuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: NJohn Arbuckle <programmingkidx@gmail.com>
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
上级 8c4bf975
...@@ -186,7 +186,7 @@ icmp_input(struct mbuf *m, int hlen) ...@@ -186,7 +186,7 @@ icmp_input(struct mbuf *m, int hlen)
sotranslate_out(so, &addr); sotranslate_out(so, &addr);
if(sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0, 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", DEBUG_MISC((dfd,"icmp_input udp sendto tx errno = %d-%s\n",
errno,strerror(errno))); errno,strerror(errno)));
icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
......
...@@ -627,7 +627,7 @@ sosendto(struct socket *so, struct mbuf *m) ...@@ -627,7 +627,7 @@ sosendto(struct socket *so, struct mbuf *m)
/* Don't care what port we get */ /* Don't care what port we get */
ret = sendto(so->s, m->m_data, m->m_len, 0, ret = sendto(so->s, m->m_data, m->m_len, 0,
(struct sockaddr *)&addr, sizeof(addr)); (struct sockaddr *)&addr, sockaddr_size(&addr));
if (ret < 0) if (ret < 0)
return -1; return -1;
......
...@@ -122,6 +122,18 @@ static inline int sockaddr_equal(struct sockaddr_storage *a, ...@@ -122,6 +122,18 @@ static inline int sockaddr_equal(struct sockaddr_storage *a,
return 0; 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 socket *solookup(struct socket **, struct socket *,
struct sockaddr_storage *, struct sockaddr_storage *); struct sockaddr_storage *, struct sockaddr_storage *);
struct socket *socreate(Slirp *); struct socket *socreate(Slirp *);
......
...@@ -413,7 +413,7 @@ int tcp_fconnect(struct socket *so, unsigned short af) ...@@ -413,7 +413,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)
sotranslate_out(so, &addr); sotranslate_out(so, &addr);
/* We don't care what port we get */ /* 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, * If it's not in progress, it failed, so we just return 0,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册