TCP

From bildr

Jump to: navigation, search

TCP (Transmission Control Protocol) is a core protocol of the Internet Protocol Suite along-side IP, creating the TCP/IP transmission standard. Where IP handled addressing and routing, TCP handles the data exchange between hosts. TCP provides reliable, handshaked, guaranteed data transfer, but at the expense of speed. If speed is valued over data reliability, UDP offers a faster alternative.


Contents

Technical Details

Structure

TCP Header

Bit offset012345678910111213141516171819202122232425262728293031
0Source portDestination port
32Sequence number
64Acknowledgment number
96Data offsetReservedC
W
R
E
C
E
U
R
G
A
C
K
P
S
H
R
S
T
S
Y
N
F
I
N
Window Size
128ChecksumUrgent pointer
160
...
Options (if Data Offset > 5)
...

Protocols

TCP segments consist of a header part, and a data part.

The header contains 11 fields: 10 mandatory, 1 optional.


  1. Source Port (16 bits) - port sending the data
  2. Destination Port (16 bits) - port receiving the data
  3. Sequence Number (32 bits) - If the SYN flag is set this is the sequence number. The first data byte is this number plus 1. This the SYN flag is not set, this is the total sequence number
  4. Acknowledgment Number (32 bits) - Ascts as a receipt. If the ACK flag is set, this is the next expected sequence number.
  5. Data Offset (4 bits) - Specifies the size of the header in 32-bit chunks from 5 to 15.
  6. Reserved (4 bits) - not used, set to zero
  7. Flags (8 bits) - 8 flags
    • CWR (1 bit) - Congestion Window Reduced flag: indicates that an ECE flag was received and is being handled
    • ECE (1 bit) - ECN-Echo: If SYN is set, then the peer is ECN capable. If SYN is not set, a packet marked has experiencing congestion was received.
    • URG (1 bit) - Urgent: Urgent pointer field is important
    • ACK (1 bit) - Acknowledgment : Acknowledgment is important, all subsequent packets should have ACK set. Disabling this prevents data verification
    • PSH (1 bit) - Push: push the buffered data to the destination client
    • RST (1 bit) - Reset: reset the connection
    • SYN (1 bit) - Synchronize: Only set on the first packet. Synchronizes the sequence numbers
    • FIN (1 bit) - Finished: Sender is done, no more packets will be sent.
  8. Window (16 bits) - size of receive window which specifies the number of bytes the receiver is willing to accept.
  9. Checksum (16 bits) - 16-bit checksum to verify received data
  10. Urgent Pointer (16 bits) - If URG is set, this is a 16-bit offset from the sequence number indicating the last urgent byte.
  11. Options (variable, up to 120 bits, divisible by 8
    • 0 (8 bits) - End of list
    • 1 (8 bits) - no padding
    • 2,4,SS (32 bits) - max segment size (must have SYN set)
    • 3,3,S (24 bits) - window scale(must have SYN set)
    • 4,2 (16 bits) - selective acknowledgment (must have SYN set)
    • 5,N,BBBB,EEEE,... (variable bits, N is either 10, 18, 26, or 34) - Selective ACK (SACK)
    • 8,10,TTTT,EEEE (80 bits) - Timestamp and echo previous timestamp
    • 14,3,S (24 bits) - Request alternate checksum (must have SYN set)
    • 15,N,... (variable bits) - Alternate checksum

TCP takes place in three phases: connection establishment, data transfer, and connection termination.

TCP also goes between several different state changes throughout its lifespan:

  1. LISTEN - Wait for a connection request.
  2. SYN-SENT - Wait for the peer to send back SYN and ACK
  3. SYN-RECEIVED - Wait for the remote peer to send a confirmation ACK after initial ACK response.
  4. ESTABLISHED - Port ready.
  5. FIN-WAIT-1
  6. FIN-WAIT-2
  7. CLOSE-WAIT
  8. CLOSING
  9. LAST-ACK
  10. TIME-WAIT - Wait to allow time for the peer to receive the ACK (max 4 minutes)
  11. CLOSED - End connection


Checksum

IPv4

As defined by RCF 793.

TCP pseudo-header (IPv4)

Bit offset0-34-78-1516-31
0Source address
32Destination address
64ZerosProtocolTCP length
96Source portDestination port
128Sequence number
160Acknowledgement number
192Data OffsetReservedFlagsWindow
224ChecksumUrgent pointer
256Options (optional)
256/288+Data


IPv6

As defined by RCF 2360.


TCP pseudo-header (IPv6)

Bit offset0 - 78–1516–2324–31
0Source address
32
64
96
128Destination address
160
192
224
256TCP length
288ZerosNext header
320Source portDestination port
352Sequence number
384Acknowledgement number
416Data offset/ReservedFlagsWindow
448ChecksumUrgent pointer
480Options (optional)
480/512+Data


Links

This page is an Article on bildr. Articles are pages that define or explain a concept, method, or generic item.

NOTE: All information contained within this article is pure opinion. Although this article is intended to help people, it may contain faulty or misleading information. This article is not to be considered professional opinion or advice, and is in no way a replacement for reading all safety/instructional documentation. Always remember to protect yourself when handling/using hazardous materials, as well as test new techniques before using them on projects/work intended to be handed in or used.

bildr and its contributers take NO responsibility for the information contained within.