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 thepackets in the capture file have:以下是資料值與鏈路層類型的對應表0 BSD loopback devices, except for later OpenBSD1 Ethernet, and Linux loopback devices 乙太網路類型,大多數的資料包為這種類型。6 802.5 Token Ring7 ARCnet8 SLIP9 PPP10 FDDI100 LLC/SNAP-encapsulated ATM101 raw IP, with no link102 BSD/OS SLIP103 BSD/OS PPP104 Cisco HDLC105 802.11108 later OpenBSD loopback devices (with the AF_value in network byte order)113 special Linux cooked capture114 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).