2011-10-29 2 views
0

안녕하세요, 나는 struct packet을 사용할 때 : struct ini를 사용할 때 : "dereferencing pointer to incomplete type"오류 메시지를 받는다. 그래서 내가 구조체 iphdr으로 다음 tryed하지만 여전히 내가 패킷 구문 분석 기능을 사용하고 여기에 같은 문제 이 : 나는이 프로그램에 다른 오류가 있지만이 문제를 해결하려는 것을 알고struct ip 및 struct 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를 포함하는 것을 잊었습니다. –

관련 문제