Search code examples
network-programmingtcpudpprotocolstcpclient

How the system identifies the received packet is TCP or UDP?


How our system idenfies whether the packet received is TCP or UDP ? For example we are giving request from our system.Server finds the packets by port number and it will respond to us.

Here how our systems identifies the packet which received is TCP or UDP ?


Solution

  • In the IPv4 header, there is a Protocol field. In IPv6, the field is called Next Header. The content of the field is the same in either case, and it is a protocol number representing the Transport Layer protocol of the IP packet's payload. IANA maintains the Protocol Numbers document.

    When host traffic passes from the Transport Layer protocol to IP, IP fills out which protocol gave the packet payload to it in the IP packet header, and on the other end, IP can tell to which protocol it must pass the packet payload.

    Only some Transport Layer protocols use addresses (ports), so you must first identify the protocol before you can determine which port it may have because the port number is in the Transport Protocol header, and each protocol has a different header. Hence, a UDP port is a different port than a TCP port.