已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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 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 指向下一个元素的指针 struct sockaddr addr a pointer to a struct sockaddr containing an address struct sockaddr netmask if not NULL a pointer to a struct sockaddr that contains the netmask corresponding to the address pointed to by addr struct 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 struct 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 pcap if Item in a list of interfaces used by pcap findalldevs 接口设备列表的一项 一个设备 比如一个网卡 Definition at line 148 of file incs pcap h Struct pcap if struct 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 struct 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 2 结构体结构体 pcap t Descriptor of an open capture instance This structure is opaque to the user that handles its content through 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 u int32 len ts 时间戳 cpalen 当前分组的长度 len 数据包的长度 5 结构体 sockaddr in 一般编程中使用 它与 sockaddr 等价的数据结构 sockaddr insockaddr in 在 Winsock2 h 中定义 struct sockaddr in typedef struct in addrin 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 family 指代协议族 在 socket 编程中只能是 AF INET sin 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 结构体名 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 in InternetAddr int nPortId 5150 InternetAddr sin family AF 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 Note that 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 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 returned 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 ebuf Device Source 为打开的网络设施 是包含要打开的源名称的以 0 结尾的 字符串 源名称得包含新的源规范语法 Source Specification Syntax 并且它不 能为 NULL 为了方便的使用源语法 snaplen 需要保留的数据包的长度 对每一个过滤器接收到的数据包 第一 个 snaplen 字节的内容将被保存到缓冲区 并且传递给用户程序 例如 snaplen 等于 100 那么仅仅每一个数据包的第一个 100 字节的内容被保存 简言之就是从每一个包的开头到 snaplen 的那段内容将被保存 flags 保存一些由于抓包需要的标志 Winpcap 定义了三种标志 PCAP 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 的指针 保存当一个用户登录到某个 远程机器上时的必要信息 假如不是远程抓包 该指针被设置为 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 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 this 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 interface 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 doesn t work on the any device if an argument of any or NULL is supplied the promisc flag is ignored to ms specifies the read timeout 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 read timeout on platforms that don t 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 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 SeeSee also 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 不一定是抓取文件的那些机器 DLT EN10MB 以太网 10Mb 100Mb 1000Mb 或者更高 DLT IEEE802 IEEE802 5 令牌环网 DLT ARCNET ARCNET DLT SLIP SLIP DLT PPP PPP 如果第一个字节是 0 xff 或 0 x03 它是类 HDLC 帧上的 PPP DLT FDDI FDDI DLT ATM RFC1483 RFC1483LLC SNAP ATM 数据包以 IEEE802 2 LLC 头开始 DLT RAW 原始 IP raw IP 数据包以 IP 头开始 DLT PPP SERIAL 按照 RFC1662 基于类 HDLC 帧的 PPP 或者按照 RFC1547 的 4 3 1 基于 HDLC 帧的 Cisco PPP 前者的第一个字节是 0 xFF 后者的第一个字节是 0 x0F 或 0 x8F 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 数据包以 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 被用来将字符串 str 编译进 过滤器程序 fp 程序 fp 是一个指向 bpf program 结构体并被 pcap compile 赋值的指针 optimize 控制是否对目标代码 resulting code 的性能进行优化 Netmask 表明 IPv4 掩码 它仅在检查过滤器程序中的 IPv4 广播地址的时候被 使用 如果网络掩码对于程序是不可知的或者数据包是在 Linux 的 任何 any 伪接口上被捕获的 则赋值 0 IPv4 广播地址的测试将不被正确进行 但过滤器程序中的其他所有的测试都不会有问题 函数返回值 函数返回值 返回 1 表示发生了错误 此时 pcap geterr 将被用来显示错 误信息 0 表示成功 Compile a packet filter converting an high level filtering expression see Filtering expression syntax in a program that can be interpreted by the kernel level filtering engine 将 str 如只捕获 ARP 分组 中给出的分组类型 翻译成内核认识的格式 该格式放到 bpf program fp 中 6 int pcap setfilter pcap t p struct bpf program fp 功能 设置过滤器 返回值 该函数返回值为 0 表示成功 不成功 返回值 0 pcap setfilter 把一个过滤器与核心驱动抓包会话关联起来 一旦 pcap setfilter 被调用 相关的过滤器将被应用到所有的来自网络的数据包上 并且所有的一致的数据包将被复制给应 用程序 Associate a filter to a capture 使用 bpf program fp 格式 设置 过滤器 只需要 fp 规定的格式 该函数之前需要使用 pcap compile pcap setfilter is used to specify a filter program fp is a pointer to a bpf program struct usually the result of a call to pcap compile 1 is returned on failu
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 科普资助项目协议书
- 租车区块链合同范本
- 电动门加工合同范本
- 电焊车间承包协议书
- 消毒供应中心护理质量评价标准
- 溃疡性结肠炎症状解析及护理学习
- 2025-2026学年广东省广州市高一上学期期中模拟地理试卷03人教版(解析版)
- 2025-2026学年安徽省县中联盟高一上学期10月联考试地理试卷(解析版)
- 子宫肌瘤常见症状及护理方法讲解
- 礼仪风采大赛自我介绍
- 刘老根大舞台开幕曲简谱乐谱
- 新闻采访学2023章节测试答案-新闻采访学超星尔雅答案
- 西安某综合办公楼弱电智能化设计方案
- 西南交通大学机械原理课后习题答案
- 初始理论课件 CHAPTER4自动飞行
- GB/T 8642-2002热喷涂抗拉结合强度的测定
- GB/T 38145-2019高含量贵金属合金首饰金、铂、钯含量的测定ICP差减法
- 计量基础知识培训 课件
- 超星网络课隋唐史答案
- 9tomo临床应用3年汇报
- 《风景名胜区条例》解读课件
评论
0/150
提交评论