pcap文件解析

您所在的位置:网站首页 有高血压人口 pcap文件解析

pcap文件解析

2023-09-30 13:03| 来源: 网络整理| 查看: 265

看了很久终于搞清楚怎么解析pcap文件啦~以前的一个版本是我把pcap包保存成.txt,删除冗余项,然后再依照格式读入,输出相应格式。后来,我发现其他同学都是用.pcap格式直接读入的,然后我就不懂了,直接读入的pcap文件格式应该是什么样子的?根据实战经验,应该就是网上各种教程解析的那种格式,根据那种格式按字节读入就可以啦!下面上代码:

这个是pcap.h 里面定义了pcap文件的主要结构体。

#include #include #include #include #include using namespace std; #include #include #include #pragma comment(lib,"ws2_32.lib") typedef long int32; typedef unsigned long u_int32; typedef unsigned short u_int16; typedef unsigned char u_int8; //pcap文件头结构 typedef struct pcap_file_header{ u_int32 magic;//标识位 u_int16 version_major;//主版本号 u_int16 version_minor;//副版本号 int32 thiszone;//区域时间 u_int32 sigfigs;//精确时间戳 u_int32 snaplen;//数据包最大长度 u_int32 linktype;//链路层类型 }pcapFileHeader; //packet数据包头文件 typedef struct pcap_packet_header{ int32 sec;//秒计时时间戳 int32 microsec;//微秒计时时间戳 u_int32 caplen;//数据包长度,即所捕获的数据包保存在pcap文件中的实际长度 u_int32 len;//数据包实际长度,即所捕获的数据包的真实长度 }pcapPacketHeader; //捕获的以太网帧头 typedef struct ehternet_header{ u_int8 dstMac[6];//目的Mac地址 u_int8 srcMac[6];//源Mac地址 u_int16 type;//帧类型 }ehternetHeader; //IP数据报头 typedef struct ip_header{ u_int8 ver_hlen;//版本+报头长度 u_int8 typeOfService;//服务类型 u_int16 totalLen;//总长度 u_int16 id;//标识 u_int16 flag_Segment;//标志+片偏移 u_int8 ttl;//生存期 u_int


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3