Merge from vendor branch SENDMAIL:
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / lwres / man / lwres_gethostent.html
1 <!--
2  - Copyright (C) 2004  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
18 <!-- $Id: lwres_gethostent.html,v 1.8.2.2 2004/03/15 04:45:02 marka Exp $ -->
19
20 <HTML
21 ><HEAD
22 ><TITLE
23 >lwres_gethostent</TITLE
24 ><META
25 NAME="GENERATOR"
26 CONTENT="Modular DocBook HTML Stylesheet Version 1.73
27 "></HEAD
28 ><BODY
29 CLASS="REFENTRY"
30 BGCOLOR="#FFFFFF"
31 TEXT="#000000"
32 LINK="#0000FF"
33 VLINK="#840084"
34 ALINK="#0000FF"
35 ><H1
36 ><A
37 NAME="AEN1"
38 >lwres_gethostent</A
39 ></H1
40 ><DIV
41 CLASS="REFNAMEDIV"
42 ><A
43 NAME="AEN8"
44 ></A
45 ><H2
46 >Name</H2
47 >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&nbsp;--&nbsp;lightweight resolver get network host entry</DIV
48 ><DIV
49 CLASS="REFSYNOPSISDIV"
50 ><A
51 NAME="AEN21"
52 ></A
53 ><H2
54 >Synopsis</H2
55 ><DIV
56 CLASS="FUNCSYNOPSIS"
57 ><A
58 NAME="AEN22"
59 ></A
60 ><P
61 ></P
62 ><PRE
63 CLASS="FUNCSYNOPSISINFO"
64 >#include &lt;lwres/netdb.h&gt;</PRE
65 ><P
66 ><CODE
67 ><CODE
68 CLASS="FUNCDEF"
69 >struct hostent *
70 lwres_gethostbyname</CODE
71 >(const char *name);</CODE
72 ></P
73 ><P
74 ><CODE
75 ><CODE
76 CLASS="FUNCDEF"
77 >struct hostent *
78 lwres_gethostbyname2</CODE
79 >(const char *name, int af);</CODE
80 ></P
81 ><P
82 ><CODE
83 ><CODE
84 CLASS="FUNCDEF"
85 >struct hostent *
86 lwres_gethostbyaddr</CODE
87 >(const char *addr, int len, int type);</CODE
88 ></P
89 ><P
90 ><CODE
91 ><CODE
92 CLASS="FUNCDEF"
93 >struct hostent *
94 lwres_gethostent</CODE
95 >(void);</CODE
96 ></P
97 ><P
98 ><CODE
99 ><CODE
100 CLASS="FUNCDEF"
101 >void
102 lwres_sethostent</CODE
103 >(int stayopen);</CODE
104 ></P
105 ><P
106 ><CODE
107 ><CODE
108 CLASS="FUNCDEF"
109 >void
110 lwres_endhostent</CODE
111 >(void);</CODE
112 ></P
113 ><P
114 ><CODE
115 ><CODE
116 CLASS="FUNCDEF"
117 >struct hostent *
118 lwres_gethostbyname_r</CODE
119 >(const char *name, struct hostent *resbuf, char *buf, int buflen, int *error);</CODE
120 ></P
121 ><P
122 ><CODE
123 ><CODE
124 CLASS="FUNCDEF"
125 >struct hostent  *
126 lwres_gethostbyaddr_r</CODE
127 >(const char *addr, int len, int type, struct hostent *resbuf, char *buf, int buflen, int *error);</CODE
128 ></P
129 ><P
130 ><CODE
131 ><CODE
132 CLASS="FUNCDEF"
133 >struct hostent  *
134 lwres_gethostent_r</CODE
135 >(struct hostent *resbuf, char *buf, int buflen, int *error);</CODE
136 ></P
137 ><P
138 ><CODE
139 ><CODE
140 CLASS="FUNCDEF"
141 >void
142 lwres_sethostent_r</CODE
143 >(int stayopen);</CODE
144 ></P
145 ><P
146 ><CODE
147 ><CODE
148 CLASS="FUNCDEF"
149 >void
150 lwres_endhostent_r</CODE
151 >(void);</CODE
152 ></P
153 ><P
154 ></P
155 ></DIV
156 ></DIV
157 ><DIV
158 CLASS="REFSECT1"
159 ><A
160 NAME="AEN84"
161 ></A
162 ><H2
163 >DESCRIPTION</H2
164 ><P
165 >These functions provide hostname-to-address and
166 address-to-hostname lookups by means of the lightweight resolver.
167 They are similar to the standard
168 <SPAN
169 CLASS="CITEREFENTRY"
170 ><SPAN
171 CLASS="REFENTRYTITLE"
172 >gethostent</SPAN
173 >(3)</SPAN
174 >
175 functions provided by most operating systems.
176 They use a
177 <SPAN
178 CLASS="TYPE"
179 >struct hostent</SPAN
180 >
181 which is usually defined in
182 <TT
183 CLASS="FILENAME"
184 >&lt;namedb.h&gt;</TT
185 >.
186
187 <PRE
188 CLASS="PROGRAMLISTING"
189 >struct  hostent {
190         char    *h_name;        /* official name of host */
191         char    **h_aliases;    /* alias list */
192         int     h_addrtype;     /* host address type */
193         int     h_length;       /* length of address */
194         char    **h_addr_list;  /* list of addresses from name server */
195 };
196 #define h_addr  h_addr_list[0]  /* address, for backward compatibility */</PRE
197 ></P
198 ><P
199 >The members of this structure are:
200 <P
201 ></P
202 ><DIV
203 CLASS="VARIABLELIST"
204 ><DL
205 ><DT
206 ><TT
207 CLASS="CONSTANT"
208 >h_name</TT
209 ></DT
210 ><DD
211 ><P
212 >The official (canonical) name of the host.</P
213 ></DD
214 ><DT
215 ><TT
216 CLASS="CONSTANT"
217 >h_aliases</TT
218 ></DT
219 ><DD
220 ><P
221 >A NULL-terminated array of alternate names (nicknames) for the host.</P
222 ></DD
223 ><DT
224 ><TT
225 CLASS="CONSTANT"
226 >h_addrtype</TT
227 ></DT
228 ><DD
229 ><P
230 >The type of address being returned &mdash;
231 <SPAN
232 CLASS="TYPE"
233 >PF_INET</SPAN
234 >
235 or
236 <SPAN
237 CLASS="TYPE"
238 >PF_INET6</SPAN
239 >.</P
240 ></DD
241 ><DT
242 ><TT
243 CLASS="CONSTANT"
244 >h_length</TT
245 ></DT
246 ><DD
247 ><P
248 >The length of the address in bytes.</P
249 ></DD
250 ><DT
251 ><TT
252 CLASS="CONSTANT"
253 >h_addr_list</TT
254 ></DT
255 ><DD
256 ><P
257 >A <SPAN
258 CLASS="TYPE"
259 >NULL</SPAN
260 >
261 terminated array of network addresses for the host.
262 Host addresses are returned in network byte order.</P
263 ></DD
264 ></DL
265 ></DIV
266 ></P
267 ><P
268 >For backward compatibility with very old software,
269 <TT
270 CLASS="CONSTANT"
271 >h_addr</TT
272 >
273 is the first address in
274 <TT
275 CLASS="CONSTANT"
276 >h_addr_list.</TT
277 ></P
278 ><P
279 ><TT
280 CLASS="FUNCTION"
281 >lwres_gethostent()</TT
282 >,
283 <TT
284 CLASS="FUNCTION"
285 >lwres_sethostent()</TT
286 >,
287 <TT
288 CLASS="FUNCTION"
289 >lwres_endhostent()</TT
290 >,
291 <TT
292 CLASS="FUNCTION"
293 >lwres_gethostent_r()</TT
294 >,
295 <TT
296 CLASS="FUNCTION"
297 >lwres_sethostent_r()</TT
298 >
299 and
300 <TT
301 CLASS="FUNCTION"
302 >lwres_endhostent_r()</TT
303 >
304 provide iteration over the known host entries on systems that
305 provide such functionality through facilities like
306 <TT
307 CLASS="FILENAME"
308 >/etc/hosts</TT
309 >
310 or NIS.  The lightweight resolver does not currently implement
311 these functions; it only provides them as stub functions that always
312 return failure.</P
313 ><P
314 ><TT
315 CLASS="FUNCTION"
316 >lwres_gethostbyname()</TT
317 > and
318 <TT
319 CLASS="FUNCTION"
320 >lwres_gethostbyname2()</TT
321 > look up the hostname
322 <TT
323 CLASS="PARAMETER"
324 ><I
325 >name</I
326 ></TT
327 >.
328 <TT
329 CLASS="FUNCTION"
330 >lwres_gethostbyname()</TT
331 > always looks for an IPv4
332 address while <TT
333 CLASS="FUNCTION"
334 >lwres_gethostbyname2()</TT
335 > looks for an
336 address of protocol family <TT
337 CLASS="PARAMETER"
338 ><I
339 >af</I
340 ></TT
341 >: either
342 <SPAN
343 CLASS="TYPE"
344 >PF_INET</SPAN
345 > or <SPAN
346 CLASS="TYPE"
347 >PF_INET6</SPAN
348 > &mdash; IPv4 or IPV6
349 addresses respectively.  Successful calls of the functions return a
350 <SPAN
351 CLASS="TYPE"
352 >struct hostent</SPAN
353 >for the name that was looked up.
354 <SPAN
355 CLASS="TYPE"
356 >NULL</SPAN
357 > is returned if the lookups by
358 <TT
359 CLASS="FUNCTION"
360 >lwres_gethostbyname()</TT
361 > or
362 <TT
363 CLASS="FUNCTION"
364 >lwres_gethostbyname2()</TT
365 > fail.</P
366 ><P
367 >Reverse lookups of addresses are performed by
368 <TT
369 CLASS="FUNCTION"
370 >lwres_gethostbyaddr()</TT
371 >.
372 <TT
373 CLASS="PARAMETER"
374 ><I
375 >addr</I
376 ></TT
377 > is an address of length
378 <TT
379 CLASS="PARAMETER"
380 ><I
381 >len</I
382 ></TT
383 > bytes and protocol family
384 <TT
385 CLASS="PARAMETER"
386 ><I
387 >type</I
388 ></TT
389 > &mdash; <SPAN
390 CLASS="TYPE"
391 >PF_INET</SPAN
392 > or
393 <SPAN
394 CLASS="TYPE"
395 >PF_INET6</SPAN
396 >.
397 <TT
398 CLASS="FUNCTION"
399 >lwres_gethostbyname_r()</TT
400 > is a thread-safe function
401 for forward lookups.  If an error occurs, an error code is returned in
402 <TT
403 CLASS="PARAMETER"
404 ><I
405 >*error</I
406 ></TT
407 >.
408 <TT
409 CLASS="PARAMETER"
410 ><I
411 >resbuf</I
412 ></TT
413 > is a pointer to a <SPAN
414 CLASS="TYPE"
415 >struct
416 hostent</SPAN
417 > which is initialised by a successful call to
418 <TT
419 CLASS="FUNCTION"
420 >lwres_gethostbyname_r()</TT
421 > .
422 <TT
423 CLASS="PARAMETER"
424 ><I
425 >buf</I
426 ></TT
427 > is a buffer of length
428 <TT
429 CLASS="PARAMETER"
430 ><I
431 >len</I
432 ></TT
433 > bytes which is used to store the
434 <TT
435 CLASS="CONSTANT"
436 >h_name</TT
437 >, <TT
438 CLASS="CONSTANT"
439 >h_aliases</TT
440 >, and
441 <TT
442 CLASS="CONSTANT"
443 >h_addr_list</TT
444 > elements of the <SPAN
445 CLASS="TYPE"
446 >struct
447 hostent</SPAN
448 > returned in <TT
449 CLASS="PARAMETER"
450 ><I
451 >resbuf</I
452 ></TT
453 >.
454 Successful calls to <TT
455 CLASS="FUNCTION"
456 >lwres_gethostbyname_r()</TT
457 >
458 return <TT
459 CLASS="PARAMETER"
460 ><I
461 >resbuf</I
462 ></TT
463 >,
464 which is a pointer to the <SPAN
465 CLASS="TYPE"
466 >struct hostent</SPAN
467 > it created.</P
468 ><P
469 ><TT
470 CLASS="FUNCTION"
471 >lwres_gethostbyaddr_r()</TT
472 > is a thread-safe function
473 that performs a reverse lookup of address <TT
474 CLASS="PARAMETER"
475 ><I
476 >addr</I
477 ></TT
478 >
479 which is <TT
480 CLASS="PARAMETER"
481 ><I
482 >len</I
483 ></TT
484 > bytes long and is of protocol
485 family <TT
486 CLASS="PARAMETER"
487 ><I
488 >type</I
489 ></TT
490 > &mdash; <SPAN
491 CLASS="TYPE"
492 >PF_INET</SPAN
493 > or
494 <SPAN
495 CLASS="TYPE"
496 >PF_INET6</SPAN
497 >.  If an error occurs, the error code is returned
498 in <TT
499 CLASS="PARAMETER"
500 ><I
501 >*error</I
502 ></TT
503 >.  The other function parameters are
504 identical to those in <TT
505 CLASS="FUNCTION"
506 >lwres_gethostbyname_r()</TT
507 >.
508 <TT
509 CLASS="PARAMETER"
510 ><I
511 >resbuf</I
512 ></TT
513 > is a pointer to a <SPAN
514 CLASS="TYPE"
515 >struct
516 hostent</SPAN
517 > which is initialised by a successful call to
518 <TT
519 CLASS="FUNCTION"
520 >lwres_gethostbyaddr_r()</TT
521 >.
522 <TT
523 CLASS="PARAMETER"
524 ><I
525 >buf</I
526 ></TT
527 > is a buffer of length
528 <TT
529 CLASS="PARAMETER"
530 ><I
531 >len</I
532 ></TT
533 > bytes which is used to store the
534 <TT
535 CLASS="CONSTANT"
536 >h_name</TT
537 >, <TT
538 CLASS="CONSTANT"
539 >h_aliases</TT
540 >, and
541 <TT
542 CLASS="CONSTANT"
543 >h_addr_list</TT
544 > elements of the <SPAN
545 CLASS="TYPE"
546 >struct
547 hostent</SPAN
548 > returned in <TT
549 CLASS="PARAMETER"
550 ><I
551 >resbuf</I
552 ></TT
553 >.  Successful
554 calls to <TT
555 CLASS="FUNCTION"
556 >lwres_gethostbyaddr_r()</TT
557 > return
558 <TT
559 CLASS="PARAMETER"
560 ><I
561 >resbuf</I
562 ></TT
563 >, which is a pointer to the
564 <TT
565 CLASS="FUNCTION"
566 >struct hostent()</TT
567 > it created.</P
568 ></DIV
569 ><DIV
570 CLASS="REFSECT1"
571 ><A
572 NAME="AEN191"
573 ></A
574 ><H2
575 >RETURN VALUES</H2
576 ><P
577 >The functions
578 <TT
579 CLASS="FUNCTION"
580 >lwres_gethostbyname()</TT
581 >,
582 <TT
583 CLASS="FUNCTION"
584 >lwres_gethostbyname2()</TT
585 >,
586 <TT
587 CLASS="FUNCTION"
588 >lwres_gethostbyaddr()</TT
589 >,
590 and
591 <TT
592 CLASS="FUNCTION"
593 >lwres_gethostent()</TT
594 >
595 return NULL to indicate an error.  In this case the global variable
596 <SPAN
597 CLASS="TYPE"
598 >lwres_h_errno</SPAN
599 >
600 will contain one of the following error codes defined in
601 <TT
602 CLASS="FILENAME"
603 >&lt;lwres/netdb.h&gt;</TT
604 >:
605
606 <P
607 ></P
608 ><DIV
609 CLASS="VARIABLELIST"
610 ><DL
611 ><DT
612 ><TT
613 CLASS="CONSTANT"
614 >HOST_NOT_FOUND</TT
615 ></DT
616 ><DD
617 ><P
618 >The host or address was not found.</P
619 ></DD
620 ><DT
621 ><TT
622 CLASS="CONSTANT"
623 >TRY_AGAIN</TT
624 ></DT
625 ><DD
626 ><P
627 >A recoverable error occurred, e.g., a timeout.
628 Retrying the lookup may succeed.</P
629 ></DD
630 ><DT
631 ><TT
632 CLASS="CONSTANT"
633 >NO_RECOVERY</TT
634 ></DT
635 ><DD
636 ><P
637 >A non-recoverable error occurred.</P
638 ></DD
639 ><DT
640 ><TT
641 CLASS="CONSTANT"
642 >NO_DATA</TT
643 ></DT
644 ><DD
645 ><P
646 >The name exists, but has no address information
647 associated with it (or vice versa in the case
648 of a reverse lookup).  The code NO_ADDRESS
649 is accepted as a synonym for NO_DATA for backwards
650 compatibility.</P
651 ></DD
652 ></DL
653 ></DIV
654 ></P
655 ><P
656 ><SPAN
657 CLASS="CITEREFENTRY"
658 ><SPAN
659 CLASS="REFENTRYTITLE"
660 >lwres_hstrerror</SPAN
661 >(3)</SPAN
662 >
663 translates these error codes to suitable error messages.</P
664 ><P
665 ><TT
666 CLASS="FUNCTION"
667 >lwres_gethostent()</TT
668 >
669 and
670 <TT
671 CLASS="FUNCTION"
672 >lwres_gethostent_r()</TT
673 >
674 always return
675 <SPAN
676 CLASS="TYPE"
677 >NULL</SPAN
678 >.</P
679 ><P
680 >Successful calls to <TT
681 CLASS="FUNCTION"
682 >lwres_gethostbyname_r()</TT
683 > and
684 <TT
685 CLASS="FUNCTION"
686 >lwres_gethostbyaddr_r()</TT
687 > return
688 <TT
689 CLASS="PARAMETER"
690 ><I
691 >resbuf</I
692 ></TT
693 >, a pointer to the <SPAN
694 CLASS="TYPE"
695 >struct
696 hostent</SPAN
697 > that was initialised by these functions.  They return
698 <SPAN
699 CLASS="TYPE"
700 >NULL</SPAN
701 > if the lookups fail or if <TT
702 CLASS="PARAMETER"
703 ><I
704 >buf</I
705 ></TT
706 >
707 was too small to hold the list of addresses and names referenced by
708 the <TT
709 CLASS="CONSTANT"
710 >h_name</TT
711 >, <TT
712 CLASS="CONSTANT"
713 >h_aliases</TT
714 >, and
715 <TT
716 CLASS="CONSTANT"
717 >h_addr_list</TT
718 > elements of the <SPAN
719 CLASS="TYPE"
720 >struct
721 hostent</SPAN
722 >.  If <TT
723 CLASS="PARAMETER"
724 ><I
725 >buf</I
726 ></TT
727 > was too small, both
728 <TT
729 CLASS="FUNCTION"
730 >lwres_gethostbyname_r()</TT
731 > and
732 <TT
733 CLASS="FUNCTION"
734 >lwres_gethostbyaddr_r()</TT
735 > set the global variable
736 <SPAN
737 CLASS="TYPE"
738 >errno</SPAN
739 > to <SPAN
740 CLASS="ERRORCODE"
741 >ERANGE</SPAN
742 >.</P
743 ></DIV
744 ><DIV
745 CLASS="REFSECT1"
746 ><A
747 NAME="AEN245"
748 ></A
749 ><H2
750 >SEE ALSO</H2
751 ><P
752 ><SPAN
753 CLASS="CITEREFENTRY"
754 ><SPAN
755 CLASS="REFENTRYTITLE"
756 >gethostent</SPAN
757 >(3)</SPAN
758 >,
759
760 <SPAN
761 CLASS="CITEREFENTRY"
762 ><SPAN
763 CLASS="REFENTRYTITLE"
764 >lwres_getipnode</SPAN
765 >(3)</SPAN
766 >,
767
768 <SPAN
769 CLASS="CITEREFENTRY"
770 ><SPAN
771 CLASS="REFENTRYTITLE"
772 >lwres_hstrerror</SPAN
773 >(3)</SPAN
774 ></P
775 ></DIV
776 ><DIV
777 CLASS="REFSECT1"
778 ><A
779 NAME="AEN257"
780 ></A
781 ><H2
782 >BUGS</H2
783 ><P
784 ><TT
785 CLASS="FUNCTION"
786 >lwres_gethostbyname()</TT
787 >,
788 <TT
789 CLASS="FUNCTION"
790 >lwres_gethostbyname2()</TT
791 >,
792 <TT
793 CLASS="FUNCTION"
794 >lwres_gethostbyaddr()</TT
795 >
796 and
797 <TT
798 CLASS="FUNCTION"
799 >lwres_endhostent()</TT
800 >
801 are not thread safe; they return pointers to static data and 
802 provide error codes through a global variable.
803 Thread-safe versions for name and address lookup are provided by
804 <TT
805 CLASS="FUNCTION"
806 >lwres_gethostbyname_r()</TT
807 >,
808 and
809 <TT
810 CLASS="FUNCTION"
811 >lwres_gethostbyaddr_r()</TT
812 >
813 respectively.</P
814 ><P
815 >The resolver daemon does not currently support any non-DNS
816 name services such as 
817 <TT
818 CLASS="FILENAME"
819 >/etc/hosts</TT
820 >
821 or
822 <SPAN
823 CLASS="TYPE"
824 >NIS</SPAN
825 >,
826 consequently the above functions don't, either.</P
827 ></DIV
828 ></BODY
829 ></HTML
830 >