Home

sockaddrin6

sockaddr_in6 is the IPv6 socket address structure used in POSIX-style networking. It is defined in netinet/in.h and is used with socket APIs that operate on socket addresses, such as bind, connect, accept, sendto, and recvfrom. The structure holds the information necessary to identify an IPv6 endpoint.

The structure contains the following fields:

- sin6_family: the address family, which must be AF_INET6.

- sin6_port: the port number in network byte order (use htons to convert from host byte order).

- sin6_flowinfo: a 32-bit field for IPv6 flow information, used for quality-of-service features.

- sin6_addr: the 128-bit IPv6 address, represented by the in6_addr structure (often accessed as an array of

- sin6_scope_id: a platform-dependent scope identifier, used to specify the interface for link-local addresses or other scoped

The in6_addr type holds the actual IPv6 address, and common helpers such as inet_pton and inet_ntop convert

sockaddr_in6 is the IPv6 counterpart to sockaddr_in used for IPv4 (AF_INET). Its size and layout are specific

16
bytes).
addresses.
between
textual
and
binary
forms.
Programs
frequently
populate
sockaddr_in6
via
getaddrinfo
or
by
constructing
the
structure
directly,
setting
sin6_family
to
AF_INET6,
sin6_port
with
htons,
and
sin6_addr
with
a
valid
IPv6
address.
For
listening
sockets,
sin6_addr
is
often
set
to
in6addr_any
to
bind
on
all
interfaces,
while
sin6_scope_id
may
be
set
for
link-local
addresses
to
specify
the
interface.
to
IPv6
and
may
differ
across
platforms,
but
the
required
semantics—family,
port,
address,
and
optional
scope—remain
consistent
for
enabling
IPv6
networking.