GETNAMEINFO(3POSIX) | POSIX Programmer's Manual | GETNAMEINFO(3POSIX) |
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
getnameinfo — get name information
#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);
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. The salen argument contains the length of the address pointed to by sa.
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.
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 bytes 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:
The getnameinfo() function shall be thread-safe.
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.
The getnameinfo() function shall fail and return the corresponding value if:
NI_NAMEREQD is set and the host's name cannot be located, or both nodename and servname were null.
The following sections are informative.
None.
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.
None.
None.
endservent(), freeaddrinfo(), gai_strerror(), inet_ntop(), socket()
The Base Definitions volume of POSIX.1‐2017, <netdb.h>, <sys_socket.h>
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
2017 | IEEE/The Open Group |