Search code examples
ctcpudpprotocolspacket

Protocol of a packet


I'm programming an offline packets decoding program in C under Windows 7 x86.

I wonder how it is possible to know packet protocol, either if it is UDP or TCP?


Solution

  • You can know by checking the IP packet header, there is a Protocol field in the packet header that is used to indicate the type of the packet according to its value :

    • 1 is ICMP
    • 6 is TCP
    • 17 is UDP

    and so on. More information on this is available on Wikipedia

    Edit: Here's the list of all the possible values for that field.

    P.S: I'm assuming IPv4 here, I don't know if things are the same with IPv6