Yash Salunke
Yash Salunke

Reputation: 21

pcap_open_live() returning address family not supported by protocol for all devices

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:

  1. eth1 - No description available
  2. any - Pseudo-device that captures on all interfaces
  3. lo - No description available
  4. eth0 - No description available
  5. wifi0 - No description available
  6. wifi1 - No description available
  7. wifi2 - No description available
  8. wifi3 - No description available
  9. bluetooth-monitor - Bluetooth Linux Monitor
  10. dbus-system - D-Bus system bus
  11. dbus-session - D-Bus session bus

Upvotes: 1

Views: 83

Answers (0)

Related Questions