//以太头
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"。
请问,我的代码是否正确?如果正确,那那些数字分别代表什么类型的数据报?还有没有可能出现其他类型的数据报?

解决方案 »

  1.   

    拨号的,数据链路层,好像是PPPOE,所以不对,用个软件看看就知道了,数据链路层有很多种的,除了类型是IP以外还有可能是ARP等等.
      

  2.   

    恩,husheng34(随意生活)
    回答了一部分。
      

  3.   

    有好多协议的至少arp,rarp,pppoe或dhcp,ip
      

  4.   

    楼主可以用Etheral之类的软件抓包看一下,另外datatype不是已经赋值为“IP”了,怎么会有不同的值?
    另外你查一下具体以太网类型字段,我这里的一本书中分析以太网数据包时分为3个case,分别是0x0806,0x0800,0x8035,分别对应IP,ARP以及RARP协议,楼主再看看哪一种对吧:)