| /* SPDX-License-Identifier: GPL-2.0 */ |
| #include <linux/unistd.h> |
| #include <linux/if_ether.h> |
| #include <linux/if_packet.h> |
| static inline int open_raw_sock(const char *name) |
| sock = socket(PF_PACKET, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, htons(ETH_P_ALL)); |
| printf("cannot create raw socket\n"); |
| memset(&sll, 0, sizeof(sll)); |
| sll.sll_family = AF_PACKET; |
| sll.sll_ifindex = if_nametoindex(name); |
| sll.sll_protocol = htons(ETH_P_ALL); |
| if (bind(sock, (struct sockaddr *)&sll, sizeof(sll)) < 0) { |
| printf("bind to %s: %s\n", name, strerror(errno)); |