TCP Demultiplexing, Checksum Handling, and FTP Header Construction

TCP Demultiplexing, Checksum Handling, and FTP Header Construction

Verified Sources
Nov 4, 2026

When a TCP segment arrives inside an IP datagram, the receiving host must (1) verify the integrity of the TCP segment (via the TCP checksum, which includes a pseudo-header), and then (2) deliver the segment to the correct TCP socket (demultiplexing) based on the 4-tuple: source IP, destination IP, source port, destination port. If demultiplexing fails—e.g., because the destination port number is corrupted—the OS/TCP will not pass the segment up the stack to an application. Instead, standard TCP behavior is to respond with a RST (reset) when appropriate (typically when the segment reaches the TCP layer but no matching listening/established socket exists).
A key nuance: the IP destination host address (the actual receiver) is still correct here: the segment arrives at 130.14.16.19/16 (same /16 destination). The corrupted part is the TCP destination port, not the IP address. Therefore the TCP layer on 130.14.16.19 still gets the segment, but it can’t find a socket matching the destination port, and reacts accordingly.

Mermaid overview of the receive path:

Key terms in this section:

  • demultiplexing
  • pseudo-header
  • RST segment
  • ephemeral port
  • well-known port

TCP Demultiplexing and RST Behavior (Network Fundamentals)

What TCP does when the destination port is corrupted

Given:

  • IP datagram’s destination host (as delivered) = 130.14.16.19/16
  • TCP segment’s destination port is corrupted
  • It therefore does not match the server’s expected FTP port or any existing connection endpoint at the receiver

The receiving TCP implementation will:

  1. Compute and verify TCP checksum (if checksum is invalid, segment is discarded; OS does not normally send application data anywhere).
  2. Attempt to demultiplex to an existing TCP socket using the corrupted destination port.
  3. If there is no matching socket (no listening FTP control port, and no established connection with that local port), TCP responds with RST to signal “no such connection/port”.

This “RST on no matching socket” behavior is commonly taught as the response to segments arriving for an unused/closed port on the destination host. (It prevents silent failures and helps the sender quickly recognize that the connection cannot be formed.)

Callout (important): If the destination IP itself were corrupted such that the datagram never reached 130.14.16.19, then the receiver TCP would never see it. Here, only the TCP destination port is wrong, so TCP at 130.14.16.19 still receives the segment but can’t deliver it.

Warning: checksum vs. destination-port corruption

Even if the destination port is wrong, TCP must still pass checksum verification to reach demultiplexing. If the checksum is bad, the segment is dropped and the OS won’t perform socket lookup or send an RST due to port mismatch.

FTP ports to use in the TCP header you must construct

For classic FTP:

  • well-known port for FTP control is 21.
  • FTP often uses ephemeral ports for the client side during the control connection (the client picks a temporary source port from the ephemeral range).

So in your constructed TCP header:

  • Choose a client ephemeral source port, e.g. 49152 (an appropriate ephemeral range value).
  • Set the server destination port to the FTP control port 21.

Because the problem statement says the destination port address is corrupted and arrives at the destination host, the real receive behavior is about mismatched destination port. But for the “Show the entries for the header … from an FTP client to an FTP server” construction, we should fill the correct FTP server well-known port number in the TCP destination port field (21) and use an ephemeral client source port.

Construct a TCP header for an FTP client → FTP server message (with checksum field = all Os)

  1. 1
    Step 1

    Source IP = 130.14.16.17 (given datagram origin context); Destination IP = 130.14.16.19 (given arrival host). Choose ephemeral source port = 49152, and set TCP destination port = 21.

  2. 2
    Step 2

    TCP segment carries application data of length 40 bytes. So TCP header fields should reflect: Data Offset = 5 (20-byte TCP header), and Total length in IP would be header (20) + TCP header (20) + data (40) if you were constructing IP too.

  3. 3
    Step 3

    Set Sequence Number and Acknowledgment Number to placeholders if not specified (commonly 0 for a first segment in simplified exercises, but any value consistent with the question’s simplification is acceptable). Set Flags appropriate for an FTP control connection segment. If no connection establishment step is specified, you can model it as a data segment with PSH+ACK.

  4. 4
    Step 4

    The checksum field is requested to be filled with Os. Interpret this as 16 bits of ASCII/bit zeros: checksum = 0x0000.

  5. 5
    Step 5

    Data Offset = 5 implies 20 bytes TCP header. With 40 bytes payload, Total TCP segment length = 60 bytes.

TCP header fields (what you would write)

Below is a conventional TCP header layout. Since the question asks “Show the entries for the header of a TCP segment … Fill the checksum field with Os … The length of the data is 40 bytes,” the main required numeric choices are ports, checksum, and payload length. For fields not specified, common simplified placeholders are used.

Example TCP header (field-by-field)

Assume:

  • Source IP: 130.14.16.17
  • Destination IP: 130.14.16.19
  • TCP Source Port (ephemeral): 49152
  • TCP Destination Port (FTP control well-known): 21
  • Data length = 40 bytes
  • TCP header length = 20 bytes (Data Offset = 5)
  • TCP flags: PSH + ACK (data-bearing segment)
TCP Header FieldValue to writeNotes
Source Port49152ephemeral port
Destination Port21FTP control well-known port
Sequence Number0 (placeholder)not specified in prompt
Acknowledgment Number0 (placeholder)not specified in prompt
Data Offset55×45 \times 4 = 20 bytes header
Reserved0standard
FlagsPSH=1, ACK=1common data segment assumption
Window0 (placeholder)not specified
Checksum0x0000 (Os)requested “Os” ⇒ zeros
Urgent Pointer0if URG not set
Payload40 bytesapplication data

Callout (pro tip): Many homework questions accept simplified placeholder values for sequence/window when they aren’t explicitly requested—focus on ports, checksum, and consistent data offset/payload length.

Pro Tip: Data Offset consistency

If you set Data Offset to 5 (20-byte TCP header), then payload length 40 bytes implies a TCP segment of 60 bytes total (excluding the IP header).

How the receiving TCP reacts (putting it together)

At 130.14.16.19:

  • If the checksum is verified as correct: TCP proceeds to demultiplexing.
  • Because the destination port is corrupted, no matching socket exists for that local port, so TCP generates an RST (reset) rather than delivering the segment to an application.

If the checksum is not correct, TCP discards the segment and may not send an RST due to port mismatch (implementation-dependent), but the typical assignment expectation is: bad checksum ⇒ drop before demux.

TCP Receive Outcomes (Conceptual)

How receiver behavior changes based on checksum and port demultiplexing success

Receiver Path for an Arriving TCP Segment

IP Delivery to Host

Arrival

Datagram reaches 130.14.16.19 based on IP destination."

TCP Checksum Check

Verification

TCP validates checksum (pseudo-header + TCP segment)."

Socket Demultiplexing

Delivery Decision

Match (srcIP, dstIP, srcPort, dstPort) to a TCP socket."

RST or Deliver

Reaction to Error

If no socket matches due to corrupted destination port: send RST; otherwise deliver to application."

TCP & FTP Ports + Demux + Error Reaction

1 / 5
Question · Term

What is demultiplexing in TCP?

Click to reveal
Answer · Definition

Selecting the correct TCP socket based on header fields (especially ports) after checksum verification.

Common Edge Cases

Knowledge Check

Question 1 of 4
Q1Single choice

A TCP segment arrives at destination host 130.14.16.19, but its TCP destination port is corrupted so no socket matches it. What is the typical TCP reaction?