ICMP(4)
๐ ICMP(4) โ the icmp girlies' guide ๐
okay so this is the ICMP page from the Kernel Interfaces Manual, and bestie, it's lowkey one of the most iconic protocols out there โ you just never noticed it carrying the whole internet on its back. ๐ซถ
โจ NAME โจ
icmp โ Internet Control Message Protocol. that's it, that's the name, no cap. ๐
๐ SYNOPSIS ๐
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int
socket(AF_INET, SOCK_RAW, proto);
๐ฆ DESCRIPTION ๐ฆ
so ICMP is the error-and-control-message protocol that IP and the whole Internet protocol family lean on. it gives main character energy to network monitoring and diagnostic functions, and you're allowed to talk to it through a "raw socket" โ yes, raw, like sushi, we love her. ๐
the proto parameter you pass to the socket call to create an ICMP socket? you get that from getprotobyname(3). periodt.
ICMP sockets are connectionless (free spirits, no strings attached โจ) and are normally used with the sendto(2) and recvfrom(2) calls โ though you can use connect(2) to fix the destination for future packets, and in that case the read(2) or recv(2) and write(2) or send(2) system calls are fair game too. slay, options. ๐
outgoing packets automatically get an IP header prepended to them (based on the destination address). incoming packets arrive with the IP header and options intact. literally untouched, we respect the original. ๐
๐ Types ๐
ICMP messages get classified according to the type and code fields chilling in the ICMP header. and here's the cute part โ those abbreviations for the types and codes may be used in rules in pf.conf(5). iykyk. ๐ฅ
the following types are defined:
0,echorepโ Echo reply3,unreachโ Destination unreachable4,squenchโ Packet loss, slow down5,redirโ Shorter route exists6,althostโ Alternate host address8,echoreqโ Echo request9,routeradvโ Router advertisement10,routersolโ Router solicitation11,timexโ Time exceeded12,paramprobโ Invalid IP header13,timereqโ Timestamp request14,timerepโ Timestamp reply15,inforeqโ Information request16,inforepโ Information reply17,maskreqโ Address mask request18,maskrepโ Address mask reply30,traceโ Traceroute31,dataconvโ Data conversion problem32,mobredirโ Mobile host redirection33,ipv6-whereโ IPv6 where-are-you34,ipv6-hereโ IPv6 i-am-here35,mobregreqโ Mobile registration request36,mobregrepโ Mobile registration reply39,skipโ SKIP40,photurisโ Photuris
and the following codes are defined โ note the number, the abbrev, which type it belongs to, and the description, because all of it matters bestie ๐ซถ:
0,net-unr,unreachโ Network unreachable1,host-unr,unreachโ Host unreachable2,proto-unr,unreachโ Protocol unreachable3,port-unr,unreachโ Port unreachable4,needfrag,unreachโ Fragmentation needed but DF bit set5,srcfail,unreachโ Source routing failed6,net-unk,unreachโ Network unknown7,host-unk,unreachโ Host unknown8,isolate,unreachโ Host isolated9,net-prohib,unreachโ Network administratively prohibited10,host-prohib,unreachโ Host administratively prohibited11,net-tos,unreachโ Invalid TOS for network12,host-tos,unreachโ Invalid TOS for host13,filter-prohib,unreachโ Prohibited access14,host-preced,unreachโ Precedence violation15,cutoff-preced,unreachโ Precedence cutoff0,redir-net,redirโ Shorter route for network1,redir-host,redirโ Shorter route for host2,redir-tos-net,redirโ Shorter route for TOS and network3,redir-tos-host,redirโ Shorter route for TOS and host0,normal-adv,routeradvโ Normal advertisement16,common-adv,routeradvโ Selective advertisement0,transit,timexโ Time exceeded in transit1,reassemb,timexโ Time exceeded in reassembly0,badhead,paramprobโ Invalid option pointer1,optmiss,paramprobโ Missing option2,badlen,paramprobโ Invalid length1,unknown-ind,photurisโ Unknown security index2,auth-fail,photurisโ Authentication failed3,decrypt-fail,photurisโ Decryption failed
๐ฎ MIB (sysctl) Variables ๐ฎ
the ICMP protocol implements a whole lil collection of variables in the net.inet.icmp branch of the sysctl(3) MIB โ and you can also read or modify them with sysctl(8). choose your fighter. ๐
bmcastechoโ (boolean) Enable/disable ICMP replies received via broadcast or multicast. Defaults to false.drop_redirectโ (boolean) Enable/disable dropping of ICMP Redirect packets. Defaults to false.icmplimโ (unsigned integer) Mean rate limit for replies in packets/second. the actual limit isicmplimplus a random jitter limited byicmplim_jitter. if set to zero, no limiting will occur. Defaults to 200.icmplim_jitterโ (unsigned integer) A random jitter between the negative oficmplim_jitterandicmplim_jitteris applied toicmplimfor limiting the sending rate of replies. ๐icmplim_jittermust be smaller thanicmplim, ificmplimis not zero. if set to zero, no jitter will be applied. Defaults to 16.icmplim_outputโ (boolean) Enable/disable logging of ICMP replies bandwidth limiting. Defaults to true.log_redirectโ (boolean) Enable/disable logging of ICMP Redirect packets. Defaults to false.maskfakeโ (unsigned integer) Whenmaskreplis set and this value is non-zero, it will be used instead of the real address mask when the system replies to an ICMP Address Mask Request packet. Defaults to 0.maskreplโ (boolean) Enable/disable replies to ICMP Address Mask Request packets. Defaults to false.quotelenโ (integer) Number of bytes from original packet to quote in ICMP reply. this number is internally enforced to be at least 8 bytes (per RFC792) and at most the maximal space left in the ICMP reply mbuf. ๐redirtimeoutโ (integer) Delay in seconds before expiring route created by ICMP redirect.reply_from_interfaceโ (boolean) Use the IP address of the interface the packet came in through for responses to packets which are not directly addressed to us. if enabled, this rule is processed before all others. by default, continue with normal source selection. Enabling this option is particularly useful on routers because it makes external traceroutes show the actual path a packet has taken instead of the possibly different return path. ๐ฅreply_srcโ (str) An interface name used for the ICMP reply source in response to packets which are not directly addressed to us. by default continue with normal source selection.tstampreplโ (boolean) Enable/disable replies to ICMP Timestamp packets. Defaults to true.
๐ ERRORS ๐
a socket operation may fail with one of the following errors returned โ no cap, these are the real ones:
[EISCONN]โ when trying to establish a connection on a socket which already has one, or when trying to send a datagram with the destination address specified and the socket is already connected;[ENOTCONN]โ when trying to send a datagram, but no destination address is specified, and the socket has not been connected;[ENOBUFS]โ when the system runs out of memory for an internal data structure;[EADDRNOTAVAIL]โ when an attempt is made to create a socket with a network address for which no network interface exists.
๐ญ bestie if you're getting ENOBUFS the system is literally out of memory for an internal data structure. it's not you. it's the mbufs.
๐ SEE ALSO ๐
recv(2), send(2), sysctl(3), inet(4), intro(4), ip(4), pf.conf(5), sysctl(8)
๐ธ HISTORY ๐ธ
the icmp protocol implementation appeared in 4.2BSD. vintage. iconic. she's been serving since day one. โจ
๐ that's the whole page bestie โ from Debian, dated December 11, 2024, ICMP(4) forever. go ping something and think of me. ๐๐ฆ๐
๐ฆ where this page comes from
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 1986, 1991, 1993 The Regents of the University of California. All rights reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms