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.10 2005/10/13 02:33:56 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.69.1">
24 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
25 <a name="id2463721"></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>
59 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"><tr>
60 <td><code class="funcdef">
62 <b class="fsfunc">lwres_freeaddrinfo</b>(</code></td>
69 If the operating system does not provide a
70 <span class="type">struct addrinfo</span>,
71 the following structure is used:
74 <pre class="programlisting">
76 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
77 int ai_family; /* PF_xxx */
78 int ai_socktype; /* SOCK_xxx */
79 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
80 size_t ai_addrlen; /* length of ai_addr */
81 char *ai_canonname; /* canonical name for hostname */
82 struct sockaddr *ai_addr; /* binary address */
83 struct addrinfo *ai_next; /* next structure in linked list */
89 <div class="refsect1" lang="en">
90 <a name="id2525883"></a><h2>DESCRIPTION</h2>
92 <code class="function">lwres_getaddrinfo()</code>
93 is used to get a list of IP addresses and port numbers for host
94 <em class="parameter"><code>hostname</code></em>
96 <em class="parameter"><code>servname</code></em>.
98 The function is the lightweight resolver's implementation of
99 <code class="function">getaddrinfo()</code>
100 as defined in RFC2133.
101 <em class="parameter"><code>hostname</code></em>
103 <em class="parameter"><code>servname</code></em>
104 are pointers to null-terminated
106 <span class="type">NULL</span>.
108 <em class="parameter"><code>hostname</code></em>
109 is either a host name or a numeric host address string: a dotted decimal
110 IPv4 address or an IPv6 address.
111 <em class="parameter"><code>servname</code></em>
112 is either a decimal port number or a service name as listed in
113 <code class="filename">/etc/services</code>.
116 <em class="parameter"><code>hints</code></em>
117 is an optional pointer to a
118 <span class="type">struct addrinfo</span>.
119 This structure can be used to provide hints concerning the type of socket
120 that the caller supports or wishes to use.
121 The caller can supply the following structure elements in
122 <em class="parameter"><code>*hints</code></em>:
125 <div class="variablelist"><dl>
126 <dt><span class="term"><code class="constant">ai_family</code></span></dt>
127 <dd><p>The protocol family that should be used.
129 <code class="constant">ai_family</code>
131 <span class="type">PF_UNSPEC</span>,
132 it means the caller will accept any protocol family supported by the
135 <dt><span class="term"><code class="constant">ai_socktype</code></span></dt>
137 denotes the type of socket —
138 <span class="type">SOCK_STREAM</span>,
139 <span class="type">SOCK_DGRAM</span>
141 <span class="type">SOCK_RAW</span>
142 — that is wanted.
144 <code class="constant">ai_socktype</code>
145 is zero the caller will accept any socket type.
147 <dt><span class="term"><code class="constant">ai_protocol</code></span></dt>
149 indicates which transport protocol is wanted: IPPROTO_UDP or
152 <code class="constant">ai_protocol</code>
153 is zero the caller will accept any protocol.
155 <dt><span class="term"><code class="constant">ai_flags</code></span></dt>
160 <span class="type">AI_CANONNAME</span>
161 bit is set, a successful call to
162 <code class="function">lwres_getaddrinfo()</code>
163 will return a null-terminated string containing the canonical name
164 of the specified hostname in
165 <code class="constant">ai_canonname</code>
167 <span class="type">addrinfo</span>
170 <span class="type">AI_PASSIVE</span>
171 bit indicates that the returned socket address structure is intended
172 for used in a call to
173 <span class="citerefentry"><span class="refentrytitle">bind</span>(2)</span>.
175 In this case, if the hostname argument is a
176 <span class="type">NULL</span>
177 pointer, then the IP address portion of the socket
178 address structure will be set to
179 <span class="type">INADDR_ANY</span>
180 for an IPv4 address or
181 <span class="type">IN6ADDR_ANY_INIT</span>
186 <code class="constant">ai_flags</code>
188 <span class="type">AI_PASSIVE</span>
189 bit, the returned socket address structure will be ready
191 <span class="citerefentry"><span class="refentrytitle">connect</span>(2
193 for a connection-oriented protocol or
194 <span class="citerefentry"><span class="refentrytitle">connect</span>(2)</span>,
196 <span class="citerefentry"><span class="refentrytitle">sendto</span>(2)</span>,
199 <span class="citerefentry"><span class="refentrytitle">sendmsg</span>(2
201 if a connectionless protocol was chosen.
202 The IP address portion of the socket address structure will be
203 set to the loopback address if
204 <em class="parameter"><code>hostname</code></em>
206 <span class="type">NULL</span>
208 <span class="type">AI_PASSIVE</span>
210 <code class="constant">ai_flags</code>.
214 <code class="constant">ai_flags</code>
216 <span class="type">AI_NUMERICHOST</span>
218 <em class="parameter"><code>hostname</code></em>
219 should be treated as a numeric string defining an IPv4 or IPv6 address
220 and no name resolution should be attempted.
227 All other elements of the <span class="type">struct addrinfo</span> passed
228 via <em class="parameter"><code>hints</code></em> must be zero.
231 A <em class="parameter"><code>hints</code></em> of <span class="type">NULL</span> is treated as if
232 the caller provided a <span class="type">struct addrinfo</span> initialized to zero
233 with <code class="constant">ai_family</code>set to
234 <code class="constant">PF_UNSPEC</code>.
237 After a successful call to
238 <code class="function">lwres_getaddrinfo()</code>,
239 <em class="parameter"><code>*res</code></em>
240 is a pointer to a linked list of one or more
241 <span class="type">addrinfo</span>
244 <span class="type">struct addrinfo</span>
245 in this list cn be processed by following
247 <code class="constant">ai_next</code>
249 <span class="type">NULL</span>
250 pointer is encountered.
252 <code class="constant">ai_family</code>,
253 <code class="constant">ai_socktype</code>,
255 <code class="constant">ai_protocol</code>
258 <span class="type">addrinfo</span>
259 structure contain the corresponding arguments for a call to
260 <span class="citerefentry"><span class="refentrytitle">socket</span>(2)</span>.
262 <span class="type">addrinfo</span>
263 structure in the list, the
264 <code class="constant">ai_addr</code>
265 member points to a filled-in socket address structure of length
266 <code class="constant">ai_addrlen</code>.
269 All of the information returned by
270 <code class="function">lwres_getaddrinfo()</code>
271 is dynamically allocated: the addrinfo structures, and the socket
272 address structures and canonical host name strings pointed to by the
273 <code class="constant">addrinfo</code>structures.
274 Memory allocated for the dynamically allocated structures created by
276 <code class="function">lwres_getaddrinfo()</code>
278 <code class="function">lwres_freeaddrinfo()</code>.
279 <em class="parameter"><code>ai</code></em>
281 <span class="type">struct addrinfo</span>
283 <code class="function">lwres_getaddrinfo()</code>.
286 <div class="refsect1" lang="en">
287 <a name="id2526309"></a><h2>RETURN VALUES</h2>
289 <code class="function">lwres_getaddrinfo()</code>
290 returns zero on success or one of the error codes listed in
291 <span class="citerefentry"><span class="refentrytitle">gai_strerror</span>(3
295 <em class="parameter"><code>hostname</code></em>
297 <em class="parameter"><code>servname</code></em>
299 <span class="type">NULL</span>
300 <code class="function">lwres_getaddrinfo()</code>
302 <span class="errorcode">EAI_NONAME</span>.
306 <div class="refsect1" lang="en">
307 <a name="id2526347"></a><h2>SEE ALSO</h2>
309 <span class="citerefentry"><span class="refentrytitle">lwres</span>(3)</span>,
311 <span class="citerefentry"><span class="refentrytitle">lwres_getaddrinfo</span>(3)</span>,
313 <span class="citerefentry"><span class="refentrytitle">lwres_freeaddrinfo</span>(3)</span>,
315 <span class="citerefentry"><span class="refentrytitle">lwres_gai_strerror</span>(3)</span>,
317 <span class="citerefentry"><span class="refentrytitle">RFC2133</span></span>,
319 <span class="citerefentry"><span class="refentrytitle">getservbyname</span>(3)</span>,
321 <span class="citerefentry"><span class="refentrytitle">bind</span>(2)</span>,
323 <span class="citerefentry"><span class="refentrytitle">connect</span>(2)</span>,
325 <span class="citerefentry"><span class="refentrytitle">sendto</span>(2)</span>,
327 <span class="citerefentry"><span class="refentrytitle">sendmsg</span>(2)</span>,
329 <span class="citerefentry"><span class="refentrytitle">socket</span>(2)</span>.