# inet_ntop

## PROLOG



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


## NAME



           inet_ntop, inet_pton — convert IPv4 and IPv6 addresses between
           binary and text form
    


## SYNOPSIS



           #include <arpa/inet.h>
    
           const char *inet_ntop(int _af_ , const void *restrict _src_ ,
               char *restrict _dst_ , socklen_t _size_);
           int inet_pton(int _af_ , const char *restrict _src_ , void *restrict _dst_);
    


## DESCRIPTION



           The _inet_ntop_() function shall convert a numeric address into a
           text string suitable for presentation. The _af_ argument shall
           specify the family of the address. This can be AF_INET or
           AF_INET6.  The _src_ argument points to a buffer holding an IPv4
           address if the _af_ argument is AF_INET, or an IPv6 address if the
           _af_ argument is AF_INET6; the address must be in network byte
           order. The _dst_ argument points to a buffer where the function
           stores the resulting text string; it shall not be NULL. The _size_
           argument specifies the size of this buffer, which shall be large
           enough to hold the text string (INET_ADDRSTRLEN characters for
           IPv4, INET6_ADDRSTRLEN characters for IPv6).
    
           The _inet_pton_() function shall convert an address in its standard
           text presentation form into its numeric binary form. The _af_
           argument shall specify the family of the address. The AF_INET and
           AF_INET6 address families shall be supported. The _src_ argument
           points to the string being passed in. The _dst_ argument points to a
           buffer into which the function stores the numeric address; this
           shall be large enough to hold the numeric address (32 bits for
           AF_INET, 128 bits for AF_INET6).
    
           If the _af_ argument of _inet_pton_() is AF_INET, the _src_ string shall
           be in the standard IPv4 dotted-decimal form:
    
               ddd.ddd.ddd.ddd
    
           where **"ddd"** is a one to three digit decimal number between 0 and
           255 (see inet_addr(3p)).  The _inet_pton_() function does not accept
           other formats (such as the octal numbers, hexadecimal numbers, and
           fewer than four numbers that _inet_addr_() accepts).
    
           If the _af_ argument of _inet_pton_() is AF_INET6, the _src_ string
           shall be in one of the following standard IPv6 text forms:
    
            1. The preferred form is **"x:x:x:x:x:x:x:x"** , where the **'x'** s are
               the hexadecimal values of the eight 16-bit pieces of the
               address.  Leading zeros in individual fields can be omitted,
               but there shall be one to four hexadecimal digits in every
               field.
    
            2. A string of contiguous zero fields in the preferred form can
               be shown as **"::"**.  The **"::"** can only appear once in an
               address. Unspecified addresses (**"0:0:0:0:0:0:0:0"**) may be
               represented simply as **"::"**.
    
            3. A third form that is sometimes more convenient when dealing
               with a mixed environment of IPv4 and IPv6 nodes is
               **"x:x:x:x:x:x:d.d.d.d"** , where the **'x'** s are the hexadecimal
               values of the six high-order 16-bit pieces of the address, and
               the **'d'** s are the decimal values of the four low-order 8-bit
               pieces of the address (standard IPv4 representation).
    
           **Note:**
               A more extensive description of the standard representations
               of IPv6 addresses can be found in RFC 2373.
    


## RETURN VALUE



           The _inet_ntop_() function shall return a pointer to the buffer
           containing the text string if the conversion succeeds, and NULL
           otherwise, and set _errno_ to indicate the error.
    
           The _inet_pton_() function shall return 1 if the conversion
           succeeds, with the address pointed to by _dst_ in network byte
           order. It shall return 0 if the input is not a valid IPv4 dotted-
           decimal string or a valid IPv6 address string, or -1 with _errno_
           set to **[EAFNOSUPPORT]** if the _af_ argument is unknown.
    


## ERRORS



           The _inet_ntop_() and _inet_pton_() functions shall fail if:
    
           **EAFNOSUPPORT**
                  The _af_ argument is invalid.
    
           **ENOSPC** The size of the _inet_ntop_() result buffer is inadequate.
    
           _The following sections are informative._
    


## EXAMPLES



           None.
    


## APPLICATION USAGE



           None.
    


## RATIONALE



           None.
    


## FUTURE DIRECTIONS



           None.
    


* * *