Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

getnameinfo(3) OSS Library Calls Reference Manual
NI_NUMERICHOST
Return the numeric form of the host address instead of the host
name.
NI_NUMERICSERV
Return the numeric port number instead of the service name.
DESCRIPTION
This function uses a socket address to search for a hostname and service name. Given a binary
IPv4 or IPv6 address and port number, it returns the corresponding hostname and service name
from a name resolution service, the /etc/ipnodes file, or the /etc/hosts file.
EXAMPLES
err = getnameinfo((struct sockaddr *)sin, addrlen, hname,
sizeof(hname), sname, sizeof(sname),
NI_NUMERICHOST | NI_NUMERICSERV);
if(err){
fprintf(stderr, "getnameinfo: %s\n", gai_strerror(err));
}
NOTES
This function, along with getipnodebyaddr( ), are protocol-independent replacements for
gethostbyaddr( ). getnameinfo( ) provides functionality beyond what getipnodebyaddr( ) pro-
vides because getnameinfo( ) handles both the host’s address and port number.
Appropriate use of this function can eliminate calls to getservbyport( ) and provide protocol
independence.
RETURN VALUES
Upon successful completion, this function returns 0 (zero) and the requested values are stored in
the buffers specified for the call. Otherwise, the value returned is one of the following values; if
the returned condition is EAI_SYSTEM, errno is set to indicate the error.
EAI_AGAIN The name could not be resolved this time. Future attempts may succeed.
EAI_BADFLAGS
The flags parameter has an invalid value.
EAI_FAIL A non-recoverable error occurred.
EAI_FAMILY Address family was not recognized or address length was invalid.
EAI_MEMORY
A memory allocation failure occurred.
EAI_NONAME
Name does not resolve to supplied parameters.
EAI_SERVICE
The service passed was not recognized for the specified socket type.
EAI_SOCKTYPE
The intended socket type was not recognized.
EAI_SYSTEM
A system error occurred; error code found in errno.
382 Hewlett-Packard Company 527187-017