From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Riku Voipio <riku.voipio@iki.fi>, Laurent Vivier <Laurent@Vivier.EU>
Subject: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket()
Date: Mon, 31 Dec 2012 20:38:00 +0100 [thread overview]
Message-ID: <1356982680-12436-3-git-send-email-laurent@vivier.eu> (raw)
In-Reply-To: <1356982680-12436-1-git-send-email-laurent@vivier.eu>
From: Laurent Vivier <Laurent@Vivier.EU>
in PACKET(7) :
protocol is the IEEE 802.3 protocol
number in network order. See the <linux/if_ether.h> 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.
Signed-off-by: Laurent Vivier <Laurent@Vivier.EU>
---
include/exec/user/abitypes.h | 22 ++++++++++++++++++++++
linux-user/syscall.c | 8 +++++++-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/include/exec/user/abitypes.h b/include/exec/user/abitypes.h
index fe7f662..f4f526a 100644
--- a/include/exec/user/abitypes.h
+++ b/include/exec/user/abitypes.h
@@ -15,6 +15,15 @@ static inline abi_ulong tswapal(abi_ulong v)
return tswap32(v);
}
+static inline abi_ulong abi_ntohl(abi_ulong v)
+{
+#if defined(HOST_BIG_ENDIAN)
+ return v;
+#else
+ return bswap_32(v);
+#endif
+}
+
#else
typedef target_ulong abi_ulong;
typedef target_long abi_long;
@@ -32,5 +41,18 @@ static inline abi_ulong tswapal(abi_ulong v)
return tswapl(v);
}
+static inline abi_ulong abi_ntohl(abi_ulong v)
+{
+#if defined(HOST_BIG_ENDIAN)
+ return v;
+#else
+#if TARGET_LONG_SIZE == 4
+ return bswap_32(v);
+#else
+ return bswap_64(v);
+#endif
+#endif
+}
+
#endif
#endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 000b640..29151a6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1874,7 +1874,7 @@ static void unlock_iovec(struct iovec *vec, abi_ulong target_addr,
}
/* do_socket() Must return target values and target errnos. */
-static abi_long do_socket(int domain, int type, int protocol)
+static abi_long do_socket(int domain, int type, abi_ulong protocol)
{
#if defined(TARGET_MIPS)
switch(type) {
@@ -1900,6 +1900,12 @@ static abi_long do_socket(int domain, int type, int protocol)
#endif
if (domain == PF_NETLINK)
return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */
+ if (type == SOCK_PACKET) {
+ /* in this case, socket() needs a network endian short */
+ protocol = tswapal(protocol); /* restore network endian long */
+ protocol = abi_ntohl(protocol); /* a host endian long */
+ protocol = htons(protocol); /* network endian short */
+ }
return get_errno(socket(domain, type, protocol));
}
--
1.7.10.4
next prev parent reply other threads:[~2012-12-31 19:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-31 19:37 [Qemu-devel] [PATCH 0/2] linux-user: dhclient support Laurent Vivier
2012-12-31 19:37 ` [Qemu-devel] [PATCH 1/2] linux-user: Add setsockopt(SO_ATTACH_FILTER) Laurent Vivier
2012-12-31 20:56 ` Peter Maydell
2012-12-31 19:38 ` Laurent Vivier [this message]
2012-12-31 21:32 ` [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() Peter Maydell
2012-12-31 22:19 ` Laurent Vivier
2013-01-01 15:03 ` Peter Maydell
2013-01-01 17:27 ` Laurent Vivier
2013-01-01 18:37 ` Laurent Vivier
2013-01-01 19:45 ` Peter Maydell
2013-01-01 22:12 ` Laurent Vivier
2013-01-01 22:50 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1356982680-12436-3-git-send-email-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).