libnet进行编程时,libnet_init()无法找到网卡的解决方法。
来源:互联网 发布:网络机顶盒电视猫 编辑:程序博客网 时间:2024/06/04 18:15
本文为转载,本人的系统是Win8 64Bit + VisualStudio2010
我也遇到同样的问题,两台电脑中在比较早的电脑运行不了,程序无法自动找到网卡接口。
这种情况下,不能在libnet_init()时参数device就不能设置成NULL了,需要自己去先找到device。在程序中加入以下一段代码试试……
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i=0;
pcap_t *adhandle;
char errbuf[PCAP_ERRBUF_SIZE];
/* Retrieve the device list */
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
exit(1);
}
/* Print the list */
for(d=alldevs; d; d=d->next)
{
printf("%d. %s", ++i, d->name);
if (d->description)
printf(" (%s)\n", d->description);
else
printf(" (No description available)\n");
}
if(i==0)
{
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
return -1;
}
printf("Enter the interface number (1-%d):",i);
scanf("%d", &inum);
cin.get();
if(inum < 1 || inum > i)
{
printf("\nInterface number out of range.\n");
/* Free the device list */
pcap_freealldevs(alldevs);
cout << "press ENTER to Exit";
cin.get();
return -1;
}
/* Jump to the selected adapter */
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
char *device = NULL;//设备名字,此时为NULL
device=d->name;
l=libnet_init(LIBNET_LINK,device,error_inf);
这样就可以自己找到网卡接口了,注意选择网卡接口的时候选择当前上网的所用的网络接口。
0 0
- libnet进行编程时,libnet_init()无法找到网卡的解决方法。
- 无法找到"WebUIValidation.js"的终极解决方法
- 无法找到软件包 libncurses5-dev 的解决方法
- 无法找到mfc90ud.dll 的解决方法
- eth0设备无法找到的解决方法
- Xcode7.0无法找到category的解决方法
- windows 无法找到unistd.h 的解决方法
- Redhat9无法激活网卡的解决方法
- CentOS7网卡无法启动的解决方法
- vmware+ubuntu无法找到网卡
- ubuntu_wireshark无法找到网卡信息
- modules.dep文件损坏无法找到网卡的处理
- 使用c#进行socket编程时,获取网卡的信息
- libnet_init()总是返回NULL的问题
- vc2005 调试时提示错误信息:“无法找到.exe的调试信息” 的解决方法
- 无法找到名为"Wscript.Shell"的 automation 类 的解决方法
- 无法找到MSVCR80D.dll 解决方法
- ubuntu下wireshark无法找到网卡信息
- 浅谈C中的malloc和free
- java常见错误整理
- 使用 Jrebel 插件实现热加载
- CSS目前最新版本为CSS3,是能够真正做到网页表现与内容分离的一种样式设计语言
- navigationBar 标题字体颜色设置
- libnet进行编程时,libnet_init()无法找到网卡的解决方法。
- Integer Inquiry
- java设计模式初体验之观察者模式
- OpenGL ES基本概念介绍
- android pcm编解码
- 在DAO中如何获得session对象
- sed的使用举例 --Unix Shell
- win7系统使用种种
- u-boot-2009.08在mini2440上的移植