The Linux Programming Interface

(nextflipdebug5) #1
Sockets: Advanced Topics 1271

(labeled M in the diagram). This information is necessary because sequence
numbers don’t begin at 0, as noted in Section 58.6.3.


  1. The server TCP must both acknowledge the client TCP’s SYN segment and
    inform the client TCP of its own initial sequence number (labeled N in the
    diagram). (Two sequence numbers are required because a stream socket is
    bidirectional.) The server TCP can perform both operations by returning a single
    segment with both the SYN and the ACK control bits set. (We say that the ACK
    is piggybacked on the SYN.)

  2. The client TCP sends an ACK segment to acknowledge the server TCP’s SYN
    segment.


Figure 61-4: TCP state transition diagram


close^

send: FIN (4)

close

send: FIN (6)

active open

; send: SYN (1)

recv: FIN
send: ACK
send: <nil>recv: ACK

recv: SYN, ACK (2)
send: ACK (3)

recv: ACK (3)
send: <nil>

send: <nil>recv: ACK (5)

recv: FIN (6)
send: ACK (7)

recv: FIN, ACK
send: ACK

close

(or timeout)

2MSL
timeout

recv: ACK (7)
send: <nil>

passive close

active close

data-transfer
state

passive open

active open

usual path for client boldface: action by local application
usual path for server
Key recv: segment from peer that caused transition

SYN_RECV

CLOSE_WAIT

LAST_ACK

CLOSED

SYN_SENT

FIN_WAIT1

FIN_WAIT2 TIME_WAIT

send: segment sent to peer during transition

CLOSING

recv: FIN (4)
send: ACK (5)

ESTABLISHED

openpassive

close

recv: SYN (1)
send: SYN, ACK (2)

LISTEN

CLOSED
Free download pdf