1GETNAMEINFO(3P)            POSIX Programmer's Manual           GETNAMEINFO(3P)
2
3
4

PROLOG

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
11

NAME

13       getnameinfo — get name information
14

SYNOPSIS

16       #include <sys/socket.h>
17       #include <netdb.h>
18
19       int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
20           char *restrict node, socklen_t nodelen, char *restrict service,
21           socklen_t servicelen, int flags);
22

DESCRIPTION

24       The getnameinfo() function shall translate a socket address to  a  node
25       name  and  service  location,  all  of  which are defined as in freead‐
26       drinfo().
27
28       The sa argument points to a socket address structure to be  translated.
29       The salen argument contains the length of the address pointed to by sa.
30
31       If the socket address structure contains an IPv4-mapped IPv6 address or
32       an IPv4-compatible IPv6 address, the implementation shall  extract  the
33       embedded IPv4 address and lookup the node name for that IPv4 address.
34
35       If  the  address is the IPv6 unspecified address ("::"), a lookup shall
36       not be performed and the behavior shall be the same as when the  node's
37       name cannot be located.
38
39       If  the node argument is non-NULL and the nodelen argument is non-zero,
40       then the node argument points to a buffer able to contain up to nodelen
41       bytes  that  receives the node name as a null-terminated string. If the
42       node argument is NULL or the nodelen argument is zero,  the  node  name
43       shall  not  be  returned.  If  the  node's  name cannot be located, the
44       numeric form of the address contained in the socket  address  structure
45       pointed to by the sa argument is returned instead of its name.
46
47       If the service argument is non-NULL and the servicelen argument is non-
48       zero, then the service argument points to a buffer able to  contain  up
49       to servicelen bytes that receives the service name as a null-terminated
50       string.  If the service argument is NULL or the servicelen argument  is
51       zero,  the  service  name  shall not be returned. If the service's name
52       cannot be located, the numeric form of the service address  (for  exam‐
53       ple, its port number) shall be returned instead of its name.
54
55       The  flags  argument  is a flag that changes the default actions of the
56       function. By default the fully-qualified domain  name  (FQDN)  for  the
57       host shall be returned, but:
58
59        *  If the flag bit NI_NOFQDN is set, only the node name portion of the
60           FQDN shall be returned for local hosts.
61
62        *  If the flag bit NI_NUMERICHOST is set,  the  numeric  form  of  the
63           address contained in the socket address structure pointed to by the
64           sa argument shall be returned instead of its name.
65
66        *  If the flag bit NI_NAMEREQD is set, an error shall be  returned  if
67           the host's name cannot be located.
68
69        *  If the flag bit NI_NUMERICSERV is set, the numeric form of the ser‐
70           vice address shall be  returned  (for  example,  its  port  number)
71           instead of its name.
72
73        *  If  the  flag  bit  NI_NUMERICSCOPE is set, the numeric form of the
74           scope identifier shall be returned (for example,  interface  index)
75           instead  of its name. This flag shall be ignored if the sa argument
76           is not an IPv6 address.
77
78        *  If the flag bit NI_DGRAM is set, this indicates that the service is
79           a  datagram service (SOCK_DGRAM). The default behavior shall assume
80           that the service is a stream service (SOCK_STREAM).
81
82       Notes:
83
84                  1. The two NI_NUMERICxxx flags are required to  support  the
85                     −n flag that many commands provide.
86
87                  2. The  NI_DGRAM  flag  is  required for the few AF_INET and
88                     AF_INET6 port numbers (for example, [512,514]) that  rep‐
89                     resent different services for UDP and TCP.
90
91       The getnameinfo() function shall be thread-safe.
92

RETURN VALUE

94       A  zero return value for getnameinfo() indicates successful completion;
95       a non-zero return value indicates failure. The possible values for  the
96       failures are listed in the ERRORS section.
97
98       Upon  successful  completion,  getnameinfo()  shall return the node and
99       service names, if requested, in  the  buffers  provided.  The  returned
100       names are always null-terminated strings.
101

ERRORS

103       The  getnameinfo()  function  shall  fail  and return the corresponding
104       value if:
105
106       [EAI_AGAIN] The name  could  not  be  resolved  at  this  time.  Future
107                   attempts may succeed.
108
109       [EAI_BADFLAGS]
110                   The flags had an invalid value.
111
112       [EAI_FAIL]  A non-recoverable error occurred.
113
114       [EAI_FAMILY]
115                   The address family was not recognized or the address length
116                   was invalid for the specified family.
117
118       [EAI_MEMORY]
119                   There was a memory allocation failure.
120
121       [EAI_NONAME]
122                   The name does not resolve for the supplied parameters.
123
124                   NI_NAMEREQD is set and the host's name cannot  be  located,
125                   or both nodename and servname were null.
126
127       [EAI_OVERFLOW]
128                   An argument buffer overflowed. The buffer pointed to by the
129                   node argument or the service argument was too small.
130
131       [EAI_SYSTEM]
132                   A system error occurred. The error code  can  be  found  in
133                   errno.
134
135       The following sections are informative.
136

EXAMPLES

138       None.
139

APPLICATION USAGE

141       If the returned values are to be used as part of any further name reso‐
142       lution (for example, passed to getaddrinfo()), applications should pro‐
143       vide buffers large enough to store any result possible on the system.
144
145       Given the IPv4-mapped IPv6 address "::ffff:1.2.3.4", the implementation
146       performs a lookup as if the socket address structure contains the  IPv4
147       address "1.2.3.4".
148
149       The  IPv6  unspecified  address  ("::")  and  the IPv6 loopback address
150       ("::1") are not IPv4-compatible addresses.
151

RATIONALE

153       None.
154

FUTURE DIRECTIONS

156       None.
157

SEE ALSO

159       endservent(), freeaddrinfo(), gai_strerror(), inet_ntop(), socket()
160
161       The Base Definitions volume of POSIX.1‐2008, <netdb.h>, <sys_socket.h>
162
164       Portions of this text are reprinted and reproduced in  electronic  form
165       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
166       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
167       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
168       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
169       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
170       event of any discrepancy between this version and the original IEEE and
171       The  Open Group Standard, the original IEEE and The Open Group Standard
172       is the referee document. The original Standard can be  obtained  online
173       at http://www.unix.org/online.html .
174
175       Any  typographical  or  formatting  errors that appear in this page are
176       most likely to have been introduced during the conversion of the source
177       files  to  man page format. To report such errors, see https://www.ker
178       nel.org/doc/man-pages/reporting_bugs.html .
179
180
181
182IEEE/The Open Group                  2013                      GETNAMEINFO(3P)
Impressum