So I'm reading Computer Networking: A top down approach (where these images are from) and I was looking at the Transport layer.

A generic segment in the transport layer has a pretty simple structure: source port, destination port, some other header fields, and application data.

Then comes UDP and TCP, which are also from the transport layer, but have some differences in how they're handled and all of that.

Looking at the images bellow, there's really no field where the segment can be identified as TCP or UDP, right?

So when the PC tries to demultiplex the segment into the respective socket, how does it know whether it is UDP or TCP?

enter image description here enter image description here enter image description here

  • Please take care about the "generic segment structure": Apart from UDP and TCP there are other transport layer protocols like GRE. These protocols do not necessarily have "source port" and "destination port" fields. And if they do have, it is not guaranteed that the port numbers are 16 bits wide, and if they are, it is not guaranteed that they are located in the first 32 bits of the segment. – Martin Rosenau Jan 19 '19 at 21:44
  • So that information is always stored in the underlying layer and transmitted to the transport layer? – Myntekt Jan 20 '19 at 22:09
  • The type of layer-4 protocol is always stored in the IP header (layer-3 header). When an IP packet arrives, the IP software is responsible for calling the UDP software, TCP software or GRE software etc. Therefore the information if the packet is a UDP or a TCP packet is needed by the IP software, not by the TCP or UDP software. For this reason it makes sense to store it in the IP header. – Martin Rosenau Jan 21 '19 at 6:17

IP knows. For IPv4 there is a 8bit protocol field where 6 represents TCP and 17 UDP. In IPv6 there is an equivalent next-header.

You can see all reserved protocol types here: https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml

| improve this answer | |

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.