Linux spends 3 packets to establish a TCP connection and 3 packets to close it, as shown by the tcpdump capture
# 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
but on OS X there are 4 packets to establish a TCP connection and 5 packets to close it, as shown by the tcpdump capture
# 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
What do the extra packets do?