Open System Services Library Calls Reference Manual (G06.27+, H06.04+)

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 le, or the /etc/hosts le.
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 hosts address and port number.
Appropriate use of this function can eliminate calls to getservbyport() and provide protocol
independence.
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));
}
RETURN VALUES
Upon successful completion, this function returns 0 (zero) and the requested values are stored in
the buffers specied 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 ags 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 specied socket type.
EAI_SOCKTYPE
The intended socket type was not recognized.
EAI_SYSTEM
A system error occurred; error code found in errno.
348 Hewlett-Packard Company 527187-004