|
Description
The inet_ntop() function converts the binary IP address to which the addr parameter is pointing to printable notation. The value passed in the af parameter indicates whether the address involved is an IPv4 address or an IPv6 address:
AF_INET: a binary IPv4 address is converted.
AF_INET6: a binary IPv6 address is converted.
inet_ntop() returns the printable address in the buffer of the length size to which the pointer dst is pointing. You can ensure that the buffer is big enough by using the integer constant INET_ADDRSTRLEN (for IPv4 addresses) or INET6_ADDRSTRLEN (for IPv6 addresses). Both constants are defined in <netinet/in.h>.
The inet_pton() function converts an IPv4 address in decimal dotted notation or an IPv6 address in hexadecimal colon notation to a binary address. The value passed in the af parameter indicates whether the address involved is an IPv4 address or an IPv6 address:
AF_INET: an IPv4 address is converted.
AF_INET6: an IPv6 address is converted.
inet_pton() returns the binary address to the buffer to which the pointer dst is pointing. The buffer must be sufficiently large: 4 bytes for AF_INET and 16 bytes for AF_INET6.
Note
If the output of inet_pton() is to be used as the input for a new function, make sure that the starting address of the destination area dst has doubleword alignment.
Return value
If the inet_ntop() function is executed successfully, it returns a pointer to the buffer in which the text string is stored. The null pointer is returned if an error occurs.
inet_pton() returns the following values:
1:
If conversion is successful.
0:
If the input is an invalid address string.
-1:
If a parameter is invalid.
Errors indicated by errno
EAFNOSUPPORT
Invalid af parameter specified, or the function is not supported on this system. See also "Dependencies on the BS2000 transport system BCAM" for more information.
ENOSPC
The result buffer is too small.