tcpdump: listening on lo, link-type EN10MB (Ethernet), capture size 96 bytes
13:27:48.919082 IP (tos 0x0, ttl 64, id 52187, offset 0, flags [DF], proto TCP (6), length 60)
127.0.0.1.39206 > 127.0.0.1.22: Flags [S], cksum 0x0338 (correct), seq 629688948, win 32792, options [mss 16396,sackOK,TS val 24019375 ecr 0,nop,wscale 6], length 0
13:27:48.919108 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
127.0.0.1.22 > 127.0.0.1.39206: Flags [S.], cksum 0x51bd (correct), seq 637536356, ack 629688949, win 32768, options [mss 16396,sackOK,TS val 24019375 ecr 24019375,nop,wscale 6], length 0
13:27:48.919135 IP (tos 0x0, ttl 64, id 52188, offset 0, flags [DF], proto TCP (6), length 52)
127.0.0.1.39206 > 127.0.0.1.22: Flags [.], cksum 0x38e0 (correct), seq 1, ack 1, win 513, options [nop,nop,TS val 24019375 ecr 24019375], length 0
--------------------------------------------------------------
第一次三次握手
--------------------------------------------------------------
13:27:48.919661 IP (tos 0x0, ttl 64, id 52189, offset 0, flags [DF], proto TCP (6), length 52)
127.0.0.1.39206 > 127.0.0.1.22: Flags [R.], cksum 0x38dc (correct), seq 1, ack 1, win 513, options [nop,nop,TS val 24019375 ecr 24019375], length 0
--------------------------------------------------------------
RST中断第一个连接
--------------------------------------------------------------
13:27:48.919687 IP (tos 0x0, ttl 64, id 19416, offset 0, flags [DF], proto TCP (6), length 56)
127.0.0.1.39207 > 127.0.0.1.22: Flags [S], cksum 0x9740 (correct), seq 629721719, win 32792, options [mss 16396,sackOK,TS val 24019375 ecr 0], length 0
13:27:48.919704 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 56)
127.0.0.1.22 > 127.0.0.1.39207: Flags [S.], cksum 0xc014 (correct), seq 631516785, ack 629721720, win 32768, options [mss 16396,sackOK,TS val 24019375 ecr 24019375], length 0
13:27:48.919723 IP (tos 0x0, ttl 64, id 19417, offset 0, flags [DF], proto TCP (6), length 52)
127.0.0.1.39207 > 127.0.0.1.22: Flags [.], cksum 0x1513 (correct), seq 1, ack 1, win 32792, options [nop,nop,TS val 24019375 ecr 24019375], length 0
--------------------------------------------------------------
第二次三次握手
--------------------------------------------------------------
13:27:48.920877 IP (tos 0x0, ttl 64, id 19418, offset 0, flags [DF], proto TCP (6), length 52)
127.0.0.1.39207 > 127.0.0.1.22: Flags [F.], cksum 0x1512 (correct), seq 1, ack 1, win 32792, options [nop,nop,TS val 24019375 ecr 24019375], length 0
13:27:48.924008 IP (tos 0x0, ttl 64, id 45021, offset 0, flags [DF], proto TCP (6), length 52)
127.0.0.1.22 > 127.0.0.1.39207: Flags [.], cksum 0x1529 (correct), seq 1, ack 2, win 32768, options [nop,nop,TS val 24019376 ecr 24019375], length 0
13:27:48.933517 IP (tos 0x0, ttl 64, id 45022, offset 0, flags [DF], proto TCP (6), length 84)
127.0.0.1.22 > 127.0.0.1.39207: Flags [P.], seq 1:33, ack 2, win 32768, options [nop,nop,TS val 24019378 ecr 24019375], length 32
13:27:48.933539 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 40)
127.0.0.1.39207 > 127.0.0.1.22: Flags [R], cksum 0x289f (correct), seq 629721721, win 0, length 0
--------------------------------------------------------------
最后只是由于程序关闭,用FIN关闭连接,接受到server端响应,由于程序已经关闭,协议栈响应RST
--------------------------------------------------------------
我们尽量在收到对方的FIN包,也就是read(2)等返回0的时候再调用connect(AF_UNSPEC)关闭连接,防止造成误会。
可能的应用:反向HTTP代理中,由代理服务器发往HTTP服务器的连接。