tcp连接建立于终止

tcp的连接建立:
在本机执行如下命令:
sudo tcpdump -S port 8080 -vv -n -i lo0

tcpdump: listening on lo0, link-type NULL (BSD loopback), capture size 262144 bytes
00:35:50.265450 IP (tos 0x10, ttl 64, id 35702, offset 0, flags [DF], proto TCP (6), length 64, bad cksum 0 (->b12f)!)
127.0.0.1.57273 > 127.0.0.1.8080: Flags [S], cksum 0xfe34 (incorrect -> 0x3271), seq 84347051, win 65535, options [mss 16344,nop,wscale 5,nop,nop,TS val 1525310591 ecr 0,sackOK,eol], length 0
00:35:50.265585 IP (tos 0x0, ttl 64, id 10086, offset 0, flags [DF], proto TCP (6), length 64, bad cksum 0 (->1550)!)
127.0.0.1.8080 > 127.0.0.1.57273: Flags [S.], cksum 0xfe34 (incorrect -> 0xa903), seq 2958367133, ack 84347052, win 65535, options [mss 16344,nop,wscale 5,nop,nop,TS val 1525310591 ecr 1525310591,sackOK,eol], length 0
00:35:50.265599 IP (tos 0x10, ttl 64, id 54858, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->6667)!)
127.0.0.1.57273 > 127.0.0.1.8080: Flags [.], cksum 0xfe28 (incorrect -> 0xf11f), seq 84347052, ack 2958367134, win 12759, options [nop,nop,TS val 1525310591 ecr 1525310591], length 0
00:35:50.265614 IP (tos 0x0, ttl 64, id 63250, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->45af)!)
127.0.0.1.8080 > 127.0.0.1.57273: Flags [.], cksum 0xfe28 (incorrect -> 0xf11f), seq 2958367134, ack 84347052, win 12759, options [nop,nop,TS val 1525310591 ecr 1525310591], length 0


下面说明下这里的标志代表tcp首部中的6个标志比特中的4个。如下图所示:
标志3个字符缩写描述
SSYN同步序号
FFIN发送方完成数据发送
RRST复位连接
PPSH尽快能地将数据送往接收进程
. 以上4个标志均设置为0

当进行关闭连接的时候,输出如下:
00:56:40.220526 IP (tos 0x10, ttl 64, id 33599, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->b972)!)
127.0.0.1.57273 > 127.0.0.1.8080: Flags [F.], cksum 0xfe28 (incorrect -> 0xe50f), seq 84347052, ack 2958367134, win 12759, options [nop,nop,TS val 1526558843 ecr 1525310591], length 0
00:56:40.220579 IP (tos 0x0, ttl 64, id 224, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->3be2)!)
127.0.0.1.8080 > 127.0.0.1.57273: Flags [.], cksum 0xfe28 (incorrect -> 0xd900), seq 2958367134, ack 84347053, win 12759, options [nop,nop,TS val 1526558843 ecr 1526558843], length 0
00:56:40.220608 IP (tos 0x10, ttl 64, id 40943, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->9cc2)!)
127.0.0.1.57273 > 127.0.0.1.8080: Flags [.], cksum 0xfe28 (incorrect -> 0xd900), seq 84347053, ack 2958367134, win 12759, options [nop,nop,TS val 1526558843 ecr 1526558843], length 0
00:56:40.227383 IP (tos 0x0, ttl 64, id 49366, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->7beb)!)
127.0.0.1.8080 > 127.0.0.1.57273: Flags [F.], cksum 0xfe28 (incorrect -> 0xd8f9), seq 2958367134, ack 84347053, win 12759, options [nop,nop,TS val 1526558849 ecr 1526558843], length 0
00:56:40.227473 IP (tos 0x10, ttl 64, id 26769, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->d420)!)
127.0.0.1.57273 > 127.0.0.1.8080: Flags [.], cksum 0xfe28 (incorrect -> 0xd8f3), seq 84347053, ack 2958367135, win 12759, options [nop,nop,TS val 1526558849 ecr 1526558849], length 0

当进行关闭后,在进入Time_wait的状态的时候,此时要等待2MSL(2倍的最大报文生命周期),防止ack丢失,进行重传ack(另外一段超时重传fin包)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值