4623N/A<!
DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 4623N/A [<!ENTITY mdash "—">]>
2605N/A - Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") 2605N/A - Copyright (C) 2001 Internet Software Consortium. 2605N/A - Permission to use, copy, modify, and/or distribute this software for any 2605N/A - purpose with or without fee is hereby granted, provided that the above 2605N/A - copyright notice and this permission notice appear in all copies. 2605N/A - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 2605N/A - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 2605N/A - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 2605N/A - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 2605N/A - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 2605N/A - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 2605N/A - PERFORMANCE OF THIS SOFTWARE. 2605N/A <
refentrytitle>lwres_gethostent</
refentrytitle>
2605N/A <
refmiscinfo>BIND9</
refmiscinfo>
2605N/A <
holder>Internet Systems Consortium, Inc. ("ISC")</
holder>
2605N/A <
holder>Internet Software Consortium.</
holder>
<
refname>lwres_gethostbyname</
refname>
<
refname>lwres_gethostbyname2</
refname>
<
refname>lwres_gethostbyaddr</
refname>
<
refname>lwres_gethostent</
refname>
<
refname>lwres_sethostent</
refname>
<
refname>lwres_endhostent</
refname>
<
refname>lwres_gethostbyname_r</
refname>
<
refname>lwres_gethostbyaddr_r</
refname>
<
refname>lwres_gethostent_r</
refname>
<
refname>lwres_sethostent_r</
refname>
<
refname>lwres_endhostent_r</
refname>
<
refpurpose>lightweight resolver get network host entry</
refpurpose>
<
funcsynopsisinfo>#include <
lwres/
netdb.h></
funcsynopsisinfo>
<
function>lwres_gethostbyname</
function></
funcdef>
<
paramdef>const char *<
parameter>name</
parameter></
paramdef>
<
function>lwres_gethostbyname2</
function></
funcdef>
<
paramdef>const char *<
parameter>name</
parameter></
paramdef>
<
paramdef>int <
parameter>af</
parameter></
paramdef>
<
function>lwres_gethostbyaddr</
function></
funcdef>
<
paramdef>const char *<
parameter>addr</
parameter></
paramdef>
<
paramdef>int <
parameter>len</
parameter></
paramdef>
<
paramdef>int <
parameter>type</
parameter></
paramdef>
<
function>lwres_gethostent</
function></
funcdef>
<
paramdef>void</
paramdef>
<
function>lwres_sethostent</
function></
funcdef>
<
paramdef>int <
parameter>stayopen</
parameter></
paramdef>
<
function>lwres_endhostent</
function></
funcdef>
<
paramdef>void</
paramdef>
<
function>lwres_gethostbyname_r</
function></
funcdef>
<
paramdef>const char *<
parameter>name</
parameter></
paramdef>
<
paramdef>struct hostent *<
parameter>resbuf</
parameter></
paramdef>
<
paramdef>char *<
parameter>buf</
parameter></
paramdef>
<
paramdef>int <
parameter>buflen</
parameter></
paramdef>
<
paramdef>int *<
parameter>error</
parameter></
paramdef>
<
function>lwres_gethostbyaddr_r</
function></
funcdef>
<
paramdef>const char *<
parameter>addr</
parameter></
paramdef>
<
paramdef>int <
parameter>len</
parameter></
paramdef>
<
paramdef>int <
parameter>type</
parameter></
paramdef>
<
paramdef>struct hostent *<
parameter>resbuf</
parameter></
paramdef>
<
paramdef>char *<
parameter>buf</
parameter></
paramdef>
<
paramdef>int <
parameter>buflen</
parameter></
paramdef>
<
paramdef>int *<
parameter>error</
parameter></
paramdef>
<
function>lwres_gethostent_r</
function></
funcdef>
<
paramdef>struct hostent *<
parameter>resbuf</
parameter></
paramdef>
<
paramdef>char *<
parameter>buf</
parameter></
paramdef>
<
paramdef>int <
parameter>buflen</
parameter></
paramdef>
<
paramdef>int *<
parameter>error</
parameter></
paramdef>
<
function>lwres_sethostent_r</
function></
funcdef>
<
paramdef>int <
parameter>stayopen</
parameter></
paramdef>
<
function>lwres_endhostent_r</
function></
funcdef>
<
paramdef>void</
paramdef>
<
title>DESCRIPTION</
title>
These functions provide hostname-to-address and
address-to-hostname lookups by means of the lightweight resolver.
They are similar to the standard
<
refentrytitle>gethostent</
refentrytitle><
manvolnum>3</
manvolnum>
functions provided by most operating systems.
<
type>struct hostent</
type>
which is usually defined in
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:
<
term><
constant>h_name</
constant></
term>
The official (canonical) name of the host.
<
term><
constant>h_aliases</
constant></
term>
A NULL-terminated array of alternate names (nicknames) for the
<
term><
constant>h_addrtype</
constant></
term>
The type of address being returned —
<
term><
constant>h_length</
constant></
term>
The length of the address in bytes.
<
term><
constant>h_addr_list</
constant></
term>
terminated array of network addresses for the host.
Host addresses are returned in network byte order.
For backward compatibility with very old software,
<
constant>h_addr</
constant>
<
constant>h_addr_list.</
constant>
<
para><
function>lwres_gethostent()</
function>,
<
function>lwres_sethostent()</
function>,
<
function>lwres_endhostent()</
function>,
<
function>lwres_gethostent_r()</
function>,
<
function>lwres_sethostent_r()</
function>
<
function>lwres_endhostent_r()</
function>
provide iteration over the known host entries on systems that
provide such functionality through facilities like
or NIS. The lightweight resolver does not currently implement
these functions; it only provides them as stub functions that always
<
para><
function>lwres_gethostbyname()</
function>
and <
function>lwres_gethostbyname2()</
function> look up the
hostname <
parameter>name</
parameter>.
<
function>lwres_gethostbyname()</
function> always looks for an
IPv4 address while <
function>lwres_gethostbyname2()</
function>
looks for an address of protocol family
<
parameter>af</
parameter>: either <
type>PF_INET</
type> or
<
type>PF_INET6</
type> — IPv4 or IPV6 addresses
respectively. Successful calls of the functions return a
<
type>struct hostent</
type>for the name that was looked up.
<
type>NULL</
type> is returned if the lookups by
<
function>lwres_gethostbyname()</
function> or
<
function>lwres_gethostbyname2()</
function> fail.
Reverse lookups of addresses are performed by
<
function>lwres_gethostbyaddr()</
function>.
<
parameter>addr</
parameter> is an address of length
<
parameter>len</
parameter> bytes and protocol family
<
parameter>type</
parameter> — <
type>PF_INET</
type> or
<
function>lwres_gethostbyname_r()</
function> is a
for forward lookups. If an error occurs, an error code is returned in
<
parameter>*error</
parameter>.
<
parameter>resbuf</
parameter> is a pointer to a
<
type>struct hostent</
type> which is initialised by a successful call to
<
function>lwres_gethostbyname_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_gethostbyname_r()</
function>
return <
parameter>resbuf</
parameter>,
which is a pointer to the <
type>struct hostent</
type> it created.
<
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
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
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
<
term><
constant>HOST_NOT_FOUND</
constant></
term>
The host or address was not found.
<
term><
constant>TRY_AGAIN</
constant></
term>
A recoverable error occurred,
e.g., a timeout.
Retrying the lookup may succeed.
<
term><
constant>NO_RECOVERY</
constant></
term>
A non-recoverable error occurred.
<
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
<
refentrytitle>lwres_hstrerror</
refentrytitle><
manvolnum>3</
manvolnum>
translates these error codes to suitable error messages.
<
para><
function>lwres_gethostent()</
function>
and <
function>lwres_gethostent_r()</
function>
always return <
type>NULL</
type>.
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
<
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</
manvolnum>
<
para><
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.