lwres_getipnode.docbook revision 14a656f94b1fd0ababd84a772228dfa52276ba15
8eea8e29cc4374d1ee24c25a07f45af132db3499ap<!--
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
8eea8e29cc4374d1ee24c25a07f45af132db3499ap -
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - Permission to use, copy, modify, and/or distribute this software for any
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - purpose with or without fee is hereby granted, provided that the above
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - copyright notice and this permission notice appear in all copies.
8eea8e29cc4374d1ee24c25a07f45af132db3499ap -
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
8eea8e29cc4374d1ee24c25a07f45af132db3499ap - PERFORMANCE OF THIS SOFTWARE.
8eea8e29cc4374d1ee24c25a07f45af132db3499ap-->
8eea8e29cc4374d1ee24c25a07f45af132db3499ap<!-- Converted by db4-upgrade version 1.0 -->
8eea8e29cc4374d1ee24c25a07f45af132db3499ap<refentry xmlns="http://docbook.org/ns/docbook" version="5.0">
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <info>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <date>2007-06-18</date>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </info>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <refentryinfo>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <corpname>ISC</corpname>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <corpauthor>Internet Systems Consortium, Inc.</corpauthor>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </refentryinfo>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <refmeta>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <refentrytitle>lwres_getipnode</refentrytitle>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <manvolnum>3</manvolnum>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <refmiscinfo>BIND9</refmiscinfo>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </refmeta>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <docinfo>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <copyright>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <year>2004</year>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <year>2005</year>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <year>2007</year>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <year>2014</year>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </copyright>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <copyright>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <year>2000</year>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <year>2001</year>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <year>2003</year>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <holder>Internet Software Consortium.</holder>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </copyright>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </docinfo>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <refnamediv>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <refname>lwres_getipnodebyname</refname>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <refname>lwres_getipnodebyaddr</refname>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <refname>lwres_freehostent</refname>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <refpurpose>lightweight resolver nodename / address translation API</refpurpose>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </refnamediv>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <refsynopsisdiv>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <funcsynopsis>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap<funcsynopsisinfo>#include &lt;lwres/netdb.h&gt;</funcsynopsisinfo>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap<funcprototype>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <funcdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499apstruct hostent *
8eea8e29cc4374d1ee24c25a07f45af132db3499ap<function>lwres_getipnodebyname</function></funcdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <paramdef>const char *<parameter>name</parameter></paramdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <paramdef>int <parameter>af</parameter></paramdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <paramdef>int <parameter>flags</parameter></paramdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <paramdef>int *<parameter>error_num</parameter></paramdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </funcprototype>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap<funcprototype>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <funcdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499apstruct hostent *
8eea8e29cc4374d1ee24c25a07f45af132db3499ap<function>lwres_getipnodebyaddr</function></funcdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <paramdef>const void *<parameter>src</parameter></paramdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <paramdef>size_t <parameter>len</parameter></paramdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <paramdef>int <parameter>af</parameter></paramdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <paramdef>int *<parameter>error_num</parameter></paramdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </funcprototype>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap<funcprototype>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <funcdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499apvoid
8eea8e29cc4374d1ee24c25a07f45af132db3499ap<function>lwres_freehostent</function></funcdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <paramdef>struct hostent *<parameter>he</parameter></paramdef>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </funcprototype>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap</funcsynopsis>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </refsynopsisdiv>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <refsection><info><title>DESCRIPTION</title></info>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap
8eea8e29cc4374d1ee24c25a07f45af132db3499ap
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <para>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap These functions perform thread safe, protocol independent
8eea8e29cc4374d1ee24c25a07f45af132db3499ap nodename-to-address and address-to-nodename
8eea8e29cc4374d1ee24c25a07f45af132db3499ap translation as defined in RFC2553.
8eea8e29cc4374d1ee24c25a07f45af132db3499ap </para>
8eea8e29cc4374d1ee24c25a07f45af132db3499ap
8eea8e29cc4374d1ee24c25a07f45af132db3499ap <para>
They use a
<type>struct hostent</type>
which is defined in
<filename>namedb.h</filename>:
</para>
<para><programlisting>
struct hostent {
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 */
</programlisting>
</para>
<para>
The members of this structure are:
<variablelist>
<varlistentry>
<term><constant>h_name</constant></term>
<listitem>
<para>
The official (canonical) name of the host.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>h_aliases</constant></term>
<listitem>
<para>
A NULL-terminated array of alternate names (nicknames) for the
host.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>h_addrtype</constant></term>
<listitem>
<para>
The type of address being returned - usually
<type>PF_INET</type>
or
<type>PF_INET6</type>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>h_length</constant></term>
<listitem>
<para>
The length of the address in bytes.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>h_addr_list</constant></term>
<listitem>
<para>
A
<type>NULL</type>
terminated array of network addresses for the host.
Host addresses are returned in network byte order.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para><function>lwres_getipnodebyname()</function>
looks up addresses of protocol family <parameter>af</parameter>
for the hostname <parameter>name</parameter>. The
<parameter>flags</parameter> parameter contains ORed flag bits
to specify the types of addresses that are searched for, and the
types of addresses that are returned. The flag bits are:
<variablelist>
<varlistentry>
<term><constant>AI_V4MAPPED</constant></term>
<listitem>
<para>
This is used with an
<parameter>af</parameter>
of AF_INET6, and causes IPv4 addresses to be returned as
IPv4-mapped
IPv6 addresses.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>AI_ALL</constant></term>
<listitem>
<para>
This is used with an
<parameter>af</parameter>
of AF_INET6, and causes all known addresses (IPv6 and IPv4) to
be returned.
If AI_V4MAPPED is also set, the IPv4 addresses are return as
mapped
IPv6 addresses.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>AI_ADDRCONFIG</constant></term>
<listitem>
<para>
Only return an IPv6 or IPv4 address if here is an active network
interface of that type. This is not currently implemented
in the BIND 9 lightweight resolver, and the flag is ignored.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>AI_DEFAULT</constant></term>
<listitem>
<para>
This default sets the
<constant>AI_V4MAPPED</constant>
and
<constant>AI_ADDRCONFIG</constant>
flag bits.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para><function>lwres_getipnodebyaddr()</function>
performs a reverse lookup of address <parameter>src</parameter>
which is <parameter>len</parameter> bytes long.
<parameter>af</parameter> denotes the protocol family, typically
<type>PF_INET</type> or <type>PF_INET6</type>.
</para>
<para><function>lwres_freehostent()</function>
releases all the memory associated with the <type>struct
hostent</type> pointer <parameter>he</parameter>. Any memory
allocated for the <constant>h_name</constant>,
<constant>h_addr_list</constant> and
<constant>h_aliases</constant> is freed, as is the memory for
the <type>hostent</type> structure itself.
</para>
</refsection>
<refsection><info><title>RETURN VALUES</title></info>
<para>
If an error occurs,
<function>lwres_getipnodebyname()</function>
and
<function>lwres_getipnodebyaddr()</function>
set
<parameter>*error_num</parameter>
to an appropriate error code and the function returns a
<type>NULL</type>
pointer.
The error codes and their meanings are defined in
<filename>&lt;lwres/netdb.h&gt;</filename>:
<variablelist>
<varlistentry>
<term><constant>HOST_NOT_FOUND</constant></term>
<listitem>
<para>
No such host is known.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>NO_ADDRESS</constant></term>
<listitem>
<para>
The server recognised the request and the name but no address is
available. Another type of request to the name server for the
domain might return an answer.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>TRY_AGAIN</constant></term>
<listitem>
<para>
A temporary and possibly transient error occurred, such as a
failure of a server to respond. The request may succeed if
retried.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>NO_RECOVERY</constant></term>
<listitem>
<para>
An unexpected failure occurred, and retrying the request
is pointless.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para><citerefentry>
<refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>
translates these error codes to suitable error messages.
</para>
</refsection>
<refsection><info><title>SEE ALSO</title></info>
<para><citerefentry>
<refentrytitle>RFC2553</refentrytitle>
</citerefentry>,
<citerefentry>
<refentrytitle>lwres</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,
<citerefentry>
<refentrytitle>lwres_gethostent</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,
<citerefentry>
<refentrytitle>lwres_getaddrinfo</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,
<citerefentry>
<refentrytitle>lwres_getnameinfo</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,
<citerefentry>
<refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>.
</para>
</refsection>
</refentry>