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

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

WinPcap初學(2)

系統 1768 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條評論
主站蜘蛛池模板: 天天摸天天添 | 男人用嘴添女人下身免费视频 | 先锋资源中文字幕 | 国产乱妇无码大黄AA片 | 欧美视频在线看 | 最新一级毛片 | 日韩免费一级片 | 日韩欧美黄色片 | 草草视频手机在线观看视频 | 免费播放春色aⅴ视频 | 无限资源动漫精彩日本 | jizz性欧美2 日本不卡在线 | 96国产精品久久久久aⅴ四区 | 尤物视频在线观看 | 日韩免费视频播放 | 国产乱肥老妇国产一区二 | 久久国产精品-国产精品 | 久久99国产伦子精品免费 | 亚洲视频在线观看地址 | 日韩免费在线观看视频 | 欧美精品一区三区 | 亚洲欧美小视频 | 六月婷婷综合激情 | 日本欧美一区二区三区视频 | 国产馆精品推荐在线观看 | 欧美一a一片一级一片 | 成人伊人 | 成人在线精品 | 欧美日韩a | 亚洲精品国偷拍自产在线观看 | 国产精品久久久久久一级毛片 | 国产综合视频在线 | 国产精品国产三级国产播12软件 | 日韩日日操| 色综合97天天综合网 | 久久99国产亚洲精品观看 | 久青草免费在线视频 | 国内精品久久久久激情影院 | 亚洲精品手机在线 | 大香伊人久久精品一区二区 | 国产999精品久久久久久 |