Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

C++
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;
}
Posted
Updated 28-Jul-15 4:27am
v5
Comments
Michael_Davies 28-Jul-15 10:52am    
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)."

1 solution

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)."
 
Share this answer
 
Comments
Member 11499804 29-Jul-15 0:36am    
Do you mean I need to execute the program with administrator's privilege? What if I try to debug it in debug mode?
Michael_Davies 29-Jul-15 1:25am    
Have you tried running with Admin privilege? Just guessing but - Winpcap is a driver and has privileges but it may use your logged in account privilege for security reasons.

Otherwise the documentation is clear as to why the function will return successful (0) and return a NULL pointer, you have to check out those conditions and see which if any are causing an issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900