Merge from vendor branch BZIP:
[dragonfly.git] / contrib / bind-9.3 / lib / lwres / man / lwres_gethostent.html
1 <!--
2  - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3  - Copyright (C) 2001 Internet Software Consortium.
4  - 
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.
8  - 
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.
16 -->
17 <!-- $Id: lwres_gethostent.html,v 1.8.2.1.4.10 2006/06/29 13:02:31 marka Exp $ -->
18 <html>
19 <head>
20 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
21 <title>lwres_gethostent</title>
22 <meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
23 </head>
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">
27 <h2>Name</h2>
28 <p>lwres_gethostbyname, lwres_gethostbyname2, lwres_gethostbyaddr, lwres_gethostent, lwres_sethostent, lwres_endhostent, lwres_gethostbyname_r, lwres_gethostbyaddr_r, lwres_gethostent_r, lwres_sethostent_r, lwres_endhostent_r &#8212; lightweight resolver get network host entry</p>
29 </div>
30 <div class="refsynopsisdiv">
31 <h2>Synopsis</h2>
32 <div class="funcsynopsis">
33 <pre class="funcsynopsisinfo">#include &lt;lwres/netdb.h&gt;</pre>
34 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
35 <tr>
36 <td><code class="funcdef">
37 struct hostent *
38 <b class="fsfunc">lwres_gethostbyname</b>(</code></td>
39 <td> </td>
40 <td>
41 <code>)</code>;</td>
42 </tr>
43 <tr>
44 <td> </td>
45 <td> </td>
46 <td>
47 <code>)</code>;</td>
48 </tr>
49 </table>
50 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
51 <tr>
52 <td><code class="funcdef">
53 struct hostent *
54 <b class="fsfunc">lwres_gethostbyname2</b>(</code></td>
55 <td> </td>
56 <td>, </td>
57 </tr>
58 <tr>
59 <td> </td>
60 <td> </td>
61 <td>, </td>
62 </tr>
63 <tr>
64 <td> </td>
65 <td> </td>
66 <td>
67 <code>)</code>;</td>
68 </tr>
69 </table>
70 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
71 <tr>
72 <td><code class="funcdef">
73 struct hostent *
74 <b class="fsfunc">lwres_gethostbyaddr</b>(</code></td>
75 <td> </td>
76 <td>, </td>
77 </tr>
78 <tr>
79 <td> </td>
80 <td> </td>
81 <td>, </td>
82 </tr>
83 <tr>
84 <td> </td>
85 <td> </td>
86 <td>, </td>
87 </tr>
88 <tr>
89 <td> </td>
90 <td> </td>
91 <td>
92 <code>)</code>;</td>
93 </tr>
94 </table>
95 <p><code class="funcdef">
96 struct hostent *
97 <b class="fsfunc">lwres_gethostent</b>(</code>void<code>)</code>;</p>
98 <p><code class="funcdef">
99 void
100 <b class="fsfunc">lwres_sethostent</b>(</code>int stayopen<code>)</code>;</p>
101 <p><code class="funcdef">
102 void
103 <b class="fsfunc">lwres_endhostent</b>(</code>void<code>)</code>;</p>
104 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
105 <tr>
106 <td><code class="funcdef">
107 struct hostent *
108 <b class="fsfunc">lwres_gethostbyname_r</b>(</code></td>
109 <td> </td>
110 <td>, </td>
111 </tr>
112 <tr>
113 <td> </td>
114 <td> </td>
115 <td>, </td>
116 </tr>
117 <tr>
118 <td> </td>
119 <td> </td>
120 <td>, </td>
121 </tr>
122 <tr>
123 <td> </td>
124 <td> </td>
125 <td>, </td>
126 </tr>
127 <tr>
128 <td> </td>
129 <td> </td>
130 <td>, </td>
131 </tr>
132 <tr>
133 <td> </td>
134 <td> </td>
135 <td>
136 <code>)</code>;</td>
137 </tr>
138 </table>
139 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
140 <tr>
141 <td><code class="funcdef">
142 struct hostent  *
143 <b class="fsfunc">lwres_gethostbyaddr_r</b>(</code></td>
144 <td> </td>
145 <td>, </td>
146 </tr>
147 <tr>
148 <td> </td>
149 <td> </td>
150 <td>, </td>
151 </tr>
152 <tr>
153 <td> </td>
154 <td> </td>
155 <td>, </td>
156 </tr>
157 <tr>
158 <td> </td>
159 <td> </td>
160 <td>, </td>
161 </tr>
162 <tr>
163 <td> </td>
164 <td> </td>
165 <td>, </td>
166 </tr>
167 <tr>
168 <td> </td>
169 <td> </td>
170 <td>, </td>
171 </tr>
172 <tr>
173 <td> </td>
174 <td> </td>
175 <td>, </td>
176 </tr>
177 <tr>
178 <td> </td>
179 <td> </td>
180 <td>
181 <code>)</code>;</td>
182 </tr>
183 </table>
184 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
185 <tr>
186 <td><code class="funcdef">
187 struct hostent  *
188 <b class="fsfunc">lwres_gethostent_r</b>(</code></td>
189 <td> </td>
190 <td>, </td>
191 </tr>
192 <tr>
193 <td> </td>
194 <td> </td>
195 <td>, </td>
196 </tr>
197 <tr>
198 <td> </td>
199 <td> </td>
200 <td>, </td>
201 </tr>
202 <tr>
203 <td> </td>
204 <td> </td>
205 <td>, </td>
206 </tr>
207 <tr>
208 <td> </td>
209 <td> </td>
210 <td>
211 <code>)</code>;</td>
212 </tr>
213 </table>
214 <p><code class="funcdef">
215 void
216 <b class="fsfunc">lwres_sethostent_r</b>(</code>int stayopen<code>)</code>;</p>
217 <p><code class="funcdef">
218 void
219 <b class="fsfunc">lwres_endhostent_r</b>(</code>void<code>)</code>;</p>
220 </div>
221 </div>
222 <div class="refsect1" lang="en">
223 <a name="id2549606"></a><h2>DESCRIPTION</h2>
224 <p>
225 These functions provide hostname-to-address and
226 address-to-hostname lookups by means of the lightweight resolver.
227 They are similar to the standard
228 <span class="citerefentry"><span class="refentrytitle">gethostent</span>(3
229 )</span>
230 functions provided by most operating systems.
231 They use a
232 <span class="type">struct hostent</span>
233 which is usually defined in
234 <code class="filename">&lt;namedb.h&gt;</code>.
235
236 </p>
237 <pre class="programlisting">
238 struct  hostent {
239         char    *h_name;        /* official name of host */
240         char    **h_aliases;    /* alias list */
241         int     h_addrtype;     /* host address type */
242         int     h_length;       /* length of address */
243         char    **h_addr_list;  /* list of addresses from name server */
244 };
245 #define h_addr  h_addr_list[0]  /* address, for backward compatibility */
246 </pre>
247 <p>
248 </p>
249 <p>
250 The members of this structure are:
251 </p>
252 <div class="variablelist"><dl>
253 <dt><span class="term"><code class="constant">h_name</code></span></dt>
254 <dd><p>
255 The official (canonical) name of the host.
256 </p></dd>
257 <dt><span class="term"><code class="constant">h_aliases</code></span></dt>
258 <dd><p>
259 A NULL-terminated array of alternate names (nicknames) for the host.
260 </p></dd>
261 <dt><span class="term"><code class="constant">h_addrtype</code></span></dt>
262 <dd><p>
263 The type of address being returned &#8212;
264 <span class="type">PF_INET</span>
265 or
266 <span class="type">PF_INET6</span>.
267 </p></dd>
268 <dt><span class="term"><code class="constant">h_length</code></span></dt>
269 <dd><p>
270 The length of the address in bytes.
271 </p></dd>
272 <dt><span class="term"><code class="constant">h_addr_list</code></span></dt>
273 <dd><p>
274 A <span class="type">NULL</span>
275 terminated array of network addresses for the host.
276 Host addresses are returned in network byte order.
277 </p></dd>
278 </dl></div>
279 <p>
280 </p>
281 <p>
282 For backward compatibility with very old software,
283 <code class="constant">h_addr</code>
284 is the first address in
285 <code class="constant">h_addr_list.</code>
286 </p>
287 <p>
288 <code class="function">lwres_gethostent()</code>,
289 <code class="function">lwres_sethostent()</code>,
290 <code class="function">lwres_endhostent()</code>,
291 <code class="function">lwres_gethostent_r()</code>,
292 <code class="function">lwres_sethostent_r()</code>
293 and
294 <code class="function">lwres_endhostent_r()</code>
295 provide iteration over the known host entries on systems that
296 provide such functionality through facilities like
297 <code class="filename">/etc/hosts</code>
298 or NIS.  The lightweight resolver does not currently implement
299 these functions; it only provides them as stub functions that always
300 return failure.
301 </p>
302 <p>
303 <code class="function">lwres_gethostbyname()</code> and
304 <code class="function">lwres_gethostbyname2()</code> look up the hostname
305 <em class="parameter"><code>name</code></em>.
306 <code class="function">lwres_gethostbyname()</code> always looks for an IPv4
307 address while <code class="function">lwres_gethostbyname2()</code> looks for an
308 address of protocol family <em class="parameter"><code>af</code></em>: either
309 <span class="type">PF_INET</span> or <span class="type">PF_INET6</span> &#8212; IPv4 or IPV6
310 addresses respectively.  Successful calls of the functions return a
311 <span class="type">struct hostent</span>for the name that was looked up.
312 <span class="type">NULL</span> is returned if the lookups by
313 <code class="function">lwres_gethostbyname()</code> or
314 <code class="function">lwres_gethostbyname2()</code> fail.
315 </p>
316 <p>
317 Reverse lookups of addresses are performed by
318 <code class="function">lwres_gethostbyaddr()</code>.
319 <em class="parameter"><code>addr</code></em> is an address of length
320 <em class="parameter"><code>len</code></em> bytes and protocol family
321 <em class="parameter"><code>type</code></em> &#8212; <span class="type">PF_INET</span> or
322 <span class="type">PF_INET6</span>.
323 <code class="function">lwres_gethostbyname_r()</code> is a thread-safe function
324 for forward lookups.  If an error occurs, an error code is returned in
325 <em class="parameter"><code>*error</code></em>.
326 <em class="parameter"><code>resbuf</code></em> is a pointer to a <span class="type">struct
327 hostent</span> which is initialised by a successful call to
328 <code class="function">lwres_gethostbyname_r()</code> .
329 <em class="parameter"><code>buf</code></em> is a buffer of length
330 <em class="parameter"><code>len</code></em> bytes which is used to store the
331 <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
332 <code class="constant">h_addr_list</code> elements of the <span class="type">struct
333 hostent</span> returned in <em class="parameter"><code>resbuf</code></em>.
334 Successful calls to <code class="function">lwres_gethostbyname_r()</code>
335 return <em class="parameter"><code>resbuf</code></em>,
336 which is a pointer to the <span class="type">struct hostent</span> it created.
337 </p>
338 <p>
339 <code class="function">lwres_gethostbyaddr_r()</code> is a thread-safe function
340 that performs a reverse lookup of address <em class="parameter"><code>addr</code></em>
341 which is <em class="parameter"><code>len</code></em> bytes long and is of protocol
342 family <em class="parameter"><code>type</code></em> &#8212; <span class="type">PF_INET</span> or
343 <span class="type">PF_INET6</span>.  If an error occurs, the error code is returned
344 in <em class="parameter"><code>*error</code></em>.  The other function parameters are
345 identical to those in <code class="function">lwres_gethostbyname_r()</code>.
346 <em class="parameter"><code>resbuf</code></em> is a pointer to a <span class="type">struct
347 hostent</span> which is initialised by a successful call to
348 <code class="function">lwres_gethostbyaddr_r()</code>.
349 <em class="parameter"><code>buf</code></em> is a buffer of length
350 <em class="parameter"><code>len</code></em> bytes which is used to store the
351 <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
352 <code class="constant">h_addr_list</code> elements of the <span class="type">struct
353 hostent</span> returned in <em class="parameter"><code>resbuf</code></em>.  Successful
354 calls to <code class="function">lwres_gethostbyaddr_r()</code> return
355 <em class="parameter"><code>resbuf</code></em>, which is a pointer to the
356 <code class="function">struct hostent()</code> it created.
357 </p>
358 </div>
359 <div class="refsect1" lang="en">
360 <a name="id2550013"></a><h2>RETURN VALUES</h2>
361 <p>
362 The functions
363 <code class="function">lwres_gethostbyname()</code>,
364 <code class="function">lwres_gethostbyname2()</code>,
365 <code class="function">lwres_gethostbyaddr()</code>,
366 and
367 <code class="function">lwres_gethostent()</code>
368 return NULL to indicate an error.  In this case the global variable
369 <span class="type">lwres_h_errno</span>
370 will contain one of the following error codes defined in
371 <code class="filename">&lt;lwres/netdb.h&gt;</code>:
372
373 </p>
374 <div class="variablelist"><dl>
375 <dt><span class="term"><code class="constant">HOST_NOT_FOUND</code></span></dt>
376 <dd><p>
377 The host or address was not found.
378 </p></dd>
379 <dt><span class="term"><code class="constant">TRY_AGAIN</code></span></dt>
380 <dd><p>
381 A recoverable error occurred, e.g., a timeout.
382 Retrying the lookup may succeed.
383 </p></dd>
384 <dt><span class="term"><code class="constant">NO_RECOVERY</code></span></dt>
385 <dd><p>
386 A non-recoverable error occurred.
387 </p></dd>
388 <dt><span class="term"><code class="constant">NO_DATA</code></span></dt>
389 <dd><p>
390 The name exists, but has no address information
391 associated with it (or vice versa in the case
392 of a reverse lookup).  The code NO_ADDRESS
393 is accepted as a synonym for NO_DATA for backwards
394 compatibility.
395 </p></dd>
396 </dl></div>
397 <p>
398 </p>
399 <p>
400 <span class="citerefentry"><span class="refentrytitle">lwres_hstrerror</span>(3
401 )</span>
402 translates these error codes to suitable error messages.
403 </p>
404 <p>
405 <code class="function">lwres_gethostent()</code>
406 and
407 <code class="function">lwres_gethostent_r()</code>
408 always return
409 <span class="type">NULL</span>.
410 </p>
411 <p>
412 Successful calls to <code class="function">lwres_gethostbyname_r()</code> and
413 <code class="function">lwres_gethostbyaddr_r()</code> return
414 <em class="parameter"><code>resbuf</code></em>, a pointer to the <span class="type">struct
415 hostent</span> that was initialised by these functions.  They return
416 <span class="type">NULL</span> if the lookups fail or if <em class="parameter"><code>buf</code></em>
417 was too small to hold the list of addresses and names referenced by
418 the <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
419 <code class="constant">h_addr_list</code> elements of the <span class="type">struct
420 hostent</span>.  If <em class="parameter"><code>buf</code></em> was too small, both
421 <code class="function">lwres_gethostbyname_r()</code> and
422 <code class="function">lwres_gethostbyaddr_r()</code> set the global variable
423 <span class="type">errno</span> to <span class="errorcode">ERANGE</span>.
424 </p>
425 </div>
426 <div class="refsect1" lang="en">
427 <a name="id2550173"></a><h2>SEE ALSO</h2>
428 <p>
429 <span class="citerefentry"><span class="refentrytitle">gethostent</span>(3)</span>,
430
431 <span class="citerefentry"><span class="refentrytitle">lwres_getipnode</span>(3)</span>,
432
433 <span class="citerefentry"><span class="refentrytitle">lwres_hstrerror</span>(3
434 )</span>
435 </p>
436 </div>
437 <div class="refsect1" lang="en">
438 <a name="id2550209"></a><h2>BUGS</h2>
439 <p>
440 <code class="function">lwres_gethostbyname()</code>,
441 <code class="function">lwres_gethostbyname2()</code>,
442 <code class="function">lwres_gethostbyaddr()</code>
443 and
444 <code class="function">lwres_endhostent()</code>
445 are not thread safe; they return pointers to static data and 
446 provide error codes through a global variable.
447 Thread-safe versions for name and address lookup are provided by
448 <code class="function">lwres_gethostbyname_r()</code>,
449 and
450 <code class="function">lwres_gethostbyaddr_r()</code>
451 respectively.
452 </p>
453 <p>
454 The resolver daemon does not currently support any non-DNS
455 name services such as 
456 <code class="filename">/etc/hosts</code>
457 or
458 <span class="type">NIS</span>,
459 consequently the above functions don't, either.
460 </p>
461 </div>
462 </div></body>
463 </html>