1 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
3 - Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
4 - Copyright (C) 2001, 2003 Internet Software Consortium.
6 - Permission to use, copy, modify, and distribute this software for any
7 - purpose with or without fee is hereby granted, provided that the above
8 - copyright notice and this permission notice appear in all copies.
10 - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 - PERFORMANCE OF THIS SOFTWARE.
19 <!-- $Id: lwres_getaddrinfo.docbook,v 1.5.206.2 2004/03/06 08:15:39 marka Exp $ -->
24 <date>Jun 30, 2000</date>
28 <refentrytitle>lwres_getaddrinfo</refentrytitle>
29 <manvolnum>3</manvolnum>
30 <refmiscinfo>BIND9</refmiscinfo>
34 <refname>lwres_getaddrinfo</refname>
35 <refname>lwres_freeaddrinfo</refname>
36 <refpurpose>socket address structure to host and service name</refpurpose>
40 <funcsynopsisinfo>#include <lwres/netdb.h></funcsynopsisinfo>
44 <function>lwres_getaddrinfo</function></funcdef>
45 <paramdef>const char *hostname</paramdef>
46 <paramdef>const char *servname</paramdef>
47 <paramdef>const struct addrinfo *hints</paramdef>
48 <paramdef>struct addrinfo **res</paramdef>
53 <function>lwres_freeaddrinfo</function></funcdef>
54 <paramdef>struct addrinfo *ai</paramdef>
59 If the operating system does not provide a
60 <type>struct addrinfo</type>,
61 the following structure is used:
65 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
66 int ai_family; /* PF_xxx */
67 int ai_socktype; /* SOCK_xxx */
68 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
69 size_t ai_addrlen; /* length of ai_addr */
70 char *ai_canonname; /* canonical name for hostname */
71 struct sockaddr *ai_addr; /* binary address */
72 struct addrinfo *ai_next; /* next structure in linked list */
80 <title>DESCRIPTION</title>
82 <function>lwres_getaddrinfo()</function>
83 is used to get a list of IP addresses and port numbers for host
84 <parameter>hostname</parameter>
86 <parameter>servname</parameter>.
88 The function is the lightweight resolver's implementation of
89 <function>getaddrinfo()</function>
90 as defined in RFC2133.
91 <parameter>hostname</parameter>
93 <parameter>servname</parameter>
94 are pointers to null-terminated
98 <parameter>hostname</parameter>
99 is either a host name or a numeric host address string: a dotted decimal
100 IPv4 address or an IPv6 address.
101 <parameter>servname</parameter>
102 is either a decimal port number or a service name as listed in
103 <filename>/etc/services</filename>.
107 <parameter>hints</parameter>
108 is an optional pointer to a
109 <type>struct addrinfo</type>.
110 This structure can be used to provide hints concerning the type of socket
111 that the caller supports or wishes to use.
112 The caller can supply the following structure elements in
113 <parameter>*hints</parameter>:
116 <varlistentry><term><constant>ai_family</constant></term>
118 <para>The protocol family that should be used.
120 <constant>ai_family</constant>
122 <type>PF_UNSPEC</type>,
123 it means the caller will accept any protocol family supported by the
125 </para></listitem></varlistentry>
126 <varlistentry><term><constant>ai_socktype</constant></term>
129 denotes the type of socket —
130 <type>SOCK_STREAM</type>,
131 <type>SOCK_DGRAM</type>
133 <type>SOCK_RAW</type>
134 — that is wanted.
136 <constant>ai_socktype</constant>
137 is zero the caller will accept any socket type.
141 <varlistentry><term><constant>ai_protocol</constant></term>
144 indicates which transport protocol is wanted: IPPROTO_UDP or
147 <constant>ai_protocol</constant>
148 is zero the caller will accept any protocol.
152 <varlistentry><term><constant>ai_flags</constant></term>
157 <type>AI_CANONNAME</type>
158 bit is set, a successful call to
159 <function>lwres_getaddrinfo()</function>
160 will return a null-terminated string containing the canonical name
161 of the specified hostname in
162 <constant>ai_canonname</constant>
164 <type>addrinfo</type>
167 <type>AI_PASSIVE</type>
168 bit indicates that the returned socket address structure is intended
169 for used in a call to
171 <refentrytitle>bind</refentrytitle><manvolnum>2</manvolnum>
174 In this case, if the hostname argument is a
176 pointer, then the IP address portion of the socket
177 address structure will be set to
178 <type>INADDR_ANY</type>
179 for an IPv4 address or
180 <type>IN6ADDR_ANY_INIT</type>
185 <constant>ai_flags</constant>
187 <type>AI_PASSIVE</type>
188 bit, the returned socket address structure will be ready
191 <refentrytitle>connect</refentrytitle><manvolnum>2
194 for a connection-oriented protocol or
196 <refentrytitle>connect</refentrytitle><manvolnum>2</manvolnum>
200 <refentrytitle>sendto</refentrytitle><manvolnum>2</manvolnum>
205 <refentrytitle>sendmsg</refentrytitle><manvolnum>2
208 if a connectionless protocol was chosen.
209 The IP address portion of the socket address structure will be
210 set to the loopback address if
211 <parameter>hostname</parameter>
215 <type>AI_PASSIVE</type>
217 <constant>ai_flags</constant>.
221 <constant>ai_flags</constant>
223 <type>AI_NUMERICHOST</type>
225 <parameter>hostname</parameter>
226 should be treated as a numeric string defining an IPv4 or IPv6 address
227 and no name resolution should be attempted.
235 All other elements of the <type>struct addrinfo</type> passed
236 via <parameter>hints</parameter> must be zero.
240 A <parameter>hints</parameter> of <type>NULL</type> is treated as if
241 the caller provided a <type>struct addrinfo</type> initialized to zero
242 with <constant>ai_family</constant>set to
243 <constant>PF_UNSPEC</constant>.
247 After a successful call to
248 <function>lwres_getaddrinfo()</function>,
249 <parameter>*res</parameter>
250 is a pointer to a linked list of one or more
251 <type>addrinfo</type>
254 <type>struct addrinfo</type>
255 in this list cn be processed by following
257 <constant>ai_next</constant>
260 pointer is encountered.
262 <constant>ai_family</constant>,
263 <constant>ai_socktype</constant>,
265 <constant>ai_protocol</constant>
268 <type>addrinfo</type>
269 structure contain the corresponding arguments for a call to
271 <refentrytitle>socket</refentrytitle><manvolnum>2</manvolnum>
274 <type>addrinfo</type>
275 structure in the list, the
276 <constant>ai_addr</constant>
277 member points to a filled-in socket address structure of length
278 <constant>ai_addrlen</constant>.
282 All of the information returned by
283 <function>lwres_getaddrinfo()</function>
284 is dynamically allocated: the addrinfo structures, and the socket
285 address structures and canonical host name strings pointed to by the
286 <constant>addrinfo</constant>structures.
287 Memory allocated for the dynamically allocated structures created by
289 <function>lwres_getaddrinfo()</function>
291 <function>lwres_freeaddrinfo()</function>.
292 <parameter>ai</parameter>
294 <type>struct addrinfo</type>
296 <function>lwres_getaddrinfo()</function>.
302 <title>RETURN VALUES</title>
304 <function>lwres_getaddrinfo()</function>
305 returns zero on success or one of the error codes listed in
307 <refentrytitle>gai_strerror</refentrytitle><manvolnum>3
312 <parameter>hostname</parameter>
314 <parameter>servname</parameter>
317 <function>lwres_getaddrinfo()</function>
319 <errorcode>EAI_NONAME</errorcode>.
324 <title>SEE ALSO</title>
327 <refentrytitle>lwres</refentrytitle><manvolnum>3</manvolnum>
331 <refentrytitle>lwres_getaddrinfo</refentrytitle><manvolnum>3</manvolnum>
335 <refentrytitle>lwres_freeaddrinfo</refentrytitle><manvolnum>3</manvolnum>
339 <refentrytitle>lwres_gai_strerror</refentrytitle><manvolnum>3</manvolnum>
343 <refentrytitle>RFC2133</refentrytitle>
347 <refentrytitle>getservbyname</refentrytitle><manvolnum>3</manvolnum>
351 <refentrytitle>bind</refentrytitle><manvolnum>2</manvolnum>
355 <refentrytitle>connect</refentrytitle><manvolnum>2</manvolnum>
359 <refentrytitle>sendto</refentrytitle><manvolnum>2</manvolnum>
363 <refentrytitle>sendmsg</refentrytitle><manvolnum>2</manvolnum>
367 <refentrytitle>socket</refentrytitle><manvolnum>2</manvolnum>