免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 15091 | 回复: 4
打印 上一主题 下一主题

如何解决'struct tcphdr' has no member named 'th_seq'? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-27 11:50 |只看该作者 |倒序浏览
想从pppd source中单独编译vjcompress.c
[root@dwang tcpcommpress]# cc -c vjcompress.c -o vjcompress.o
vjcompress.c: In function 'vj_compress_init':
vjcompress.c:76: warning: incompatible implicit declaration of built-in function 'bzero'
vjcompress.c: In function 'vj_compress_tcp':
vjcompress.c:173: error: 'struct tcphdr' has no member named 'th_flags'
vjcompress.c:173: error: 'TH_SYN' undeclared (first use in this function)
vjcompress.c:173: error: (Each undeclared identifier is reported only once
vjcompress.c:173: error: for each function it appears in.)
vjcompress.c:173: error: 'TH_FIN' undeclared (first use in this function)
vjcompress.c:173: error: 'TH_RST' undeclared (first use in this function)
vjcompress.c:173: error: 'TH_ACK' undeclared (first use in this function)
vjcompress.c:220: error: 'struct tcphdr' has no member named 'th_off'
vjcompress.c:252: error: 'struct tcphdr' has no member named 'th_off'
vjcompress.c:260: error: 'struct tcphdr' has no member named 'th_off'
.....

这个文件中使用了
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
这些文件都存在的,且PATH环境变量也设置了/usr/include:
[root@dwang tcpcommpress]# cd /usr/include/netinet/
ether.h     if_ether.h  if_tr.h     in.h        ip6.h       ip_icmp.h   udp.h      
icmp6.h     if_fddi.h   igmp.h      in_systm.h  ip.h        tcp.h  

tcp.h中tcphdr定义如下:
    56  # ifdef __FAVOR_BSD
&nbsp;&nbsp;&nbsp;&nbsp;57  typedef u_int32_t tcp_seq;
&nbsp;&nbsp;&nbsp;&nbsp;58  /*
&nbsp;&nbsp;&nbsp;&nbsp;59   * TCP header.
&nbsp;&nbsp;&nbsp;&nbsp;60   * Per RFC 793, September, 1981.
&nbsp;&nbsp;&nbsp;&nbsp;61   */

