Decoding UDP headers

In the Decoding IP headers recipe of this chapter, we created a decodeIp() function that decoded the IP headers of a packet. If the protocol type was UDP in that function, we called a decodeUdp() function. We will create the decodeUdp() function in this recipe.

The UDP header is a part of the third layer (Protocol layer) of our header stack. This is what the UDP header looks like:

Decoding UDP headers

Let's take a look at the fields of the UDP header:

  • Source Port: This field identifies the port used by the sender, and it can be assumed that any reply should be sent to this port. If no reply is needed or wanted, we should set this port to 0, indicating ...

Get iOS and OS X Network Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.