pcap文件格式
2020-12-09 11:39 宋海宾 阅读(918) 评论(0) 编辑 收藏 举报pcap文件格式是常用的数据报存储格式,包括wireshark在内的主流抓包软件都可以生成这种格式的数据包
文件头 24字节
数据报头 + 数据报 数据包头为16字节,后面紧跟数据报
数据报头 + 数据报 ......
1 struct pcap_file_header 2 { 3 bpf_u_int32 magic; 4 u_short version_major; 5 u_short version_minor; 6 bpf_int32 thiszone; 7 bpf_u_int32 sigfigs; 8 bpf_u_int32 snaplen; 9 bpf_u_int32 linktype; 10 };
![](http://hi.csdn.net/attachment/201003/27/4633639_1269693284d53M.png)
Pcap文件头24B各字段说明:
1 Ethernet, and Linux loopback devices
6 802.5 Token Ring
7 ARCnet
8 SLIP
9 PPP
10 FDDI
100 LLC/SNAP-encapsulated ATM
101 “raw IP”, with no link
102 BSD/OS SLIP
103 BSD/OS PPP
104 Cisco HDLC
105 802.11
108 later OpenBSD loopback devices (with the AF_value in network byte order)
113 special Linux “cooked” capture
114 LocalTalk
![](http://hi.csdn.net/attachment/201003/27/4633639_1269693284nnZd.png)
struct pcap_pkthdr
{
struct tim ts;
DWORD caplen;
DWORD len;
}
struct tim
{
DWORD GMTtime;
DWORD microTime
}
说明:
1、时间戳,包括:
秒计时:32位,一个UNIX格式的精确到秒时间值,用来记录数据包抓获的时间,记录方式是记录从格林尼治时间的1970年1月1日 00:00:00 到抓包时经过的秒数;
微秒计时:32位, 抓取数据包时的微秒值。
a time stamp, consisting of:
a UNIX-format time-in-seconds when the packet was captured, i.e. the number of seconds since January 1,1970, 00:00:00 GMT (that GMT, *NOT* local time!);
the number of microseconds since that second when the packet was captured;
2、数据包长度:32位 ,标识所抓获的数据包保存在pcap文件中的实际长度,以字节为单位。
a 32-bit value giving the number of bytes of packet data that were captured;
Caplen:当前数据区的长度,即抓取到的数据帧长度,由此可以得到下一个数据帧的位置。
3、数据包实际长度: 所抓获的数据包的真实长度,如果文件中保存不是完整的数据包,那么这个值可能要比前面的数据包长度的值大。
a 32-bit value giving the actual length of the packet, in bytes (which may be greater than the previous number, if you are not saving the entire packet).
四:packet数据:
即Packet(通常就是链路层的数据帧)具体内容,长度就是Caplen,这个长度的后面,就是当前PCAP文件中存放的下一个Packet数据包,也就是说:PCAP文件里面并没有规定捕获的Packet数据包之间有什么间隔字符串,下一组数据在文件中的起始位置。我们需要靠第一个Packet包确定。最后,Packet数据部分的格式其实就是标准的网路协议格式了可以任何网络教材上找得到。