From patchwork Thu Apr 28 16:53:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 8973341 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 6FFEC9F1C1 for ; Thu, 28 Apr 2016 16:54:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C5EC020117 for ; Thu, 28 Apr 2016 16:54:23 +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 B54C2200F3 for ; Thu, 28 Apr 2016 16:54:22 +0000 (UTC) Received: from localhost ([::1]:50216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avpCn-0004g4-Sz for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Apr 2016 12:54:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38290) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avpBj-0002md-VX for qemu-devel@nongnu.org; Thu, 28 Apr 2016 12:53:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avpBf-00066Y-6G for qemu-devel@nongnu.org; Thu, 28 Apr 2016 12:53:15 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:36546) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avpBe-00065b-SI for qemu-devel@nongnu.org; Thu, 28 Apr 2016 12:53:11 -0400 X-IronPort-AV: E=Sophos;i="5.24,547,1454972400"; d="scan'208";a="176116428" 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 18:53:09 +0200 Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.87) (envelope-from ) id 1avpBd-0007sa-0V; Thu, 28 Apr 2016 18:53:09 +0200 From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 28 Apr 2016 18:53:08 +0200 Message-Id: <1461862388-30249-2-git-send-email-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1461862388-30249-1-git-send-email-samuel.thibault@ens-lyon.org> References: <1461862388-30249-1-git-send-email-samuel.thibault@ens-lyon.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.134.164.104 Subject: [Qemu-devel] [PULL] 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 , 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 (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 --- 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,