如何使用" pcap_lookupdev()"在libpcap的? [英] How to use the "pcap_lookupdev()" in libpcap?
本文介绍了如何使用" pcap_lookupdev()"在libpcap的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在code找不到任何设备,我想知道是什么pcap_lookupdev()呢?谢谢
的#include< pcap.h>
INT主(INT ARGC,CHAR *的argv [])
{
pcap_t *手柄; 字符*开发; // =eth0的;
烧焦errbuf [PCAP_ERRBUF_SIZE]
开发= pcap_lookupdev(errbuf);
如果(DEV == NULL){
fprintf中(标准错误,无法找到默认设备:%S \\ n,errbuf);
返回(2);
}
的printf(设备:%S \\ n,DEV);
返回(0); 处理= pcap_open_live(DEV,BUFSIZ,1,1000,errbuf);
如果(手柄== NULL){
fprintf中(标准错误,无法打开设备%S:%S \\ n,开发,errbuf);
返回(2);
}
}
解决方案
pcap_lookupdev似乎只返回第一个设备,它可以找到(如果有的话),除了回环设备。
你运行该以root身份?普通用户将不能打开或检查这些设备。
我个人觉得pcap_lookupdev而没用,因为你真的没有在什么设备,它给你的控制。
The code cant find any device, I want to know what does pcap_lookupdev() do ? thanks
#include <pcap.h>
int main(int argc, char *argv[])
{
pcap_t *handle;
char *dev;// = "eth0";
char errbuf[PCAP_ERRBUF_SIZE];
dev = pcap_lookupdev(errbuf);
if (dev == NULL) {
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
return(2);
}
printf("Device: %s\n", dev);
return(0);
handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
if (handle == NULL) {
fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf);
return(2);
}
}
解决方案
pcap_lookupdev seems to just return the first device it can find(if any) except the loopback device.
Do you run this as root ? Normal users won't be allowed to open or inspect these devices.
Personally I find pcap_lookupdev rather useless as you don't really have control over what device it gives you.
这篇关于如何使用&QUOT; pcap_lookupdev()&QUOT;在libpcap的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文