lwres_resutil.docbook revision 194e2dfffa6a167b8eef0ad11864026b423a1c30
306N/A<!--
306N/A - Copyright (C) 2000, 2001, 2004, 2005, 2007, 2014-2016 Internet Systems Consortium, Inc. ("ISC")
935N/A -
306N/A - This Source Code Form is subject to the terms of the Mozilla Public
306N/A - License, v. 2.0. If a copy of the MPL was not distributed with this
919N/A - file, You can obtain one at http://mozilla.org/MPL/2.0/.
919N/A-->
919N/A
919N/A<!-- Converted by db4-upgrade version 1.0 -->
919N/A<refentry xmlns="http://docbook.org/ns/docbook" version="5.0">
919N/A <info>
919N/A <date>2007-06-18</date>
919N/A </info>
919N/A <refentryinfo>
919N/A <corpname>ISC</corpname>
919N/A <corpauthor>Internet Systems Consortium, Inc.</corpauthor>
919N/A </refentryinfo>
919N/A
919N/A <refmeta>
919N/A <refentrytitle>lwres_resutil</refentrytitle>
919N/A <manvolnum>3</manvolnum>
919N/A <refmiscinfo>BIND9</refmiscinfo>
306N/A </refmeta>
306N/A
493N/A <docinfo>
493N/A <copyright>
306N/A <year>2000</year>
493N/A <year>2001</year>
306N/A <year>2004</year>
493N/A <year>2005</year>
493N/A <year>2007</year>
935N/A <year>2014</year>
935N/A <year>2015</year>
935N/A <year>2016</year>
810N/A <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
810N/A </copyright>
810N/A </docinfo>
493N/A
493N/A <refnamediv>
493N/A <refname>lwres_string_parse</refname>
837N/A <refname>lwres_addr_parse</refname>
493N/A <refname>lwres_getaddrsbyname</refname>
306N/A <refname>lwres_getnamebyaddr</refname>
963N/A <refpurpose>lightweight resolver utility functions</refpurpose>
963N/A </refnamediv>
963N/A <refsynopsisdiv>
306N/A <funcsynopsis>
493N/A<funcsynopsisinfo>#include &lt;lwres/lwres.h&gt;</funcsynopsisinfo>
306N/A<funcprototype>
306N/A <funcdef>
561N/Alwres_result_t
306N/A<function>lwres_string_parse</function></funcdef>
963N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
963N/A <paramdef>char **<parameter>c</parameter></paramdef>
963N/A <paramdef>lwres_uint16_t *<parameter>len</parameter></paramdef>
837N/A </funcprototype>
837N/A<funcprototype>
837N/A <funcdef>
837N/Alwres_result_t
837N/A<function>lwres_addr_parse</function></funcdef>
837N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
963N/A <paramdef>lwres_addr_t *<parameter>addr</parameter></paramdef>
837N/A </funcprototype>
306N/A<funcprototype>
837N/A <funcdef>
837N/Alwres_result_t
963N/A<function>lwres_getaddrsbyname</function></funcdef>
837N/A <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
837N/A <paramdef>const char *<parameter>name</parameter></paramdef>
837N/A <paramdef>lwres_uint32_t <parameter>addrtypes</parameter></paramdef>
837N/A <paramdef>lwres_gabnresponse_t **<parameter>structp</parameter></paramdef>
837N/A </funcprototype>
837N/A<funcprototype>
837N/A <funcdef>
851N/Alwres_result_t
851N/A<function>lwres_getnamebyaddr</function></funcdef>
<paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
<paramdef>lwres_uint32_t <parameter>addrtype</parameter></paramdef>
<paramdef>lwres_uint16_t <parameter>addrlen</parameter></paramdef>
<paramdef>const unsigned char *<parameter>addr</parameter></paramdef>
<paramdef>lwres_gnbaresponse_t **<parameter>structp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection><info><title>DESCRIPTION</title></info>
<para><function>lwres_string_parse()</function>
retrieves a DNS-encoded string starting the current pointer of
lightweight resolver buffer <parameter>b</parameter>: i.e.
<constant>b-&gt;current</constant>. When the function returns,
the address of the first byte of the encoded string is returned
via <parameter>*c</parameter> and the length of that string is
given by <parameter>*len</parameter>. The buffer's current
pointer is advanced to point at the character following the
string length, the encoded string, and the trailing
<type>NULL</type> character.
</para>
<para><function>lwres_addr_parse()</function>
extracts an address from the buffer <parameter>b</parameter>.
The buffer's current pointer <constant>b-&gt;current</constant>
is presumed to point at an encoded address: the address preceded
by a 32-bit protocol family identifier and a 16-bit length
field. The encoded address is copied to
<constant>addr-&gt;address</constant> and
<constant>addr-&gt;length</constant> indicates the size in bytes
of the address that was copied.
<constant>b-&gt;current</constant> is advanced to point at the
next byte of available data in the buffer following the encoded
address.
</para>
<para><function>lwres_getaddrsbyname()</function>
and <function>lwres_getnamebyaddr()</function> use the
<type>lwres_gnbaresponse_t</type> structure defined below:
</para>
<para><programlisting>
typedef struct {
lwres_uint32_t flags;
lwres_uint16_t naliases;
lwres_uint16_t naddrs;
char *realname;
char **aliases;
lwres_uint16_t realnamelen;
lwres_uint16_t *aliaslen;
lwres_addrlist_t addrs;
void *base;
size_t baselen;
} lwres_gabnresponse_t;
</programlisting></para>
<para>
The contents of this structure are not manipulated directly but
they are controlled through the
<citerefentry>
<refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>
functions.
</para>
<para>
The lightweight resolver uses
<function>lwres_getaddrsbyname()</function> to perform
forward lookups.
Hostname <parameter>name</parameter> is looked up using the
resolver
context <parameter>ctx</parameter> for memory allocation.
<parameter>addrtypes</parameter> is a bitmask indicating
which type of
addresses are to be looked up. Current values for this bitmask are
<type>LWRES_ADDRTYPE_V4</type> for IPv4 addresses and
<type>LWRES_ADDRTYPE_V6</type> for IPv6 addresses. Results of the
lookup are returned in <parameter>*structp</parameter>.
</para>
<para><function>lwres_getnamebyaddr()</function>
performs reverse lookups. Resolver context
<parameter>ctx</parameter> is used for memory allocation. The
address type is indicated by <parameter>addrtype</parameter>:
<type>LWRES_ADDRTYPE_V4</type> or
<type>LWRES_ADDRTYPE_V6</type>. The address to be looked up is
given by <parameter>addr</parameter> and its length is
<parameter>addrlen</parameter> bytes. The result of the
function call is made available through
<parameter>*structp</parameter>.
</para>
</refsection>
<refsection><info><title>RETURN VALUES</title></info>
<para>
Successful calls to
<function>lwres_string_parse()</function>
and
<function>lwres_addr_parse()</function>
return
<errorcode>LWRES_R_SUCCESS.</errorcode>
Both functions return
<errorcode>LWRES_R_FAILURE</errorcode>
if the buffer is corrupt or
<errorcode>LWRES_R_UNEXPECTEDEND</errorcode>
if the buffer has less space than expected for the components of the
encoded string or address.
</para>
<para><function>lwres_getaddrsbyname()</function>
returns <errorcode>LWRES_R_SUCCESS</errorcode> on success and it
returns <errorcode>LWRES_R_NOTFOUND</errorcode> if the hostname
<parameter>name</parameter> could not be found.
</para>
<para><errorcode>LWRES_R_SUCCESS</errorcode>
is returned by a successful call to
<function>lwres_getnamebyaddr()</function>.
</para>
<para>
Both
<function>lwres_getaddrsbyname()</function>
and
<function>lwres_getnamebyaddr()</function>
return
<errorcode>LWRES_R_NOMEMORY</errorcode>
when memory allocation requests fail and
<errorcode>LWRES_R_UNEXPECTEDEND</errorcode>
if the buffers used for sending queries and receiving replies are too
small.
</para>
</refsection>
<refsection><info><title>SEE ALSO</title></info>
<para><citerefentry>
<refentrytitle>lwres_buffer</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,
<citerefentry>
<refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>.
</para>
</refsection>
</refentry>