ICMP(4)

๐Ÿ“ฆ
version 15.1 ยท 4 versions
, in freebsd 15.1, nixpkgs unstable

๐Ÿ’– 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 reply
  • 3, unreach โ€” Destination unreachable
  • 4, squench โ€” Packet loss, slow down
  • 5, redir โ€” Shorter route exists
  • 6, althost โ€” Alternate host address
  • 8, echoreq โ€” Echo request
  • 9, routeradv โ€” Router advertisement
  • 10, routersol โ€” Router solicitation
  • 11, timex โ€” Time exceeded
  • 12, paramprob โ€” Invalid IP header
  • 13, timereq โ€” Timestamp request
  • 14, timerep โ€” Timestamp reply
  • 15, inforeq โ€” Information request
  • 16, inforep โ€” Information reply
  • 17, maskreq โ€” Address mask request
  • 18, maskrep โ€” Address mask reply
  • 30, trace โ€” Traceroute
  • 31, dataconv โ€” Data conversion problem
  • 32, mobredir โ€” Mobile host redirection
  • 33, ipv6-where โ€” IPv6 where-are-you
  • 34, ipv6-here โ€” IPv6 i-am-here
  • 35, mobregreq โ€” Mobile registration request
  • 36, mobregrep โ€” Mobile registration reply
  • 39, skip โ€” SKIP
  • 40, 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 unreachable
  • 1, host-unr, unreach โ€” Host unreachable
  • 2, proto-unr, unreach โ€” Protocol unreachable
  • 3, port-unr, unreach โ€” Port unreachable
  • 4, needfrag, unreach โ€” Fragmentation needed but DF bit set
  • 5, srcfail, unreach โ€” Source routing failed
  • 6, net-unk, unreach โ€” Network unknown
  • 7, host-unk, unreach โ€” Host unknown
  • 8, isolate, unreach โ€” Host isolated
  • 9, net-prohib, unreach โ€” Network administratively prohibited
  • 10, host-prohib, unreach โ€” Host administratively prohibited
  • 11, net-tos, unreach โ€” Invalid TOS for network
  • 12, host-tos, unreach โ€” Invalid TOS for host
  • 13, filter-prohib, unreach โ€” Prohibited access
  • 14, host-preced, unreach โ€” Precedence violation
  • 15, cutoff-preced, unreach โ€” Precedence cutoff
  • 0, redir-net, redir โ€” Shorter route for network
  • 1, redir-host, redir โ€” Shorter route for host
  • 2, redir-tos-net, redir โ€” Shorter route for TOS and network
  • 3, redir-tos-host, redir โ€” Shorter route for TOS and host
  • 0, normal-adv, routeradv โ€” Normal advertisement
  • 16, common-adv, routeradv โ€” Selective advertisement
  • 0, transit, timex โ€” Time exceeded in transit
  • 1, reassemb, timex โ€” Time exceeded in reassembly
  • 0, badhead, paramprob โ€” Invalid option pointer
  • 1, optmiss, paramprob โ€” Missing option
  • 2, badlen, paramprob โ€” Invalid length
  • 1, unknown-ind, photuris โ€” Unknown security index
  • 2, auth-fail, photuris โ€” Authentication failed
  • 3, 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 is icmplim plus a random jitter limited by icmplim_jitter. if set to zero, no limiting will occur. Defaults to 200.
  • icmplim_jitter โ€” (unsigned integer) A random jitter between the negative of icmplim_jitter and icmplim_jitter is applied to icmplim for limiting the sending rate of replies. ๐ŸŒ€ icmplim_jitter must be smaller than icmplim, if icmplim is 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) When maskrepl is 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