众所周知,MSS是TCP数据的最大段大小。

在Ipv4中,MSS通常为1460,在Ipv6中,MSS通常为1440。

但是奇怪的是:struct tcp_info中有两种类型的MSS,即tcpi_snd_msstcpi_rcv_mss

我做了一个简单的实验,连接www.stackoverflow.com并输出这两个值。

#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <stdio.h>
#include <assert.h>

int main() {
    int fd = socket(AF_INET, SOCK_STREAM, 0);
    assert(fd >= 0);

    struct sockaddr_in server;
    server.sin_family = AF_INET;
    server.sin_port = htons(80);
    server.sin_addr.s_addr = inet_addr("151.101.193.69");

    int rc = connect(fd, (void*)&server, sizeof(server));
    assert(rc >= 0);

    struct tcp_info info;
    socklen_t len = sizeof(info);
    rc = getsockopt(fd, SOL_TCP, TCP_INFO, (void*)&info, &len);
    assert(rc >= 0);


    printf("%u\n", info.tcpi_snd_mss);
    printf("%u\n", info.tcpi_rcv_mss);
    return 0;
}

$ ./a.out
1440
536
tcpi_rcv_mss是536!

但是根据tcpdump,MSS应该是1440(我的MSS是1460,stackoverflow'MSS是1440)。

$ sudo tcpdump -n host 151.101.193.69
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
18:39:52.690772 IP 10.101.25.77.14947 > 151.101.193.69.80: Flags [S], seq 548910783, win 29200, options [mss 1460,sackOK,TS val 3459919655 ecr 0,nop,wscale 8], length 0
18:39:52.797959 IP 151.101.193.69.80 > 10.101.25.77.14947: Flags [S.], seq 577830562, ack 548910784, win 28800, options [mss 1440,nop,nop,sackOK,nop,wscale 9], length 0
18:39:52.798000 IP 10.101.25.77.14947 > 151.101.193.69.80: Flags [.], ack 1, win 115, length 0
18:39:52.798333 IP 10.101.25.77.14947 > 151.101.193.69.80: Flags [F.], seq 1, ack 1, win 115, length 0
18:39:53.160527 IP 10.101.25.77.14947 > 151.101.193.69.80: Flags [F.], seq 1, ack 1, win 115, length 0
18:39:53.241597 IP 151.101.193.69.80 > 10.101.25.77.14947: Flags [F.], seq 1, ack 2, win 57, length 0
18:39:53.241657 IP 10.101.25.77.14947 > 151.101.193.69.80: Flags [.], ack 2, win 115, length 0

所以我有两个问题:
  • tcpi_rcv_mss是什么意思?
  • 为什么我的实验中使用tcpi_rcv_mss 536?
  • 最佳答案

    接收MSS是您向其他对等方宣布可以接受的最大段大小,而发送MSS是您的对等方宣布的值,并标记您可以发送给它的最大段大小。当然,有两个,您的不必等于伴侣的。

    关于c - tcpi_rcv_mss是什么意思?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56850692/

    10-09 13:11