Tcp – How does the transport layer tell UDP apart from TCP

tcptransport-protocoludp

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

Best Answer

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