getaddrinfo.3n (2010 09)
g
getaddrinfo(3N) getaddrinfo(3N)
EAI_FAIL Non-recoverable failure in name resolution.
EAI_OVERFLOW Argument buffer overflow
EAI_FAMILY ai_family not supported.
EAI_MEMORY Memory allocation failure.
EAI_NODATA No address associated with hostname .
EAI_NONAME No hostname nor servname provided, or not known.
EAI_SERVICE The servname is not supported for ai_socktype
.
EAI_SOCKTYPE ai_socktype not supported.
EAI_SYSTEM System error returned in errno.
freeaddrinfo()
All the information returned by
getaddrinfo()
is dynamically allocated: the addrinfo structures,
the socket address structures, and canonical host name strings pointed to by the
addrinfo structures.
To return this information to the system, the function
freeaddrinfo() is called:
#include <sys/socket.h>
#include <netdb.h>
void freeaddrinfo(struct addrinfo *ai);
The addrinfo structure pointed to by the ai argument is freed, along with any dynamic storage
pointed to by the structure. This operation is repeated until a NULL ai_next pointer is encountered.
gai_strerror()
To aid applications in printing error messages based on the
EAI_xxx codes returned by getad-
drinfo(), the gai_strerror function is defined.
#include <sys/socket.h>
#include <netdb.h>
const char *gai_strerror(int ecode);
The argument is one of the EAI_xxx values defined earlier, and the return value points to a string
describing the error. If the argument is not one of the EAI_xxx values, the function still returns a
pointer to a string whose contents indicate an unknown error.
getnameinfo()
The
getnameinfo() function is used to look up a hostname and service name, given the binary
address and port. The function is defined as follows:
#include <sys/socket.h>
#include <netdb.h>
int getnameinfo(const struct sockaddr *sa, socklen_t salen,
char *host, socklen_t hostlen, char *serv,
socklen_t servlen, int flags);
This function looks up an IP address and port number provided by the caller in the DNS and system-
specific database, and returns text strings for both in buffers provided by the caller.
The function indicates successful completion by a zero return value; a non-zero return value indicates
failure.
If the address is IPv6 unspecified address ( :: ), then the following actions occur:
getnameinfo() returns EAI_NONAME, if the NI_NAMEREQD flag is set.
getnameinfo() returns success, if the NI_NAMEREQD flag is not set.
The host argument contains the numeric form of the IPv6 address and
getnameinfo() does not per-
form a lookup for the IPv6 address.
The first argument,
sa, points to either a sockaddr_in structure (for IPv4) or a sockaddr_in6
structure (for IPv6) that holds the IP address and port number. The salen argument gives the length of
the sockaddr_in or sockaddr_in6 structure.
HP-UX 11i Version 3: September 2010 − 3 − Hewlett-Packard Company 3