NETINET_IN.H(7) Miscellaneous Information Manual NETINET_IN.H(7)

netinet/in.hInternet address family

#include <netinet/in.h>

The <netinet/in.h> header shall define the following types:

Equivalent to the type uint16_t as described in <inttypes.h> .
Equivalent to the type uint32_t as described in <inttypes.h> .

The <netinet/in.h> header shall define the type as described in <sys/socket.h>.

The <netinet/in.h> header shall define the and types as described in <inttypes.h>. Inclusion of the <netinet/in.h> header may also make visible all symbols from <inttypes.h> and <sys/socket.h>.

The <netinet/in.h> header shall define the structure, which shall include at least the following member:

in_addr_t  s_addr

The <netinet/in.h> header shall define the sockaddr_in structure, which shall include at least the following members:

sa_family_t     sin_family   AF_INET.
in_port_t       sin_port     Port number.
struct in_addr  sin_addr     IP address.

The and members shall be in network byte order.

The sockaddr_in structure is used to store addresses for the Internet address family. Pointers to this type shall be cast by applications to struct sockaddr * for use with socket functions.

[IP6] The <netinet/in.h> header shall define the structure, which shall include at least the following member:

uint8_t s6_addr[16]

This array is used to contain a 128-bit IPv6 address, stored in network byte order.

The <netinet/in.h> header shall define the sockaddr_in6 structure, which shall include at least the following members:

sa_family_t      sin6_family    AF_INET6.
in_port_t        sin6_port      Port number.
uint32_t         sin6_flowinfo  IPv6 traffic class and flow information.
struct in6_addr  sin6_addr      IPv6 address.
uint32_t         sin6_scope_id  Set of interfaces for a scope.

The and sin6_addr members shall be in network byte order.

Prior to calling a function in this standard which reads values from a sockaddr_in6 structure (for example, bind(3) or connect(3)), the application shall ensure that all members of the structure, including any additional non-standard members, if any, are initialized. If the sockaddr_in6 structure has a non-standard member, and that member has a value other than the value that would result from default initialization, the behavior of any function in this standard that reads values from the sockaddr_in6 structure is implementation-defined. All functions in this standard that return data in a sockaddr_in6 structure (for example, getaddrinfo(3) or accept(3)) shall initialize the structure in a way that meets the above requirements, and shall ensure that each non-standard member, if any, has a value that produces the same behavior as default initialization would in all functions in this standard which read values from a sockaddr_in6 structure.

The sin6_scope_id field is a 32-bit integer that identifies a set of interfaces as appropriate for the scope of the address carried in the sin6_addr field. For a link scope sin6_addr, the application shall ensure that sin6_scope_id is a link index. For a site scope sin6_addr, the application shall ensure that sin6_scope_id is a site index. The mapping of sin6_scope_id to an interface or set of interfaces is implementation-defined.

The <netinet/in.h> header shall declare the following external variable:

const struct in6_addr in6addr_any

This variable is initialized by the system to contain the wildcard IPv6 address. The <netinet/in.h> header also defines the IN6ADDR_ANY_INIT macro. This macro must be constant at compile time and can be used to initialize a variable of type struct in6_addr to the IPv6 wildcard address.

The <netinet/in.h> header shall declare the following external variable:

const struct in6_addr in6addr_loopback

This variable is initialized by the system to contain the loopback IPv6 address. The <netinet/in.h> header also defines the IN6ADDR_LOOPBACK_INIT macro. This macro must be constant at compile time and can be used to initialize a variable of type struct in6_addr to the IPv6 loopback address.

The <netinet/in.h> header shall define the structure, which shall include at least the following members:

struct in6_addr  ipv6mr_multiaddr  IPv6 multicast address.
unsigned         ipv6mr_interface  Interface index.

The <netinet/in.h> header shall define the following symbolic constants for use as values of the argument of getsockopt(3) and setsockopt(3):

Internet protocol.
[IP6] Internet Protocol Version 6.
Control message protocol.
[RS] Raw IP Packets Protocol.
Transmission control protocol.
User datagram protocol.

The <netinet/in.h> header shall define the following symbolic constant for use as a local address in the structure passed to bind(3):

