# inet

## NAME



           inet_aton, inet_addr, inet_network, inet_ntoa, inet_makeaddr,
           inet_lnaof, inet_netof - Internet address manipulation routines
    


## LIBRARY



           Standard C library (_libc_ , _-lc_)
    


## SYNOPSIS



           **#include <sys/socket.h>**
           **#include <netinet/in.h>**
           **#include <arpa/inet.h>**
    
           **int inet_aton(const char ***_cp_**, struct in_addr ***_inp_**);**
    
           **in_addr_t inet_addr(const char ***_cp_**);**
           **in_addr_t inet_network(const char ***_cp_**);**
    
           **[[deprecated]] char *inet_ntoa(struct in_addr** _in_**);**
    
           **[[deprecated]] struct in_addr inet_makeaddr(in_addr_t** _net_**,**
                                                       **in_addr_t** _host_**);**
    
           **[[deprecated]] in_addr_t inet_lnaof(struct in_addr** _in_**);**
           **[[deprecated]] in_addr_t inet_netof(struct in_addr** _in_**);**
    
       Feature Test Macro Requirements for glibc (see
       feature_test_macros(7)):
    
           **inet_aton**(), **inet_ntoa**():
               Since glibc 2.19:
                   _DEFAULT_SOURCE
               In glibc up to and including 2.19:
                   _BSD_SOURCE || _BSD_SOURCE
    


## DESCRIPTION



           **inet_aton**() converts the Internet host address _cp_ from the IPv4
           numbers-and-dots notation into binary form (in network byte order)
           and stores it in the structure that _inp_ points to.  **inet_aton**()
           returns nonzero if the address is valid, zero if not.  The address
           supplied in _cp_ can have one of the following forms:
    
           _a.b.c.d_
                  Each of the four numeric parts specifies a byte of the
                  address; the bytes are assigned in left-to-right order to
                  produce the binary address.
    
           _a.b.c_  Parts _a_ and _b_ specify the first two bytes of the binary
                  address.  Part _c_ is interpreted as a 16-bit value that
                  defines the rightmost two bytes of the binary address.
                  This notation is suitable for specifying (outmoded) Class B
                  network addresses.
    
           _a.b_    Part _a_ specifies the first byte of the binary address.
                  Part _b_ is interpreted as a 24-bit value that defines the
                  rightmost three bytes of the binary address.  This notation
                  is suitable for specifying (outmoded) Class A network
                  addresses.
    
           _a_      The value _a_ is interpreted as a 32-bit value that is stored
                  directly into the binary address without any byte
                  rearrangement.
    
           In all of the above forms, components of the dotted address can be
           specified in decimal, octal (with a leading _0_), or hexadecimal,
           with a leading _0X_).  Addresses in any of these forms are
           collectively termed _IPV4 numbers-and-dots notation_.  The form that
           uses exactly four decimal numbers is referred to as _IPv4 dotted-_
           _decimal notation_ (or sometimes: _IPv4 dotted-quad notation_).
    
           **inet_aton**() returns 1 if the supplied string was successfully
           interpreted, or 0 if the string is invalid (**errno** is _not_ set on
           error).
    
           The **inet_addr**() function converts the Internet host address _cp_
           from IPv4 numbers-and-dots notation into binary data in network
           byte order.  If the input is invalid, **INADDR_NONE**(usually -1) is
           returned.  Use of this function is problematic because -1 is a
           valid address (255.255.255.255).  Avoid its use in favor of
           **inet_aton**(), inet_pton(3), or getaddrinfo(3), which provide a
           cleaner way to indicate error return.
    
           The **inet_network**() function converts _cp_ , a string in IPv4 numbers-
           and-dots notation, into a number in host byte order suitable for
           use as an Internet network address.  On success, the converted
           address is returned.  If the input is invalid, -1 is returned.
    
           The **inet_ntoa**() function converts the Internet host address _in_ ,
           given in network byte order, to a string in IPv4 dotted-decimal
           notation.  The string is returned in a statically allocated
           buffer, which subsequent calls will overwrite.
    
           The **inet_lnaof**() function returns the local network address part
           of the Internet address _in_.  The returned value is in host byte
           order.
    
           The **inet_netof**() function returns the network number part of the
           Internet address _in_.  The returned value is in host byte order.
    
           The **inet_makeaddr**() function is the converse of **inet_netof**() and
           **inet_lnaof**().  It returns an Internet host address in network byte
           order, created by combining the network number.I net with the
           local address _host_ , both in host byte order.
    
           The structure _in_addr_ as used in **inet_ntoa**(), **inet_makeaddr**(),
           **inet_lnaof**(), and **inet_netof**() is defined in _< netinet/in.h>_ as:
    
               typedef uint32_t in_addr_t;
    
               struct in_addr {
                   in_addr_t s_addr;
               };
    


