#include#else#include#endif由于是Win32平臺的開發,#ifndefWIN32...#else那段都是沒用的" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

WinPcap初學(2)

系統 1687 0

??? 還是按照“winpcap使用系列” http://www.smatrix.org/bbs/read.php?tid=359&fpage=4 ?一步步學習。先看文章里頭包含的頭文件。
#include? " pcap.h "
#ifndef?WIN32
#include?
< sys / socket.h >
#include?
< netinet / in .h >
#else
#include?
< winsock.h >
#endif
??? 由于是Win32平臺的開發,#ifndef WIN32...#else那段都是沒用的。真正要使用到的是#include<winsock.h>。首先聲名一下,我做出來的測試程序是MFC的窗口程序。而 MFC程序中的自動生成的stdaf x.h文件中有這么一句 #include < af xwi n.h >? // M FC 核心組件和標準組件,而在afxwin.h里頭有就winsock2.h的聲名。事實上winsock與winsock2是干同樣活的,不過是新舊之分,所以假如你在程序中加上#include<winsock.h>的話就必然會出現函數同名的錯誤(winsock與winsock2很多同名的函數)。因此在我的程序中只須聲名#include "pcap.h"。
??? 接著,看下代碼。
Code

??? 這些使用到一些控制臺程序的函數,不過對于MFC程序沒有大礙。先不說ifprint和iptos的作用,我們來看來pcap_if_t這個結構。
??? 在pcap.h中它有一個另名pcap_if,至于為什么要改名字我也不太清楚。(為了說明這個一個type?)在官方的文檔中(...\WpdPack\docs\html\structpcap__if.html)對pcap_if進行如下定義:
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是對下一個設備驅動的指針,name是本驅動的名字(基本上是一些不知所云的數字),description是驅動的描述(如Realtek RTL8169/8110 Family Gigabit Ethernet NIC,這個程序員就比較清楚了),pcap_addr則是另一個pcap.h中定義的結構,最后的flags目前為0。 官方文檔對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
??? 其中,addr為IP地址,netmask為子網掩碼(以上兩個都為平時常用的網絡連接設置),broadaddr為廣播地址(說明參照百度百科 http://baike.baidu.com/view/473043.htm#3 ),dstaddr為目標地址(具體使用不太清楚,什么叫點對點接口?什么情況下會有這個接口?哪位高人給我指點一下!)。以上4部分都是sockaddr這個結構,它的定義在ws2def.h中。
Code

??? 上面的0x0600是vista的版本號,就是說當系統為XP或以下的時候用u_short的定義(其實ADDRESS_FAMILY也就是個ushort,只是換個名字)。還是回來看下它的結構,主要是后面的sa_data[14],這個參考 http://baike.baidu.com/view/2355183.html ,里面說得很詳細。下面是截圖,可以很清楚地看到前2個字節都是0,接下來的4個是有值的,后面的都是0。
??? 實際上那4個有值的字節就是32位的地址,如192.168.0.1等。
??? 現在讓我們回來看那兩個函數ifprint及iptos。在看完pcap_if_t等結構的說明后,想必你也看出來ifprint就是對pcap_if_t結構的解析,iptos就是對sockaddr的解析了吧。
??? 目前為止還沒有自己寫的東西,誰叫我還是個新手,一步步學吧。下一步是做一個可以測試在1000M網卡下WinPcap發送能力的極限能到多少的小程序,以前100M的話好像只能到60M。

WinPcap初學(2)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日本一级爽爽爽爽 | 伊人蕉| 精品国产免费久久久久久婷婷 | 国产成人亚洲精品无广告 | 久久精品国产欧美成人 | 亚洲国产成人在线观看 | 91手机在线 | 国产二级片 | 久久国产欧美日韩精品 | 色香蕉在线 | 乱码一区二区三区完整视频 | 热久久在线 | 亚洲精品久久久久综合中文字幕 | 欧美日韩亚洲国产无线码 | 国产精品99久久久久久夜夜嗨 | 五月天婷婷久久 | 97在线视频观看 | 欧美亚洲国产成人高清在线 | 欧美日中文字幕 | 一区二区三区在线视频观看 | 国产成人综合久久精品红 | 亚洲国产综合视频 | 伊人99热| 国内精品91久久久久 | 久草手机在线 | 中文日本在线 | 亚洲美女性生活视频 | 我色综合 | 91精品国产综合久久欧美 | 黄色在线免费网站 | 免费一级毛片在线观看 | 国产福利视频在线观看 | 婷婷网五月天天综合天天爱 | 不卡在线 | 色狠狠一区 | 波多野结衣三区 | 成年人黄视频大全 | 国产成人综合久久精品亚洲 | 最近中文字幕在线 | 中文 | 国产精品女仆装在线播放 | 欧美亚洲专区 |