lwres_resutil.docbook revision 1753d3c4d74241a847794f7e7cfd94cc79be6600
176N/A<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
176N/A "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
176N/A [<!ENTITY mdash "&#8212;">]>
246N/A<!--
176N/A - Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
176N/A - Copyright (C) 2000, 2001 Internet Software Consortium.
176N/A -
176N/A - Permission to use, copy, modify, and/or distribute this software for any
176N/A - purpose with or without fee is hereby granted, provided that the above
176N/A - copyright notice and this permission notice appear in all copies.
176N/A -
176N/A - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
176N/A - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
176N/A - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
176N/A - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
176N/A - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
176N/A - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
176N/A - PERFORMANCE OF THIS SOFTWARE.
176N/A-->
176N/A
176N/A<refentry>
176N/A
176N/A <refentryinfo>
176N/A <date>June 18, 2007</date>
176N/A </refentryinfo>
176N/A
176N/A <refmeta>
176N/A <refentrytitle>lwres_resutil</refentrytitle>
176N/A <manvolnum>3</manvolnum>
176N/A <refmiscinfo>BIND9</refmiscinfo>
176N/A </refmeta>
176N/A
176N/A <docinfo>
176N/A <copyright>
176N/A <year>2004</year>
176N/A <year>2005</year>
176N/A <year>2007</year>
176N/A <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
176N/A </copyright>
176N/A <copyright>
176N/A <year>2000</year>
176N/A <year>2001</year>
176N/A <holder>Internet Software Consortium.</holder>
176N/A </copyright>
176N/A </docinfo>
176N/A
176N/A <refnamediv>
176N/A <refname>lwres_string_parse</refname>
176N/A <refname>lwres_addr_parse</refname>
176N/A <refname>lwres_getaddrsbyname</refname>
176N/A <refname>lwres_getnamebyaddr</refname>
176N/A <refpurpose>lightweight resolver utility functions</refpurpose>
176N/A </refnamediv>
176N/A <refsynopsisdiv>
176N/A <funcsynopsis>
176N/A<funcsynopsisinfo>#include &lt;lwres/lwres.h&gt;</funcsynopsisinfo>
176N/A<funcprototype>
176N/A <funcdef>
176N/Alwres_result_t
176N/A<function>lwres_string_parse</function></funcdef>
176N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
176N/A <paramdef>char **<parameter>c</parameter></paramdef>
176N/A <paramdef>lwres_uint16_t *<parameter>len</parameter></paramdef>
176N/A </funcprototype>
176N/A<funcprototype>
176N/A <funcdef>
176N/Alwres_result_t
176N/A<function>lwres_addr_parse</function></funcdef>
176N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
176N/A <paramdef>lwres_addr_t *<parameter>addr</parameter></paramdef>
176N/A </funcprototype>
176N/A<funcprototype>
176N/A <funcdef>
176N/Alwres_result_t
176N/A<function>lwres_getaddrsbyname</function></funcdef>
176N/A <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
176N/A <paramdef>const char *<parameter>name</parameter></paramdef>
176N/A <paramdef>lwres_uint32_t <parameter>addrtypes</parameter></paramdef>
176N/A <paramdef>lwres_gabnresponse_t **<parameter>structp</parameter></paramdef>
176N/A </funcprototype>
176N/A<funcprototype>
176N/A <funcdef>
176N/Alwres_result_t
176N/A<function>lwres_getnamebyaddr</function></funcdef>
176N/A <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
176N/A <paramdef>lwres_uint32_t <parameter>addrtype</parameter></paramdef>
176N/A <paramdef>lwres_uint16_t <parameter>addrlen</parameter></paramdef>
176N/A <paramdef>const unsigned char *<parameter>addr</parameter></paramdef>
176N/A <paramdef>lwres_gnbaresponse_t **<parameter>structp</parameter></paramdef>
176N/A </funcprototype>
176N/A</funcsynopsis>
176N/A </refsynopsisdiv>
176N/A
176N/A <refsect1>
176N/A <title>DESCRIPTION</title>
176N/A
176N/A <para><function>lwres_string_parse()</function>
176N/A retrieves a DNS-encoded string starting the current pointer of
176N/A lightweight resolver buffer <parameter>b</parameter>: i.e.
176N/A <constant>b-&gt;current</constant>. When the function returns,
176N/A the address of the first byte of the encoded string is returned
176N/A via <parameter>*c</parameter> and the length of that string is
176N/A given by <parameter>*len</parameter>. The buffer's current
176N/A pointer is advanced to point at the character following the
176N/A string length, the encoded string, and the trailing
176N/A <type>NULL</type> character.
176N/A </para>
176N/A
176N/A <para><function>lwres_addr_parse()</function>
176N/A extracts an address from the buffer <parameter>b</parameter>.
176N/A The buffer's current pointer <constant>b-&gt;current</constant>
176N/A is presumed to point at an encoded address: the address preceded
176N/A by a 32-bit protocol family identifier and a 16-bit length
176N/A field. The encoded address is copied to
176N/A <constant>addr-&gt;address</constant> and
176N/A <constant>addr-&gt;length</constant> indicates the size in bytes
176N/A of the address that was copied.
176N/A <constant>b-&gt;current</constant> is advanced to point at the
176N/A next byte of available data in the buffer following the encoded
176N/A address.
176N/A </para>
176N/A
176N/A <para><function>lwres_getaddrsbyname()</function>
176N/A and <function>lwres_getnamebyaddr()</function> use the
176N/A <type>lwres_gnbaresponse_t</type> structure defined below:
176N/A </para>
176N/A
176N/A<para><programlisting>
176N/Atypedef struct {
176N/A lwres_uint32_t flags;
176N/A lwres_uint16_t naliases;
176N/A lwres_uint16_t naddrs;
176N/A char *realname;
176N/A char **aliases;
176N/A lwres_uint16_t realnamelen;
176N/A lwres_uint16_t *aliaslen;
176N/A lwres_addrlist_t addrs;
176N/A void *base;
176N/A size_t baselen;
176N/A} lwres_gabnresponse_t;
176N/A</programlisting></para>
176N/A
176N/A <para>
176N/A The contents of this structure are not manipulated directly but
176N/A they are controlled through the
176N/A <citerefentry>
176N/A <refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum>
176N/A </citerefentry>
176N/A functions.
176N/A </para>
176N/A
176N/A <para>
176N/A The lightweight resolver uses
176N/A <function>lwres_getaddrsbyname()</function> to perform
176N/A foward lookups.
176N/A Hostname <parameter>name</parameter> is looked up using the
176N/A resolver
176N/A context <parameter>ctx</parameter> for memory allocation.
176N/A <parameter>addrtypes</parameter> is a bitmask indicating
176N/A which type of
176N/A addresses are to be looked up. Current values for this bitmask are
176N/A <type>LWRES_ADDRTYPE_V4</type> for IPv4 addresses and
176N/A <type>LWRES_ADDRTYPE_V6</type> for IPv6 addresses. Results of the
176N/A lookup are returned in <parameter>*structp</parameter>.
176N/A </para>
176N/A
176N/A <para><function>lwres_getnamebyaddr()</function>
176N/A performs reverse lookups. Resolver context
176N/A <parameter>ctx</parameter> is used for memory allocation. The
176N/A address type is indicated by <parameter>addrtype</parameter>:
176N/A <type>LWRES_ADDRTYPE_V4</type> or
176N/A <type>LWRES_ADDRTYPE_V6</type>. The address to be looked up is
176N/A given by <parameter>addr</parameter> and its length is
176N/A <parameter>addrlen</parameter> bytes. The result of the
176N/A function call is made available through
176N/A <parameter>*structp</parameter>.
176N/A </para>
176N/A </refsect1>
176N/A
246N/A <refsect1>
246N/A <title>RETURN VALUES</title>
176N/A <para>
176N/A Successful calls to
176N/A <function>lwres_string_parse()</function>
176N/A and
176N/A <function>lwres_addr_parse()</function>
176N/A return
176N/A <errorcode>LWRES_R_SUCCESS.</errorcode>
176N/A Both functions return
176N/A <errorcode>LWRES_R_FAILURE</errorcode>
176N/A if the buffer is corrupt or
176N/A <errorcode>LWRES_R_UNEXPECTEDEND</errorcode>
176N/A if the buffer has less space than expected for the components of the
176N/A encoded string or address.
176N/A </para>
176N/A
176N/A <para><function>lwres_getaddrsbyname()</function>
176N/A returns <errorcode>LWRES_R_SUCCESS</errorcode> on success and it
176N/A returns <errorcode>LWRES_R_NOTFOUND</errorcode> if the hostname
176N/A <parameter>name</parameter> could not be found.
176N/A </para>
176N/A <para><errorcode>LWRES_R_SUCCESS</errorcode>
176N/A is returned by a successful call to
176N/A <function>lwres_getnamebyaddr()</function>.
176N/A </para>
176N/A
176N/A <para>
176N/A Both
176N/A <function>lwres_getaddrsbyname()</function>
176N/A and
176N/A <function>lwres_getnamebyaddr()</function>
176N/A return
176N/A <errorcode>LWRES_R_NOMEMORY</errorcode>
176N/A when memory allocation requests fail and
176N/A <errorcode>LWRES_R_UNEXPECTEDEND</errorcode>
176N/A if the buffers used for sending queries and receiving replies are too
176N/A small.
176N/A </para>
176N/A
176N/A </refsect1>
176N/A <refsect1>
176N/A <title>SEE ALSO</title>
176N/A <para><citerefentry>
176N/A <refentrytitle>lwres_buffer</refentrytitle><manvolnum>3</manvolnum>
176N/A </citerefentry>,
176N/A
176N/A <citerefentry>
176N/A <refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum>
176N/A </citerefentry>.
176N/A </para>
176N/A
176N/A </refsect1>
176N/A</refentry><!--
176N/A - Local variables:
176N/A - mode: sgml
176N/A - End:
176N/A-->
176N/A