inet_aton()

convert a string into an Internet address stored in a structure

Synopsis:

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int inet_aton( const char *cp,
               struct in_addr *pin );

Description:

The inet_aton() routine interprets the specified character string as an Internet address, placing the address into the structure provided. It returns 1 if the string was successfully interpreted; 0 if the string is invalid.

All Internet addresses are returned in network byte order (bytes are ordered from left to right). All network numbers and local address parts are returned as machine-format integer values.

Internet addresses

Using the dot notation, you can specify addresses in one of the following forms:

a.b.c.d
When you specify a four-part address, each part is interpreted as a byte of data and assigned, from left to right, to the four bytes of an Internet address.
a.b.c
When you specify a three-part address, the last part is interpreted as a 16-bit quantity and placed in the rightmost two bytes of the network address. This makes the three-part address format convenient for specifying Class B network addresses as:

net.net.host

a.b
When you specify a two-part address, the last part is interpreted as a 24-bit quantity and placed in the rightmost three bytes of the network address. This makes the two-part address format convenient for specifying Class A network addresses as:

net.host

a
When you specify a one-part address, the value is stored directly in the network address without any byte rearrangement.

All numbers supplied as ``parts'' in a dot notation may be decimal, octal, or hex, as specified in the C language. That is, a number is interpreted as decimal unless it has a leading 0 (octal), or a leading 0x or 0X (hex).

Returns:

A numeric representation of an Internet address, or 0 if an error occurs.

Classification:

POSIX 1003.1g (draft)

Safety:
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

gethostbyname(), getnetent(), inet_addr(), inet_lnaof(), inet_makeaddr(), inet_netof(), inet_network(), inet_ntoa()

/etc/hosts, /etc/networks in the TCP/IP User's Guide