C语言编译时出现invalid application of 'sizeof' to an incomplete type 'struct tcphdr'怎么办?

Hello!
简而言之,所谓"struct tcphdr"是一个来自外部的被include的库文件的结构体.
而且它这个结构体的构造有点诡异.我不知道什么是__extension__ union,这会让它更难处理吗?

struct tcphdr
  {
    __extension__ union
    {
      struct
      {
    uint16_t th_sport;    /* source port */
    uint16_t th_dport;    /* destination port */
    tcp_seq th_seq;        /* sequence number */
    tcp_seq th_ack;        /* acknowledgement number */
# if __BYTE_ORDER == __LITTLE_ENDIAN
    uint8_t th_x2:4;    /* (unused) */
    uint8_t th_off:4;    /* data offset */
# endif
# if __BYTE_ORDER == __BIG_ENDIAN
    uint8_t th_off:4;    /* data offset */
    uint8_t th_x2:4;    /* (unused) */
# endif
    uint8_t th_flags;
# define TH_FIN    0x01
# define TH_SYN    0x02
# define TH_RST    0x04
# define TH_PUSH    0x08
# define TH_ACK    0x10
# define TH_URG    0x20
    uint16_t th_win;    /* window */
    uint16_t th_sum;    /* checksum */
    uint16_t th_urp;    /* urgent pointer */
      };
      struct
      {
    uint16_t source;
    uint16_t dest;
    uint32_t seq;
    uint32_t ack_seq;
# if __BYTE_ORDER == __LITTLE_ENDIAN
    uint16_t res1:4;
    uint16_t doff:4;
    uint16_t fin:1;
    uint16_t syn:1;
    uint16_t rst:1;
    uint16_t psh:1;
    uint16_t ack:1;
    uint16_t urg:1;
    uint16_t res2:2;
# elif __BYTE_ORDER == __BIG_ENDIAN
    uint16_t doff:4;
    uint16_t res1:4;
    uint16_t res2:2;
    uint16_t urg:1;
    uint16_t ack:1;
    uint16_t psh:1;
    uint16_t rst:1;
    uint16_t syn:1;
    uint16_t fin:1;
# else
#  error "Adjust your <bits/endian.h> defines"
# endif
    uint16_t window;
    uint16_t check;
    uint16_t urg_ptr;
      };
    };
};

我不能在程序里对它进行sizeof,或者对指向它的类型的地址进行->操作,无法编译通过.
问题是这是官方给的源码,它肯定自己编译是通过的啊?是我的编译选项有问题吗?我是本地交叉编译.
而且,sizeof实在不行的话我可以直接把它全改成具体的数字,但->这个操作我不可能把它混过去.
怎么办好呢?

阅读 4.2k
1 个回答

莫名其妙把-std=c11变成-std=gnu11就过了,,