Winpcap 的PCap文件格式解析

来源:互联网 发布:银行卡绑定了很多软件 编辑:程序博客网 时间:2024/06/10 06:31

Winpcap 的PCap文件格式解析


SourceCode:  WinPcap Ver4.02

Tools:       WireShark Ver 1.3.0-SVN-29835


Pcap为WireShark, Ethereal等网络协议分析器支持的常用格式之一。


如下将阐述PCAP的文件格式。

 

structpcap_file_header {

    bpf_u_int32 magic;      /* 0xa1b2c3d4 */

    u_short version_major;  /* magjor Version 2 */

  u_shortversion_minor;  /* magjorVersion 4 */

    bpf_int32 thiszone;     /* gmt to local correction */

    bpf_u_int32 sigfigs;    /* accuracy of timestamps */

    bpf_u_int32 snaplen;    /* max length saved portion of each pkt */

    bpf_u_int32 linktype;   /* data link type (LINKTYPE_*) */

};

 

表一

linktype

Value

 

LINKTYPE_NULL

0

 

LINKTYPE_ETHERNET

1

/* also for 100Mb and up */

LINKTYPE_EXP_ETHERNET

2

/* 3Mb experimental Ethernet */

LINKTYPE_AX25

3

 

LINKTYPE_PRONET

4

 

LINKTYPE_CHAOS

5

 

LINKTYPE_TOKEN_RING

6

/* DLT_IEEE802 is used for Token Ring */

LINKTYPE_ARCNET

7

 

LINKTYPE_SLIP

8

 

LINKTYPE_PPP

9

 

LINKTYPE_FDDI

10

 

 

structtimeval {

        long   tv_sec;         /* seconds 含义同time_t对象的值 */

        long   tv_usec;        /* andmicroseconds */

};

structpcap_pkthdr {

    struct timeval ts;  /* time stamp */

    bpf_u_int32 caplen; /* length of portion present */

    bpf_u_int32 len;    /* length this packet (off wire) */

};

 

pcap文件格式结构


文件头

格式如结构体pcap_file_header

数据包头1

格式如pcap_pkthdr

数据包

数据

数据包头n-1

格式如pcap_pkthdr

数据包

数据

数据包头n

格式如pcap_pkthdr

数据包

数据