ImageVerifierCode 换一换
格式:DOCX , 页数:9 ,大小:23.15KB ,
资源ID:5310167      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5310167.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(WinPcap下的主要结构体和主要函数.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

WinPcap下的主要结构体和主要函数.docx

1、WinPcap下的主要结构体和主要函数WinPCap中的主要结构体:1. struct pcap_if_t(称为网络设备结构,表示一个网络接口设备(如网卡)结构体包含以下5个域(其结构体与pcap_if相同,可以用pcap_if_t代替pcap_if):struct pcap_if struct pcap_if *next; char *name; /* name to hand to pcap_open_live() */ char *description; /* textual description of interface, or NULL */ struct pcap_addr *

2、addresses; bpf_u_int32 flags; /* PCAP_IF_ interface flags */;Struct pcap_addr : Representation of an interface address (表示接口地址)Struct pcap_addr struct pcap_addr *next:if not NULL, a pointer to the next element in the list; NULL for the last element of the list (指向下一个元素的指针)c:iknowdocsharedataWpdPackd

3、ocshtmlstructpcap_addr.html - b151e8e96bdb23ae8dd8d644de561999struct sockaddr *addr a pointer to a struct sockaddr containing an address c:iknowdocsharedataWpdPackdocshtmlstructpcap_addr.html - 4863f5b8767cd19fe6ea4db75456e5dfstruct sockaddr *netmask if not NULL, a pointer to a struct sockaddr that

4、contains the netmask corresponding to the address pointed to by addr. c:iknowdocsharedataWpdPackdocshtmlstructpcap_addr.html - c43963e42e4d901e55e433ab9c3ea686struct sockaddr *broadaddr if not NULL, a pointer to a struct sockaddr that contains the broadcast address corre sponding to the address poin

5、ted to by addr; may be null if the interface doesnt support broadcasts c:iknowdocsharedataWpdPackdocshtmlstructpcap_addr.html - 0077647e1560caa72d457120b36c248cstruct sockaddr *dstaddr if not NULL, a pointer to a struct sockaddr that contains the destination address corre sponding to the address poi

6、nted to by addr; may be null if the interface isnt a point- to-point interfacepcap_ifItem in a list of interfaces, used by pcap_findalldevs().(接口设备列表的一项(一个设备,比如一个网卡) Definition at line 148 of file incs/pcap.h.Struct pcap_ifstruct pcap_if * next if not NULL, a pointer to the next element in the list;

7、 NULL for the last element of the listchar * 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 devicestruct pcap_addr * addresses a pointer to the first element of a list

8、 of addresses for the interfaceu_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.2. 结构体pcap_t Descriptor of an open capture instance. This structure is opaque to the user, that handles its content through

9、the functions provided by wpcap.dll. (该结构体描述一个捕获的实例(例如指向一个发现的网卡,称为网卡描述符),其结构体在.h文件中看不到) 3. 结构体pcap_pkthdr/ Header of a packet in the dump file. Each packet in the dump file is prepended with this generic header.(每一个分组都有不同的头部,分组的头部用该结构体表示)struct pcap_pkthdr struct timeval ts; bpf_u_int32 caplen; bpf_

10、u_int32 len;ts:时间戳cpalen:当前分组的长度len:数据包的长度5. 结构体sockaddr_in一般编程中使用,它与sockaddr等价的数据结构sockaddr_in(在Winsock2.h中定义):struct sockaddr_in ;typedef struct in_addr union struct unsigned char s_b1, s_b2, s_b3, s_b4; S_un_b; struct unsigned short s_w1, s_w2; S_un_w; unsigned long S_addr; S_un; IN_ADDR;sin_fami

11、ly指代协议族,在socket编程中只能是AF_INETsin_port存储端口号(使用网络字节顺序)sin_addr存储IP地址,使用in_addr这个数据结构sin_zero是为了让sockaddr与sockaddr_in两个数据结构保持大小相同而保留的空字节。s_addr按照网络字节顺序存储IP地址sockaddr_in和sockaddr是并列的结构,指向sockaddr_in的结构体的指针也可以指向sockadd的结构体,并代替它。也就是说,你可以使用sockaddr_in建立你所需要的信息,在最后用进行类型转换就可以了bzero(char*)&mysock,sizeof(mysock

12、);/初始化mysock结构体名mysock.sa_family=AF_INET;mysock.sin_addr.S_un.S_addr=inet_addr(192.168.0.1);等到要做转换的时候用:(struct sockaddr*)mysock 例子:获得子网掩码pcap_if_t *d;netmask = ( (sockaddr_in *) (d-addresses-netmask) )-sin_addr.S_un.S_addr;例子:Socketaddr_inInternetAddr;int nPortId = 5150;InternetAddr.sin_family = AF_

13、INET;InternetAddr.sin_addr.s_addr = inet_addr(198.198.10.216);InternetAddr.sin_port = htonl(nPortId); WinPcap下的主要函数:1. int pcap_findalldevs ( pcap_if_t * alldevsp, char * errbuf ) /获取设备列表,以供函数pcap_open_live()打开这些设备Construct a list of network devices that can be opened with pcap_open_live(). Note:tha

14、t there may be network devices that cannot be opened with pcap_open_live() by the process calling pcap_findalldevs(), because, for example, that process might not have sufficient privileges to open them for capturing; if so, those devices will not appear on the list. alldevsp is set to point to the

15、first element of the list; each element of the list is of type pcap_if_t,-1 is returned on failure, in which case errbuf is filled in with an appropriate error message; 0 is returned on success.2. void pcap_freealldevs ( pcap_if_t * alldevsp ) 释放由函数pcap_findalldevs()获取的设备列表Free an interface list ret

16、urned by pcap_findalldevs().pcap_freealldevs() is used to free a list allocated by pcap_findalldevs().See also: pcap_findalldevs()3. pcap_t* pcap_open_live ( const char * device, /要打开的网络设施, int snaplen, /捕捉的分组最大长度,单位Byte int promisc, /是否为混杂模式,1为混杂模式 int to_ms, /read time_out 给予阅读分组的最大时间,单位ms char *

17、ebuf ) Device(Source):为打开的网络设施,是包含要打开的源名称的以0结尾的字符串。源名称得包含新的源规范语法(Source Specification Syntax),并且它不能为NULL。为了方便的使用源语法, snaplen:需要保留的数据包的长度。对每一个过滤器接收到的数据包,第一个snaplen字节的内容将被保存到缓冲区,并且传递给用户程序。例如,snaplen等于100,那么仅仅每一个数据包的第一个100字节的内容被保存。简言之就是从每一个包的开头到snaplen的那段内容将被保存。flags:保存一些由于抓包需要的标志。Winpcap定义了三种标志: PCAP_

18、OPENFLAG_PROMISCUOUS:1,它定义了适配器(网卡)是否进入混杂模式(promiscuous mode)。 PCAP_OPENFLAG_DATATX_UDP:2,它定义了数据传输(假如是远程抓包)是否用UDP协议来处理。 PCAP_OPENFLAG_NOCAPTURE_RPCAP:4,它定义了远程探测器是否捕获它自己产生的数据包。read_timeout:以毫秒为单位。read timeout被用来设置在遇到一个数据包的时候读操作不必立即返回,而是等待一段时间,让更多的数据包到来后从OS内核一次读多个数据包。auth:一个指向struct pcap_rmtauth的指针,保存当

19、一个用户登录到某个远程机器上时的必要信息。假如不是远程抓包,该指针被设置为NULL。(本地抓包不需要该参数)errbuf:一个指向用户申请的缓冲区的指针,存放当该函数出错时的错误信息。函数的返回值:该函数正常情况下,返回值是一个pcap_t(网卡描述符),它可以作为下一步其他函数调用该网卡的参数(例如,ppcap_compile()等)的参数。在遇到问题的情况下,该函数返回NULL并且errbuf变量保存了错误信息。Open a live capture from the network. pcap_open_live() is used to obtain a packet capture

20、descriptor to look at packets on the network. device is a string that specifies the network device to open; on Linux systems with 2.2 or later kernels, a device argument of any or NULL can be used to capture packets from all interfaces. snaplen specifies the maximum number of bytes to capture. If th

21、is value is less than the size of a packet that is captured, only the first snaplen bytes of that packet will be captured and provided as packet data. A value of 65535 should be sufficient, on most if not all networks, to capture all the data available from the packet. promisc specifies if the inter

22、face is to be put into promiscuous mode. (Note that even if this parameter is false, the interface could well be in promiscuous mode for some other reason.) For now, this doesnt work on the any device; if an argument of any or NULL is supplied, the promisc flag is ignored. to_ms specifies the read t

23、imeout in milliseconds. The read timeout is used to arrange that the read not necessarily return immediately when a packet is seen, but that it wait for some amount of time to allow more packets to arrive and to read multiple packets from the OS kernel in one operation. Not all platforms support a r

24、ead timeout; on platforms that dont, the read timeout is ignored. A zero value for to_ms, on platforms that support a read timeout, will cause a read to wait forever to allow enough packets to arrive, with no timeout. errbuf is used to return error or warning text. It will be set to error text when

25、pcap_open_live() fails and returns NULL. errbuf may also be set to warning text when pcap_open_live() succeds; to detect this case the caller should store a zero-length string in errbuf before calling pcap_open_live() and display the warning to the user if errbuf is no longer a zero-length string.Se

26、e also:pcap_open_offline(), pcap_open_dead(), pcap_findalldevs(), pcap_close() 4. int pcap_datalink ( pcap_t * p ) 返回链路层的类型,链路层的类型包括: DLT_NULL: BSD回路封装;链路层协议头是一个4字节的域,以主机字节顺序(host byte order),包含一个从socket.h来的PF_value。主机字节顺序(host byte order)是捕获数据包的机器的字节顺序,而PF_value是捕获数据包的机器的OS。如果一个读取一个文件,字节顺序和PF_value

27、不一定是抓取文件的那些机器。 DLT_EN10MB: 以太网(10Mb, 100Mb, 1000Mb, 或者更高)。 DLT_IEEE802: IEEE802.5令牌环网。 DLT_ARCNET:ARCNET。 DLT_SLIP:SLIP。 DLT_PPP:PPP;如果第一个字节是0xff或0x03,它是类HDLC帧上的PPP。 DLT_FDDI:FDDI DLT_ATM_RFC1483:RFC1483LLC/SNAP ATM;数据包以IEEE802.2 LLC头开始。 DLT_RAW:原始IP(raw IP);数据包以IP头开始。 DLT_PPP_SERIAL:按照RFC1662,基于类HD

28、LC帧的PPP,或者按照RFC1547的4.3.1,基于HDLC帧的Cisco PPP;前者的第一个字节是0xFF,后者的第一个字节是0x0F或0x8F。 DLT_PPP_ETHER:按照RFC2516,PPPoE;数据包以PPPoE头开始。 DLT_C_HDLC:按照RFC1547的4.3.1,基于HDLC帧的Cisco PPP。 DLT_IEEE802_11:IEEE 802.11无线局域网。 DLT_FRELAY:帧中继(Frame Relay)。 DLT_LOOP:OpenBSD回路封装。 DLT_LINUX_SLL:Linux抓包封装。 DLT_LTALK:苹果的LocalTalk,

29、数据包以AppleTalk LLAP头开始。 DLT_PFLOG:OpenBSD pflog。 DLT_PRISM_HEADER:后接802.11头的棱镜监视器模式(Prism monitor mode)信息。 DLT_IP_OVER_FC:RFC2625 IP-over-Fiber 频道,以RFC2625中定义的Network_Header开始。 DLT_SUNATM:SunATM设备。 DLT_IEEE802_11_RADIO:后接802.11头的链路层信息。 DLT_ARCNET_LINUX:没有异常帧的ARCNET。 DLT_LINUX_IRDA:Linux-IrDA数据包,DLT_LINUX_SLL头后接IrLAP头5. int pcap_compile (pcap_t * p, struct bpf_program * fp, char * str, int optimize, bpf_u_int32 netmask ) /翻译分组过滤器简单的说:pcap_complie()将程序中的字符串str集成到(翻译到)数据包驱动中的低级字节码fp。Str - fp(内核认识的格式)编译一个数据包过滤器,将一个能被核心态(kernel-level)过滤器引擎解释的程序中的高层过滤表达式(filtering expression)进行转化。pcap_compile(

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1