From patchwork Mon May 9 12:07:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9046211 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CD5069F30C for ; Mon, 9 May 2016 12:42:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 170BC2014A for ; Mon, 9 May 2016 12:42:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DE14220114 for ; Mon, 9 May 2016 12:42:22 +0000 (UTC) Received: from localhost ([::1]:41072 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azkVw-0003ZF-6E for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 May 2016 08:42:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azkUL-0000mc-6K for qemu-devel@nongnu.org; Mon, 09 May 2016 08:40:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1azkUF-0002mG-MB for qemu-devel@nongnu.org; Mon, 09 May 2016 08:40:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47697) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azkUF-0002m0-E2 for qemu-devel@nongnu.org; Mon, 09 May 2016 08:40:35 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B914A62667; Mon, 9 May 2016 12:40:34 +0000 (UTC) Received: from localhost (ovpn-112-46.ams2.redhat.com [10.36.112.46]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u49C8RjI022067; Mon, 9 May 2016 08:08:28 -0400 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Mon, 9 May 2016 13:07:52 +0100 Message-Id: <1462795687-25698-9-git-send-email-stefanha@redhat.com> In-Reply-To: <1462795687-25698-1-git-send-email-stefanha@redhat.com> References: <1462795687-25698-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 09 May 2016 12:40:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 08/23] slirp: fix guest network access with darwin host X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marc.mari.barcelo@gmail.com, Paolo Bonzini , jsnow@redhat.com, Peter Maydell , Samuel Thibault Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Samuel Thibault 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 Reviewed-by: John Arbuckle Signed-off-by: Peter Maydell --- slirp/ip_icmp.c | 2 +- slirp/socket.c | 2 +- slirp/socket.h | 12 ++++++++++++ slirp/tcp_subr.c | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 590dada..5ffc7a6 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -186,7 +186,7 @@ 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, strerror(errno)); diff --git a/slirp/socket.c b/slirp/socket.c index bd97b2d..a10eff1 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -627,7 +627,7 @@ 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)); + (struct sockaddr *)&addr, sockaddr_size(&addr)); if (ret < 0) return -1; diff --git a/slirp/socket.h b/slirp/socket.h index 7dca506..b602e69 100644 --- a/slirp/socket.h +++ b/slirp/socket.h @@ -122,6 +122,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/slirp/tcp_subr.c b/slirp/tcp_subr.c index 32ff452..6b9fef2 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -413,7 +413,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,