The Open Group Base Specifications Issue 7
IEEE Std 1003.1-2008
Copyright © 2001-2008 The IEEE and The Open Group

NAME

getnameinfo - get name information

SYNOPSIS

#include <sys/socket.h>
#include <netdb.h>

int getnameinfo(const struct sockaddr *restrict
sa, socklen_t salen,
       char *restrict
node, socklen_t nodelen, char *restrict service,
       socklen_t
servicelen, int flags);

DESCRIPTION

The getnameinfo() function shall translate a socket address to a node name and service location, all of which are defined as in freeaddrinfo .

The sa argument points to a socket address structure to be translated.

[IP6] [Option Start] If the socket address structure contains an IPv4-mapped IPv6 address or an IPv4-compatible IPv6 address, the implementation shall extract the embedded IPv4 address and lookup the node name for that IPv4 address. [Option End]

If the address is the IPv6 unspecified address ( "::" ), a lookup shall not be performed and the behavior shall be the same as when the node's name cannot be located.

If the node argument is non-NULL and the nodelen argument is non-zero, then the node argument points to a buffer able to contain up to nodelen characters that receives the node name as a null-terminated string. If the node argument is NULL or the nodelen argument is zero, the node name shall not be returned. If the node's name cannot be located, the numeric form of the address contained in the socket address structure pointed to by the sa argument is returned instead of its name.

If the service argument is non-NULL and the servicelen argument is non-zero, then the service argument points to a buffer able to contain up to servicelen bytes that receives the service name as a null-terminated string. If the service argument is NULL or the servicelen argument is zero, the service name shall not be returned. If the service's name cannot be located, the numeric form of the service address (for example, its port number) shall be returned instead of its name.

The flags argument is a flag that changes the default actions of the function. By default the fully-qualified domain name (FQDN) for the host shall be returned, but:

Notes:
  1. The two NI_NUMERICxxx flags are required to support the -n flag that many commands provide.

  2. The NI_DGRAM flag is required for the few AF_INET and AF_INET6 port numbers (for example, [512,514]) that represent different services for UDP and TCP.

The getnameinfo() function shall be thread-safe.

RETURN VALUE

A zero return value for getnameinfo() indicates successful completion; a non-zero return value indicates failure. The possible values for the failures are listed in the ERRORS section.

Upon successful completion, getnameinfo() shall return the node and service names, if requested, in the buffers provided. The returned names are always null-terminated strings.

ERRORS

The getnameinfo() function shall fail and return the corresponding value if:

[EAI_AGAIN]
The name could not be resolved at this time. Future attempts may succeed.
[EAI_BADFLAGS]

The flags had an invalid value.
[EAI_FAIL]
A non-recoverable error occurred.
[EAI_FAMILY]
The address family was not recognized or the address length was invalid for the specified family.
[EAI_MEMORY]
There was a memory allocation failure.
[EAI_NONAME]
The name does not resolve for the supplied parameters.

NI_NAMEREQD is set and the host's name cannot be located, or both nodename and servname were null.

[EAI_OVERFLOW]

An argument buffer overflowed. The buffer pointed to by the node argument or the service argument was too small.
[EAI_SYSTEM]
A system error occurred. The error code can be found in errno.

The following sections are informative.

EXAMPLES

None.

APPLICATION USAGE

If the returned values are to be used as part of any further name resolution (for example, passed to getaddrinfo()), applications should provide buffers large enough to store any result possible on the system.

Given the IPv4-mapped IPv6 address "::ffff:1.2.3.4" , the implementation performs a lookup as if the socket address structure contains the IPv4 address "1.2.3.4" .

The IPv6 unspecified address ( "::" ) and the IPv6 loopback address ( "::1" ) are not IPv4-compatible addresses.

RATIONALE

None.

FUTURE DIRECTIONS

None.

SEE ALSO

endservent , freeaddrinfo , gai_strerror , inet_ntop , socket

XBD <netdb.h> , <sys/socket.h>

CHANGE HISTORY

First released in Issue 6. Derived from the XNS, Issue 5.2 specification.

The restrict keyword is added to the getnameinfo() prototype for alignment with the ISO/IEC 9899:1999 standard.

IEEE Std 1003.1-2001/Cor 1-2002, item XSH/TC1/D6/23 is applied, making various changes in the SYNOPSIS and DESCRIPTION for alignment with IPv6.

IEEE Std 1003.1-2001/Cor 1-2002, item XSH/TC1/D6/24 is applied, adding the [EAI_OVERFLOW] error to the ERRORS section.

Issue 7

SD5-XSH-ERN-127 is applied, clarifying the behavior if the address is the IPv6 unspecified address.

End of informative text.

 

return to top of page

UNIX ® is a registered Trademark of The Open Group.
POSIX ® is a registered Trademark of The IEEE.
Copyright © 2001-2008 The IEEE and The Open Group, All Rights Reserved
[ Main Index | XBD | XSH | XCU | XRAT ]