libnetutils/packet.c - fix a raw socket reception race
A socket created bound to a specific protocol can receive packets before
it's bound to a specific interface/mac.
It's best to rely on the bind().
This replicates the way packet sockets are created in external/android-clat.
See: ring.c ring_create() and clatd.c configure_packet_socket()
Test: builds, atest
Bug: 155297277
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I569d2b81a396f352ab5d1b71bd5ad0d96217aab1
diff --git a/libnetutils/packet.c b/libnetutils/packet.c
index 2debc28..b3fa909 100644
--- a/libnetutils/packet.c
+++ b/libnetutils/packet.c
@@ -40,7 +40,7 @@
int fatal(const char*);
int open_raw_socket(const char* ifname __unused, uint8_t hwaddr[ETH_ALEN], int if_index) {
- int s = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
+ int s = socket(PF_PACKET, SOCK_DGRAM, 0);
if (s < 0) return fatal("socket(PF_PACKET)");
struct sockaddr_ll bindaddr = {