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

NAME

12       getnameinfo - get name information
13

SYNOPSIS

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

144       None.
145

APPLICATION USAGE

147       If the returned values are to be used as part of any further name reso‐
148       lution (for example, passed to getaddrinfo()), applications should pro‐
149       vide buffers large enough to store any result possible on the system.
150
151       Given the IPv4-mapped IPv6 address "::ffff:1.2.3.4", the implementation
152       performs a lookup as if the socket address structure contains the  IPv4
153       address "1.2.3.4" .
154

RATIONALE

156       None.
157

FUTURE DIRECTIONS

159       None.
160

SEE ALSO

162       gai_strerror(),  getaddrinfo(), getservbyname(), inet_ntop(), socket(),
163       the  Base  Definitions  volume  of   IEEE Std 1003.1-2001,   <netdb.h>,
164       <sys/socket.h>
165
167       Portions  of  this text are reprinted and reproduced in electronic form
168       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
169       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
170       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
171       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
172       event of any discrepancy between this version and the original IEEE and
173       The  Open Group Standard, the original IEEE and The Open Group Standard
174       is the referee document. The original Standard can be  obtained  online
175       at http://www.opengroup.org/unix/online.html .
176
177
178
179IEEE/The Open Group                  2003                      GETNAMEINFO(3P)
Impressum