ICMP6

Internet Control Message Protocol for IP6

Synopsis:

#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/icmp6.h>

int socket( AF_INET6, 
            SOCK_RAW, 
            proto);

Description:

ICMP6 is the error and control message protocol that IP6 and the Internet Protocol family use. It may be accessed through a “raw socket” for network monitoring and diagnostic functions. Use the getprotobyname() function to obtain the proto parameter to the socket() function, or simply pass IPPROTO_ICMPV6.

ICMPv6 sockets are connectionless, and are normally used with the sendto() and recvfrom() functions. You may also use the connect() function to fix the destination for future packets (in which case, you may also use the read() or recv() functions and the write() or send() system calls).

Outgoing packets automatically have an IP6 header prepended to them (based on the destination address). The ICMP6 pseudo header checksum field (icmp6_cksum, found in the icmp6_hdr structure in <netinet/icmp6.h>) is filled automatically by the socket manager. Incoming packets are received without the IP6 header or extension headers.

Note: This behavior is opposite from both IPv4 raw sockets and ICMPv4 sockets.

ICMP6 type/code filter

Each ICMP6 raw socket has an associated filter whose data type is defined as struct icmp6_filter. This structure, along with the macros and constants defined below are defined in the <netinet/icmp6.h> header.

You can get and set the current filter by calling getsockopt() and setsockopt() with a level of IPPROTO_ICMPV6 and an option name of ICMP6_FILTER.

The following macros operate on an icmp6_filter structure. If the first argument is an integer, it represents an ICMP6 message type, with a value between 0 and 255. The pointer arguments are pointers to the filters that are either set or examined, depending on the macro:

ICMP6_FILTER_SETPASSALL( struct icmp6_filter* )
Pass all ICMPv6 messages to the application.
ICMP6_FILTER_SETBLOCKALL( struct icmp6_filter* )
Block all ICMPv6 messages from the application.
ICMP6_FILTER_SETPASS( int, struct icmp6_filter* )
Pass messages of a certain ICMPv6 type to the application.
ICMP6_FILTER_SETBLOCK( int, struct icmp6_filter* )
Block messages of a certain ICMPv6 type from the application.
ICMP6_FILTER_WILLPASS( int, const struct icmp6_filter* )
Return true or false, depending on whether or not the specified message type is passed to the application.
ICMP6_FILTER_WILLBLOCK( int, const struct icmp6_filter* )
Return true or false, depending on whether or not the specified message type is blocked from the application.

When you create an ICMP6 raw socket, it passes all ICMPv6 message types to the application by default.

Based on:

RFC 2292