libbpf: return error when if_nametoindex returns 0
sll_ifindex=0 matches any interface, which is not exepected here
@@ -432,6 +432,11 @@ int bpf_open_raw_sock(const char *name)
memset(&sll, 0, sizeof(sll));
sll.sll_family = AF_PACKET;
sll.sll_ifindex = if_nametoindex(name);
+ if (sll.sll_ifindex == 0) {
+ fprintf(stderr, "bpf: Resolving device name to index: %s\n", strerror(errno));
+ close(sock);
+ return -1;
+ }
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));
