This function is deprecated for AF_INET6 in favor of the inet_ntop6_zone Subroutine .
Library (libc.a)
This function converts from an address in binary format (as specified by the src parameter) to standard text format, and places the result in the dst parameter (if size, which specifies the space available in the dst parameter, is sufficient). The af parameter specifies the family of the address. This can be AF_INET or AF_INET6.
The src parameter points to a buffer holding an IPv4 address if the af parameter is AF_INET, or an IPv6 address if the af parameter is AF_INET6. The dst parameter points to a buffer where the function will store the resulting text string. The size parameter specifies the size of this buffer (in bytes). The application must specify a non-NULL dst parameter. For IPv6 addresses, the buffer must be at least INET6_ADDRSTRLEN bytes. For IPv4 addresses, the buffer must be at least INET_ADDRSTRLEN bytes.
In order to allow applications to easily declare buffers of the proper size to store IPv4 and IPv6 addresses in string form, the following two constants are defined in the <netinet/in.h> library:
#define INET_ADDRSTRLEN 16
#define INET6_ADDRSTRLEN 46
Item | Description |
---|---|
af | Specifies the family of the address. This can be AF_INET or AF_INET6. |
src | Points to a buffer holding an IPv4 address if the af parameter is set to AF_INET, or an IPv6 address if the af parameter is set to AF_INET6. |
dst | Points to a buffer where the resulting text string is stored. |
size | Specifies the size (in bytes) of the buffer pointed to by the dst parameter. |
If successful, a pointer to the buffer containing the converted address is returned. If unsuccessful, NULL is returned. Upon failure, the errno global variable is set to EAFNOSUPPORT if the specified address family (af) is unsupported, or to ENOSPC if the size parameter indicates the destination buffer is too small.