//以太头
typedef struct ether_header
{
u_char dmac[6];// detination hardware address
u_char smac[6];// source hardware address
u_short ether_type;//!< \brief Protocol type.
}ether_header;我用winpcap中的pcap_loop()函数捕获数据报,并在函数void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)中进行处理。以下是部分代码:
ether_header *ethh;
ethh=(ether_header *)pkt_data;
switch(ntohs(ethh->ether_type))
{
case 2048:
datatype="IP";
break;
default:
datatype.Format("%d",ntohs(ethh->ether_type));
}
结果,在我自己拨号上网的时候,datatype出现了很多不同的值,比如:"38"、"34983"、"2054"、"34916"。
请问,我的代码是否正确?如果正确,那那些数字分别代表什么类型的数据报?还有没有可能出现其他类型的数据报?
typedef struct ether_header
{
u_char dmac[6];// detination hardware address
u_char smac[6];// source hardware address
u_short ether_type;//!< \brief Protocol type.
}ether_header;我用winpcap中的pcap_loop()函数捕获数据报,并在函数void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)中进行处理。以下是部分代码:
ether_header *ethh;
ethh=(ether_header *)pkt_data;
switch(ntohs(ethh->ether_type))
{
case 2048:
datatype="IP";
break;
default:
datatype.Format("%d",ntohs(ethh->ether_type));
}
结果,在我自己拨号上网的时候,datatype出现了很多不同的值,比如:"38"、"34983"、"2054"、"34916"。
请问,我的代码是否正确?如果正确,那那些数字分别代表什么类型的数据报?还有没有可能出现其他类型的数据报?
回答了一部分。
另外你查一下具体以太网类型字段,我这里的一本书中分析以太网数据包时分为3个case,分别是0x0806,0x0800,0x8035,分别对应IP,ARP以及RARP协议,楼主再看看哪一种对吧:)