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

NAME

6       getnameinfo - get name information
7

SYNOPSIS

9       #include <sys/socket.h>
10       #include <netdb.h>
11
12       int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
13              char *restrict node, socklen_t nodelen, char *restrict service,
14              socklen_t servicelen, int flags);
15
16

DESCRIPTION

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

RETURN VALUE

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

ERRORS

99       The  getnameinfo()  function  shall  fail  and return the corresponding
100       value if:
101
102       EAI_AGAIN
103              The name could not be resolved at this time. Future attempts may
104              succeed.
105
106       EAI_BADFLAGS
107
108              The flags had an invalid value.
109
110       EAI_FAIL
111              A non-recoverable error occurred.
112
113       EAI_FAMILY
114              The  address family was not recognized or the address length was
115              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, or both node‐
124       name and servname were null.
125
126       EAI_OVERFLOW
127
128              An argument buffer overflowed. The buffer pointed to by the node
129              argument or the service argument was too small.
130
131       EAI_SYSTEM
132              A system error occurred. The error code can be found in errno.
133
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  implementa‐
146       tion  performs a lookup as if the socket address structure contains the
147       IPv4 address "1.2.3.4" .
148

RATIONALE

150       None.
151

FUTURE DIRECTIONS

153       None.
154

SEE ALSO

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