pcap文件頭的組織格式

PCAP文件格式分析
、基本格式:
文件頭 數據包頭 數據報 數據包頭 數據報......
二、文件頭結構體:
sturct pcap_file_header
{
DWORD              magic;
     WORD                 version_major;
     WORD                 version_minor;
DWORD              thiszone;
DWORD              sigfigs;
DWORD              snaplen;
DWORD              linktype;
}
說明:
1、標識位:32位的,這個標識位的值是16進制的 0xa1b2c3d4。
a 32-bit        magic number ,The magic number has the value hex a1b2c3d4.
2、主版本號:16位, 默認值爲0x2。
a 16-bit          major version number,The major version number should have the value 2.
3、副版本號:16位,默認值爲0x04。
a 16-bit          minor version number,The minor version number should have the value 4.
4、區域時間:32位,實際上該值並未使用,因此可以將該位設置爲0。
a 32-bit          time zone offset field that actually not used, so you can (and probably should) just make it 0;
5、精確時間戳:32位,實際上該值並未使用,因此可以將該值設置爲0。
a 32-bit time stamp accuracy field tha not actually used,so you can (and probably should) just make it 0;
6、數據包最大長度:32位,該值設置所抓獲的數據包的最大長度,如果所有數據包都要抓獲,將該值設置爲65535; 例如:想獲取數據包的前64字節,可將該值設置爲64。
a 32-bit          snapshot length" field;The snapshot length field should be the maximum number of bytes perpacket that will be captured. If the entire packet is captured, make it 65535; if you only capture, for example, the first 64 bytes of the packet, make it 64.
7、鏈路層類型:32位, 數據包的鏈路層包頭決定了鏈路層的類型。
a 32-bit link layer type field.The link-layer type depends on the type of link-layer header that the
packets in the capture file have:
以下是數據值與鏈路層類型的對應表
0            BSD       loopback devices, except for later OpenBSD
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
三、數據包頭結構體:
struct pcap_pkthdr
{
struct timeval         ts;
     DWORD              caplen;
     DWORD              len;
}
struct timeval
{
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;
3、數據包實際長度: 所抓獲的數據包的真實長度,如果文件中保存不是完整的數據包,那麼這個值可能要比前面的數據包長度的值大(一般是上面的值+32)。
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).
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章