The Internet Control Message Protocol (ICMP) is a network layer protocol used by hosts and routers to communicate network-level information. It allows for error reporting (for unreachable hosts, networks, ports, protocols). It runs in the network layer just “above” IP, in that ICMP messages are carried inside IP datagrams (with protocol number 1), just as TCP or UDP might be.
Structure
ICMP messages have an 8-byte header and variable-sized data section.
- The first byte is for the ICMP type.
- The second byte is for the ICMP code.
- The third and fourth bytes are a checksum of the entire ICMP message.
- And the remaining 4 bytes will vary based on the ICMP type and code.

A list of codes:

Functionality
The ping command sends an ICMP type 8 code 0 echo message to the host, which sends a type 0 code 0 ICMP echo reply.
We’ll observe that ICMP doesn’t correct errors, it simply reports them. Error messages are always sent to the original source, because that’s the only metadata known in the datagram (source/destination addresses). ICMP uses the source IP address to send the error message to the source of the datagram.

