18,356
社区成员
发帖
与我相关
我的任务
分享
if ((adhandle= pcap_open_live(devN, // name of the device
65536, // portion of the packet to capture.
// 65536 grants that the whole packet will be captured on all the MACs.
1, // promiscuous mode (nonzero means promiscuous)
1000, // read timeout
errbuf // error buffer
)) == NULL)
{
...
return 0;
}
if (lpPD->filterLen!= 0)
{
// We should loop through the adapters returned by the pcap_findalldevs_ex()
// in order to locate the correct one.
//
// Let's do things simpler: we suppose to be in a C class network ;-)
NetMask=0xffffff;
//compile the filter
if(pcap_compile(adhandle, &fcode, filter, 1, NetMask) < 0)
{
...
pcap_close(adhandle);
return 3;
}
//set the filter
if(pcap_setfilter(adhandle, &fcode)<0)
{
...
pcap_close(adhandle);
return 4;
}
delete[] filter;
}
dumpfile=pcap_dump_open(adhandle,(const char *)tmpfile);
if(dumpfile==NULL)
{
...
return 0;
}
/* Retrieve the packets */
while(1)
{
...
if(bExit) break;
res = pcap_next_ex(adhandle, &header, &data);
if(res==0)
{
Sleep(10);
continue;
}
else if(res<0)
{
break;
}
pcap_dump((u_char *)dumpfile, header, data);
...
}