The Linux Programming Interface

(nextflipdebug5) #1

1268 Chapter 61


allow the receiving TCP to double-check that an incoming segment has arrived
at the correct destination (i.e., that IP has not wrongly accepted a datagram
that was addressed to another host or passed TCP a packet that should have
gone to another upper layer). UDP calculates the checksum in its packet headers
in a similar manner and for similar reasons. See [Stevens, 1994] for further
details on the pseudoheader.

z Urgent pointer: If the URG control bit is set, then this field indicates the location
of so-called urgent data within the stream of data being transmitted from the
sender to the receiver. We briefly discuss urgent data in Section 61.13.1.
z Options: This is a variable-length field containing options controlling the opera-
tion of the TCP connection.
z Data: This field contains the user data transmitted in this segment. This field
may be of length 0 if this segment doesn’t contain any data (e.g., if it is simply
an ACK segment).

61.6.2 TCP Sequence Numbers and Acknowledgements


Each byte that is transmitted over a TCP connection is assigned a logical sequence
number by TCP. (Each of the two streams in a connection has its own sequence num-
bering.) When a segment is transmitted, its sequence number field is set to the logical
offset of the first byte of data in the segment within the stream of data being
transmitted in this direction over the connection. This allows the receiving TCP to
assemble the received segments in the correct order, and to indicate which data
was received when sending an acknowledgement to the sender.
To implement reliable communication, TCP uses positive acknowledgements;
that is, when a segment is successfully received, an acknowledgement message (i.e.,
a segment with the ACK bit set) is sent from the receiving TCP to the sending TCP,
as shown in Figure 61-3. The acknowledgement number field of this message is set to
indicate the logical sequence number of the next byte of data that the receiver
expects to receive. (In other words, the value in the acknowledgement number
field is the sequence number of the last byte in the segment that it acknowledges,
plus 1.)

Figure 61-3: Acknowledgements in TCP

When the sending TCP transmits a segment, it sets a timer. If an acknowledgement
is not received before the timer expires, the segment is retransmitted.

segment (x bytes)
(Seq # range: N to N+x – 1
)

ACK of segment
(Ack #: N+x)

Sender Receiver

Network

Host A Host B
Free download pdf