NAME | SYNOPSIS | DESCRIPTION | DIAGNOSTICS | ATTRIBUTES | SEE ALSO
#include <sys/socket.h> #include <netinet.h> #include <netinet/icmp6.h>int socket(AF_INET6, SOCK_RAW, proto);
ICMPv6 is the error and control message protocol used by IPv6 and the Internet protocol family. It can be accessed through a raw socket for network monitoring and diagnostic functions. The proto parameter to the socket call to create an ICMPv6 socket is obtained from getprotobyname(3POSIX), or you can use IPPROTO_ICMPV6. ICMPv6 sockets are connectionless, and are normally used with the sendto(2POSIX) and recvfrom(2POSIX) calls, though the connect(2POSIX) call may also be used to fix the destination for future packets (in which case the read(2POSIX) or recv(2POSIX) and write(2POSIX) or send(2POSIX) system calls may be used).
Outgoing packets automatically have an IPv6 header prepended to them (based on the destination address). ICMPv6 pseudo header checksum field (icmp6_cksum) will be filled automatically by the microkernel. Incoming packets are received without the IPv6 header nor IPv6 extension headers. Note that this behavior is opposite from IPv4 raw sockets and ICMPv4 sockets.
Each ICMPv6 raw socket has an associated filter whose datatype is defined as struct icmp6_filter.
This structure, along with the macros and constants defined later in this section, are defined as a result of including the <netinet/icmp6.h> header.
The current filter is fetched and stored using getsockopt(2POSIX) and setsockopt(2POSIX) with a level of IPPROTO_ICMPV6 and an option name of ICMP6_FILTER.
Six macros operate on an icmp6_filter structure:
ICMP6_FILTER_SETPASSALL(struct icmp6_filter *)
ICMP6_FILTER_SETBLOCKALL(struct icmp6_filter *)
ICMP6_FILTER_SETPASS(int, struct icmp6_filter *)
ICMP6_FILTER_SETBLOCK(int, struct icmp6_filter *)
ICMP6_FILTER_WILLPASS(int, const struct icmp6_filter *)
ICMP6_FILTER_WILLBLOCK(int, const struct icmp6_filter *)
The first argument to the last four macros (an integer) is an ICMPv6 message type, between 0 and 255. The pointer argument to all six macros is a pointer to a filter that is modified by the first four macros examined by the last two macros.
The first two macros, SETPASSALL and SETBLOCKALL, let us specify that all ICMPv6 messages are passed to the application or that all ICMPv6 messages are blocked from being passed to the application.
The next two macros, SETPASS and SETBLOCK, let us specify that messages of a given ICMPv6 type should be passed to the application or not passed to the application (blocked).
The final two macros, WILLPASS and WILLBLOCK, return true or false depending on whether the specified message type is passed to the application or blocked from being passed to the application by the filter pointed to by the second argument.
When an ICMPv6 raw socket is created, it will by default pass all ICMPv6 message types to the application.
For further discussions see RFC2292.
A socket operation may fail and return one of the following error conditions:
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.
When trying to send a datagram with no destination address specified, and the socket is not connected.
When the system runs out of memory for an internal data structure.
When an attempt is made to create a socket with a network address for which no network interface exists.
See attributes(5) for descriptions of the following attributes:
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|---|---|
| Interface Stability | Evolving |
NAME | SYNOPSIS | DESCRIPTION | DIAGNOSTICS | ATTRIBUTES | SEE ALSO