Go to the first, previous, next, last section, table of contents.


Host Address Functions

These additional functions for manipulating Internet addresses are declared in `arpa/inet.h'. They represent Internet addresses in network byte order; they represent network numbers and local-address-within-network numbers in host byte order. See section Byte Order Conversion, for an explanation of network and host byte order.

Function: int inet_aton (const char *name, struct in_addr *addr)
This function converts the Internet host address name from the standard numbers-and-dots notation into binary data and stores it in the struct in_addr that addr points to. inet_aton returns nonzero if the address is valid, zero if not.

Function: unsigned long int inet_addr (const char *name)
This function converts the Internet host address name from the standard numbers-and-dots notation into binary data. If the input is not valid, inet_addr returns INADDR_NONE. This is an obsolete interface to inet_aton, described immediately above; it is obsolete because INADDR_NONE is a valid address (255.255.255.255), and inet_aton provides a cleaner way to indicate error return.

Function: unsigned long int inet_network (const char *name)
This function extracts the network number from the address name, given in the standard numbers-and-dots notation. If the input is not valid, inet_network returns -1.

Function: char * inet_ntoa (struct in_addr addr)
This function converts the Internet host address addr to a string in the standard numbers-and-dots notation. The return value is a pointer into a statically-allocated buffer. Subsequent calls will overwrite the same buffer, so you should copy the string if you need to save it.

In multi-threaded programs each thread has an own statically-allocated buffer. But still subsequent calls of inet_ntoa in the same thread will overwrite the result of the last call.

Function: struct in_addr inet_makeaddr (int net, int local)
This function makes an Internet host address by combining the network number net with the local-address-within-network number local.

Function: int inet_lnaof (struct in_addr addr)
This function returns the local-address-within-network part of the Internet host address addr.

Function: int inet_netof (struct in_addr addr)
This function returns the network number part of the Internet host address addr.

Function: int inet_pton (int af, const char *cp, void *buf)
This function converts an Internet address (either IPv4 or IPv6) from presentation (textual) to network (binary) format. af should be either AF_INET or AF_INET6, as appropriate for the type of address being converted. cp is a pointer to the input string, and buf is a pointer to a buffer for the result. It is the caller's responsibility to make sure the buffer is large enough.

Function: char * inet_ntop (int af, const void *cp, char *buf, size_t len)
This function converts an Internet address (either IPv4 or IPv6) from network (binary) to presentation (textual) form. af should be either AF_INET or AF_INET6, as appropriate. cp is a pointer to the address to be converted. buf should be a pointer to a buffer to hold the result, and len is the length of this buffer. The return value from the function will be this buffer address.


Go to the first, previous, next, last section, table of contents.