Siddhant
Siddhant

Reputation: 2525

libpcap : No Wireless Devices detected

I want to capture packets going out of my machine, and I'm using libpcap (version 1.0.0-1) for the same. The problem is, that a basic program like this -

#include <stdio.h>
#include <pcap.h>

int main(int argc, char *argv[]) {
    char *dev, errbuf[PCAP_ERRBUF_SIZE];
    dev = pcap_lookupdev(errbuf);
    if (dev == NULL) {
        fprintf(stderr, "%s\n", errbuf);
        return (2);
    }
    printf("Device : %s\n", dev);
    return (0);
}

does not seem to display the wireless interface. Everytime I compile and run the program, it detects eth0. How can I make it capture the wireless interfaces as well?

Upvotes: 1

Views: 1932

Answers (3)

benzado
benzado

Reputation: 84308

As others have stated, pcap_lookupdev() simply returns the first device found. You need to use pcap_findalldevs() to build a list of all available devices, then prompt the user to pick one (or let the user specify a number n on the command line, and then use the _n_th device).

But, if this is just a quick-and-dirty test program, you can find out the interface name and code it directly into your program. You can use ifconfig or tcpdump -D to find out the interface names on your system, then make a call like pcap_create("en1", errbuf).

Upvotes: 1

mrcrassic
mrcrassic

Reputation: 66

pcap_lookupdev() returns the default networking device on the system, which is usually the first device listed. pcap_findalldevs() returns an enumeration of all devices in the system, which you can use to select a device and capture from it.

Upvotes: 5

Gautham Ganapathy
Gautham Ganapathy

Reputation: 511

try using pcap_findalldevs(). i guess pcap_lookupdev() matches the first entry in the list is suitable interfaces

Upvotes: 3

Related Questions