Why does TCP segment contain source and destination port numbers while this information is already present in Network layer Datagram (IP)?

Can't we make use of the latter to get port numbers?

  • A port number is an address for some transport protocols (TCP and UDP), the same way that a MAC address is an address for some data-link protocols (IEEE LAN protocols), and an IP address (either IPv4 or IPv6) is an address for for a network/internet protocol. Each type of address is found in the header of the layer of the network stack it serves.
    – Ron Maupin
    Apr 22 '18 at 14:03

Huh? I assume your "network layer datagram" is supposed to be the IP packet - the IP packet just carries the protocol number for the transport layer, nothing else transport-layer specific.

The headers's protocol number field containing 0x06 indicates that the packet's payload is a TCP segment.

The TCP segment has got its own header indicating the source and destination port numbers.

You can check out what's in the headers yourself:

IPv4: https://en.wikipedia.org/wiki/IPv4#Header

IPv6: https://en.wikipedia.org/wiki/IPv6_packet#Fixed_header

TCP: https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure

  • the IP packet carries address and port number of sender and receiver, I meant can't we make use of this info rather than adding it again in TCP segment
    – Jrct
    Apr 21 '18 at 19:31
  • 2
    There's no port number in the IP packet header. If present, the port number is a property of the transport layer and present in the TCP/UDP/... header.
    – Zac67
    Apr 21 '18 at 19:44
  • ohh thanks. So in NAT, does the router change the port numbers in TCP segment?
    – Jrct
    Apr 21 '18 at 20:05
  • Often it does (NAPT), but not necessarily so.
    – Zac67
    Apr 21 '18 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.