??? 還是按照“winpcap使用系列” http://www.smatrix.org/bbs/read.php?tid=359&fpage=4 ?一步步學(xué)習(xí)。先看文章里頭包含的頭文件。
#ifndef?WIN32
#include? < sys / socket.h >
#include? < netinet / in .h >
#else
#include? < winsock.h >
#endif
??? 接著,看下代碼。
??? 這些使用到一些控制臺(tái)程序的函數(shù),不過(guò)對(duì)于MFC程序沒(méi)有大礙。先不說(shuō)ifprint和iptos的作用,我們來(lái)看來(lái)pcap_if_t這個(gè)結(jié)構(gòu)。
??? 在pcap.h中它有一個(gè)另名pcap_if,至于為什么要改名字我也不太清楚。(為了說(shuō)明這個(gè)一個(gè)type?)在官方的文檔中(...\WpdPack\docs\html\structpcap__if.html)對(duì)pcap_if進(jìn)行如下定義:
| pcap_if *? | next |
| ? |
if not NULL, a pointer to the next element in the list; NULL for the last element of the list
|
| char *? | name |
| ? |
a pointer to a string giving a name for the device to pass to
pcap_open_live()
|
| char *? | description |
| ? |
if not NULL, a pointer to a string giving a human-readable description of the device
|
| pcap_addr *? | addresses |
| ? |
a pointer to the first element of a list of addresses for the interface
|
| u_int? | flags |
| ? |
PCAP_IF_ interface flags. Currently the only possible flag is
PCAP_IF_LOOPBACK
, that is set if the interface is a loopback interface.
|
??? next是對(duì)下一個(gè)設(shè)備驅(qū)動(dòng)的指針,name是本驅(qū)動(dòng)的名字(基本上是一些不知所云的數(shù)字),description是驅(qū)動(dòng)的描述(如Realtek RTL8169/8110 Family Gigabit Ethernet NIC,這個(gè)程序員就比較清楚了),pcap_addr則是另一個(gè)pcap.h中定義的結(jié)構(gòu),最后的flags目前為0。 官方文檔對(duì)pcap_addr定義如下:
| pcap_addr *? | next |
| ? |
if not NULL, a pointer to the next element in the list; NULL for the last element of the list
|
| sockaddr *? | addr |
| ? |
a pointer to a struct sockaddr containing an address
|
| sockaddr *? | netmask |
| ? |
if not NULL, a pointer to a struct sockaddr that contains the netmask corresponding to the address pointed to by addr.
|
| sockaddr *? | broadaddr |
| ? |
if not NULL, a pointer to a struct sockaddr that contains the broadcast address corre- sponding to the address pointed to by addr; may be null if the interface doesn't support broadcasts
|
| sockaddr *? | dstaddr |
| ? | if not NULL, a pointer to a struct sockaddr that contains the destination address corre- sponding to the address pointed to by addr; may be null if the interface isn't a point- to-point interface |
??? 上面的0x0600是vista的版本號(hào),就是說(shuō)當(dāng)系統(tǒng)為XP或以下的時(shí)候用u_short的定義(其實(shí)ADDRESS_FAMILY也就是個(gè)ushort,只是換個(gè)名字)。還是回來(lái)看下它的結(jié)構(gòu),主要是后面的sa_data[14],這個(gè)參考 http://baike.baidu.com/view/2355183.html ,里面說(shuō)得很詳細(xì)。下面是截圖,可以很清楚地看到前2個(gè)字節(jié)都是0,接下來(lái)的4個(gè)是有值的,后面的都是0。
??? 實(shí)際上那4個(gè)有值的字節(jié)就是32位的地址,如192.168.0.1等。
??? 現(xiàn)在讓我們回來(lái)看那兩個(gè)函數(shù)ifprint及iptos。在看完pcap_if_t等結(jié)構(gòu)的說(shuō)明后,想必你也看出來(lái)ifprint就是對(duì)pcap_if_t結(jié)構(gòu)的解析,iptos就是對(duì)sockaddr的解析了吧。
??? 目前為止還沒(méi)有自己寫(xiě)的東西,誰(shuí)叫我還是個(gè)新手,一步步學(xué)吧。下一步是做一個(gè)可以測(cè)試在1000M網(wǎng)卡下WinPcap發(fā)送能力的極限能到多少的小程序,以前100M的話好像只能到60M。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元

