I am supposed to sniff on all network interfaces installed on fiven machine (Linux – Ubuntu). I am using pcap library for this purpose. So I am finding all capable devices using pcap_findalldevs(…) function, but the result are also usb and loopback devices, which I dont want to use.
Can you sugegst me, how to filter only network (ethernet and wifi) devices?
I suppose it depends what you mean by “network” devices.
If you mean IPv4/IPv6 devices, you can interrogate the
pcap_if_t->addressreturned bypcap_findalldevsand look at each address’saddr.sa_familyfield to determine if that device supportsAF_INETand/orAF_INET6. The loopback devices will(pcap_if_t->flags & PCAP_IF_LOOPBACK) != 0.The problem with that is that will include devices which are not Ethernet and WiFi, like Token Ring, IP-over-Firewire, PPP, and such. PCAP doesn’t provide a portable way to know the hardware type.