#include <sys/socket.h> #include <netinet/in.h> #include <netinet/ip_icmp.h> #include <netinet/icmp6.h>
s = socket(AF_INET6, SOCK_RAW, proto);
t = t_open("/dev/icmp6", O_RDWR);
The ICMP6 protocol is the error and control message protocol used with Version 6 of the Internet Protocol. It is used by the kernel to handle and report errors in protocol processing. It is also used for IPv6 neighbor and router discovery, and for multicast group membership queries and reports. It may also be accessed by programs using the socket interface or the Transport Level Interface (TLI ) for network monitoring and diagnostic functions. When used with the socket interface, a “raw socket” type is used. The protocol number for ICMP6, used in the proto parameter to the socket call, can be obtained from getprotobyname(3SOCKET). ICMP6 file descriptors and sockets are connectionless and are normally used with the t_sndudata / t_rcvudata and the sendto() / recvfrom() calls. They may also be used with the sendmsg()/ recvgmsg() calls when sending or receiving ancillary data.
Outgoing packets automatically have an Internet Protocol Version 6 (IPv6) header and zero or more IPv6 extension headers prepended. These headers are prepended by the kernel. Unlike ICMP for IPv4, the IP_HDRINCL option is not supported for ICMP6, so ICMP6 applications neither build their own outbound IPv6 headers, nor do they receive the inbound IPv6 headers with received data. IPv6 extension headers and relevant fields of the IPv6 header may be set or received as ancillary data to a sendmsg(3SOCKET) or recvmsg(3SOCKET) system call. Each of these fields and extension headers may also be set on a per socket basis with the setsockopt(3SOCKET) system call. Such "sticky" options are used on all outgoing packets unless overridden by ancillary data. When any ancillary data is present with a sendmsg(3SOCKET) system call, all sticky options are ignored for that system call, but subsequently remain configured.
ICMP6 is a datagram protocol layered above IPv6. Received ICMP6 messages may be reflected back to users of higher-level protocols such as TCP or UDP as error returns from system calls. A copy of each ICMP6error message received by the system is provided to every holder of an open ICMP6 socket or TLI descriptor.
Conta, A. and Deering, S., RFC 2463, Internet Control Message Protocol (ICMPv6) for the Internet Protocol Version 6 (IPv6) Specification , The Internet Society, December 1998.
A socket operation may fail with one of the following errors returned:
An attempt was made 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.
An attempt was made to send a datagram, but no destination address is specified, and the socket has not been connected.
The system ran out of memory for an internal data structure.
An attempt was made to create a socket with a network address for which no network interface exists.
The system was unable to allocate memory for an internal data structure.
An attempt was made to set an IPv4 socket option on an IPv6 socket.
An attempt was made to set an invalid or malformed socket option.
An attempt was made to bind or connect to an IPv4 or mapped address, or to specify an IPv4 or mapped address as the next hop.