2011-10-29 39 views
0

你好,我試圖解析一些數據包,並在使用結構IP我得到的:「提領指向不完全類型」的錯誤消息。 所以我用結構iphdr然後tryed,但仍然有同樣的問題 下面是函數我使用解析報文:提領指向不完全類型與結構的IP,並與結構iphdr

PrintPacketInHex(char *mesg, unsigned char *p, int len){ 
printf(mesg); 
while(len--){ 
printf("%.2X ",*p); 
p++; 
} 
} 


/*parse the sniffed packets*/ 

ParseEthernetHeader(unsigned char *packet, int len){ 
struct ethhdr *ethernet_header; 
struct ip *ip_header; 
//+sizeof(struct iphdr) 
if(len> sizeof(struct ethhdr)){ 
ethernet_header = (struct ethhdr*) packet; 
packet = packet +16; 
ip_header = (struct ip*) packet; 

/* first set of 6 bytes are destination MAC*/ 

PrintPacketInHex("destination MAC : ", ethernet_header->h_dest,6); 
printf("\n"); 

/*scond set of 6 bytes are source MAC */ 

PrintPacketInHex("source MAC : ", ethernet_header->h_source,6); 
printf("\n"); 

/*last 2 bytes in ethernet header are the protocol in carries */ 

PrintPacketInHex("protocol: ", (void*)&ethernet_header->h_proto,2); 
printf("\n"); 

/*the next 4 bytes are ip version bytes */ 

PrintPacketInHex("ip version: ", ip_header->ip_v,4); 
printf("\n"); 

/*the next 4 bytes are internet header length */ 

PrintPacketInHex("internet header length: ", ip_header->ip_ihl,4); 
printf("\n"); 

/*the next 8 bytes are type of srvice bytes */ 

PrintPacketInHex("type of service: ", ip_header->ip_tos,8); 
printf("\n"); 

/*the next 8 bytes are total length bytes */ 

PrintPacketInHex("total length: ", ip_header->ip_len,16); 
printf("\n"); 

/*the next 8 bytes are identification bytes */ 

PrintPacketInHex("identification: ", ip_header->ip_id,16); 
printf("\n"); 

/*the next 8 bytes are flags bytes 

PrintPacketInHex("Flags: ", "flags",3); 
printf("\n");*/ 

/*the next 13 bytes flags and offset bytes */ 

PrintPacketInHex("offset: ", ip_header->ip_off,16); 
printf("\n"); 

/*the next 8 bytes time to live bytes */ 
PrintPacketInHex("time to live: ", ip_header->ip_ttl,8); 
printf("\n"); 

/*the next 8 bytes protocol bytes */ 

PrintPacketInHex("protocol: ", ip_header->ip_p,8); 
printf("\n"); 

/*the next 16 bytes are checksum bytes */ 

PrintPacketInHex("checksum: ", ip_header->ip_sum,16); 
printf("\n"); 

/*the next 32 bytes source ip adress bytes */ 

PrintPacketInHex("source ip: ", ip_header->ip_src,32); 
printf("\n"); 

/*the next 32 bytes destination ip adress bytes */ 

PrintPacketInHex("destination ip: ", ip_header->dip_dst,32); 
printf("\n"); 
} 
else printf("packet size too small ! \n"); 
} 

我知道,有在程序中的其他錯誤,但要解決這個問題問題在尋找其他問題之前。 謝謝

+0

你能提供的樣本數據? – Aif

+0

已包含定義結構'ip'頭文件? –

+0

「struct ip」的定義在哪裏? – Mat

回答

1

您的編譯單元必須包含struct ethhdrstruct ip的定義,以便您能夠訪問其成員。

+0

謝謝,這是我的一個愚蠢的錯誤:d,我忘了,包括netinet.h –