486N/A<!
DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
486N/A - Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") 486N/A - Copyright (C) 2001 Internet Software Consortium. 486N/A - Permission to use, copy, modify, and distribute this software for any 486N/A - purpose with or without fee is hereby granted, provided that the above 486N/A - copyright notice and this permission notice appear in all copies. 486N/A - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 486N/A - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 486N/A - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 486N/A - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 486N/A - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 486N/A - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 486N/A - PERFORMANCE OF THIS SOFTWARE. 486N/A<
date>Jun 30, 2000</
date>
486N/A<
refentrytitle>lwres_gethostent</
refentrytitle>
486N/A<
manvolnum>3</
manvolnum>
486N/A<
refmiscinfo>BIND9</
refmiscinfo>
486N/A<
refname>lwres_gethostbyname</
refname>
486N/A<
refname>lwres_gethostbyname2</
refname>
486N/A<
refname>lwres_gethostbyaddr</
refname>
486N/A<
refname>lwres_gethostent</
refname>
619N/A<
refname>lwres_sethostent</
refname>
619N/A<
refname>lwres_endhostent</
refname>
619N/A<
refname>lwres_gethostbyname_r</
refname>
619N/A<
refname>lwres_gethostbyaddr_r</
refname>
619N/A<
refname>lwres_gethostent_r</
refname>
619N/A<
refname>lwres_sethostent_r</
refname>
619N/A<
refname>lwres_endhostent_r</
refname>
619N/A<
refpurpose>lightweight resolver get network host entry</
refpurpose>
2650N/A<
function>lwres_gethostbyname</
function></
funcdef>
2650N/A<
paramdef>const char *name</
paramdef>
1194N/A<
function>lwres_gethostbyname2</
function></
funcdef>
486N/A<
paramdef>const char *name</
paramdef>
619N/A<
function>lwres_gethostbyaddr</
function></
funcdef>
2650N/A<
paramdef>const char *addr</
paramdef>
2650N/A<
paramdef>int len</
paramdef>
2650N/A<
paramdef>int type</
paramdef>
2650N/A<
function>lwres_gethostent</
function></
funcdef>
2650N/A<
function>lwres_sethostent</
function></
funcdef>
619N/A<
paramdef>int stayopen</
paramdef>
486N/A<
function>lwres_endhostent</
function></
funcdef>
486N/A<
function>lwres_gethostbyname_r</
function></
funcdef>
486N/A<
paramdef>const char *name</
paramdef>
486N/A<
paramdef>struct hostent *resbuf</
paramdef>
486N/A<
paramdef>char *buf</
paramdef>
486N/A<
paramdef>int buflen</
paramdef>
486N/A<
paramdef>int *error</
paramdef>
486N/A<
function>lwres_gethostbyaddr_r</
function></
funcdef>
486N/A<
paramdef>const char *addr</
paramdef>
486N/A<
paramdef>int len</
paramdef>
486N/A<
paramdef>int type</
paramdef>
486N/A<
paramdef>struct hostent *resbuf</
paramdef>
486N/A<
paramdef>char *buf</
paramdef>
486N/A<
paramdef>int buflen</
paramdef>
486N/A<
paramdef>int *error</
paramdef>
486N/A<
function>lwres_gethostent_r</
function></
funcdef>
536N/A<
paramdef>struct hostent *resbuf</
paramdef>
536N/A<
paramdef>char *buf</
paramdef>
536N/A<
paramdef>int buflen</
paramdef>
536N/A<
paramdef>int *error</
paramdef>
1181N/A<
function>lwres_sethostent_r</
function></
funcdef>
1181N/A<
paramdef>int stayopen</
paramdef>
1181N/A<
function>lwres_endhostent_r</
function></
funcdef>
536N/AThese functions provide hostname-to-address and
2650N/Aaddress-to-hostname lookups by means of the lightweight resolver.
961N/AThey are similar to the standard
832N/A<
refentrytitle>gethostent</
refentrytitle><
manvolnum>3
961N/Afunctions provided by most operating systems.
961N/Awhich is usually defined in
486N/A char *h_name; /* official name of host */
857N/A char **h_aliases; /* alias list */
961N/A int h_addrtype; /* host address type */
2296N/A int h_length; /* length of address */
961N/A char **h_addr_list; /* list of addresses from name server */
961N/A#define h_addr h_addr_list[0] /* address, for backward compatibility */
2296N/AThe members of this structure are:
2296N/A<
varlistentry><
term><
constant>h_name</
constant></
term>
961N/AThe official (canonical) name of the host.
961N/A</
listitem></
varlistentry>
961N/A<
varlistentry><
term><
constant>h_aliases</
constant></
term>
961N/AA NULL-terminated array of alternate names (nicknames) for the host.
961N/A</
listitem></
varlistentry>
961N/A<
varlistentry><
term><
constant>h_addrtype</
constant></
term>
961N/AThe type of address being returned —
961N/A<
varlistentry><
term><
constant>h_length</
constant></
term>
961N/AThe length of the address in bytes.
961N/A</
listitem></
varlistentry>
857N/A<
varlistentry><
term><
constant>h_addr_list</
constant></
term>
961N/Aterminated array of network addresses for the host.
961N/AHost addresses are returned in network byte order.
857N/A</
listitem></
varlistentry>
961N/AFor backward compatibility with very old software,
961N/A<
constant>h_addr_list.</
constant>
961N/A<
function>lwres_gethostent()</
function>,
961N/A<
function>lwres_sethostent()</
function>,
961N/A<
function>lwres_endhostent()</
function>,
486N/A<
function>lwres_gethostent_r()</
function>,
2230N/A<
function>lwres_sethostent_r()</
function>
2230N/A<
function>lwres_endhostent_r()</
function>
2230N/Aprovide iteration over the known host entries on systems that
486N/Aprovide such functionality through facilities like
486N/Aor NIS. The lightweight resolver does not currently implement
961N/Athese functions; it only provides them as stub functions that always
961N/A<
function>lwres_gethostbyname()</
function> and
961N/A<
function>lwres_gethostbyname2()</
function> look up the hostname
961N/A<
parameter>name</
parameter>.
961N/A<
function>lwres_gethostbyname()</
function> always looks for an IPv4
961N/Aaddress while <
function>lwres_gethostbyname2()</
function> looks for an
961N/Aaddress of protocol family <
parameter>af</
parameter>: either
961N/A<
type>PF_INET</
type> or <
type>PF_INET6</
type> — IPv4 or IPV6
961N/Aaddresses respectively. Successful calls of the functions return a
961N/A<
type>struct hostent</
type>for the name that was looked up.
961N/A<
type>NULL</
type> is returned if the lookups by
961N/A<
function>lwres_gethostbyname()</
function> or
2296N/A<
function>lwres_gethostbyname2()</
function> fail.
2296N/AReverse lookups of addresses are performed by
2296N/A<
function>lwres_gethostbyaddr()</
function>.
2296N/A<
parameter>addr</
parameter> is an address of length
2296N/A<
parameter>len</
parameter> bytes and protocol family
2296N/A<
parameter>type</
parameter> — <
type>PF_INET</
type> or
961N/A<
function>lwres_gethostbyname_r()</
function> is a thread-safe function
961N/Afor forward lookups. If an error occurs, an error code is returned in
961N/A<
parameter>*error</
parameter>.
961N/A<
parameter>resbuf</
parameter> is a pointer to a <
type>struct
961N/Ahostent</
type> which is initialised by a successful call to
961N/A<
function>lwres_gethostbyname_r()</
function> .
961N/A<
parameter>buf</
parameter> is a buffer of length
961N/A<
parameter>len</
parameter> bytes which is used to store the
961N/A<
constant>h_name</
constant>, <
constant>h_aliases</
constant>, and
961N/A<
constant>h_addr_list</
constant> elements of the <
type>struct
961N/Ahostent</
type> returned in <
parameter>resbuf</
parameter>.
486N/ASuccessful calls to <
function>lwres_gethostbyname_r()</
function>
486N/Areturn <
parameter>resbuf</
parameter>,
2650N/Awhich is a pointer to the <
type>struct hostent</
type> it created.
<
function>lwres_gethostbyaddr_r()</
function> is a thread-safe function
that performs a reverse lookup of address <
parameter>addr</
parameter>
which is <
parameter>len</
parameter> bytes long and is of protocol
family <
parameter>type</
parameter> — <
type>PF_INET</
type> or
<
type>PF_INET6</
type>. If an error occurs, the error code is returned
in <
parameter>*error</
parameter>. The other function parameters are
identical to those in <
function>lwres_gethostbyname_r()</
function>.
<
parameter>resbuf</
parameter> is a pointer to a <
type>struct
hostent</
type> which is initialised by a successful call to
<
function>lwres_gethostbyaddr_r()</
function>.
<
parameter>buf</
parameter> is a buffer of length
<
parameter>len</
parameter> bytes which is used to store the
<
constant>h_name</
constant>, <
constant>h_aliases</
constant>, and
<
constant>h_addr_list</
constant> elements of the <
type>struct
hostent</
type> returned in <
parameter>resbuf</
parameter>. Successful
calls to <
function>lwres_gethostbyaddr_r()</
function> return
<
parameter>resbuf</
parameter>, which is a pointer to the
<
function>struct hostent()</
function> it created.
<
title>RETURN VALUES</
title>
<
function>lwres_gethostbyname()</
function>,
<
function>lwres_gethostbyname2()</
function>,
<
function>lwres_gethostbyaddr()</
function>,
<
function>lwres_gethostent()</
function>
return NULL to indicate an error. In this case the global variable
<
type>lwres_h_errno</
type>
will contain one of the following error codes defined in
<
varlistentry><
term><
constant>HOST_NOT_FOUND</
constant></
term>
The host or address was not found.
</
listitem></
varlistentry>
<
varlistentry><
term><
constant>TRY_AGAIN</
constant></
term>
A recoverable error occurred,
e.g., a timeout.
Retrying the lookup may succeed.
</
listitem></
varlistentry>
<
varlistentry><
term><
constant>NO_RECOVERY</
constant></
term>
A non-recoverable error occurred.
</
listitem></
varlistentry>
<
varlistentry><
term><
constant>NO_DATA</
constant></
term>
The name exists, but has no address information
associated with it (or vice versa in the case
of a reverse lookup). The code NO_ADDRESS
is accepted as a synonym for NO_DATA for backwards
</
listitem></
varlistentry>
<
refentrytitle>lwres_hstrerror</
refentrytitle><
manvolnum>3
translates these error codes to suitable error messages.
<
function>lwres_gethostent()</
function>
<
function>lwres_gethostent_r()</
function>
Successful calls to <
function>lwres_gethostbyname_r()</
function> and
<
function>lwres_gethostbyaddr_r()</
function> return
<
parameter>resbuf</
parameter>, a pointer to the <
type>struct
hostent</
type> that was initialised by these functions. They return
<
type>NULL</
type> if the lookups fail or if <
parameter>buf</
parameter>
was too small to hold the list of addresses and names referenced by
the <
constant>h_name</
constant>, <
constant>h_aliases</
constant>, and
<
constant>h_addr_list</
constant> elements of the <
type>struct
hostent</
type>. If <
parameter>buf</
parameter> was too small, both
<
function>lwres_gethostbyname_r()</
function> and
<
function>lwres_gethostbyaddr_r()</
function> set the global variable
<
type>errno</
type> to <
errorcode>ERANGE</
errorcode>.
<
refentrytitle>gethostent</
refentrytitle><
manvolnum>3</
manvolnum>
<
refentrytitle>lwres_getipnode</
refentrytitle><
manvolnum>3</
manvolnum>
<
refentrytitle>lwres_hstrerror</
refentrytitle><
manvolnum>3
<
function>lwres_gethostbyname()</
function>,
<
function>lwres_gethostbyname2()</
function>,
<
function>lwres_gethostbyaddr()</
function>
<
function>lwres_endhostent()</
function>
are not thread safe; they return pointers to static data and
provide error codes through a global variable.
Thread-safe versions for name and address lookup are provided by
<
function>lwres_gethostbyname_r()</
function>,
<
function>lwres_gethostbyaddr_r()</
function>
The resolver daemon does not currently support any non-DNS
consequently the above functions don't, either.