The routines
inet_aton(),
inet_addr() and
inet_network() interpret character strings representing numbers expressed in the Internet standard “dotted quad” notation.
The
inet_pton() function converts a presentation format address (that is, printable form as held in a character string) to network format (usually a
struct in_addr or some other internal binary representation, in network byte order). It returns 1 if the address was valid for the specified address family, or 0 if the address wasn't parsable in the specified address family, or -1 if some system error occurred (in which case
errno will have been set). This function is presently valid for
AF_INET and
AF_INET6.
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, or 0 if the string is invalid.
The
inet_addr() and
inet_network() functions return numbers suitable for use as Internet addresses and Internet network numbers, respectively.
The function
inet_ntop() converts an address from network format (usually a
struct in_addr or some other binary form, in network byte order) to presentation format (suitable for external display purposes). It returns NULL if a system error occurs (in which case,
errno will have been set), or it returns a pointer to the destination string.
The routine
inet_ntoa() takes an Internet address and returns an ASCII string representing the address in “dotted quad” notation.
The routine
inet_makeaddr() takes an Internet network number and a local network address (both in host order) and constructs an Internet address from it. Note that to convert only a single value to a
struct in_addr form that value should be passed as the first parameter and ‘0L' should be given for the second parameter.
The routines
inet_netof() and
inet_lnaof() break apart Internet host addresses, returning the network number and local network address part, respectively (both in host order).
All Internet addresses are returned in network order (bytes ordered from left to right). All network numbers and local address parts are returned as machine format integer values.