2 - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
5 - Permission to use, copy, modify, and distribute this software for any
6 - purpose with or without fee is hereby granted, provided that the above
7 - copyright notice and this permission notice appear in all copies.
9 - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 - PERFORMANCE OF THIS SOFTWARE.
17 <!-- $Id: lwres_getaddrinfo.html,v 1.8.2.1.4.12 2006/06/29 13:02:31 marka Exp $ -->
20 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
21 <title>lwres_getaddrinfo</title>
22 <meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
24 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
25 <a name="id2482688"></a><div class="titlepage"></div>
26 <div class="refnamediv">
28 <p>lwres_getaddrinfo, lwres_freeaddrinfo — socket address structure to host and service name</p>
30 <div class="refsynopsisdiv">
32 <div class="funcsynopsis">
33 <pre class="funcsynopsisinfo">#include <lwres/netdb.h></pre>
34 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
36 <td><code class="funcdef">
38 <b class="fsfunc">lwres_getaddrinfo</b>(</code></td>
64 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0">
66 <td><code class="funcdef">
68 <b class="fsfunc">lwres_freeaddrinfo</b>(</code></td>
82 If the operating system does not provide a
83 <span class="type">struct addrinfo</span>,
84 the following structure is used:
87 <pre class="programlisting">
89 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
90 int ai_family; /* PF_xxx */
91 int ai_socktype; /* SOCK_xxx */
92 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
93 size_t ai_addrlen; /* length of ai_addr */
94 char *ai_canonname; /* canonical name for hostname */
95 struct sockaddr *ai_addr; /* binary address */
96 struct addrinfo *ai_next; /* next structure in linked list */
102 <div class="refsect1" lang="en">
103 <a name="id2549448"></a><h2>DESCRIPTION</h2>
105 <code class="function">lwres_getaddrinfo()</code>
106 is used to get a list of IP addresses and port numbers for host
107 <em class="parameter"><code>hostname</code></em>
109 <em class="parameter"><code>servname</code></em>.
111 The function is the lightweight resolver's implementation of
112 <code class="function">getaddrinfo()</code>
113 as defined in RFC2133.
114 <em class="parameter"><code>hostname</code></em>
116 <em class="parameter"><code>servname</code></em>
117 are pointers to null-terminated
119 <span class="type">NULL</span>.
121 <em class="parameter"><code>hostname</code></em>
122 is either a host name or a numeric host address string: a dotted decimal
123 IPv4 address or an IPv6 address.
124 <em class="parameter"><code>servname</code></em>
125 is either a decimal port number or a service name as listed in
126 <code class="filename">/etc/services</code>.
129 <em class="parameter"><code>hints</code></em>
130 is an optional pointer to a
131 <span class="type">struct addrinfo</span>.
132 This structure can be used to provide hints concerning the type of socket
133 that the caller supports or wishes to use.
134 The caller can supply the following structure elements in
135 <em class="parameter"><code>*hints</code></em>:
138 <div class="variablelist"><dl>
139 <dt><span class="term"><code class="constant">ai_family</code></span></dt>
140 <dd><p>The protocol family that should be used.
142 <code class="constant">ai_family</code>
144 <span class="type">PF_UNSPEC</span>,
145 it means the caller will accept any protocol family supported by the
148 <dt><span class="term"><code class="constant">ai_socktype</code></span></dt>
150 denotes the type of socket —
151 <span class="type">SOCK_STREAM</span>,
152 <span class="type">SOCK_DGRAM</span>
154 <span class="type">SOCK_RAW</span>
155 — that is wanted.
157 <code class="constant">ai_socktype</code>
158 is zero the caller will accept any socket type.
160 <dt><span class="term"><code class="constant">ai_protocol</code></span></dt>
162 indicates which transport protocol is wanted: IPPROTO_UDP or
165 <code class="constant">ai_protocol</code>
166 is zero the caller will accept any protocol.
168 <dt><span class="term"><code class="constant">ai_flags</code></span></dt>
173 <span class="type">AI_CANONNAME</span>
174 bit is set, a successful call to
175 <code class="function">lwres_getaddrinfo()</code>
176 will return a null-terminated string containing the canonical name
177 of the specified hostname in
178 <code class="constant">ai_canonname</code>
180 <span class="type">addrinfo</span>
183 <span class="type">AI_PASSIVE</span>
184 bit indicates that the returned socket address structure is intended
185 for used in a call to
186 <span class="citerefentry"><span class="refentrytitle">bind</span>(2)</span>.
188 In this case, if the hostname argument is a
189 <span class="type">NULL</span>
190 pointer, then the IP address portion of the socket
191 address structure will be set to
192 <span class="type">INADDR_ANY</span>
193 for an IPv4 address or
194 <span class="type">IN6ADDR_ANY_INIT</span>
199 <code class="constant">ai_flags</code>
201 <span class="type">AI_PASSIVE</span>
202 bit, the returned socket address structure will be ready
204 <span class="citerefentry"><span class="refentrytitle">connect</span>(2
206 for a connection-oriented protocol or
207 <span class="citerefentry"><span class="refentrytitle">connect</span>(2)</span>,
209 <span class="citerefentry"><span class="refentrytitle">sendto</span>(2)</span>,
212 <span class="citerefentry"><span class="refentrytitle">sendmsg</span>(2
214 if a connectionless protocol was chosen.
215 The IP address portion of the socket address structure will be
216 set to the loopback address if
217 <em class="parameter"><code>hostname</code></em>
219 <span class="type">NULL</span>
221 <span class="type">AI_PASSIVE</span>
223 <code class="constant">ai_flags</code>.
227 <code class="constant">ai_flags</code>
229 <span class="type">AI_NUMERICHOST</span>
231 <em class="parameter"><code>hostname</code></em>
232 should be treated as a numeric string defining an IPv4 or IPv6 address
233 and no name resolution should be attempted.
240 All other elements of the <span class="type">struct addrinfo</span> passed
241 via <em class="parameter"><code>hints</code></em> must be zero.
244 A <em class="parameter"><code>hints</code></em> of <span class="type">NULL</span> is treated as if
245 the caller provided a <span class="type">struct addrinfo</span> initialized to zero
246 with <code class="constant">ai_family</code>set to
247 <code class="constant">PF_UNSPEC</code>.
250 After a successful call to
251 <code class="function">lwres_getaddrinfo()</code>,
252 <em class="parameter"><code>*res</code></em>
253 is a pointer to a linked list of one or more
254 <span class="type">addrinfo</span>
257 <span class="type">struct addrinfo</span>
258 in this list cn be processed by following
260 <code class="constant">ai_next</code>
262 <span class="type">NULL</span>
263 pointer is encountered.
265 <code class="constant">ai_family</code>,
266 <code class="constant">ai_socktype</code>,
268 <code class="constant">ai_protocol</code>
271 <span class="type">addrinfo</span>
272 structure contain the corresponding arguments for a call to
273 <span class="citerefentry"><span class="refentrytitle">socket</span>(2)</span>.
275 <span class="type">addrinfo</span>
276 structure in the list, the
277 <code class="constant">ai_addr</code>
278 member points to a filled-in socket address structure of length
279 <code class="constant">ai_addrlen</code>.
282 All of the information returned by
283 <code class="function">lwres_getaddrinfo()</code>
284 is dynamically allocated: the addrinfo structures, and the socket
285 address structures and canonical host name strings pointed to by the
286 <code class="constant">addrinfo</code>structures.
287 Memory allocated for the dynamically allocated structures created by
289 <code class="function">lwres_getaddrinfo()</code>
291 <code class="function">lwres_freeaddrinfo()</code>.
292 <em class="parameter"><code>ai</code></em>
294 <span class="type">struct addrinfo</span>
296 <code class="function">lwres_getaddrinfo()</code>.
299 <div class="refsect1" lang="en">
300 <a name="id2549874"></a><h2>RETURN VALUES</h2>
302 <code class="function">lwres_getaddrinfo()</code>
303 returns zero on success or one of the error codes listed in
304 <span class="citerefentry"><span class="refentrytitle">gai_strerror</span>(3
308 <em class="parameter"><code>hostname</code></em>
310 <em class="parameter"><code>servname</code></em>
312 <span class="type">NULL</span>
313 <code class="function">lwres_getaddrinfo()</code>
315 <span class="errorcode">EAI_NONAME</span>.
319 <div class="refsect1" lang="en">
320 <a name="id2549912"></a><h2>SEE ALSO</h2>
322 <span class="citerefentry"><span class="refentrytitle">lwres</span>(3)</span>,
324 <span class="citerefentry"><span class="refentrytitle">lwres_getaddrinfo</span>(3)</span>,
326 <span class="citerefentry"><span class="refentrytitle">lwres_freeaddrinfo</span>(3)</span>,
328 <span class="citerefentry"><span class="refentrytitle">lwres_gai_strerror</span>(3)</span>,
330 <span class="citerefentry"><span class="refentrytitle">RFC2133</span></span>,
332 <span class="citerefentry"><span class="refentrytitle">getservbyname</span>(3)</span>,
334 <span class="citerefentry"><span class="refentrytitle">bind</span>(2)</span>,
336 <span class="citerefentry"><span class="refentrytitle">connect</span>(2)</span>,
338 <span class="citerefentry"><span class="refentrytitle">sendto</span>(2)</span>,
340 <span class="citerefentry"><span class="refentrytitle">sendmsg</span>(2)</span>,
342 <span class="citerefentry"><span class="refentrytitle">socket</span>(2)</span>.