Reputation: 21
I am trying to implement a packet sniffer using C ran on WSL with Ubuntu, and when calling pcap_open_live, for any device, returns: Couldn't open device: `pG��: socket: Address family not supported by protocol.
int main() {
pcap_t *handle;
pcap_if_t *alldevs;
char errbuf[PCAP_ERRBUF_SIZE];
if (pcap_findalldevs(&alldevs, errbuf) == -1) {
fprintf(stderr, "Error finding devices: %s\n", errbuf);
return 1;
}
printf("Available network devices:\n");
int i = 0;
for (pcap_if_t *dev = alldevs; dev != NULL; dev = dev->next) {
printf("%d. %s - %s\n", ++i, dev->name, dev->description ? dev->description : "No description available");
}
// Open the first available network interface for packet capture
handle = pcap_open_live(alldevs->next->next->next, BUFSIZ, 1, 1000, errbuf);
if (handle == NULL) {
fprintf(stderr, "Couldn't open device: %s\n", errbuf);
return 1;
}
Tried switching between all devices(see alldevs->next->next...) Available network devices:
Upvotes: 1
Views: 83