1 .\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 .\" Permission to use, copy, modify, and distribute this software for any
4 .\" purpose with or without fee is hereby granted, provided that the above
5 .\" copyright notice and this permission notice appear in all copies.
7 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
8 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
10 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 .\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 .\" Copyright (c) 1983, 1987, 1991, 1993
16 .\" The Regents of the University of California. All rights reserved.
18 .\" Redistribution and use in source and binary forms, with or without
19 .\" modification, are permitted provided that the following conditions
21 .\" 1. Redistributions of source code must retain the above copyright
22 .\" notice, this list of conditions and the following disclaimer.
23 .\" 2. Redistributions in binary form must reproduce the above copyright
24 .\" notice, this list of conditions and the following disclaimer in the
25 .\" documentation and/or other materials provided with the distribution.
26 .\" 3. All advertising materials mentioning features or use of this software
27 .\" must display the following acknowledgement:
28 .\" This product includes software developed by the University of
29 .\" California, Berkeley and its contributors.
30 .\" 4. Neither the name of the University nor the names of its contributors
31 .\" may be used to endorse or promote products derived from this software
32 .\" without specific prior written permission.
34 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
35 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 .\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
47 .\" Id: getaddrinfo.man3,v 1.2 2009/01/21 00:12:34 each Exp
56 .Nd nodename-to-address translation in protocol-independent manner
58 .Fd #include <sys/socket.h>
59 .Fd #include <netdb.h>
61 .Fn getaddrinfo "const char *nodename" "const char *servname" \
62 "const struct addrinfo *hints" "struct addrinfo **res"
64 .Fn freeaddrinfo "struct addrinfo *ai"
66 .Fn gai_strerror "int ecode"
70 function is defined for protocol-independent nodename-to-address translation.
71 It performs functionality of
75 in more sophisticated manner.
77 The addrinfo structure is defined as a result of including the
82 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
83 int ai_family; /* PF_xxx */
84 int ai_socktype; /* SOCK_xxx */
85 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
86 size_t ai_addrlen; /* length of ai_addr */
87 char *ai_canonname; /* canonical name for nodename */
88 struct sockaddr *ai_addr; /* binary address */
89 struct addrinfo *ai_next; /* next structure in linked list */
97 arguments are pointers to null-terminated strings or
99 One or both of these two arguments must be a
102 In the normal client scenario, both the
107 In the normal server scenario, only the
113 string can be either a node name or a numeric host address string
114 (i.e., a dotted-decimal IPv4 address or an IPv6 hex address).
118 string can be either a service name or a decimal port number.
120 The caller can optionally pass an
122 structure, pointed to by the third argument,
123 to provide hints concerning the type of socket that the caller supports.
126 structure all members other than
139 means the caller will accept any protocol family.
142 means the caller will accept any socket type.
145 means the caller will accept any protocol.
146 For example, if the caller handles only TCP and not UDP, then the
148 member of the hints structure should be set to
153 If the caller handles only IPv4 and not IPv6, then the
157 structure should be set to
162 If the third argument to
166 pointer, this is the same as if the caller had filled in an
168 structure initialized to zero with
172 Upon successful return a pointer to a linked list of one or more
174 structures is returned through the final argument.
175 The caller can process each
177 structure in this list by following the
181 pointer is encountered.
184 structure the three members
189 are the corresponding arguments for a call to the
196 member points to a filled-in socket address structure whose length is
207 structure, then the caller plans to use the returned socket address
208 structure in a call to
214 pointer, then the IP address portion of the socket
215 address structure will be set to
217 for an IPv4 address or
223 bit is not set in the
227 structure, then the returned socket address structure will be ready for a
230 .Pq for a connection-oriented protocol
236 .Pq for a connectionless protocol .
241 pointer, then the IP address portion of the
242 socket address structure will be set to the loopback address.
250 structure, then upon successful return the
254 structure in the linked list will point to a null-terminated string
255 containing the canonical name of the specified
267 string must be a numeric host address string.
268 Otherwise an error of
271 This flag prevents any type of name resolution service (e.g., the DNS)
274 All of the information returned by
276 is dynamically allocated:
279 structures, and the socket address structures and canonical node name
280 strings pointed to by the addrinfo structures.
281 To return this information to the system the function
286 structure pointed to by the
288 is freed, along with any dynamic storage pointed to by the structure.
289 This operation is repeated until a
292 pointer is encountered.
294 To aid applications in printing error messages based on the
300 The argument is one of the
302 values defined earlier and the return value points to a string describing
304 If the argument is not one of the
306 values, the function still returns a pointer to a string whose contents
307 indicate an unknown error.
309 .Bl -tag -width /etc/resolv.conf -compact
311 .It Pa /etc/host.conf
312 .It Pa /etc/resolv.conf
315 Error return status from
317 is zero on success and non-zero on errors.
318 Non-zero error codes are defined in
322 .Bl -tag -width EAI_ADDRFAMILY -compact
323 .It Dv EAI_ADDRFAMILY
324 address family for nodename not supported
326 temporary failure in name resolution
328 invalid value for ai_flags
330 non-recoverable failure in name resolution
332 ai_family not supported
334 memory allocation failure
336 no address associated with nodename
338 nodename nor servname provided, or not known
340 servname not supported for ai_socktype
342 ai_socktype not supported
344 system error returned in errno
347 If called with proper argument,
349 returns a pointer to a string describing the given error code.
350 If the argument is not one of the
352 values, the function still returns a pointer to a string whose contents
353 indicate an unknown error.
356 .Xr gethostbyname 3 ,
357 .Xr getservbyname 3 ,
362 R. Gilligan, S. Thomson, J. Bound, and W. Stevens,
363 ``Basic Socket Interface Extensions for IPv6,'' RFC2133, April 1997.
365 The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit.
369 function is defined IEEE POSIX 1003.1g draft specification,
370 and documented in ``Basic Socket Interface Extensions for IPv6''
373 The text was shamelessly copied from RFC2133.