- Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") - Copyright (C) 2001 Internet Software Consortium. - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - PERFORMANCE OF THIS SOFTWARE. <
meta http-
equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<
title>lwres_gethostent</
title>
<
meta name="generator" content="DocBook XSL Stylesheets V1.71.1">
<
body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><
div class="refentry" lang="en">
<
a name="id2476275"></
a><
div class="titlepage"></
div>
<
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 — lightweight resolver get network host entry</
p>
<
div class="refsynopsisdiv">
<
div class="funcsynopsis">
<
pre class="funcsynopsisinfo">#include <
lwres/
netdb.h></
pre>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><
tr>
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_gethostbyname</
b>(</
code></
td>
<
var class="pdparam">name</
var><
code>)</
code>;</
td>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_gethostbyname2</
b>(</
code></
td>
<
var class="pdparam">name</
var>, </
td>
<
var class="pdparam">af</
var><
code>)</
code>;</
td>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_gethostbyaddr</
b>(</
code></
td>
<
var class="pdparam">addr</
var>, </
td>
<
var class="pdparam">len</
var>, </
td>
<
var class="pdparam">type</
var><
code>)</
code>;</
td>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><
tr>
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_gethostent</
b>(</
code></
td>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><
tr>
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_sethostent</
b>(</
code></
td>
<
var class="pdparam">stayopen</
var><
code>)</
code>;</
td>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><
tr>
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_endhostent</
b>(</
code></
td>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_gethostbyname_r</
b>(</
code></
td>
<
var class="pdparam">name</
var>, </
td>
<
td>struct hostent *�</
td>
<
var class="pdparam">resbuf</
var>, </
td>
<
var class="pdparam">buf</
var>, </
td>
<
var class="pdparam">buflen</
var>, </
td>
<
var class="pdparam">error</
var><
code>)</
code>;</
td>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_gethostbyaddr_r</
b>(</
code></
td>
<
var class="pdparam">addr</
var>, </
td>
<
var class="pdparam">len</
var>, </
td>
<
var class="pdparam">type</
var>, </
td>
<
td>struct hostent *�</
td>
<
var class="pdparam">resbuf</
var>, </
td>
<
var class="pdparam">buf</
var>, </
td>
<
var class="pdparam">buflen</
var>, </
td>
<
var class="pdparam">error</
var><
code>)</
code>;</
td>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_gethostent_r</
b>(</
code></
td>
<
td>struct hostent *�</
td>
<
var class="pdparam">resbuf</
var>, </
td>
<
var class="pdparam">buf</
var>, </
td>
<
var class="pdparam">buflen</
var>, </
td>
<
var class="pdparam">error</
var><
code>)</
code>;</
td>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><
tr>
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_sethostent_r</
b>(</
code></
td>
<
var class="pdparam">stayopen</
var><
code>)</
code>;</
td>
<
table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"><
tr>
<
td><
code class="funcdef">
<
b class="fsfunc">lwres_endhostent_r</
b>(</
code></
td>
<
div class="refsect1" lang="en">
<
a name="id2543609"></
a><
h2>DESCRIPTION</
h2>
These functions provide hostname-to-address and
address-to-hostname lookups by means of the lightweight resolver.
They are similar to the standard
<
span class="citerefentry"><
span class="refentrytitle">gethostent</
span>(3)</
span>
functions provided by most operating systems.
<
span class="type">struct hostent</
span>
which is usually defined in
<
code class="filename"><
namedb.h></
code>.
<
pre class="programlisting">
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses from name server */
#define h_addr h_addr_list[0] /* address, for backward compatibility */
The members of this structure are:
<
div class="variablelist"><
dl>
<
dt><
span class="term"><
code class="constant">h_name</
code></
span></
dt>
The official (canonical) name of the host.
<
dt><
span class="term"><
code class="constant">h_aliases</
code></
span></
dt>
A NULL-terminated array of alternate names (nicknames) for the
<
dt><
span class="term"><
code class="constant">h_addrtype</
code></
span></
dt>
The type of address being returned —
<
span class="type">PF_INET</
span>
<
span class="type">PF_INET6</
span>.
<
dt><
span class="term"><
code class="constant">h_length</
code></
span></
dt>
The length of the address in bytes.
<
dt><
span class="term"><
code class="constant">h_addr_list</
code></
span></
dt>
A <
span class="type">NULL</
span>
terminated array of network addresses for the host.
Host addresses are returned in network byte order.
For backward compatibility with very old software,
<
code class="constant">h_addr</
code>
<
code class="constant">h_addr_list.</
code>
<
p><
code class="function">lwres_gethostent()</
code>,
<
code class="function">lwres_sethostent()</
code>,
<
code class="function">lwres_endhostent()</
code>,
<
code class="function">lwres_gethostent_r()</
code>,
<
code class="function">lwres_sethostent_r()</
code>
<
code class="function">lwres_endhostent_r()</
code>
provide iteration over the known host entries on systems that
provide such functionality through facilities like
<
code class="filename">/
etc/
hosts</
code>
or NIS. The lightweight resolver does not currently implement
these functions; it only provides them as stub functions that always
<
p><
code class="function">lwres_gethostbyname()</
code>
and <
code class="function">lwres_gethostbyname2()</
code> look up the
hostname <
em class="parameter"><
code>name</
code></
em>.
<
code class="function">lwres_gethostbyname()</
code> always looks for an
IPv4 address while <
code class="function">lwres_gethostbyname2()</
code>
looks for an address of protocol family
<
em class="parameter"><
code>af</
code></
em>: either <
span class="type">PF_INET</
span> or
<
span class="type">PF_INET6</
span> — IPv4 or IPV6 addresses
respectively. Successful calls of the functions return a
<
span class="type">struct hostent</
span>for the name that was looked up.
<
span class="type">NULL</
span> is returned if the lookups by
<
code class="function">lwres_gethostbyname()</
code> or
<
code class="function">lwres_gethostbyname2()</
code> fail.
Reverse lookups of addresses are performed by
<
code class="function">lwres_gethostbyaddr()</
code>.
<
em class="parameter"><
code>addr</
code></
em> is an address of length
<
em class="parameter"><
code>len</
code></
em> bytes and protocol family
<
em class="parameter"><
code>type</
code></
em> — <
span class="type">PF_INET</
span> or
<
span class="type">PF_INET6</
span>.
<
code class="function">lwres_gethostbyname_r()</
code> is a
for forward lookups. If an error occurs, an error code is returned in
<
em class="parameter"><
code>*error</
code></
em>.
<
em class="parameter"><
code>resbuf</
code></
em> is a pointer to a
<
span class="type">struct hostent</
span> which is initialised by a successful call to
<
code class="function">lwres_gethostbyname_r()</
code>.
<
em class="parameter"><
code>buf</
code></
em> is a buffer of length
<
em class="parameter"><
code>len</
code></
em> bytes which is used to store the
<
code class="constant">h_name</
code>, <
code class="constant">h_aliases</
code>, and
<
code class="constant">h_addr_list</
code> elements of the
<
span class="type">struct hostent</
span> returned in <
em class="parameter"><
code>resbuf</
code></
em>.
Successful calls to <
code class="function">lwres_gethostbyname_r()</
code>
return <
em class="parameter"><
code>resbuf</
code></
em>,
which is a pointer to the <
span class="type">struct hostent</
span> it created.
<
p><
code class="function">lwres_gethostbyaddr_r()</
code>
is a thread-safe function
that performs a reverse lookup of address <
em class="parameter"><
code>addr</
code></
em>
which is <
em class="parameter"><
code>len</
code></
em> bytes long and is of
family <
em class="parameter"><
code>type</
code></
em> — <
span class="type">PF_INET</
span> or
<
span class="type">PF_INET6</
span>. If an error occurs, the error code is returned
in <
em class="parameter"><
code>*error</
code></
em>. The other function
identical to those in <
code class="function">lwres_gethostbyname_r()</
code>.
<
em class="parameter"><
code>resbuf</
code></
em> is a pointer to a
<
span class="type">struct hostent</
span> which is initialised by a successful call to
<
code class="function">lwres_gethostbyaddr_r()</
code>.
<
em class="parameter"><
code>buf</
code></
em> is a buffer of length
<
em class="parameter"><
code>len</
code></
em> bytes which is used to store the
<
code class="constant">h_name</
code>, <
code class="constant">h_aliases</
code>, and
<
code class="constant">h_addr_list</
code> elements of the
<
span class="type">struct hostent</
span> returned in <
em class="parameter"><
code>resbuf</
code></
em>.
Successful calls to <
code class="function">lwres_gethostbyaddr_r()</
code> return
<
em class="parameter"><
code>resbuf</
code></
em>, which is a pointer to the
<
code class="function">struct hostent()</
code> it created.
<
div class="refsect1" lang="en">
<
a name="id2543960"></
a><
h2>RETURN VALUES</
h2>
<
code class="function">lwres_gethostbyname()</
code>,
<
code class="function">lwres_gethostbyname2()</
code>,
<
code class="function">lwres_gethostbyaddr()</
code>,
<
code class="function">lwres_gethostent()</
code>
return NULL to indicate an error. In this case the global variable
<
span class="type">lwres_h_errno</
span>
will contain one of the following error codes defined in
<
div class="variablelist"><
dl>
<
dt><
span class="term"><
code class="constant">HOST_NOT_FOUND</
code></
span></
dt>
The host or address was not found.
<
dt><
span class="term"><
code class="constant">TRY_AGAIN</
code></
span></
dt>
A recoverable error occurred,
e.g., a timeout.
Retrying the lookup may succeed.
<
dt><
span class="term"><
code class="constant">NO_RECOVERY</
code></
span></
dt>
A non-recoverable error occurred.
<
dt><
span class="term"><
code class="constant">NO_DATA</
code></
span></
dt>
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
<
p><
span class="citerefentry"><
span class="refentrytitle">lwres_hstrerror</
span>(3)</
span>
translates these error codes to suitable error messages.
<
p><
code class="function">lwres_gethostent()</
code>
and <
code class="function">lwres_gethostent_r()</
code>
always return <
span class="type">NULL</
span>.
Successful calls to <
code class="function">lwres_gethostbyname_r()</
code> and
<
code class="function">lwres_gethostbyaddr_r()</
code> return
<
em class="parameter"><
code>resbuf</
code></
em>, a pointer to the
<
span class="type">struct hostent</
span> that was initialised by these functions. They return
<
span class="type">NULL</
span> if the lookups fail or if <
em class="parameter"><
code>buf</
code></
em>
was too small to hold the list of addresses and names referenced by
the <
code class="constant">h_name</
code>, <
code class="constant">h_aliases</
code>, and
<
code class="constant">h_addr_list</
code> elements of the
<
span class="type">struct hostent</
span>.
If <
em class="parameter"><
code>buf</
code></
em> was too small, both
<
code class="function">lwres_gethostbyname_r()</
code> and
<
code class="function">lwres_gethostbyaddr_r()</
code> set the global
<
span class="type">errno</
span> to <
span class="errorcode">ERANGE</
span>.
<
div class="refsect1" lang="en">
<
a name="id2544194"></
a><
h2>SEE ALSO</
h2>
<
p><
span class="citerefentry"><
span class="refentrytitle">gethostent</
span>(3)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">lwres_getipnode</
span>(3)</
span>,
<
span class="citerefentry"><
span class="refentrytitle">lwres_hstrerror</
span>(3)</
span>
<
div class="refsect1" lang="en">
<
a name="id2544228"></
a><
h2>BUGS</
h2>
<
p><
code class="function">lwres_gethostbyname()</
code>,
<
code class="function">lwres_gethostbyname2()</
code>,
<
code class="function">lwres_gethostbyaddr()</
code>
<
code class="function">lwres_endhostent()</
code>
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
<
code class="function">lwres_gethostbyname_r()</
code>,
<
code class="function">lwres_gethostbyaddr_r()</
code>
The resolver daemon does not currently support any non-DNS
<
code class="filename">/
etc/
hosts</
code>
<
span class="type">NIS</
span>,
consequently the above functions don't, either.