pcap文件格式

604 篇文章 8 订阅
579 篇文章 5 订阅
一 基本格式:
    文件头 数据包头数据报数据包头数据报......
二、文件头:
    pcap文件格式(转)
    文件头结构体
 
sturct pcap_file_header
 
{
 
        DWORD                    magic;
 
        DWORD                      version_major;
 
        DWORD                      version_minor;
 
        DWORD                      thiszone;
 
        DWORD                      sigfigs;
 
        DWORD                      snaplen;
 
        DWORD                      linktype;
 
}
 

说明:
 

1、标识位:32位的,这个标识位的值是16进制的 0xa1b2c3d4。
a32-bit 
            magic number ,The magic number has the value hex a1b2c3d4.
2、主版本号:16位, 默认值为0x2。
a16-bit 
                major version number,The major version number should have the value2.
3、副版本号:16位,默认值为0x04。
a16-bit 
                minor version number,The minor version number should have the value4.
4、区域时间:32位,实际上该值并未使用,因此可以将该位设置为0。
a32-bit 
                time zone offset field that actually not used, so you can (andprobably should) just make it 0;
5、精确时间戳:32位,实际上该值并未使用,因此可以将该值设置为0。
a32-bit 
                time stamp accuracy field tha not actually used,so you can (andprobably should) just make it 0;
6、数据包最大长度:32位,该值设置所抓获的数据包的最大长度,如果所有数据包都要抓获,将该值设置为65535;例如:想获取数据包的前64字节,可将该值设置为64。
a32-bit 
                snapshot length" field;The snapshot lengthfield should be the maximum number of bytes perpacket that will becaptured. If the entire packet is captured, make it 65535; if youonly capture, for example, the first 64 bytes of the packet, makeit 64.
7、链路层类型:32位, 数据包的链路层包头决定了链路层的类型。
a 32-bit link layer type field.The link-layer type depends on thetype of link-layer header that the
packets in the capture file have:
 

以下是数据值与链路层类型的对应表
                    BSD            loopback devices, except for later OpenBSD
                    Ethernet, and Linux loopbackdevices    以太网类型,大多数的数据包为这种类型。
                    802.5 Token Ring
                    ARCnet
                    SLIP
                    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 byteorder)
113 
                          special Linux cooked capture
114 
                          LocalTalk
 
三 packet数据包头:
pcap文件格式(转)
struct pcap_pkthdr
{
structtim 
              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 wascaptured;
 

2、数据包长度:32位 ,标识所抓获的数据包保存在pcap文件中的实际长度,以字节为单位。
a 32-bit value giving the number of bytes of packet data that werecaptured;
 

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 notsaving the entire packet).
四:packet数据:
 即Packet(通常就是链路层的数据帧)具体内容,长度就是Caplen,这个长度的后面,就是当前PCAP文件中存放的下一个Packet数据包,也就是说:PCAP文件里面并没有规定捕获的Packet数据包之间有什么间隔字符串,下一组数据在文件中的起始位置。我们需要靠第一个Packet包确定。
最后,Packet数据部分必须包含pcacket头和实际的数据
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值