&nbsp;&nbsp;&nbsp;&nbsp;62  struct tcphdr
&nbsp;&nbsp;&nbsp;&nbsp;63    {
&nbsp;&nbsp;&nbsp;&nbsp;64      u_int16_t th_sport;         /* source port */
&nbsp;&nbsp;&nbsp;&nbsp;65      u_int16_t th_dport;         /* destination port */
&nbsp;&nbsp;&nbsp;&nbsp;66      tcp_seq th_seq;             /* sequence number */
&nbsp;&nbsp;&nbsp;&nbsp;67      tcp_seq th_ack;             /* acknowledgement number */
&nbsp;&nbsp;&nbsp;&nbsp;68  #  if __BYTE_ORDER == __LITTLE_ENDIAN
&nbsp;&nbsp;&nbsp;&nbsp;69      u_int8_t th_x2:4;           /* (unused) */
&nbsp;&nbsp;&nbsp;&nbsp;70      u_int8_t th_off:4;          /* data offset */
&nbsp;&nbsp;&nbsp;&nbsp;71  #  endif
&nbsp;&nbsp;&nbsp;&nbsp;72  #  if __BYTE_ORDER == __BIG_ENDIAN
&nbsp;&nbsp;&nbsp;&nbsp;73      u_int8_t th_off:4;          /* data offset */
&nbsp;&nbsp;&nbsp;&nbsp;74      u_int8_t th_x2:4;           /* (unused) */
&nbsp;&nbsp;&nbsp;&nbsp;75  #  endif
&nbsp;&nbsp;&nbsp;&nbsp;76      u_int8_t th_flags;
&nbsp;&nbsp;&nbsp;&nbsp;77  #  define TH_FIN        0x01
&nbsp;&nbsp;&nbsp;&nbsp;78  #  define TH_SYN        0x02
&nbsp;&nbsp;&nbsp;&nbsp;79  #  define TH_RST        0x04
&nbsp;&nbsp;&nbsp;&nbsp;80  #  define TH_PUSH       0x08
&nbsp;&nbsp;&nbsp;&nbsp;81  #  define TH_ACK        0x10
&nbsp;&nbsp;&nbsp;&nbsp;82  #  define TH_URG        0x20
&nbsp;&nbsp;&nbsp;&nbsp;83      u_int16_t th_win;           /* window */
&nbsp;&nbsp;&nbsp;&nbsp;84      u_int16_t th_sum;           /* checksum */
&nbsp;&nbsp;&nbsp;&nbsp;85      u_int16_t th_urp;           /* urgent pointer */
&nbsp;&nbsp;&nbsp;&nbsp;86  };
&nbsp;&nbsp;&nbsp;&nbsp;87
&nbsp;&nbsp;&nbsp;&nbsp;88  # else /* !__FAVOR_BSD */
&nbsp;&nbsp;&nbsp;&nbsp;89  struct tcphdr
&nbsp;&nbsp;&nbsp;&nbsp;90    {
&nbsp;&nbsp;&nbsp;&nbsp;91      u_int16_t source;
&nbsp;&nbsp;&nbsp;&nbsp;92      u_int16_t dest;
&nbsp;&nbsp;&nbsp;&nbsp;93      u_int32_t seq;
&nbsp;&nbsp;&nbsp;&nbsp;94      u_int32_t ack_seq;
&nbsp;&nbsp;&nbsp;&nbsp;95  #  if __BYTE_ORDER == __LITTLE_ENDIAN
&nbsp;&nbsp;&nbsp;&nbsp;96      u_int16_t res1:4;
&nbsp;&nbsp;&nbsp;&nbsp;97      u_int16_t doff:4;
&nbsp;&nbsp;&nbsp;&nbsp;98      u_int16_t fin:1;
&nbsp;&nbsp;&nbsp;&nbsp;99      u_int16_t syn:1;
&nbsp;&nbsp;&nbsp;100      u_int16_t rst:1;
&nbsp;&nbsp;&nbsp;101      u_int16_t psh:1;
&nbsp;&nbsp;&nbsp;102      u_int16_t ack:1;
&nbsp;&nbsp;&nbsp;103      u_int16_t urg:1;
&nbsp;&nbsp;&nbsp;104      u_int16_t res2:2;
&nbsp;&nbsp;&nbsp;105  #  elif __BYTE_ORDER == __BIG_ENDIAN
&nbsp;&nbsp;&nbsp;106      u_int16_t doff:4;
&nbsp;&nbsp;&nbsp;107      u_int16_t res1:4;
&nbsp;&nbsp;&nbsp;108      u_int16_t res2:2;
&nbsp;&nbsp;&nbsp;109      u_int16_t urg:1;
&nbsp;&nbsp;&nbsp;110      u_int16_t ack:1;
&nbsp;&nbsp;&nbsp;111      u_int16_t psh:1;
&nbsp;&nbsp;&nbsp;112      u_int16_t rst:1;
&nbsp;&nbsp;&nbsp;113      u_int16_t syn:1;
&nbsp;&nbsp;&nbsp;114      u_int16_t fin:1;
&nbsp;&nbsp;&nbsp;115  #  else
&nbsp;&nbsp;&nbsp;116  #   error "Adjust your <bits/endian.h> defines"
&nbsp;&nbsp;&nbsp;117  #  endif
&nbsp;&nbsp;&nbsp;118      u_int16_t window;
&nbsp;&nbsp;&nbsp;119      u_int16_t check;
&nbsp;&nbsp;&nbsp;120      u_int16_t urg_ptr;
&nbsp;&nbsp;&nbsp;121  };
&nbsp;&nbsp;&nbsp;122  # endif /* __FAVOR_BSD */


可能与__FAVOR_BSD变量有关,我怎么才可以知道__FAVOR_BSD变量有没有定义?

论坛徽章:
0
2 [报告]
发表于 2009-09-27 12:28 |只看该作者
估计头文件,不完整

论坛徽章:
0
3 [报告]
发表于 2009-09-27 12:42 |只看该作者
在tcp.h中加上
#ifndef __FAVOR_BSD
#define __FAVOR_BSD
#endif
就可以了。。。

可是这有一个潜在的问题,/usr/include/netinet/tcp.h文件是系统范围内公用的,默认没有定义__FAVOR_BSD,我这么直接修改了这个头文件,可能会影响其他程序的编译。

有别的解决方法吗?

[ 本帖最后由 wangdan1600 于 2009-9-27 12:58 编辑 ]

论坛徽章:
0
4 [报告]
发表于 2014-01-10 17:18 |只看该作者
现在已经解决了吧,为啥没有答案呢?
在编译时加上 -D_BSD_SOURCE 选项是正确解决方法,当然不能修改系统文件了。

至于为啥直接定义-D__FAVOR_BSD不好用,看一看features.h就知道了
(PS: 不看也知道每个地方进行了#undef  __FAVOR_BSD)

论坛徽章:
0
5 [报告]
发表于 2014-01-10 17:19 |只看该作者
抱歉,上面打错了个,是某个地方进行了#undef  __FAVOR_BSD
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP