資源簡介
使用Winpcap捕獲并解析TCP報文 需要配置Winpcap的庫和頭文件
代碼片段和文件信息
#include?“pcap.h“
//分析udp數(shù)據(jù)包
//6個字節(jié)的mac地址
typedef?struct?mac_address
{
????u_char?byte1;
????u_char?byte2;
????u_char?byte3;
????u_char?byte4;
????u_char?byte5;
????u_char?byte6;
}mac_address;
typedef?struct?mac_header
{
????mac_address??daddr;??????//?目的地址(Destination?address)
????mac_address??saddr;??????//?源地址(Source?address)
????u_short?type;???????????//Type?默認是0x0800
}mac_header;
/*?4字節(jié)的IP地址?*/
typedef?struct?ip_address
{
????u_char?byte1;
????u_char?byte2;
????u_char?byte3;
????u_char?byte4;
}?ip_address;
/*?IPv4?首部?*/
typedef?struct?ip_header
{
????//u_char??ver_ihl;????????//?版本?(4?bits)?+?首部長度?(4?bits)
????u_char??ihl:4ver:4;///注意:由于字節(jié)序的緣故,這里定義的時候需要反過來
????u_char??tos;????????????//?服務類型(Type?of?service)
????u_short?tlen;???????????//?總長(Total?length)
????u_short?identification;?//?標識(Identification)
????u_short?flags_fo;???????//?標志位(Flags)?(3?bits)?+?段偏移量(Fragment?offset)?(13?bits)
????u_char??ttl;????????????//?存活時間(Time?
評論
共有 條評論