diff options
author | Laurent Vivier <laurent@vivier.eu> | 2015-10-28 21:40:42 +0100 |
---|---|---|
committer | Riku Voipio <riku.voipio@linaro.org> | 2016-01-08 15:18:47 +0200 |
commit | ff626f2d9e43c74659e8f4c284c62bb223a3bf56 (patch) | |
tree | 9a41f4bd6bd9fed185a41f97f24fa04e569094f7 /linux-user | |
parent | 0e173b24b523b432854689717e09de5c95c158f8 (diff) |
linux-user: SOCK_PACKET uses network endian to encode protocol in socket()
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 <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.
[...]
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 <laurent@vivier.eu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
Diffstat (limited to 'linux-user')
-rw-r--r-- | linux-user/syscall.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 06a59b4417..965d7db7df 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); |