我们知道,MSS是TCP数据的最大段大小。
在Ivv4中,MSS总体上为1460,在Ivv6中,MSS总体上为1440。
但是奇怪的是:结构tcp_info中有两种类型的MSS,分别是tcpi_snd_mss
和tcpi_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在我的实验中?答案 0 :(得分:0)
接收MSS是您向其他对等方宣布可以接受的最大段大小,而发送MSS是您的对等方宣布的值,并标记可以发送给它的最大段大小。当然,有两个,您的不必等于伴侣的。