ICMP(4)

πŸ¦‹ ICMP πŸ¦‹

okay bestie so this is the icmp page from the Kernel Interfaces Manual β€” yes the whole thing, no skips, we're doing this πŸ’…

✨ NAME ✨

icmp β€” Internet Control Message Protocol


🌸 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 use. you can get at it through a β€œraw socket” if you're doing network monitoring or diagnostic stuff β€” very main character of it honestly. the proto parameter you hand to the socket call when you're making an ICMP socket comes from getprotobyname(3). 🫢

ICMP sockets are connectionless, and normally you're vibing with the sendto(2) and recvfrom(2) calls. that said, you can also use connect(2) to lock in the destination for future packets β€” and if you do that, then read(2) or recv(2) and write(2) or send(2) are the moves. ✨

Outgoing packets automatically get an IP header prepended to them (based on the destination address). Incoming packets show up with the IP header and options intact. no cap.

πŸ”₯ Types πŸ”₯

ICMP messages get sorted by the type and code fields sitting in the ICMP header. and psst β€” the abbreviations for the types and codes can be used in rules in pf.conf(5). πŸŽ€

These are the types that 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 these are the codes that are defined πŸ‘‘ (watch out, the numbers repeat across different types, that's just how it is, it's giving overlap):

  • 0 Β· net-unr β€” type unreach β€” Network unreachable
  • 1 Β· host-unr β€” type unreach β€” Host unreachable
  • 2 Β· proto-unr β€” type unreach β€” Protocol unreachable
  • 3 Β· port-unr β€” type unreach β€” Port unreachable
  • 4 Β· needfrag β€” type unreach β€” Fragmentation needed but DF bit set
  • 5 Β· srcfail β€” type unreach β€” Source routing failed
  • 6 Β· net-unk β€” type unreach β€” Network unknown
  • 7 Β· host-unk β€” type unreach β€” Host unknown
  • 8 Β· isolate β€” type unreach β€” Host isolated
  • 9 Β· net-prohib β€” type unreach β€” Network administratively prohibited
  • 10 Β· host-prohib β€” type unreach β€” Host administratively prohibited
  • 11 Β· net-tos β€” type unreach β€” Invalid TOS for network
  • 12 Β· host-tos β€” type unreach β€” Invalid TOS for host
  • 13 Β· filter-prohib β€” type unreach β€” Prohibited access
  • 14 Β· host-preced β€” type unreach β€” Precedence violation
  • 15 Β· cutoff-preced β€” type unreach β€” Precedence cutoff
  • 0 Β· redir-net β€” type redir β€” Shorter route for network
  • 1 Β· redir-host β€” type redir β€” Shorter route for host
  • 2 Β· redir-tos-net β€” type redir β€” Shorter route for TOS and network
  • 3 Β· redir-tos-host β€” type redir β€” Shorter route for TOS and host
  • 0 Β· normal-adv β€” type routeradv β€” Normal advertisement
  • 16 Β· common-adv β€” type routeradv β€” Selective advertisement
  • 0 Β· transit β€” type timex β€” Time exceeded in transit
  • 1 Β· reassemb β€” type timex β€” Time exceeded in reassembly
  • 0 Β· badhead β€” type paramprob β€” Invalid option pointer
  • 1 Β· optmiss β€” type paramprob β€” Missing option
  • 2 Β· badlen β€” type paramprob β€” Invalid length
  • 1 Β· unknown-ind β€” type photuris β€” Unknown security index
  • 2 Β· auth-fail β€” type photuris β€” Authentication failed
  • 3 Β· decrypt-fail β€” type photuris β€” Decryption failed

🧚 MIB Variables 🧚

the ICMP protocol implements a bunch of variables in the net.inet.icmp branch of the sysctl(3) MIB. here's the whole lineup, don't skip, every single one matters:

  • maskrepl β€” (boolean) Enable/disable replies to ICMP Address Mask Request 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.
  • icmplim β€” (integer) Bandwidth limit for ICMP replies in packets/second. If set to zero, no limiting will occur. Defaults to 200.
  • icmplim_output β€” (boolean) Enable/disable logging of ICMP replies bandwidth limiting. Defaults to true.
  • drop_redirect β€” (boolean) Enable/disable dropping of ICMP Redirect packets. Defaults to false.
  • log_redirect β€” (boolean) Enable/disable logging of ICMP Redirect packets. Defaults to false.
  • bmcastecho β€” (boolean) Enable/disable ICMP replies received via broadcast or multicast. Defaults to false.
  • 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.
  • reply_from_interface β€” (boolean) Use the IP address of the interface the packet came through in 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.
  • 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.
  • tstamprepl β€” (boolean) Enable/disable replies to ICMP Timestamp packets. Defaults to true.

πŸ’€ ERRORS πŸ’€

a socket operation may fail and throw one of these back at you, and honestly same:

  • [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.

🌈 SEE ALSO 🌈

recv(2), send(2), inet(4), intro(4), ip(4), pf.conf(5)


⭐ HISTORY ⭐

The icmp protocol appeared in 4.3BSD. a legend, truly, an icon, a moment in history πŸŽ€


πŸ’– okay that's the whole page bestie, you ate that. go ping something and think of me. πŸ’–

and that's a wrap, mwah πŸ’… β€” this was the Debian flavoured version, dated March 26, 2015. iykyk πŸ¦‹

πŸ“¦ where this page comes from