开发者

libpcap : No Wireless Devices detected

开发者 https://www.devze.com 2022-12-08 17:48 出处:网络
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 -

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?


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.


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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消