wireshark(
http://www.wireshark.org/)是我经常用到的抓包工具,这对于网络程序的调试至关重要,特别是客户端人员和服务端人员都认为自己的代码没问题时,wireshark本身是开源的,在windows平台下基于 winpcap(
http://www.winpcap.org/)开发的,安装wireshark的时候,会提示在线安装winpcap,今天在笔记本上用VS2008,编译了Examples-pcap下面的basic_dump和basic_dump_ex,不曾想到的是抓不到包,甚是奇怪,因为用wireshark抓包是可以的,因此怀疑是不是哪个参数设施不对,终于比对wireshark,得出结论:将pcap_open_live的第四个参数设为0,即不能打开混杂模式,
if ((adhandle= pcap_open_live(d->name, // name of the device
65536, // portion of the packet to capture.
// 65536 grants that the whole packet will be captured on all the MACs.
0, // promiscuous mode (nonzero means promiscuous)
1000, // read timeout
errbuf // error buffer
)) == NULL)
{
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
/* Free the device list */
pcap_freealldevs(alldevs);
return -1;
}