netinet_in.h(3)            POSIX Programmer's Manual           netinet_in.h(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       netinet/in.h -- Internet address family

SSYYNNOOPPSSIISS
       #include <netinet/in.h>

DDEESSCCRRIIPPTTIIOONN
       The _<_n_e_t_i_n_e_t_/_i_n_._h_> header shall define the following types:

       iinn__ppoorrtt__tt Equivalent to the type uuiinntt1166__tt as described in _<_i_n_t_t_y_p_e_s_._h_>.

       iinn__aaddddrr__tt Equivalent to the type uuiinntt3322__tt as described in _<_i_n_t_t_y_p_e_s_._h_>.

       The _<_n_e_t_i_n_e_t___i_n_._h_> header shall define the ssaa__ffaammiillyy__tt type as
       described in _<_s_y_s_/_s_o_c_k_e_t_._h_>.

       The _<_n_e_t_i_n_e_t___i_n_._h_> header shall define the uuiinntt88__tt and uuiinntt3322__tt types
       as described in _<_i_n_t_t_y_p_e_s_._h_>.  Inclusion of the _<_n_e_t_i_n_e_t_/_i_n_._h_> header
       may also make visible all symbols from _<_i_n_t_t_y_p_e_s_._h_> and _<_s_y_s_/_s_o_c_k_e_t_._h_>.

       The _<_n_e_t_i_n_e_t_/_i_n_._h_> header shall define the iinn__aaddddrr structure, which
       shall include at least the following member:


           in_addr_t  s_addr

       The _<_n_e_t_i_n_e_t_/_i_n_._h_> header shall define the ssoocckkaaddddrr__iinn 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 _s_i_n___p_o_r_t and _s_i_n___a_d_d_r members shall be in network byte order.

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

       The _<_n_e_t_i_n_e_t_/_i_n_._h_> header shall define the iinn66__aaddddrr 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 _<_n_e_t_i_n_e_t_/_i_n_._h_> header shall define the ssoocckkaaddddrr__iinn66 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 _s_i_n_6___p_o_r_t and _s_i_n_6___a_d_d_r members shall be in network byte order.

       Prior to calling a function in this standard which reads values from a
       ssoocckkaaddddrr__iinn66 structure (for example, _b_i_n_d() or _c_o_n_n_e_c_t()), the
       application shall ensure that all members of the structure, including
       any additional non-standard members, if any, are initialized.  If the
       ssoocckkaaddddrr__iinn66 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 ssoocckkaaddddrr__iinn66 structure is implementation-defined.
       All functions in this standard that return data in a ssoocckkaaddddrr__iinn66
       structure (for example, _g_e_t_a_d_d_r_i_n_f_o() or _a_c_c_e_p_t()) 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 ssoocckkaaddddrr__iinn66 structure.

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

       The _<_n_e_t_i_n_e_t_/_i_n_._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 _<_n_e_t_i_n_e_t_/_i_n_._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 ssttrruucctt iinn66__aaddddrr to the IPv6 wildcard
       address.

       The _<_n_e_t_i_n_e_t_/_i_n_._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 _<_n_e_t_i_n_e_t_/_i_n_._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 ssttrruucctt iinn66__aaddddrr
       to the IPv6 loopback address.

       The _<_n_e_t_i_n_e_t_/_i_n_._h_> header shall define the iippvv66__mmrreeqq structure, which
       shall include at least the following members:


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

       The _<_n_e_t_i_n_e_t_/_i_n_._h_> header shall define the following symbolic constants
       for use as values of the _l_e_v_e_l argument of _g_e_t_s_o_c_k_o_p_t() and
       _s_e_t_s_o_c_k_o_p_t():

       IPPROTO_IP      Internet protocol.

       IPPROTO_IPV6    Internet Protocol Version 6.

       IPPROTO_ICMP    Control message protocol.

       IPPROTO_RAW     Raw IP Packets Protocol.

       IPPROTO_TCP     Transmission control protocol.

       IPPROTO_UDP     User datagram protocol.

       The _<_n_e_t_i_n_e_t_/_i_n_._h_> header shall define the following symbolic constant
       for use as a local address in the structure passed to _b_i_n_d():

       INADDR_ANY      IPv4 wildcard address.

       The _<_n_e_t_i_n_e_t_/_i_n_._h_> header shall define the following symbolic constant
       for use as a destination address in the structures passed to _c_o_n_n_e_c_t(),
       _s_e_n_d_m_s_g(), and _s_e_n_d_t_o():

       INADDR_BROADCAST
                       IPv4 broadcast address.

       The _<_n_e_t_i_n_e_t_/_i_n_._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:

       INET_ADDRSTRLEN 16. Length of the string form for IP.

       The _h_t_o_n_l(), _h_t_o_n_s(), _n_t_o_h_l(), and _n_t_o_h_s() functions shall be available
       as described in _<_a_r_p_a_/_i_n_e_t_._h_>.  Inclusion of the _<_n_e_t_i_n_e_t_/_i_n_._h_> header
       may also make visible all symbols from _<_a_r_p_a_/_i_n_e_t_._h_>.

       The _<_n_e_t_i_n_e_t_/_i_n_._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:

       INET6_ADDRSTRLEN
                       46. Length of the string form for IPv6.

       The _<_n_e_t_i_n_e_t_/_i_n_._h_> header shall define the following symbolic
       constants, with distinct integer values, for use in the _o_p_t_i_o_n___n_a_m_e
       argument in the _g_e_t_s_o_c_k_o_p_t() or _s_e_t_s_o_c_k_o_p_t() functions at protocol
       level IPPROTO_IPV6:

       IPV6_JOIN_GROUP Join a multicast group.

       IPV6_LEAVE_GROUP
                       Quit a multicast group.

       IPV6_MULTICAST_HOPS
                       Multicast hop limit.

       IPV6_MULTICAST_IF
                       Interface to use for outgoing multicast packets.

       IPV6_MULTICAST_LOOP
                       Multicast packets are delivered back to the local
                       application.

       IPV6_UNICAST_HOPS
                       Unicast hop limit.

       IPV6_V6ONLY     Restrict AF_INET6 socket to IPv6 communications only.

       The _<_n_e_t_i_n_e_t_/_i_n_._h_> header shall define the following macros that test
       for special IPv6 addresses. Each macro is of type iinntt and takes a
       single argument of type ccoonnsstt ssttrruucctt iinn66__aaddddrr **:

       IN6_IS_ADDR_UNSPECIFIED
             Unspecified address.

       IN6_IS_ADDR_LOOPBACK
             Loopback address.

       IN6_IS_ADDR_MULTICAST
             Multicast address.

       IN6_IS_ADDR_LINKLOCAL
             Unicast link-local address.

       IN6_IS_ADDR_SITELOCAL
             Unicast site-local address.

       IN6_IS_ADDR_V4MAPPED
             IPv4 mapped address.

       IN6_IS_ADDR_V4COMPAT
             IPv4-compatible address.

       IN6_IS_ADDR_MC_NODELOCAL
             Multicast node-local address.

       IN6_IS_ADDR_MC_LINKLOCAL
             Multicast link-local address.

       IN6_IS_ADDR_MC_SITELOCAL
             Multicast site-local address.

       IN6_IS_ADDR_MC_ORGLOCAL
             Multicast organization-local address.

       IN6_IS_ADDR_MC_GLOBAL
             Multicast global address.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

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

       Although it is common practice to initialize a ssoocckkaaddddrr__iinn66 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
       ssoocckkaaddddrr__iinn66 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.

RRAATTIIOONNAALLEE
       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 _h_t_o_n_l() when using them in a ssoocckkaaddddrr__iinn
       structure.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _4_._1_0, _H_o_s_t _a_n_d _N_e_t_w_o_r_k _B_y_t_e _O_r_d_e_r_s, <<aarrppaa__iinneett..hh>>,
       <<iinnttttyyppeess..hh>>, <<ssyyss__ssoocckkeett..hh>>

       The System Interfaces volume of POSIX.1-2017, _c_o_n_n_e_c_t(), _g_e_t_s_o_c_k_o_p_t(),
       _h_t_o_n_l(), _s_e_n_d_m_s_g(), _s_e_n_d_t_o(), _s_e_t_s_o_c_k_o_p_t()

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                      netinet_in.h(3)
