How to use pcap_stats in libpcap?
I added the following function to the sniffex code (http://www.tcpdump.org/sniffex.c):
typedef struct pcap_stat mystat;
mystat *mystatp;
/* Put the interface in statstics mode */
if(pcap_stats(handle, mystatp) < 0)
{
fprintf(stderr,"\nError setting the mode.\n");
pcap_close(handle);
/* Free the device list */
return;
}
Sniffex code is working fine for me - but as soon as I add this code, I am 开发者_如何学Pythongetting a segmentation fault error :(
Can anyone please help me out ?
Thanks a ton.
I believe you forgot to allocate memory for mystat.
Try this:
typedef struct pcap_stat mystat;
...
mystat actualStat; /* allocate memory for mystat on stack - you can also do it on the heap by malloc-ing */
mystat *mystatp = &actualStat; /* use allocated memory */
/* Put the interface in statistics mode */
if(pcap_stats(handle, mystatp) < 0)
{
fprintf(stderr,"\nError setting the mode.\n");
pcap_close(handle);
/* Free the device list */
return;
}
In Pcap.Net I use pcap_stats_ex()
but it's probably only available on WinPcap and not on libpcap.
精彩评论