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