IPv6 addresses are 16 byte quantities, stored in network standard byteorder. The include file
<netinet/in.h> defines this address as a discriminated union.
Sockets bound to the
inet6 family use the following addressing structure:
struct sockaddr_in6 {
uint8_t sin6_len;
sa_family_t sin6_family;
in_port_t sin6_port;
uint32_t sin6_flowinfo;
struct in6_addr sin6_addr;
uint32_t sin6_scope_id;
};
Sockets may be created with the local address “
::” (which is equal to IPv6 address
0:0:0:0:0:0:0:0) to effect “wildcard” matching on incoming messages.
The IPv6 specification defines scoped addresses, like link-local or site-local addresses. A scoped address is ambiguous to the kernel, if it is specified without a scope identifier. To manipulate scoped addresses properly from the userland, programs must use the advanced API defined in RFC 2292. A compact description of the advanced API is available in
ip6(4). If a scoped address is specified without an explicit scope, the kernel may raise an error. Note that scoped addresses are not for daily use at this moment, both from a specification and an implementation point of view.
The KAME implementation supports an extended numeric IPv6 address notation for link-local addresses, like “
fe80::1%de0” to specify “
fe80::1 on
de0 interface”. This notation is supported by
getaddrinfo(3) and
getnameinfo(3). Some of normal userland programs, such as
telnet(1) or
ftp(1), are able to use this notation. With special programs like
ping6(8), you can specify the outgoing interface by an extra command line option to disambiguate scoped addresses.
Scoped addresses are handled specially in the kernel. In kernel structures like routing tables or interface structures, a scoped address will have its interface index embedded into the address. Therefore, the address in some kernel structures is not the same as that on the wire. The embedded index will become visible through a
PF_ROUTE socket, kernel memory accesses via
kvm(3) and on some other occasions. HOWEVER, users should never use the embedded form. For details please consult
http://www.kame.net/dev/cvsweb.cgi/kame/IMPLEMENTATION. Note that the above URL describes the situation with the latest KAME tree, not the
NetBSD tree.