编译错误有问题

时间:2012-07-27 13:31:58

标签: c pointers network-programming compiler-errors

我收到一些我无法弄清楚的编译错误,虽然我确定它们非常愚蠢但我找不到能够通过其他渠道帮助我的答案。

问题1 :(这些是TCP协议的一部分)

error: ‘TH_SYN’ undeclared (first use in this function)
error: ‘TH_ACK’ undeclared (first use in this function)

tcp.tcph_flags = TH_SYN;
tcp.tcph_flags = TH_ACK;

问题2:

error: conversion to non-scalar type requested

const int one = 1;
char buffer[PCKT_LEN];
struct sockaddr_in sin;
struct ipheader ip;
struct tcpheader tcp;

ip = (struct ipheader) buffer;                      /* ERROR POINTS HERE */
tcp = (struct tcpheader) buffer + ip.iph_ihl *4;    /* AND HERE */

问题3:

warning: assignment makes integer from pointer without a cast

case 'i': dip = inet_addr(optarg);
          dstip = (optarg);  /* ERROR POINTS TO THIS LINE */
          break;

现在我希望我已经复制了足够的有关错误的相关信息,以便您能够提供帮助,但如果我遗漏了某些内容,请告诉我。对于问题1,我相信我错过了某种类型的头文件,但我不知道哪个。问题2和3是指针问题,但我不确定它们为什么不正确。在此先感谢:)

1 个答案:

答案 0 :(得分:4)

  • 对于第一个问题,请添加定义TH_SYNTH_ACK的标头。在我的系统上,它是netinet/tcp.h
  • 对于第二个问题,请将ipheadertcpheader转换为指针
  • 对于第三个问题,我认为你需要一个strtoul,但我不确定