【100】 为什么会报错?请指点

heuristic 2005-03-26 10:46:46
/* 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
...全文
342 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
heuristic 2005-03-28
  • 打赏
  • 举报
回复
struct ip 是在 /netinet/ip.h 中定义的
#include <netinet/ip.h>
heuristic 2005-03-26
  • 打赏
  • 举报
回复

/* 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,i;
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;
if(hlen > 20){
unsigned char *cp;
int pos = 0;
cp = (unsigned char *)packet + sizeof(struct ip) +3;
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(ntohl(l));
fprintf(stdout,"%s\n",ip);
sprintf(ri->rspace,"%s",ip);
}
cp += 4;
}
}
}



报错:

gcc -DDEBUG -Wall -g -I. -c -o engine.o engine.c
engine.c: In function `fill_return_info':
engine.c:211: request for member `ip_hl' in something not a structure or union
engine.c:215: sizeof applied to an incomplete type
engine.c:217: sizeof applied to an incomplete type
make: *** [engine.o] Error 1
飞在天空的鱼 2005-03-26
  • 打赏
  • 举报
回复
语法错误,定义有问题吧,
heuristic 2005-03-26
  • 打赏
  • 举报
回复
struct ip 有啥问题?

程序…… 好大,这只是一个文件的一个函数,以前没遇到这种情况
greenteanet 2005-03-26
  • 打赏
  • 举报
回复
可能是结构体或者是联合出现的问题,楼主还是把程序贴完好一点..
dongpy 2005-03-26
  • 打赏
  • 举报
回复
for(i = 0; i < NROUTES; i++){
//变量i没有定义!
huangyang88 2005-03-26
  • 打赏
  • 举报
回复
1.struct ip

2. `i' undeclared (first use in this function)
Student02370236 2005-03-26
  • 打赏
  • 举报
回复
都是些语法错误啊,你没有把程序贴完吧,那两个出错的地方所涉及的东西你都没有给出来啊?
比如你的各个结构体的定义,函数的声明,至少这些要有啊
heuristic 2005-03-26
  • 打赏
  • 举报
回复
struct ip 和 sizeof

诡异
zhousqy 2005-03-26
  • 打赏
  • 举报
回复
up
arrowcy 2005-03-26
  • 打赏
  • 举报
回复
看了前几条错误,好像都是因为struct ip的原因,是不是这个结构除了问题啊
CMyMfc 2005-03-26
  • 打赏
  • 举报
回复
因为你的程序有语法问题,回答完毕!
搂住给分!
xuelong_zl 2005-03-26
  • 打赏
  • 举报
回复
希望楼主能加些注释,说说你每个地方的意图
ShardowM 2005-03-26
  • 打赏
  • 举报
回复
ntohl(((struct iphdr *) packet)->saddr);
这是什么意思

dongpy 2005-03-26
  • 打赏
  • 举报
回复
我感觉你只是在fill_return_info之前声明了struct ip,没有给出它的定义!
dongpy 2005-03-26
  • 打赏
  • 举报
回复
你确定在fill_return_info这个函数前定义了struct ip?
heuristic 2005-03-26
  • 打赏
  • 举报
回复
up新势力~

69,374

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