2 - Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2001 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.
18 <!-- $Id: lwres_gethostent.html,v 1.8.2.2 2004/03/15 04:45:02 marka Exp $ -->
23 >lwres_gethostent</TITLE
26 CONTENT="Modular DocBook HTML Stylesheet Version 1.73
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 -- lightweight resolver get network host entry</DIV
49 CLASS="REFSYNOPSISDIV"
63 CLASS="FUNCSYNOPSISINFO"
64 >#include <lwres/netdb.h></PRE
70 lwres_gethostbyname</CODE
71 >(const char *name);</CODE
78 lwres_gethostbyname2</CODE
79 >(const char *name, int af);</CODE
86 lwres_gethostbyaddr</CODE
87 >(const char *addr, int len, int type);</CODE
94 lwres_gethostent</CODE
102 lwres_sethostent</CODE
103 >(int stayopen);</CODE
110 lwres_endhostent</CODE
118 lwres_gethostbyname_r</CODE
119 >(const char *name, struct hostent *resbuf, char *buf, int buflen, int *error);</CODE
126 lwres_gethostbyaddr_r</CODE
127 >(const char *addr, int len, int type, struct hostent *resbuf, char *buf, int buflen, int *error);</CODE
134 lwres_gethostent_r</CODE
135 >(struct hostent *resbuf, char *buf, int buflen, int *error);</CODE
142 lwres_sethostent_r</CODE
143 >(int stayopen);</CODE
150 lwres_endhostent_r</CODE
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
171 CLASS="REFENTRYTITLE"
175 functions provided by most operating systems.
179 >struct hostent</SPAN
181 which is usually defined in
184 ><namedb.h></TT
188 CLASS="PROGRAMLISTING"
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 */
196 #define h_addr h_addr_list[0] /* address, for backward compatibility */</PRE
199 >The members of this structure are:
212 >The official (canonical) name of the host.</P
221 >A NULL-terminated array of alternate names (nicknames) for the host.</P
230 >The type of address being returned —
248 >The length of the address in bytes.</P
261 terminated array of network addresses for the host.
262 Host addresses are returned in network byte order.</P
268 >For backward compatibility with very old software,
273 is the first address in
281 >lwres_gethostent()</TT
285 >lwres_sethostent()</TT
289 >lwres_endhostent()</TT
293 >lwres_gethostent_r()</TT
297 >lwres_sethostent_r()</TT
302 >lwres_endhostent_r()</TT
304 provide iteration over the known host entries on systems that
305 provide such functionality through facilities like
310 or NIS. The lightweight resolver does not currently implement
311 these functions; it only provides them as stub functions that always
316 >lwres_gethostbyname()</TT
320 >lwres_gethostbyname2()</TT
321 > look up the hostname
330 >lwres_gethostbyname()</TT
331 > always looks for an IPv4
334 >lwres_gethostbyname2()</TT
336 address of protocol family <TT
348 > — IPv4 or IPV6
349 addresses respectively. Successful calls of the functions return a
352 >struct hostent</SPAN
353 >for the name that was looked up.
357 > is returned if the lookups by
360 >lwres_gethostbyname()</TT
364 >lwres_gethostbyname2()</TT
367 >Reverse lookups of addresses are performed by
370 >lwres_gethostbyaddr()</TT
377 > is an address of length
383 > bytes and protocol family
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
413 > is a pointer to a <SPAN
417 > which is initialised by a successful call to
420 >lwres_gethostbyname_r()</TT
427 > is a buffer of length
433 > bytes which is used to store the
444 > elements of the <SPAN
454 Successful calls to <TT
456 >lwres_gethostbyname_r()</TT
464 which is a pointer to the <SPAN
466 >struct hostent</SPAN
471 >lwres_gethostbyaddr_r()</TT
472 > is a thread-safe function
473 that performs a reverse lookup of address <TT
484 > bytes long and is of protocol
497 >. If an error occurs, the error code is returned
503 >. The other function parameters are
504 identical to those in <TT
506 >lwres_gethostbyname_r()</TT
513 > is a pointer to a <SPAN
517 > which is initialised by a successful call to
520 >lwres_gethostbyaddr_r()</TT
527 > is a buffer of length
533 > bytes which is used to store the
544 > elements of the <SPAN
556 >lwres_gethostbyaddr_r()</TT
563 >, which is a pointer to the
566 >struct hostent()</TT
580 >lwres_gethostbyname()</TT
584 >lwres_gethostbyname2()</TT
588 >lwres_gethostbyaddr()</TT
593 >lwres_gethostent()</TT
595 return NULL to indicate an error. In this case the global variable
600 will contain one of the following error codes defined in
603 ><lwres/netdb.h></TT
618 >The host or address was not found.</P
627 >A recoverable error occurred, e.g., a timeout.
628 Retrying the lookup may succeed.</P
637 >A non-recoverable error occurred.</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
659 CLASS="REFENTRYTITLE"
660 >lwres_hstrerror</SPAN
663 translates these error codes to suitable error messages.</P
667 >lwres_gethostent()</TT
672 >lwres_gethostent_r()</TT
680 >Successful calls to <TT
682 >lwres_gethostbyname_r()</TT
686 >lwres_gethostbyaddr_r()</TT
693 >, a pointer to the <SPAN
697 > that was initialised by these functions. They return
701 > if the lookups fail or if <TT
707 was too small to hold the list of addresses and names referenced by
718 > elements of the <SPAN
727 > was too small, both
730 >lwres_gethostbyname_r()</TT
734 >lwres_gethostbyaddr_r()</TT
735 > set the global variable
755 CLASS="REFENTRYTITLE"
763 CLASS="REFENTRYTITLE"
764 >lwres_getipnode</SPAN
771 CLASS="REFENTRYTITLE"
772 >lwres_hstrerror</SPAN
786 >lwres_gethostbyname()</TT
790 >lwres_gethostbyname2()</TT
794 >lwres_gethostbyaddr()</TT
799 >lwres_endhostent()</TT
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
806 >lwres_gethostbyname_r()</TT
811 >lwres_gethostbyaddr_r()</TT
815 >The resolver daemon does not currently support any non-DNS
816 name services such as
826 consequently the above functions don't, either.</P