From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrW9w-000491-BX for qemu-devel@nongnu.org; Wed, 28 Oct 2015 15:13:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrW9s-0005nQ-GH for qemu-devel@nongnu.org; Wed, 28 Oct 2015 15:13:20 -0400 Received: from smtp4-g21.free.fr ([2a01:e0c:1:1599::13]:32127) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrW9s-0005lz-AO for qemu-devel@nongnu.org; Wed, 28 Oct 2015 15:13:16 -0400 From: Laurent Vivier Date: Wed, 28 Oct 2015 20:13:00 +0100 Message-Id: <1446059583-16340-2-git-send-email-laurent@vivier.eu> In-Reply-To: <1446059583-16340-1-git-send-email-laurent@vivier.eu> References: <1446059583-16340-1-git-send-email-laurent@vivier.eu> Subject: [Qemu-devel] [PATCH v2 1/4] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, riku.voipio@iki.fi, Laurent Vivier in PACKET(7) : packet_socket = socket(AF_PACKET, int socket_type, int protocol); [...] protocol is the IEEE 802.3 protocol number in network order. See the include file for a list of allowed protocols. When protocol is set to htons(ETH_P_ALL) then all protocols are received. All incoming packets of that protocol type will be passed to the packet socket before they are passed to the protocols implemented in the kernel. [...] Compatibility In Linux 2.0, the only way to get a packet socket was by calling socket(AF_INET, SOCK_PACKET, protocol). We need to tswap16() the protocol because on big-endian, the ABI is waiting for, for instance for ETH_P_ALL, 0x0003 (big endian == network order), whereas on little-endian it is waiting for 0x0300. Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 4b4159d..7c724ab 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2089,6 +2089,12 @@ static abi_long do_socket(int domain, int type, int protocol) if (domain == PF_NETLINK) return -TARGET_EAFNOSUPPORT; + + if (domain == AF_PACKET || + (domain == AF_INET && type == SOCK_PACKET)) { + protocol = tswap16(protocol); + } + ret = get_errno(socket(domain, type, protocol)); if (ret >= 0) { ret = sock_flags_fixup(ret, target_type); -- 2.4.3