Decoding ICMP 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 ICMP in that function, we called a decodeICMP() function. We will create the decodeICMP() function in this recipe.

Even though our layer diagram shows the ICMP packet as a part of the Internet layer, from the libpcap point of view, it is a part of the third layer (Protocol layer) of our header stack; this is because the IP header encapsulates the ICMP header.

Decoding ICMP headers

The ICMP header looks like this:

The components are explained as follows:

  • ICMP Type: This field identifies the ICMP message ...

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.