【100】 为什么会报错?请指点
/* Fill a return packet info. */
static void fill_return_info(struct return_info *ri, unsigned char type,
unsigned short idx, const char *packet,
const struct timeval *recv_time)
{
struct waiting_info *wi = &_waiting_array[idx];
int hlen;
memset(ri, 0, sizeof(struct return_info));
if (type != RPK_TIMEOUT) { /* the return timeout */
ri->from = ntohl(((struct iphdr *) packet)->saddr);
ri->id = ntohs(((struct iphdr *) packet)->id);
ri->rtt = delta_time(&(wi->tv), recv_time);
ri->ttl = ((struct iphdr *) packet)->ttl;
}
ri->seq = (wi->pi).seq;
ri->type = type;
/*
* 2005-03-04
*/
hlen = (struct ip *)packet->ip_hl << 2; /////// 197 line
if(hlen > 20){
unsigned char *cp;
int pos = 0;
cp = (unsigned char *)packet + sizeof(struct ip) +3; //// 201 line
for(pos = 0; pos < 3; pos++){
ri->rspace[pos] = (unsigned char *)packet[sizeof(struct ip) + pos];
}
for(i = 0; i < NROUTES; i++){
unsigned long l;
char *ip;
l = (*cp << 24)|(*(cp+1) << 16)|(*(cp+2) << 8)|*(cp+3);
if(l == 0)
fprintf(stdout,"0.0.0.0\n");
else{
ip = pr_addr(ntoh(l));
fprintf(stdout,"%s\n",ip);
sprintf(ri->rspace,"%s",ip);
}
cp += 4;
}
}
}
gcc 编译报错:
gcc -DDEBUG -Wall -g -I. -c -o engine.o engine.c
engine.c: In function `fill_return_info':
engine.c:197: request for member `ip_hl' in something not a structure or union
engine.c:201: sizeof applied to an incomplete type
engine.c:203: sizeof applied to an incomplete type
engine.c:203: warning: cast to pointer from integer of different size
engine.c:203: warning: assignment makes integer from pointer without a cast
engine.c:205: `i' undeclared (first use in this function)
engine.c:205: (Each undeclared identifier is reported only once
engine.c:205: for each function it appears in.)
engine.c:212: warning: implicit declaration of function `pr_addr'
engine.c:212: warning: implicit declaration of function `ntoh'
engine.c:212: warning: assignment makes pointer from integer without a cast
engine.c: At top level:
engine.c:230: warning: type mismatch with previous implicit declaration
engine.c:212: warning: previous implicit declaration of `pr_addr'
engine.c:230: warning: `pr_addr' was previously implicitly declared to return `int'
engine.c: In function `pr_addr':
engine.c:233: warning: implicit declaration of function `gethostbyaddr'
engine.c:233: warning: assignment makes pointer from integer without a cast
engine.c:234: warning: implicit declaration of function `inet_ntoa'
engine.c:234: warning: format argument is not a pointer (arg 3)
engine.c:236: dereferencing pointer to incomplete type
engine.c:236: warning: format argument is not a pointer (arg 4)
engine.c: In function `check_return_pk':
engine.c:297: warning: passing arg 4 of `fill_return_info' discards qualifiers from pointer target type
make: *** [engine.o] Error 1