ICMP // RFC 792
The control and error plane of IPv4. ICMP has an eight-byte common header and a type-specific body: echo requests keep latency probes simple, while unreachable and time-exceeded messages quote the packet that caused them. No ports, no pseudo-header, and no security beyond the checksum.
01Message layout
common header · 8 bytesEvery ICMPv4 message starts with Type, Code and a 16-bit Checksum. The next four bytes are the rest of header: their meaning is fixed by the type and code, not by the common header. Everything after byte eight is the message body. The checksum covers the complete ICMP message, including the body, and not the IPv4 header that carries it.
ICMPv4 is a network-layer protocol, not a transport protocol. It has no source or
destination ports and its checksum does not include an IPv4 pseudo-header.
ICMPv6 is different: it uses next header 58, a separate type space and a
checksum that includes the IPv6 pseudo-header.
02Types & codes
information, errors and diagnosticsThe 8-bit type selects the message class; the 8-bit code refines it. Echo and timestamp messages are informational, while unreachable, redirect, time-exceeded and parameter-problem messages report errors. A handful of old types are formally deprecated and should be ignored or filtered.
08 00
RFC 792
| Type | Message | Common codes | Rest of header | Body | Reference |
|---|---|---|---|---|---|
0 | Echo Reply | 0 | Identifier + Sequence | Echoed payload | RFC 792 |
3 | Destination Unreachable | 0 net · 1 host · 2 protocol · 3 port · 4 frag needed | Unused + Length + MTU/unused | Original IPv4 header + 8+ bytes | RFC 792 · RFC 1191 · RFC 4884 |
4 | Source Quench | 0 | Unused | Original datagram | RFC 792 · deprecated |
5 | Redirect | 0 net · 1 host · 2 TOS+net · 3 TOS+host | Gateway IPv4 address | Original datagram | RFC 792 |
8 | Echo Request | 0 | Identifier + Sequence | Echo payload | RFC 792 |
9 | Router Advertisement | 0 | Num Addrs + Entry Size + Lifetime | Router entries | RFC 1256 |
10 | Router Solicitation | 0 | Reserved | No body | RFC 1256 |
11 | Time Exceeded | 0 TTL · 1 reassembly | Unused + Length + unused | Original datagram | RFC 792 · RFC 4884 |
12 | Parameter Problem | 0 pointer · 1 missing option · 2 bad length | Pointer + Length + unused | Original datagram | RFC 792 · RFC 4884 |
13 | Timestamp Request | 0 | Identifier + Sequence | Three 32-bit timestamps | RFC 792 |
14 | Timestamp Reply | 0 | Identifier + Sequence | Three 32-bit timestamps | RFC 792 |
17 | Address Mask Request | 0 | Identifier + Sequence | 4-byte subnet mask | RFC 950 · deprecated |
18 | Address Mask Reply | 0 | Identifier + Sequence | 4-byte subnet mask | RFC 950 · deprecated |
30 | Traceroute | 0 | ID + hop counts | Type-specific | RFC 1393 · obsolete |
42 | Extended Echo Request | 0 | Identifier + Sequence + L | RFC 4884 extension | RFC 8335 |
43 | Extended Echo Reply | 0–4 | Identifier + Sequence + flags | RFC 4884 extension | RFC 8335 |
Common code values
| Type | Code | Meaning | Why it matters |
|---|---|---|---|
3 | 0 | Network Unreachable | No route to the destination network. |
3 | 1 | Host Unreachable | The last-hop network cannot reach the host. |
3 | 2 | Protocol Unreachable | No upper-layer protocol handler on the target. |
3 | 3 | Port Unreachable | UDP port closed; also used by some TCP stacks. |
3 | 4 | Fragmentation Needed and DF Set | Path-MTU Discovery; the rest-of-header carries the next-hop MTU. |
3 | 9/10 | Network / host administratively prohibited | A firewall or routing policy rejected the packet. |
3 | 13 | Communication Administratively Prohibited | Common firewall rejection code. |
5 | 0–3 | Redirect for network / host / TOS variants | Router suggests a better next hop; usually ignored for security. |
11 | 0 | TTL Exceeded in Transit | The building block of traceroute. |
11 | 1 | Fragment Reassembly Time Exceeded | A fragmented datagram did not arrive in time. |
12 | 0 | Pointer Indicates Error | The pointer names the malformed octet in the original header. |
12 | 1 | Missing Required Option | An option required by the type or code was absent. |
12 | 2 | Bad Length | The original datagram's length field is inconsistent. |
type 8 / code 0Echo request; the reply is type 0 with the same identifier, sequence and payload.type 11 / code 0Routers report TTL expiry. The quoted original datagram identifies the probe.type 3 / code 4“Fragmentation needed and DF set” carries the next-hop MTU. Blocking it can black-hole TCP.type 3 / code 3UDP has no handshake; this is often the only signal that a service is closed.type 12 / code 0The pointer identifies the offending octet. Useful when an option or length field is malformed.type 5 / code 1An ICMP redirect points at another gateway. Most hosts ignore redirects by default.Any host that can reach the path can send an ICMP error. The checksum protects against accidental corruption, not forgery. Validate quoted datagrams before changing connection state, rate-limit ICMP generation, and do not blanket-drop all ICMP: path-MTU discovery and IPv6 depend on it.
03Rest-of-header formats
the same 32 bits, different meaningsThe second 32-bit word — the four bytes after the checksum — is where most ICMP parsers go wrong. Echo uses an identifier and sequence; redirect carries a gateway address; Parameter Problem carries a pointer. The error types that quote an original datagram also use the sixth octet for an RFC 4884 Length field when an extension structure is present.
| Type(s) | Bits 32–63 | Body interpretation | Reference |
|---|---|---|---|
0, 8, 13, 14, 15, 16, 17, 18 | Identifier (16) · Sequence (16) | Echo payload, timestamp fields or subnet mask. | RFC 792 · RFC 950 |
3 | Unused (8) · Length (8) · Next-Hop MTU or unused (16) | Original IPv4 header plus quoted payload; code 4 supplies the MTU. | RFC 792 · RFC 1191 · RFC 4884 |
4 | Unused (32) | Deprecated Source Quench. | RFC 792 · RFC 6633 |
5 | Gateway IPv4 address (32) | Original datagram after the ICMP header. | RFC 792 |
9 | Num Addrs (8) · Addr Entry Size (8) · Lifetime (16) | Router address and preference entries. | RFC 1256 |
10 | Reserved (32) | No body. | RFC 1256 |
11 | Unused (8) · Length (8) · unused (16) | Original datagram plus optional RFC 4884 extensions. | RFC 792 · RFC 4884 |
12 | Pointer (8) · Length (8) · unused (16) | Original datagram; pointer identifies the malformed octet. | RFC 792 · RFC 4884 |
42 | Identifier (16) · Sequence (8) · Reserved (7) · L (1) | RFC 4884 extension structure identifying the probed interface. | RFC 8335 |
43 | Identifier (16) · Sequence (8) · State (3) · Res (2) · A · 4 · 6 | Extended Echo Reply flags and state. | RFC 8335 |
Before extensions, the sixth octet of Destination Unreachable, Time Exceeded and Parameter Problem was “unused.” RFC 4884 redefined it as the length of the original datagram in 32-bit words. A value of zero means no extension structure. When it is non-zero, the original datagram is padded to a 32-bit boundary and an extension header (version 2) follows it.
04Encoder
checksum computed over the full messageBuild an ICMPv4 message with the type-specific rest-of-header. The checksum is calculated after the header and body are assembled. Optionally wrap the message in a minimal IPv4 packet so you can paste a complete on-wire unit into a lab tool or capture.
ICMP parameters
RFC 792The encoder computes the ICMP checksum first, then the IPv4 header checksum when wrapping. It does not add Ethernet framing or an FCS; use the Ethernet explorer for that layer.
wire output
waitingno bytes built yet
A correct checksum only means the bytes arrived intact. A forged ICMP redirect or unreachable message is still a valid ICMP message; the receiver must decide whether the sender is credible.
05Decoder
raw ICMP, IPv4 packet or Ethernet frame
Paste an ICMP message, an IPv4 packet with Protocol 1, or an Ethernet II
frame carrying IPv4. The decoder validates both checksums, follows the type-specific
rest-of-header, and parses quoted original datagrams and RFC 4884 extensions. Raw ICMP
is accepted directly, which is useful when your capture tool strips the IP header.
parse bytes
RFC 792 · type-specific body06Wire notes
what the pcap does not tell youICMPv6 is IPv6 next header 58 and is defined by RFC 4443. It has a different
type/code space, includes Neighbor Discovery (RFC 4861) and uses an IPv6 pseudo-header in
its checksum. Do not reuse an ICMPv4 checksum routine or type table for ICMPv6. The IPv6 explorer covers the base header and next-header chain.
- The checksum covers only ICMP. For ICMPv4, sum the eight-byte header and the entire body. There is no pseudo-header. A receiver summing the message including the checksum should get
0xFFFF. - Error messages quote the trigger. Destination Unreachable, Redirect, Source Quench, Time Exceeded and Parameter Problem carry the original IPv4 header and at least eight bytes of its payload. The quote may be truncated or rewritten by NAT.
- Length is in 32-bit words. RFC 4884 reuses the sixth octet for the length of the original datagram when an extension structure is present. Zero means no extension. The quoted datagram is padded to a 4-byte boundary.
- Type 3 code 4 is path-MTU discovery. The next-hop MTU in the rest-of-header tells the sender how small to fragment. Filtering this message can cause TCP black holes, especially with DF set.
- TTL expiry is not an error in the transport sense. Time Exceeded is normal traceroute behavior. The quoted datagram is how the sender knows which probe expired.
- Redirects are a security liability. A host that accepts ICMP redirects can be steered through an attacker. Most modern stacks ignore redirects by default or require strict source/interface checks.
- No authentication. ICMP has no signature, nonce or source authentication. The checksum detects accidental corruption only. ICMP filtering, rate limiting and quoted-packet validation are operational controls, not protocol guarantees.
- Deprecated does not mean absent. RFC 6633 deprecates Source Quench; RFC 6918 deprecates types 6, 15, 16, 17, 18 and 30–39. Old devices and lab traffic still emit them.
References
- RFC 792ICMP
- RFC 1122Host requirements
- RFC 1812Router requirements
- RFC 1191Path MTU Discovery
- RFC 950Address Mask Request/Reply
- RFC 1256Router Discovery
- RFC 1393Traceroute message
- RFC 4884ICMP extensions
- RFC 8335Extended Echo / PROBE
- RFC 6633Source Quench deprecation
- RFC 6918Deprecated ICMPv4 types
- RFC 4443ICMPv6