From patchwork Thu Apr 28 12:26:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 8969501 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4D000BF29F for ; Thu, 28 Apr 2016 12:27:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A42A8202AE for ; Thu, 28 Apr 2016 12:27:45 +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 9A71F2026C for ; Thu, 28 Apr 2016 12:27:44 +0000 (UTC) Received: from localhost ([::1]:48550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avl2l-0000A1-T8 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Apr 2016 08:27:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avl26-0007Tj-88 for qemu-devel@nongnu.org; Thu, 28 Apr 2016 08:27:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avl22-0005vZ-Ou for qemu-devel@nongnu.org; Thu, 28 Apr 2016 08:27:01 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:59416) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avl22-0005uN-HI for qemu-devel@nongnu.org; Thu, 28 Apr 2016 08:26:58 -0400 X-IronPort-AV: E=Sophos;i="5.24,546,1454972400"; d="scan'208";a="176077719" Received: from unknown (HELO var.youpi.perso.aquilenet.fr) ([193.50.110.248]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 28 Apr 2016 14:26:56 +0200 Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.87) (envelope-from ) id 1avl20-0003Hp-Ps; Thu, 28 Apr 2016 14:26:56 +0200 From: Samuel Thibault To: qemu-devel@nongnu.org Date: Thu, 28 Apr 2016 14:26:52 +0200 Message-Id: <1461846412-12596-1-git-send-email-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.8.0.rc3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.134.164.104 Subject: [Qemu-devel] [PATCH] 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: Samuel Thibault , jasowang@redhat.com, thuth@redhat.com, jan.kiszka@siemens.com 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 On darwin, connect, sendto and friends want the exact size of the sockaddr, not more. This adds the sockaddr_size helper to be used when passing a sockaddr size to such function, and makes use of it for sendto and connect calls. Signed-off-by: Samuel Thibault Reviewed-by: Thomas Huth --- 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,