1 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
3 [<!ENTITY mdash "—">]>
5 - Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
6 - Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
8 - Permission to use, copy, modify, and/or distribute this software for any
9 - purpose with or without fee is hereby granted, provided that the above
10 - copyright notice and this permission notice appear in all copies.
12 - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
13 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14 - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16 - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
17 - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18 - PERFORMANCE OF THIS SOFTWARE.
21 <!-- Id: lwres_getaddrinfo.docbook,v 1.13 2007/06/18 23:47:51 tbox Exp -->
25 <date>Jun 30, 2000</date>
29 <refentrytitle>lwres_getaddrinfo</refentrytitle>
30 <manvolnum>3</manvolnum>
31 <refmiscinfo>BIND9</refmiscinfo>
39 <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
45 <holder>Internet Software Consortium.</holder>
50 <refname>lwres_getaddrinfo</refname>
51 <refname>lwres_freeaddrinfo</refname>
52 <refpurpose>socket address structure to host and service name</refpurpose>
56 <funcsynopsisinfo>#include <lwres/netdb.h></funcsynopsisinfo>
60 <function>lwres_getaddrinfo</function></funcdef>
61 <paramdef>const char *<parameter>hostname</parameter></paramdef>
62 <paramdef>const char *<parameter>servname</parameter></paramdef>
63 <paramdef>const struct addrinfo *<parameter>hints</parameter></paramdef>
64 <paramdef>struct addrinfo **<parameter>res</parameter></paramdef>
69 <function>lwres_freeaddrinfo</function></funcdef>
70 <paramdef>struct addrinfo *<parameter>ai</parameter></paramdef>
75 If the operating system does not provide a
76 <type>struct addrinfo</type>,
77 the following structure is used:
79 <para><programlisting>
81 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
82 int ai_family; /* PF_xxx */
83 int ai_socktype; /* SOCK_xxx */
84 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
85 size_t ai_addrlen; /* length of ai_addr */
86 char *ai_canonname; /* canonical name for hostname */
87 struct sockaddr *ai_addr; /* binary address */
88 struct addrinfo *ai_next; /* next structure in linked list */
96 <title>DESCRIPTION</title>
98 <para><function>lwres_getaddrinfo()</function>
99 is used to get a list of IP addresses and port numbers for host
100 <parameter>hostname</parameter> and service
101 <parameter>servname</parameter>.
103 The function is the lightweight resolver's implementation of
104 <function>getaddrinfo()</function> as defined in RFC2133.
105 <parameter>hostname</parameter> and
106 <parameter>servname</parameter> are pointers to null-terminated
107 strings or <type>NULL</type>.
109 <parameter>hostname</parameter> is either a host name or a
110 numeric host address string: a dotted decimal IPv4 address or an
111 IPv6 address. <parameter>servname</parameter> is either a
112 decimal port number or a service name as listed in
113 <filename>/etc/services</filename>.
116 <para><parameter>hints</parameter>
117 is an optional pointer to a
118 <type>struct addrinfo</type>.
119 This structure can be used to provide hints concerning the type of
121 that the caller supports or wishes to use.
122 The caller can supply the following structure elements in
123 <parameter>*hints</parameter>:
127 <term><constant>ai_family</constant></term>
130 The protocol family that should be used.
132 <constant>ai_family</constant>
134 <type>PF_UNSPEC</type>,
135 it means the caller will accept any protocol family supported by
142 <term><constant>ai_socktype</constant></term>
145 denotes the type of socket —
146 <type>SOCK_STREAM</type>,
147 <type>SOCK_DGRAM</type>
149 <type>SOCK_RAW</type>
150 — that is wanted.
152 <constant>ai_socktype</constant>
153 is zero the caller will accept any socket type.
158 <term><constant>ai_protocol</constant></term>
161 indicates which transport protocol is wanted: IPPROTO_UDP or
164 <constant>ai_protocol</constant>
165 is zero the caller will accept any protocol.
170 <term><constant>ai_flags</constant></term>
175 <type>AI_CANONNAME</type>
176 bit is set, a successful call to
177 <function>lwres_getaddrinfo()</function>
178 will return a null-terminated string containing the canonical
180 of the specified hostname in
181 <constant>ai_canonname</constant>
183 <type>addrinfo</type>
186 <type>AI_PASSIVE</type>
187 bit indicates that the returned socket address structure is
189 for used in a call to
191 <refentrytitle>bind</refentrytitle><manvolnum>2</manvolnum>
194 In this case, if the hostname argument is a
196 pointer, then the IP address portion of the socket
197 address structure will be set to
198 <type>INADDR_ANY</type>
199 for an IPv4 address or
200 <type>IN6ADDR_ANY_INIT</type>
205 <constant>ai_flags</constant>
207 <type>AI_PASSIVE</type>
208 bit, the returned socket address structure will be ready
211 <refentrytitle>connect</refentrytitle><manvolnum>2</manvolnum>
213 for a connection-oriented protocol or
215 <refentrytitle>connect</refentrytitle><manvolnum>2</manvolnum>
219 <refentrytitle>sendto</refentrytitle><manvolnum>2</manvolnum>
224 <refentrytitle>sendmsg</refentrytitle><manvolnum>2</manvolnum>
226 if a connectionless protocol was chosen.
227 The IP address portion of the socket address structure will be
228 set to the loopback address if
229 <parameter>hostname</parameter>
233 <type>AI_PASSIVE</type>
235 <constant>ai_flags</constant>.
239 <constant>ai_flags</constant>
241 <type>AI_NUMERICHOST</type>
243 <parameter>hostname</parameter>
244 should be treated as a numeric string defining an IPv4 or IPv6
246 and no name resolution should be attempted.
254 All other elements of the <type>struct addrinfo</type> passed
255 via <parameter>hints</parameter> must be zero.
259 A <parameter>hints</parameter> of <type>NULL</type> is
261 the caller provided a <type>struct addrinfo</type> initialized to zero
262 with <constant>ai_family</constant>set to
263 <constant>PF_UNSPEC</constant>.
267 After a successful call to
268 <function>lwres_getaddrinfo()</function>,
269 <parameter>*res</parameter>
270 is a pointer to a linked list of one or more
271 <type>addrinfo</type>
274 <type>struct addrinfo</type>
275 in this list cn be processed by following
277 <constant>ai_next</constant>
280 pointer is encountered.
282 <constant>ai_family</constant>,
283 <constant>ai_socktype</constant>,
285 <constant>ai_protocol</constant>
288 <type>addrinfo</type>
289 structure contain the corresponding arguments for a call to
291 <refentrytitle>socket</refentrytitle><manvolnum>2</manvolnum>
294 <type>addrinfo</type>
295 structure in the list, the
296 <constant>ai_addr</constant>
297 member points to a filled-in socket address structure of length
298 <constant>ai_addrlen</constant>.
302 All of the information returned by
303 <function>lwres_getaddrinfo()</function>
304 is dynamically allocated: the addrinfo structures, and the socket
305 address structures and canonical host name strings pointed to by the
306 <constant>addrinfo</constant>structures.
307 Memory allocated for the dynamically allocated structures created by
309 <function>lwres_getaddrinfo()</function>
311 <function>lwres_freeaddrinfo()</function>.
312 <parameter>ai</parameter>
314 <type>struct addrinfo</type>
316 <function>lwres_getaddrinfo()</function>.
322 <title>RETURN VALUES</title>
324 <para><function>lwres_getaddrinfo()</function>
325 returns zero on success or one of the error codes listed in
327 <refentrytitle>gai_strerror</refentrytitle><manvolnum>3</manvolnum>
329 if an error occurs. If both <parameter>hostname</parameter> and
330 <parameter>servname</parameter> are <type>NULL</type>
331 <function>lwres_getaddrinfo()</function> returns
332 <errorcode>EAI_NONAME</errorcode>.
336 <title>SEE ALSO</title>
338 <refentrytitle>lwres</refentrytitle><manvolnum>3</manvolnum>
342 <refentrytitle>lwres_getaddrinfo</refentrytitle><manvolnum>3</manvolnum>
346 <refentrytitle>lwres_freeaddrinfo</refentrytitle><manvolnum>3</manvolnum>
350 <refentrytitle>lwres_gai_strerror</refentrytitle><manvolnum>3</manvolnum>
354 <refentrytitle>RFC2133</refentrytitle>
358 <refentrytitle>getservbyname</refentrytitle><manvolnum>3</manvolnum>
362 <refentrytitle>bind</refentrytitle><manvolnum>2</manvolnum>
366 <refentrytitle>connect</refentrytitle><manvolnum>2</manvolnum>
370 <refentrytitle>sendto</refentrytitle><manvolnum>2</manvolnum>
374 <refentrytitle>sendmsg</refentrytitle><manvolnum>2</manvolnum>
378 <refentrytitle>socket</refentrytitle><manvolnum>2</manvolnum>