Converts an IPv4 or IPv6 address in its binary format into a text string.
#include <arpa/inet.h> const char *inet_ntop ( int af, const void *src, char *dst, size_t size);
(IN) Specifies the address family. Currently, AF_INET and AF_INET6 are supported.
(IN) Points to the address, in network byte order, of the type specified in the af parameter. If af is set to AF_INET, src points to an in_addr structure; if set to AF_INET6, src points to an in6_addr structure.
(OUT) Points to the character buffer where inet_ntop can copy the converted address in string format. It should be non-NULL. For AF_INET, the string is standard dotted decimal format. For AF_INET6, the string is the most appropriate format for the address.
(IN) Specifies the length of the character buffer dst. For AF_INTET, it must be at least INET_ADDRSTRLEN, and for AF_INET6, it must be at least INET6_ADDSTRLEN.
If successful, returns the pointer to the converted address (same as dst). Otherwise, returns a NULL pointer and sets errno to one of the following:
The dst argument points to a buffer, owned by the application, where the function stores the resulting text string. This buffer must be at least
46 octets for IPv6 addresses
16 bytes for IPv4 addresses
Applications can use the following macros to size the buffer:
#define INET_ADDRSTRLEN 16 #define INET6_ADDRSTRLEN 46
If successful, the return value is a pointer to the buffer containing the text string, which is the same as dst.