C: "tcp_seq"之前的预期说明符限定符列表

标签 c tcp libpcap

我不断收到此错误:我的头文件中“tcp_seq”之前的预期说明符限定符列表。

这是头文件:

#include <netinet/ip.h>

/* TCP header */
struct sniff_tcp {
    u_short th_sport; /* source port */
    u_short th_dport; /* destination port */
    tcp_seq th_seq; /* sequence number */
    tcp_seq th_ack; /* acknowledgement number */
    #if BYTE_ORDER == LITTLE_ENDIAN
    u_int th_x2:4, /* (unused) */
    th_off:4; /* data offset */
    #endif
    #if BYTE_ORDER == BIG_ENDIAN
    u_int th_off:4, /* data offset */
    th_x2:4; /* (unused) */
    #endif
    u_char 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
    #define TH_ECE 0x40
    #define TH_CWR 0x80
    #define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)
    u_short th_win; /* window */
    u_short th; /* checksum */
    u_short th_urp; /* urgent pointer */
};


/* Ethernet header */
struct sniff_ethernet {
    u_char ether_dhost[ETHER_ADDR_LEN]; /* Destination host address */
    u_char ether_shost[ETHER_ADDR_LEN]; /* Source host address */
    u_short ether_type;                 /* IP? ARP? RARP? etc */
};

/* IP header */
struct sniff_ip {
    #if BYTE_ORDER == LITTLE_ENDIAN
    u_int ip_hl:4,                      /* header length */
    ip_v:4;                             /* version */
    #if BYTE_ORDER == BIG_ENDIAN
    u_int ip_v:4,                       /* version */
    ip_hl:4;                            /* header length */
    #endif
    #endif                              /* not _IP_VHL */
    u_char ip_tos;                      /* type of service */
    u_short ip_len;                     /* total length */
    u_short ip_id;                      /* identification */
    u_short ip_off;                     /* fragment offset field */
    #define IP_RF 0x8000                /* reserved fragment flag */
    #define IP_DF 0x4000                /* dont fragment flag */
    #define IP_MF 0x2000                /* more fragments flag */
    #define IP_OFFMASK 0x1fff           /* mask for fragmenting bits */
    u_char ip_ttl;                      /* time to live */
    u_char ip_p;                        /* protocol */
    u_short ip_sum;                     /* checksum */
    struct in_addr ip_src,ip_dst;       /* source and dest address */
};

即使使用谷歌,我也无法深入了解。

希望有人能给点建议。

非常感谢,

最佳答案

看起来你复制复制了tcphdr来自 netinet/tcp.h 的结构。

您收到的错误消息只是一种复杂的方式,表示 tcp_seq 类型未知。对我来说,这是由 netinet/tcp.h 定义的 if 预处理器宏 __FAVOR_BSD 已定义。

或者,您可以只使用 u_long 或任何其他无符号 32 位整数类型。

关于C: "tcp_seq"之前的预期说明符限定符列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6842897/

相关文章:

c++ - 异步 lib​​pcap : losing packets?

packet - 使用 libpcap 丢弃数据包

c - C可变参数宏是否能够递归扩展##__VA_ARGS__?

node.js - 使用 Node-Js 作为消息传递层

C++ : how can I fourier transform an array into an other array of different size using fftw3

java - 从数据包 header 设置 Java 字节数组大小

c++ - 如何使用 TCP 在单个 ip 上处理来自多个客户端的单个连接

networking - Pcap丢弃数据包

c - C 中的 abs 函数

c - current->pid 如何在 linux 上工作?