【发布时间】:2021-06-11 10:54:34
【问题描述】:
在 C 中使用原始套接字时,我试图设置 tcp 数据包的最大段大小,并且在尝试实现之前提出的问题的答案时遇到编译错误 -> setting the maximum segment size in the tcp header
我在谷歌上尝试过其他东西,忘记记录我的试验和他们犯的错误。我有我最近的尝试,我会在这里发布。
struct tcp_option_mss {
uint8_t kind; /* 2 */
uint8_t len; /* 4 */
uint16_t mss;
} __attribute__((packed));
struct tcp_option_mss mss;
mss.kind = 2;
mss.len = 4;
mss.mss = htons(32000);
struct tcphdr_mss {
struct tcphdr tcp_header;
struct tcp_option_mss mss;
};
void setup_tcp_header(struct tcphdr *tcp_hdr)
{
struct tcphdr_mss *tcp_header;
tcp_header = malloc(sizeof(struct tcphdr_mss));
tcp_hdr->source = htons(5678);
tcp_hdr->seq = rand();
tcp_hdr->ack_seq = 0;
tcp_hdr->res2 = 0;
tcp_hdr->doff = 5;
tcp_hdr->syn = 1;
tcp_hdr->window = htons(0);
tcp_hdr->check = 0;
tcp_hdr->urg_ptr = 0;
tcp_header->mss.kind = 2;
tcp_header->mss.len = 4;
tcp_header->mss.mss = htons(32000);
}
有了这个,我得到了 3 个错误,每个错误都在 mss。行,说。出乎意料
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
mss.kind = 2;
这只是其中的 1 个错误,其他 2 个相同,仅针对其他 2 个 mss。线。如果您有任何解决此编译问题的提示/如果您知道我的代码设置是否不起作用,请给我一个提示。此外,如果有办法将我的代码压缩到更少的行,也将不胜感激!谢谢!!
【问题讨论】:
标签: c tcp raw-sockets