1 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.0//EN"
2 "http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd"
3 [<!ENTITY mdash "—">]>
5 - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
6 - Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
8 - Permission to use, copy, modify, and 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.5.206.4 2005/05/12 21:36:14 sra Exp $ -->
26 <date>Jun 30, 2000</date>
30 <refentrytitle>lwres_getaddrinfo</refentrytitle>
31 <manvolnum>3</manvolnum>
32 <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 *hostname</paramdef>
62 <paramdef>const char *servname</paramdef>
63 <paramdef>const struct addrinfo *hints</paramdef>
64 <paramdef>struct addrinfo **res</paramdef>
69 <function>lwres_freeaddrinfo</function></funcdef>
70 <paramdef>struct addrinfo *ai</paramdef>
75 If the operating system does not provide a
76 <type>struct addrinfo</type>,
77 the following structure is used:
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 <function>lwres_getaddrinfo()</function>
99 is used to get a list of IP addresses and port numbers for host
100 <parameter>hostname</parameter>
102 <parameter>servname</parameter>.
104 The function is the lightweight resolver's implementation of
105 <function>getaddrinfo()</function>
106 as defined in RFC2133.
107 <parameter>hostname</parameter>
109 <parameter>servname</parameter>
110 are pointers to null-terminated
114 <parameter>hostname</parameter>
115 is either a host name or a numeric host address string: a dotted decimal
116 IPv4 address or an IPv6 address.
117 <parameter>servname</parameter>
118 is either a decimal port number or a service name as listed in
119 <filename>/etc/services</filename>.
123 <parameter>hints</parameter>
124 is an optional pointer to a
125 <type>struct addrinfo</type>.
126 This structure can be used to provide hints concerning the type of socket
127 that the caller supports or wishes to use.
128 The caller can supply the following structure elements in
129 <parameter>*hints</parameter>:
132 <varlistentry><term><constant>ai_family</constant></term>
134 <para>The protocol family that should be used.
136 <constant>ai_family</constant>
138 <type>PF_UNSPEC</type>,
139 it means the caller will accept any protocol family supported by the
141 </para></listitem></varlistentry>
142 <varlistentry><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.
157 <varlistentry><term><constant>ai_protocol</constant></term>
160 indicates which transport protocol is wanted: IPPROTO_UDP or
163 <constant>ai_protocol</constant>
164 is zero the caller will accept any protocol.
168 <varlistentry><term><constant>ai_flags</constant></term>
173 <type>AI_CANONNAME</type>
174 bit is set, a successful call to
175 <function>lwres_getaddrinfo()</function>
176 will return a null-terminated string containing the canonical name
177 of the specified hostname in
178 <constant>ai_canonname</constant>
180 <type>addrinfo</type>
183 <type>AI_PASSIVE</type>
184 bit indicates that the returned socket address structure is intended
185 for used in a call to
187 <refentrytitle>bind</refentrytitle><manvolnum>2</manvolnum>
190 In this case, if the hostname argument is a
192 pointer, then the IP address portion of the socket
193 address structure will be set to
194 <type>INADDR_ANY</type>
195 for an IPv4 address or
196 <type>IN6ADDR_ANY_INIT</type>
201 <constant>ai_flags</constant>
203 <type>AI_PASSIVE</type>
204 bit, the returned socket address structure will be ready
207 <refentrytitle>connect</refentrytitle><manvolnum>2
210 for a connection-oriented protocol or
212 <refentrytitle>connect</refentrytitle><manvolnum>2</manvolnum>
216 <refentrytitle>sendto</refentrytitle><manvolnum>2</manvolnum>
221 <refentrytitle>sendmsg</refentrytitle><manvolnum>2
224 if a connectionless protocol was chosen.
225 The IP address portion of the socket address structure will be
226 set to the loopback address if
227 <parameter>hostname</parameter>
231 <type>AI_PASSIVE</type>
233 <constant>ai_flags</constant>.
237 <constant>ai_flags</constant>
239 <type>AI_NUMERICHOST</type>
241 <parameter>hostname</parameter>
242 should be treated as a numeric string defining an IPv4 or IPv6 address
243 and no name resolution should be attempted.
251 All other elements of the <type>struct addrinfo</type> passed
252 via <parameter>hints</parameter> must be zero.
256 A <parameter>hints</parameter> of <type>NULL</type> is treated as if
257 the caller provided a <type>struct addrinfo</type> initialized to zero
258 with <constant>ai_family</constant>set to
259 <constant>PF_UNSPEC</constant>.
263 After a successful call to
264 <function>lwres_getaddrinfo()</function>,
265 <parameter>*res</parameter>
266 is a pointer to a linked list of one or more
267 <type>addrinfo</type>
270 <type>struct addrinfo</type>
271 in this list cn be processed by following
273 <constant>ai_next</constant>
276 pointer is encountered.
278 <constant>ai_family</constant>,
279 <constant>ai_socktype</constant>,
281 <constant>ai_protocol</constant>
284 <type>addrinfo</type>
285 structure contain the corresponding arguments for a call to
287 <refentrytitle>socket</refentrytitle><manvolnum>2</manvolnum>
290 <type>addrinfo</type>
291 structure in the list, the
292 <constant>ai_addr</constant>
293 member points to a filled-in socket address structure of length
294 <constant>ai_addrlen</constant>.
298 All of the information returned by
299 <function>lwres_getaddrinfo()</function>
300 is dynamically allocated: the addrinfo structures, and the socket
301 address structures and canonical host name strings pointed to by the
302 <constant>addrinfo</constant>structures.
303 Memory allocated for the dynamically allocated structures created by
305 <function>lwres_getaddrinfo()</function>
307 <function>lwres_freeaddrinfo()</function>.
308 <parameter>ai</parameter>
310 <type>struct addrinfo</type>
312 <function>lwres_getaddrinfo()</function>.
318 <title>RETURN VALUES</title>
320 <function>lwres_getaddrinfo()</function>
321 returns zero on success or one of the error codes listed in
323 <refentrytitle>gai_strerror</refentrytitle><manvolnum>3
328 <parameter>hostname</parameter>
330 <parameter>servname</parameter>
333 <function>lwres_getaddrinfo()</function>
335 <errorcode>EAI_NONAME</errorcode>.
340 <title>SEE ALSO</title>
343 <refentrytitle>lwres</refentrytitle><manvolnum>3</manvolnum>
347 <refentrytitle>lwres_getaddrinfo</refentrytitle><manvolnum>3</manvolnum>
351 <refentrytitle>lwres_freeaddrinfo</refentrytitle><manvolnum>3</manvolnum>
355 <refentrytitle>lwres_gai_strerror</refentrytitle><manvolnum>3</manvolnum>
359 <refentrytitle>RFC2133</refentrytitle>
363 <refentrytitle>getservbyname</refentrytitle><manvolnum>3</manvolnum>
367 <refentrytitle>bind</refentrytitle><manvolnum>2</manvolnum>
371 <refentrytitle>connect</refentrytitle><manvolnum>2</manvolnum>
375 <refentrytitle>sendto</refentrytitle><manvolnum>2</manvolnum>
379 <refentrytitle>sendmsg</refentrytitle><manvolnum>2</manvolnum>
383 <refentrytitle>socket</refentrytitle><manvolnum>2</manvolnum>