1GETNAMEINFO(3P) POSIX Programmer's Manual GETNAMEINFO(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 getnameinfo — get name information
13
15 #include <sys/socket.h>
16 #include <netdb.h>
17
18 int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
19 char *restrict node, socklen_t nodelen, char *restrict service,
20 socklen_t servicelen, int flags);
21
23 The getnameinfo() function shall translate a socket address to a node
24 name and service location, all of which are defined as in freead‐
25 drinfo().
26
27 The sa argument points to a socket address structure to be translated.
28 The salen argument contains the length of the address pointed to by sa.
29
30 If the socket address structure contains an IPv4-mapped IPv6 address or
31 an IPv4-compatible IPv6 address, the implementation shall extract the
32 embedded IPv4 address and lookup the node name for that IPv4 address.
33
34 If the address is the IPv6 unspecified address ("::"), a lookup shall
35 not be performed and the behavior shall be the same as when the node's
36 name cannot be located.
37
38 If the node argument is non-NULL and the nodelen argument is non-zero,
39 then the node argument points to a buffer able to contain up to nodelen
40 bytes that receives the node name as a null-terminated string. If the
41 node argument is NULL or the nodelen argument is zero, the node name
42 shall not be returned. If the node's name cannot be located, the
43 numeric form of the address contained in the socket address structure
44 pointed to by the sa argument is returned instead of its name.
45
46 If the service argument is non-NULL and the servicelen argument is non-
47 zero, then the service argument points to a buffer able to contain up
48 to servicelen bytes that receives the service name as a null-terminated
49 string. If the service argument is NULL or the servicelen argument is
50 zero, the service name shall not be returned. If the service's name
51 cannot be located, the numeric form of the service address (for exam‐
52 ple, its port number) shall be returned instead of its name.
53
54 The flags argument is a flag that changes the default actions of the
55 function. By default the fully-qualified domain name (FQDN) for the
56 host shall be returned, but:
57
58 * If the flag bit NI_NOFQDN is set, only the node name portion of the
59 FQDN shall be returned for local hosts.
60
61 * If the flag bit NI_NUMERICHOST is set, the numeric form of the
62 address contained in the socket address structure pointed to by the
63 sa argument shall be returned instead of its name.
64
65 * If the flag bit NI_NAMEREQD is set, an error shall be returned if
66 the host's name cannot be located.
67
68 * If the flag bit NI_NUMERICSERV is set, the numeric form of the ser‐
69 vice address shall be returned (for example, its port number)
70 instead of its name.
71
72 * If the flag bit NI_NUMERICSCOPE is set, the numeric form of the
73 scope identifier shall be returned (for example, interface index)
74 instead of its name. This flag shall be ignored if the sa argument
75 is not an IPv6 address.
76
77 * If the flag bit NI_DGRAM is set, this indicates that the service is
78 a datagram service (SOCK_DGRAM). The default behavior shall assume
79 that the service is a stream service (SOCK_STREAM).
80
81 Notes:
82
83 1. The two NI_NUMERICxxx flags are required to support the
84 -n flag that many commands provide.
85
86 2. The NI_DGRAM flag is required for the few AF_INET and
87 AF_INET6 port numbers (for example, [512,514]) that rep‐
88 resent different services for UDP and TCP.
89
90 The getnameinfo() function shall be thread-safe.
91
93 A zero return value for getnameinfo() indicates successful completion;
94 a non-zero return value indicates failure. The possible values for the
95 failures are listed in the ERRORS section.
96
97 Upon successful completion, getnameinfo() shall return the node and
98 service names, if requested, in the buffers provided. The returned
99 names are always null-terminated strings.
100
102 The getnameinfo() function shall fail and return the corresponding
103 value if:
104
105 [EAI_AGAIN] The name could not be resolved at this time. Future
106 attempts may succeed.
107
108 [EAI_BADFLAGS]
109 The flags had an invalid value.
110
111 [EAI_FAIL] A non-recoverable error occurred.
112
113 [EAI_FAMILY]
114 The address family was not recognized or the address length
115 was invalid for the specified family.
116
117 [EAI_MEMORY]
118 There was a memory allocation failure.
119
120 [EAI_NONAME]
121 The name does not resolve for the supplied parameters.
122
123 NI_NAMEREQD is set and the host's name cannot be located,
124 or both nodename and servname were null.
125
126 [EAI_OVERFLOW]
127 An argument buffer overflowed. The buffer pointed to by the
128 node argument or the service argument was too small.
129
130 [EAI_SYSTEM]
131 A system error occurred. The error code can be found in
132 errno.
133
134 The following sections are informative.
135
137 None.
138
140 If the returned values are to be used as part of any further name reso‐
141 lution (for example, passed to getaddrinfo()), applications should pro‐
142 vide buffers large enough to store any result possible on the system.
143
144 Given the IPv4-mapped IPv6 address "::ffff:1.2.3.4", the implementation
145 performs a lookup as if the socket address structure contains the IPv4
146 address "1.2.3.4".
147
148 The IPv6 unspecified address ("::") and the IPv6 loopback address
149 ("::1") are not IPv4-compatible addresses.
150
152 None.
153
155 None.
156
158 endservent(), freeaddrinfo(), gai_strerror(), inet_ntop(), socket()
159
160 The Base Definitions volume of POSIX.1‐2017, <netdb.h>, <sys_socket.h>
161
163 Portions of this text are reprinted and reproduced in electronic form
164 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
165 table Operating System Interface (POSIX), The Open Group Base Specifi‐
166 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
167 Electrical and Electronics Engineers, Inc and The Open Group. In the
168 event of any discrepancy between this version and the original IEEE and
169 The Open Group Standard, the original IEEE and The Open Group Standard
170 is the referee document. The original Standard can be obtained online
171 at http://www.opengroup.org/unix/online.html .
172
173 Any typographical or formatting errors that appear in this page are
174 most likely to have been introduced during the conversion of the source
175 files to man page format. To report such errors, see https://www.ker‐
176 nel.org/doc/man-pages/reporting_bugs.html .
177
178
179
180IEEE/The Open Group 2017 GETNAMEINFO(3P)