Reference

icmp(4)

Internet Control Message Protocol

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

ICMP is the error and control message protocol used by IP and the Internet protocol family. It may be accessed through a “raw socket” for network monitoring and diagnostic functions. The proto parameter to the socket call to create an ICMP socket is obtained from getprotobyname(3). ICMP sockets are connectionless, and are normally used with the sendto(2) and recvfrom(2) calls, though the connect(2) call may also be used to fix the destination for future packets (in which case the read(2) or recv(2) and write(2) or send(2) system calls may be used).

Outgoing packets automatically have an IP header prepended to them (based on the destination address). Incoming packets are received with the IP header and options intact.

Types

ICMP messages are classified according to the type and code fields present in the ICMP header. The abbreviations for the types and codes may be used in rules in pf.conf(5). The following types are defined:

NumAbbrev.Description
0echorepEcho reply
3unreachDestination unreachable
4squenchPacket loss, slow down
5redirShorter route exists
6althostAlternate host address
8echoreqEcho request
9routeradvRouter advertisement
10routersolRouter solicitation
11timexTime exceeded
12paramprobInvalid IP header
13timereqTimestamp request
14timerepTimestamp reply
15inforeqInformation request
16inforepInformation reply
17maskreqAddress mask request
18maskrepAddress mask reply
30traceTraceroute
31dataconvData conversion problem
32mobredirMobile host redirection
33ipv6-whereIPv6 where-are-you
34ipv6-hereIPv6 i-am-here
35mobregreqMobile registration request
36mobregrepMobile registration reply
39skipSKIP
40photurisPhoturis

The following codes are defined:

NumAbbrev.TypeDescription
0net-unrunreachNetwork unreachable
1host-unrunreachHost unreachable
2proto-unrunreachProtocol unreachable
3port-unrunreachPort unreachable
4needfragunreachFragmentation needed but DF bit set
5srcfailunreachSource routing failed
6net-unkunreachNetwork unknown
7host-unkunreachHost unknown
8isolateunreachHost isolated
9net-prohibunreachNetwork administratively prohibited
10host-prohibunreachHost administratively prohibited
11net-tosunreachInvalid TOS for network
12host-tosunreachInvalid TOS for host
13filter-prohibunreachProhibited access
14host-precedunreachPrecedence violation
15cutoff-precedunreachPrecedence cutoff
0redir-netredirShorter route for network
1redir-hostredirShorter route for host
2redir-tos-netredirShorter route for TOS and network
3redir-tos-hostredirShorter route for TOS and host
0normal-advrouteradvNormal advertisement
16common-advrouteradvSelective advertisement
0transittimexTime exceeded in transit
1reassembtimexTime exceeded in reassembly
0badheadparamprobInvalid option pointer
1optmissparamprobMissing option
2badlenparamprobInvalid length
1unknown-indphoturisUnknown security index
2auth-failphoturisAuthentication failed
3decrypt-failphoturisDecryption failed

MIB (sysctl) Variables

The ICMP protocol implements a number of variables in the net.inet.icmp branch of the sysctl(3) MIB, which can also be read or modified with sysctl(8).

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:

[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), sysctl(3), dtrace_mib(4), inet(4), intro(4), ip(4), pf.conf(5), sysctl(8)

HISTORY

The icmp protocol implementation appeared in 4.2BSD.

History