## ATTRIBUTES



           For an explanation of the terms used in this section, see
           attributes(7).
           ┌───────────────────────────────┬───────────────┬────────────────┐
           │ **Interface** │ **Attribute** │ **Value** │
           ├───────────────────────────────┼───────────────┼────────────────┤
           │ **inet_aton**(), **inet_addr**(),     │ Thread safety │ MT-Safe locale │
           │ **inet_network**(), **inet_ntoa**()   │               │                │
           ├───────────────────────────────┼───────────────┼────────────────┤
           │ **inet_makeaddr**(),              │ Thread safety │ MT-Safe        │
           │ **inet_lnaof**(), **inet_netof**()    │               │                │
           └───────────────────────────────┴───────────────┴────────────────┘
    


## STANDARDS



           **inet_addr**()
           **inet_ntoa**()
                  POSIX.1-2008.
    
           **inet_aton**()
                  None.
    


## STANDARDS



           **inet_addr**()
           **inet_ntoa**()
                  POSIX.1-2001, 4.3BSD.
    
           **inet_lnaof**(), **inet_netof**(), and **inet_makeaddr**() are legacy
           functions that assume they are dealing with _classful network_
           _addresses_.  Classful networking divides IPv4 network addresses
           into host and network components at byte boundaries, as follows:
    
           Class A
                  This address type is indicated by the value 0 in the most
                  significant bit of the (network byte ordered) address.  The
                  network address is contained in the most significant byte,
                  and the host address occupies the remaining three bytes.
    
           Class B
                  This address type is indicated by the binary value 10 in
                  the most significant two bits of the address.  The network
                  address is contained in the two most significant bytes, and
                  the host address occupies the remaining two bytes.
    
           Class C
                  This address type is indicated by the binary value 110 in
                  the most significant three bits of the address.  The
                  network address is contained in the three most significant
                  bytes, and the host address occupies the remaining byte.
    
           Classful network addresses are now obsolete, having been
           superseded by Classless Inter-Domain Routing (CIDR), which divides
           addresses into network and host components at arbitrary bit
           (rather than byte) boundaries.
    


## NOTES



           On x86 architectures, the host byte order is Least Significant
           Byte first (little endian), whereas the network byte order, as
           used on the Internet, is Most Significant Byte first (big endian).
    


## EXAMPLES



           An example of the use of **inet_aton**() and **inet_ntoa**() is shown
           below.  Here are some example runs:
    
               $ **./a.out 226.000.000.037** # Last byte is in octal
               226.0.0.31
               $ **./a.out 0x7f.1** # First byte is in hex
               127.0.0.1
    
       **Program source**
    
           #define _DEFAULT_SOURCE
           #include <arpa/inet.h>
           #include <stdio.h>
           #include <stdlib.h>
    
           int
           main(int argc, char *argv[])
           {
               struct in_addr addr;
    
               if (argc != 2) {
                   fprintf(stderr, "%s <dotted-address>\n", argv[0]);
                   exit(EXIT_FAILURE);
               }
    
               if (inet_aton(argv[1], &addr) == 0) {
                   fprintf(stderr, "Invalid address\n");
                   exit(EXIT_FAILURE);
               }
    
               printf("%s\n", inet_ntoa(addr));
               exit(EXIT_SUCCESS);
           }
    


* * *