wireshark(
http://www.wireshark.org/)是我經(jīng)常用到的抓包工具,這對于網(wǎng)絡程序的調試至關重要,特別是客戶端人員和服務端人員都認為自己的代碼沒問題時,wireshark本身是開源的,在windows平臺下基于 winpcap(
http://www.winpcap.org/)開發(fā)的,安裝wireshark的時候,會提示在線安裝winpcap,今天在筆記本上用VS2008,編譯了Examples-pcap下面的basic_dump和basic_dump_ex,不曾想到的是抓不到包,甚是奇怪,因為用wireshark抓包是可以的,因此懷疑是不是哪個參數(shù)設施不對,終于比對wireshark,得出結論:將pcap_open_live的第四個參數(shù)設為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;
}