libnetutils/packet.c - create socket with close-on-exec

This prevents fork/exec leaking sockets to child processes.

Test: builds, atest
Bug: 155297277
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I57cb2003dd75b0bc5528978fd131730273e37a43
Merged-In: I57cb2003dd75b0bc5528978fd131730273e37a43
This commit is contained in:
Maciej Żenczykowski 2020-05-06 14:17:07 -07:00
parent 74346aac9c
commit ecfb05d4ce

View file

@ -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, 0);
int s = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (s < 0) return fatal("socket(PF_PACKET)");
struct sockaddr_ll bindaddr = {