ipv6(7)

๐Ÿ’– ipv6 โ€” the one where Linux does Internet Protocol version 6 ๐Ÿ’–

okay bestie, welcome to ipv6(7), from the Miscellaneous Information Manual section. this is the Linux IPv6 protocol implementation page and it's lowkey iconic, so let's get into it ๐Ÿฆ‹


โœจ NAME โœจ

ipv6 โ€” Linux IPv6 protocol implementation. that's it, that's the name ๐Ÿ’…


โœจ SYNOPSIS โœจ

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

tcp6_socket = socket(AF_INET6, SOCK_STREAM, 0);
raw6_socket = socket(AF_INET6, SOCK_RAW, protocol);
udp6_socket = socket(AF_INET6, SOCK_DGRAM, protocol);

look at those three socket babies, all lined up ๐Ÿฅน TCP, raw, and UDP โ€” pick your fighter.


โœจ DESCRIPTION โœจ

so. Linux 2.2 optionally implements the Internet Protocol, version 6. yes, "optionally" โ€” it was giving very much optional-at-launch energy. this man page contains a description of the IPv6 basic API as implemented by the Linux kernel and glibc 2.1. ๐ŸŒธ

the interface is based on the BSD sockets interface; go peek at socket(7) for that.

the IPv6 API aims to be mostly compatible with the IPv4 API (see ip(7)). and because it's so sweet and compatible, only the differences are described in this man page. so if you don't see it here, it's probably just like v4. iykyk โœจ

if you wanna bind an AF_INET6 socket to any process, the local address should be copied from the in6addr_any variable, which has type in6_addr. for static initializations you can also use IN6ADDR_ANY_INIT, which expands to a constant expression. both of them are in network byte order, no cap. ๐Ÿ”ฅ

the IPv6 loopback address (::1) lives in the global in6addr_loopback variable. and for initializations, you should use IN6ADDR_LOOPBACK_INIT. she's the homecoming queen of "talk to myself" ๐Ÿ’–

IPv4 connections can be handled with the v6 API by using the v4-mapped-on-v6 address type; so a program only needs to support this one API type and boom โ€” it supports both protocols. that is transparently handled by the address handling functions in the C library. the C library is doing the labor and not even asking for credit, honestly ๐Ÿซถ

IPv4 and IPv6 share the local port space. and when you get an IPv4 connection or packet to an IPv6 socket, its source address will be mapped to v6. automatic glow-up.

๐ŸŽ€ Address format ๐ŸŽ€

struct sockaddr_in6 {
    sa_family_t     sin6_family;   /* AF_INET6 */
    in_port_t       sin6_port;     /* port number */
    uint32_t        sin6_flowinfo; /* IPv6 flow information */
    struct in6_addr sin6_addr;     /* IPv6 address */
    uint32_t        sin6_scope_id; /* Scope ID (new in Linux 2.4) */
};

struct in6_addr {
    unsigned char   s6_addr[16];   /* IPv6 address */
};

okay let's break this down, bestie. ๐Ÿ’…

sin6_family is always set to AF_INET6. always. don't try anything cute.

sin6_port is the protocol port (see sin_port in ip(7)).

sin6_flowinfo is the IPv6 flow identifier.

sin6_addr is the 128-bit IPv6 address.

sin6_scope_id is an ID depending on the scope of the address. it's new in Linux 2.4. Linux supports it only for link-local addresses, and in that case sin6_scope_id contains the interface index (see netdevice(7)).

IPv6 supports several address types, and honestly, she contains multitudes:

  • unicast โ€” to address a single host
  • multicast โ€” to address a group of hosts
  • anycast โ€” to address the nearest member of a group of hosts (not implemented in Linux, so don't get excited)
  • IPv4-on-IPv6 โ€” to address an IPv4 host
  • and other reserved address types

the address notation for IPv6 is a group of 8 4-digit hexadecimal numbers, separated with a ':'. and "::" stands for a string of 0 bits. special addresses are ::1 for loopback and ::FFFF:<IPv4 address> for IPv4-mapped-on-IPv6. ๐ŸŒˆ

also reminder: the port space of IPv6 is shared with IPv4. always has been ๐Ÿ•ฏ๏ธ

๐Ÿ’œ Socket options ๐Ÿ’œ

see IPPROTO_IPV6(2const). that's the whole section, she's brief and mysterious. ๐Ÿ™ˆ


โœจ ERRORS โœจ

  • ENODEV โ€” the user tried to bind(2) to a link-local IPv6 address, but the sin6_scope_id in the supplied sockaddr_in6 structure is not a valid interface index. bestie. the interface index has to be real. ๐Ÿ˜ญ

โœจ VERSIONS โœจ

heads up, this part is giving breaking-change energy: Linux 2.4 will break binary compatibility for the sockaddr_in6 for 64-bit hosts by changing the alignment of in6_addr and adding an additional sin6_scope_id field. ๐Ÿ’€

the kernel interfaces stay compatible, but a program that includes sockaddr_in6 or in6_addr into other structures may not be. this is not a problem for 32-bit hosts like i386. so i386 said "not my problem" and kept eating.

the sin6_flowinfo field is new in Linux 2.4. it is transparently passed/read by the kernel when the passed address length contains it. and some programs that pass a longer address buffer and then check the outgoing address length may break. so if that's youโ€ฆ good luck, girlie ๐Ÿ“


โœจ NOTES โœจ

the sockaddr_in6 structure is bigger than the generic sockaddr. so programs that assume all address types can be stored safely in a struct sockaddr need to be changed to use struct sockaddr_storage for that instead. glow-up required, no wiggle room. โœจ

SOL_IP, SOL_IPV6, SOL_ICMPV6, and other SOL_* socket options are nonportable variants of IPPROTO_*. see also ip(7). nonportable is a choice and she made it ๐Ÿ’…


โœจ BUGS โœจ

  • the IPv6 extended API as in RFC 2292 is currently only partly implemented; although the 2.2 kernel has near complete support for receiving options, the macros for generating IPv6 options are missing in glibc 2.1. ๐Ÿ˜ญ
  • IPSec support for EH and AH headers is missing. ๐Ÿ˜ญ
  • flow label management is not complete and not documented here. ๐Ÿ˜ญ
  • this man page is not complete. ๐Ÿ˜ญ

we're all just doing our best out here, fr fr.


โœจ SEE ALSO โœจ


mwah ๐Ÿ’– that's the whole page. go forth and AF_INET6, bestie, you've got this, periodt. ๐Ÿฆ‹โœจ๐Ÿ‘‘

โ€” from Linux man-pages 6.20, dated 2026-02-08. yes, the date is from the future, and yes, she ate. ๐ŸŽ€

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-1-para
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms