Linux 花费 3 个数据包来建立 TCP 连接,并花费 3 个数据包来关闭它,如 tcpdump 捕获所示
# establishing TCP connection
22:37:09.150456 IP 127.0.0.1.49327 > 127.0.0.1.8000: Flags [S], seq 598953185, win 65535, options [mss 1368,nop,wscale 4,nop,nop,TS val 808887890 ecr 0,sackOK,eol], length 0
22:37:09.150498 IP 127.0.0.1.8000 > 127.0.0.1.49327: Flags [S.], seq 1017784291, ack 598953186, win 14480, options [mss 1460,sackOK,TS val 116674605 ecr 808887890,nop,wscale 6], length 0
22:37:09.159764 IP 127.0.0.1.49327 > 127.0.0.1.8000: Flags [.], ack 1, win 8220, options [nop,nop,TS val 808887900 ecr 116674605], length 0
# closing TCP connection
22:37:18.297179 IP 127.0.0.1.49327 > 127.0.0.1.8000: Flags [F.], seq 1, ack 1, win 8220, options [nop,nop,TS val 808897004 ecr 116674605], length 0
22:37:18.297426 IP 127.0.0.1.8000 > 127.0.0.1.49327: Flags [F.], seq 1, ack 2, win 227, options [nop,nop,TS val 116676892 ecr 808897004], length 0
22:37:18.308698 IP 127.0.0.1.49327 > 127.0.0.1.8000: Flags [.], ack 2, win 8220, options [nop,nop,TS val 808897016 ecr 116676892], length 0
但在 OS X 上,建立 TCP 连接需要 4 个数据包,关闭连接需要 5 个数据包,如 tcpdump 捕获所示
# establishing TCP connection
22:37:54.586720 IP 127.0.0.1.49341 > 127.0.0.1.6060: Flags [S], seq 2470554991, win 65535, options [mss 16344,nop,wscale 4,nop,nop,TS val 808939126 ecr 0,sackOK,eol], length 0
22:37:54.586765 IP 127.0.0.1.6060 > 127.0.0.1.49341: Flags [S.], seq 1700081564, ack 2470554992, win 65535, options [mss 16344,nop,wscale 4,nop,nop,TS val 808939126 ecr 808939126,sackOK,eol], length 0
22:37:54.586774 IP 127.0.0.1.49341 > 127.0.0.1.6060: Flags [.], ack 1, win 9186, options [nop,nop,TS val 808939126 ecr 808939126], length 0
22:37:54.586781 IP 127.0.0.1.6060 > 127.0.0.1.49341: Flags [.], ack 1, win 9186, options [nop,nop,TS val 808939126 ecr 808939126], length 0
# closing TCP connection
22:38:00.631596 IP 127.0.0.1.49341 > 127.0.0.1.6060: Flags [F.], seq 1, ack 1, win 9186, options [nop,nop,TS val 808945145 ecr 808939126], length 0
22:38:00.631631 IP 127.0.0.1.6060 > 127.0.0.1.49341: Flags [.], ack 2, win 9186, options [nop,nop,TS val 808945145 ecr 808945145], length 0
22:38:00.631641 IP 127.0.0.1.49341 > 127.0.0.1.6060: Flags [.], ack 1, win 9186, options [nop,nop,TS val 808945145 ecr 808945145], length 0
22:38:00.631719 IP 127.0.0.1.6060 > 127.0.0.1.49341: Flags [F.], seq 1, ack 2, win 9186, options [nop,nop,TS val 808945145 ecr 808945145], length 0
22:38:00.631768 IP 127.0.0.1.49341 > 127.0.0.1.6060: Flags [.], ack 2, win 9186, options [nop,nop,TS val 808945145 ecr 808945145], length 0
额外的数据包起什么作用?
答案1
正如你所看到的,经过三次握手后,有一个没有主体的 TCP 数据报。但是 win 从 65535 变为 9186。
如果你使用 Wireshark 工具转储 TCP 数据包,你会看到以下内容:
TCP 窗口更新从 65535 到 9186。