Commit e9fa659e authored by Prashant Bhole's avatar Prashant Bhole Committed by Brenden Blanco

libbpf: return error when if_nametoindex returns 0

sll_ifindex=0 matches any interface, which is not exepected here
parent 7c9d8c93
......@@ -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));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment