The Internet Control Message Protocol (ICMP) is an error-reporting mechanism and is used by IP or an upper-layer protocol (TCP or UDP). An ICMP message is encapsulated as a part of an IP datagram and transmitted through the Internet.
An IP datagram contains information about only the source and destination, not about all nodes along the entire path through which the IP datagram passes. The IP datagram can record information about all nodes along the path only when route record options are set in the IP datagram. Therefore, if a device detects an error, it reports the error to the source and not to intermediate devices.
When an error occurs during the IP datagram forwarding, ICMP reports the error to the source of the IP datagram, but does not rectify the error or notify the intermediate devices of the error. A majority of errors generally occur on the source. When an error occurs on an intermediate device, however, the source cannot locate the device on which the error occurs even after receiving the error report.
During the process of forwarding or assembling an IP datagram, if the time to live (TTL) field in the IP datagram is zero, the receiving device sends a Time Exceeded message to the source.
If a host or routing device receives a local UDP or TCP datagram but cannot find the process corresponding to the destination port of the datagram, the host or routing device sends a Port Unreachable message to the source.
If a network is unreachable, route selection fails. If a host is unreachable, message delivery fails. The source device can determine which address is unreachable by checking the IP header and the 64 most significant bits in the original IP datagram (Internet Header + 64 bits of the Original Data Datagram field).
The routing device will discard the message and return an ICMP Net Unreachable message to the source address to inform the source host to stop sending messages to this destination.