IPv4 wildcard address.

The <netinet/in.h> header shall define the following symbolic constant for use as a destination address in the structures passed to connect(3), sendmsg(3), and sendto(3):

IPv4 broadcast address.

The <netinet/in.h> header shall define the following symbolic constant, with the value specified, to help applications declare buffers of the proper size to store IPv4 addresses in string form:

16. Length of the string form for IP.

The htonl(3), htons(3), ntohl(3), and ntohs(3) functions shall be available as described in <arpa/inet.h>. Inclusion of the <netinet/in.h> header may also make visible all symbols from <arpa/inet.h>.

[IP6] The <netinet/in.h> header shall define the following symbolic constant, with the value specified, to help applications declare buffers of the proper size to store IPv6 addresses in string form:

46. Length of the string form for IPv6.

[IP6] The <netinet/in.h> header shall define the following symbolic constants, with distinct integer values, for use in the argument in the getsockopt(3) or setsockopt(3) functions at protocol level IPPROTO_IPV6:

Join a multicast group.
Quit a multicast group.
Multicast hop limit.
Interface to use for outgoing multicast packets.
Multicast packets are delivered back to the local application.
Unicast hop limit.
Restrict AF_INET6 socket to IPv6 communications only.

The <netinet/in.h> header shall define the following macros that test for special IPv6 addresses. Each macro is of type and takes a single argument of type const struct in6_addr *:

Unspecified address.
Loopback address.
Multicast address.
Unicast link-local address.
Unicast site-local address.
IPv4 mapped address.
IPv4-compatible address.
Multicast node-local address.
Multicast link-local address.
Multicast site-local address.
Multicast organization-local address.
Multicast global address.

Although applications are required to initialize all members (including any non-standard ones) of a sockaddr_in6 structure, the same is not required for the sockaddr_in structure, since historically many applications only initialized the standard members. Despite this, applications are encouraged to initialize sockaddr_in structures in a manner similar to the required initialization of sockaddr_in6 structures.

Although it is common practice to initialize a sockaddr_in6 structure using:

struct sockaddr_in6 sa;
memset(&sa, 0, sizeof sa);

this method is not portable according to this standard, because the structure can contain pointer or floating-point members that are not required to have an all-bits-zero representation after default initialization. Portable methods make use of default initialization; for example:

struct sockaddr_in6 sa = { 0 };

or:

static struct sockaddr_in6 sa_init;
struct sockaddr_in6 sa = sa_init;

A future version of this standard may require that a pointer object with an all-bits-zero representation is a null pointer, and that sockaddr_in6 does not have any floating-point members if a floating-point object with an all-bits-zero representation does not have the value 0.0.

The INADDR_ANY and INADDR_BROADCAST values are byte-order-neutral and thus their byte order is not specified. Many implementations have additional constants as extensions, such as INADDR_LOOPBACK, that are not byte-order-neutral. Traditionally, these constants are in host byte order, requiring the use of htonl(3) when using them in a sockaddr_in structure.

None.

V1_chap04(7), <arpa/inet.h>, <inttypes.h> , <sys/socket.h>

XSH connect(3), getsockopt(3), htonl(3), sendmsg(3), sendto(3), setsockopt(3)

First released in Issue 6. Derived from the XNS, Issue 5.2 specification.

The member was removed from the sockaddr_in structure as per The Open Group Base Resolution bwg2001-004.

IEEE Std 1003.1-2001 (“POSIX.1”)/Cor 1-2002, item XBD/TC1/D6/12 is applied, adding const qualifiers to the and external variables.

IEEE Std 1003.1-2001 (“POSIX.1”)/Cor 2-2004, item XBD/TC2/D6/22 is applied, making it clear which structure members are in network byte order.

This reference page is clarified with respect to macros and symbolic constants.

POSIX.1-2008, Technical Corrigendum 1, XBD/TC1-2008/0061 [355] is applied.

POSIX.1-2008, Technical Corrigendum 2, XBD/TC2-2008/0065 [934], XBD/TC2-2008/0066 [952], XBD/TC2-2008/0067 [934], and XBD/TC2-2008/0068 [952] are applied.

January 31, 2018 posix.fail