lwres_gethostent.docbook revision dafcb997e390efa4423883dafd100c975c4095d6
486N/A<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
486N/A<!--
486N/A - Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
486N/A - Copyright (C) 2001 Internet Software Consortium.
486N/A -
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 -
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-->
486N/A
486N/A<!-- $Id: lwres_gethostent.docbook,v 1.6 2004/03/05 05:12:56 marka Exp $ -->
873N/A
486N/A<refentry>
486N/A
486N/A<refentryinfo>
486N/A<date>Jun 30, 2000</date>
486N/A</refentryinfo>
873N/A
486N/A<refmeta>
486N/A<refentrytitle>lwres_gethostent</refentrytitle>
486N/A<manvolnum>3</manvolnum>
486N/A<refmiscinfo>BIND9</refmiscinfo>
486N/A</refmeta>
486N/A
486N/A<refnamediv>
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>
619N/A</refnamediv>
619N/A<refsynopsisdiv>
619N/A<funcsynopsis>
619N/A<funcsynopsisinfo>#include &lt;lwres/netdb.h&gt;</funcsynopsisinfo>
619N/A<funcprototype>
619N/A<funcdef>
619N/Astruct hostent *
2650N/A<function>lwres_gethostbyname</function></funcdef>
2650N/A<paramdef>const char *name</paramdef>
2650N/A</funcprototype>
486N/A<funcprototype>
2650N/A<funcdef>
486N/Astruct hostent *
1194N/A<function>lwres_gethostbyname2</function></funcdef>
486N/A<paramdef>const char *name</paramdef>
1194N/A<paramdef>int af</paramdef>
2650N/A</funcprototype>
2650N/A<funcprototype>
486N/A<funcdef>
2650N/Astruct hostent *
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</funcprototype>
2650N/A<funcprototype>
2650N/A<funcdef>
2650N/Astruct hostent *
2650N/A<function>lwres_gethostent</function></funcdef>
2650N/A<paramdef>void</paramdef>
2650N/A</funcprototype>
2650N/A<funcprototype>
2650N/A<funcdef>
2650N/Avoid
2650N/A<function>lwres_sethostent</function></funcdef>
619N/A<paramdef>int stayopen</paramdef>
2650N/A</funcprototype>
2650N/A<funcprototype>
619N/A<funcdef>
486N/Avoid
486N/A<function>lwres_endhostent</function></funcdef>
2650N/A<paramdef>void</paramdef>
2650N/A</funcprototype>
486N/A<funcprototype>
486N/A<funcdef>
486N/Astruct hostent *
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</funcprototype>
486N/A<funcprototype>
486N/A<funcdef>
486N/Astruct hostent *
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</funcprototype>
486N/A<funcprototype>
486N/A<funcdef>
486N/Astruct hostent *
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</funcprototype>
1181N/A<funcprototype>
1181N/A<funcdef>
2650N/Avoid
1181N/A<function>lwres_sethostent_r</function></funcdef>
1181N/A<paramdef>int stayopen</paramdef>
1181N/A</funcprototype>
1181N/A<funcprototype>
1181N/A<funcdef>
1181N/Avoid
1181N/A<function>lwres_endhostent_r</function></funcdef>
2650N/A<paramdef>void</paramdef>
1181N/A</funcprototype>
1181N/A</funcsynopsis>
1181N/A</refsynopsisdiv>
2650N/A
1181N/A<refsect1>
1181N/A<title>DESCRIPTION</title>
1181N/A<para>
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
961N/A<citerefentry>
832N/A<refentrytitle>gethostent</refentrytitle><manvolnum>3
961N/A</manvolnum>
961N/A</citerefentry>
961N/Afunctions provided by most operating systems.
961N/AThey use a
2296N/A<type>struct hostent</type>
961N/Awhich is usually defined in
961N/A<filename>&lt;namedb.h&gt;</filename>.
961N/A
961N/A<programlisting>
961N/Astruct hostent {
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};
961N/A#define h_addr h_addr_list[0] /* address, for backward compatibility */
486N/A</programlisting>
961N/A</para>
961N/A<para>
2296N/AThe members of this structure are:
2296N/A<variablelist>
2296N/A<varlistentry><term><constant>h_name</constant></term>
2296N/A<listitem>
961N/A<para>
961N/AThe official (canonical) name of the host.
486N/A</para>
961N/A</listitem></varlistentry>
961N/A<varlistentry><term><constant>h_aliases</constant></term>
961N/A<listitem>
961N/A<para>
961N/AA NULL-terminated array of alternate names (nicknames) for the host.
2296N/A</para>
961N/A</listitem></varlistentry>
961N/A<varlistentry><term><constant>h_addrtype</constant></term>
961N/A<listitem>
961N/A<para>
961N/AThe type of address being returned &mdash;
961N/A<type>PF_INET</type>
2296N/Aor
2296N/A<type>PF_INET6</type>.
2296N/A</para>
2296N/A</listitem></varlistentry>
961N/A<varlistentry><term><constant>h_length</constant></term>
961N/A<listitem>
832N/A<para>
961N/AThe length of the address in bytes.
832N/A</para>
961N/A</listitem></varlistentry>
857N/A<varlistentry><term><constant>h_addr_list</constant></term>
857N/A<listitem>
961N/A<para>
961N/AA <type>NULL</type>
961N/Aterminated array of network addresses for the host.
961N/AHost addresses are returned in network byte order.
961N/A</para>
857N/A</listitem></varlistentry>
961N/A</variablelist>
961N/A</para>
961N/A<para>
961N/AFor backward compatibility with very old software,
2650N/A<constant>h_addr</constant>
961N/Ais the first address in
961N/A<constant>h_addr_list.</constant>
961N/A</para>
961N/A<para>
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/Aand
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/A<filename>/etc/hosts</filename>
486N/Aor NIS. The lightweight resolver does not currently implement
961N/Athese functions; it only provides them as stub functions that always
961N/Areturn failure.
961N/A</para>
961N/A
961N/A<para>
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> &mdash; 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/A</para>
2296N/A
2296N/A<para>
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> &mdash; <type>PF_INET</type> or
2296N/A<type>PF_INET6</type>.
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.
961N/A</para>
<para>
<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> &mdash; <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.
</para>
</refsect1>
<refsect1>
<title>RETURN VALUES</title>
<para>
The functions
<function>lwres_gethostbyname()</function>,
<function>lwres_gethostbyname2()</function>,
<function>lwres_gethostbyaddr()</function>,
and
<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
<filename>&lt;lwres/netdb.h&gt;</filename>:
<variablelist>
<varlistentry><term><constant>HOST_NOT_FOUND</constant></term>
<listitem>
<para>
The host or address was not found.
</para>
</listitem></varlistentry>
<varlistentry><term><constant>TRY_AGAIN</constant></term>
<listitem>
<para>
A recoverable error occurred, e.g., a timeout.
Retrying the lookup may succeed.
</para>
</listitem></varlistentry>
<varlistentry><term><constant>NO_RECOVERY</constant></term>
<listitem>
<para>
A non-recoverable error occurred.
</para>
</listitem></varlistentry>
<varlistentry><term><constant>NO_DATA</constant></term>
<listitem>
<para>
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
compatibility.
</para>
</listitem></varlistentry>
</variablelist>
</para>
<para>
<citerefentry>
<refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3
</manvolnum>
</citerefentry>
translates these error codes to suitable error messages.
</para>
<para>
<function>lwres_gethostent()</function>
and
<function>lwres_gethostent_r()</function>
always return
<type>NULL</type>.
</para>
<para>
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>.
</para>
</refsect1>
<refsect1>
<title>SEE ALSO</title>
<para>
<citerefentry>
<refentrytitle>gethostent</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,
<citerefentry>
<refentrytitle>lwres_getipnode</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,
<citerefentry>
<refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3
</manvolnum>
</citerefentry>
</para>
</refsect1>
<refsect1>
<title>BUGS</title>
<para>
<function>lwres_gethostbyname()</function>,
<function>lwres_gethostbyname2()</function>,
<function>lwres_gethostbyaddr()</function>
and
<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>,
and
<function>lwres_gethostbyaddr_r()</function>
respectively.
</para>
<para>
The resolver daemon does not currently support any non-DNS
name services such as
<filename>/etc/hosts</filename>
or
<type>NIS</type>,
consequently the above functions don't, either.
</para>
</refsect1>
</refentry>