调用pcap_findalldevs()时,device为NULL(winpcap) [英] device is NULL when pcap_findalldevs() is called (winpcap)
本文介绍了调用pcap_findalldevs()时,device为NULL(winpcap)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好!
我正在尝试使用Visual Studio 2013的MFC程序中的winpcap。
当调用pcap_findalldevs(& alldevs,errbuf)时,其返回值为0,但alldevs为NULL。
下面的代码是函数的开头。
如何解决问题?
Hello!
I'm trying winpcap in MFC program of Visual Studio 2013.
When pcap_findalldevs(&alldevs, errbuf) is called, its return value is 0, but alldevs is NULL.
The code below is the very start of a function.
How can I solve the problem?
ETHER_HDR *ethhdr;
IPV4_HDR *iphdr;
TCP_HDR *tcpheader;
UDP_HDR *udpheader;
unsigned char *pkt_data;
unsigned char *data;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_if_t *alldevs, *dev;
pcap_t *fp;
struct pcap_pkthdr *header;
int res = 0;
int iphdrlen = 0;
int data_size = 0;
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
CString msg;
msg.Format("Error in pcap_findalldevs: %s", errbuf);
dlg->MessageBox(msg);
return -1;
}
推荐答案
如果pcap_findalldevs找不到设备,它将成功返回0,如果有的话您可能没有权限访问的设备。
请参阅:
http://www.tcpdump .org / manpages / pcap_findalldevs.3pcap.html
如果pcap_findalldevs()成功,alldevsp指向的指针将设置为指向列表的第一个元素,如果没有找到设备,则为NULL(这被认为是成功)。
If pcap_findalldevs does not find a device it will return 0 as successful, if there are devices you may not have privilege to access.
See :
http://www.tcpdump.org/manpages/pcap_findalldevs.3pcap.html
"If pcap_findalldevs() succeeds, the pointer pointed to by alldevsp is set to point to the first element of the list, or to NULL if no devices were found (this is considered success)."
这篇关于调用pcap_findalldevs()时,device为NULL(winpcap)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文