lwres_resutil.html revision e21a2904f02a03fa06b6db04d348f65fe9c67b2b
11e9368a226272085c337e9e74b79808c16fbdbaTinderbox User - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - Copyright (C) 2000, 2001 Internet Software Consortium.
4a14ce5ba00ab7bc55c99ffdcf59c7a4ab902721Automatic Updater - Permission to use, copy, modify, and distribute this software for any
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - purpose with or without fee is hereby granted, provided that the above
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - copyright notice and this permission notice appear in all copies.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - PERFORMANCE OF THIS SOFTWARE.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<!-- $Id: lwres_resutil.html,v 1.23 2006/12/12 01:45:21 marka Exp $ -->
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt<meta name="generator" content="DocBook XSL Stylesheets V1.71.1">
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
9a5087bf58f651bfff841192aba5afd06760d6ceTinderbox User<a name="id2476419"></a><div class="titlepage"></div>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<p>lwres_string_parse, lwres_addr_parse, lwres_getaddrsbyname, lwres_getnamebyaddr — lightweight resolver utility functions</p>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt<pre class="funcsynopsisinfo">#include <lwres/lwres.h></pre>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewslwres_result_t
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<b class="fsfunc">lwres_string_parse</b>(</code></td>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<var class="pdparam">len</var><code>)</code>;</td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Huntlwres_result_t
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<b class="fsfunc">lwres_addr_parse</b>(</code></td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<var class="pdparam">addr</var><code>)</code>;</td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewslwres_result_t
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<b class="fsfunc">lwres_getaddrsbyname</b>(</code></td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<var class="pdparam">structp</var><code>)</code>;</td>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0">
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Huntlwres_result_t
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt<b class="fsfunc">lwres_getnamebyaddr</b>(</code></td>
e68c527dff2f1f7df2a542f8d6f9181a27e05eb7Tinderbox User<var class="pdparam">structp</var><code>)</code>;</td>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt<p><code class="function">lwres_string_parse()</code>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt retrieves a DNS-encoded string starting the current pointer of
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt lightweight resolver buffer <em class="parameter"><code>b</code></em>: i.e.
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <code class="constant">b->current</code>. When the function returns,
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt the address of the first byte of the encoded string is returned
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User via <em class="parameter"><code>*c</code></em> and the length of that string is
a1b05dea35aa30b152a47115e18bbe679d3fcf19Mark Andrews given by <em class="parameter"><code>*len</code></em>. The buffer's current
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User pointer is advanced to point at the character following the
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt string length, the encoded string, and the trailing
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt<p><code class="function">lwres_addr_parse()</code>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt extracts an address from the buffer <em class="parameter"><code>b</code></em>.
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt The buffer's current pointer <code class="constant">b->current</code>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt is presumed to point at an encoded address: the address preceded
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt by a 32-bit protocol family identifier and a 16-bit length
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User field. The encoded address is copied to
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <code class="constant">addr->address</code> and
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User <code class="constant">addr->length</code> indicates the size in bytes
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews of the address that was copied.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <code class="constant">b->current</code> is advanced to point at the
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt next byte of available data in the buffer following the encoded
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<p><code class="function">lwres_getaddrsbyname()</code>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User and <code class="function">lwres_getnamebyaddr()</code> use the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <span class="type">lwres_gnbaresponse_t</span> structure defined below:
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewstypedef struct {
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User lwres_uint32_t flags;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews lwres_uint16_t naliases;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews lwres_uint16_t naddrs;
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User char *realname;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews char **aliases;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews lwres_uint16_t realnamelen;
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User lwres_uint16_t *aliaslen;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews lwres_addrlist_t addrs;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews size_t baselen;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews} lwres_gabnresponse_t;
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User The contents of this structure are not manipulated directly but
c4d99a62407cebca29653666ae11f87e4f56ebbcAutomatic Updater they are controlled through the
c4d99a62407cebca29653666ae11f87e4f56ebbcAutomatic Updater <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3)</span>
0e1dece22e128f9dfa723316a35c4b3f06912381Tinderbox User The lightweight resolver uses
0e1dece22e128f9dfa723316a35c4b3f06912381Tinderbox User <code class="function">lwres_getaddrsbyname()</code> to perform
0e1dece22e128f9dfa723316a35c4b3f06912381Tinderbox User foward lookups.
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt Hostname <em class="parameter"><code>name</code></em> is looked up using the
c4d99a62407cebca29653666ae11f87e4f56ebbcAutomatic Updater context <em class="parameter"><code>ctx</code></em> for memory allocation.
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User <em class="parameter"><code>addrtypes</code></em> is a bitmask indicating
c4d99a62407cebca29653666ae11f87e4f56ebbcAutomatic Updater addresses are to be looked up. Current values for this bitmask are
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <span class="type">LWRES_ADDRTYPE_V4</span> for IPv4 addresses and
c4d99a62407cebca29653666ae11f87e4f56ebbcAutomatic Updater <span class="type">LWRES_ADDRTYPE_V6</span> for IPv6 addresses. Results of the
c4d99a62407cebca29653666ae11f87e4f56ebbcAutomatic Updater lookup are returned in <em class="parameter"><code>*structp</code></em>.
c4d99a62407cebca29653666ae11f87e4f56ebbcAutomatic Updater<p><code class="function">lwres_getnamebyaddr()</code>
c4d99a62407cebca29653666ae11f87e4f56ebbcAutomatic Updater performs reverse lookups. Resolver context
c4d99a62407cebca29653666ae11f87e4f56ebbcAutomatic Updater <em class="parameter"><code>ctx</code></em> is used for memory allocation. The
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt address type is indicated by <em class="parameter"><code>addrtype</code></em>:
c4d99a62407cebca29653666ae11f87e4f56ebbcAutomatic Updater <span class="type">LWRES_ADDRTYPE_V4</span> or
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <span class="type">LWRES_ADDRTYPE_V6</span>. The address to be looked up is
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt given by <em class="parameter"><code>addr</code></em> and its length is
c4d99a62407cebca29653666ae11f87e4f56ebbcAutomatic Updater <em class="parameter"><code>addrlen</code></em> bytes. The result of the
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User function call is made available through
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User <em class="parameter"><code>*structp</code></em>.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews Successful calls to
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <code class="function">lwres_string_parse()</code>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <code class="function">lwres_addr_parse()</code>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <span class="errorcode">LWRES_R_SUCCESS.</span>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews Both functions return
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews if the buffer is corrupt or
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <span class="errorcode">LWRES_R_UNEXPECTEDEND</span>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if the buffer has less space than expected for the components of the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews encoded string or address.
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<p><code class="function">lwres_getaddrsbyname()</code>
2a1d6afad5c725cbc796c10f1d2b9041eda9f077Automatic Updater returns <span class="errorcode">LWRES_R_SUCCESS</span> on success and it
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User returns <span class="errorcode">LWRES_R_NOTFOUND</span> if the hostname
2a1d6afad5c725cbc796c10f1d2b9041eda9f077Automatic Updater <em class="parameter"><code>name</code></em> could not be found.
0e1dece22e128f9dfa723316a35c4b3f06912381Tinderbox User is returned by a successful call to
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <code class="function">lwres_getnamebyaddr()</code>.
0e1dece22e128f9dfa723316a35c4b3f06912381Tinderbox User <code class="function">lwres_getaddrsbyname()</code>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <code class="function">lwres_getnamebyaddr()</code>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User <span class="errorcode">LWRES_R_NOMEMORY</span>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews when memory allocation requests fail and
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <span class="errorcode">LWRES_R_UNEXPECTEDEND</span>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User if the buffers used for sending queries and receiving replies are too
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<p><span class="citerefentry"><span class="refentrytitle">lwres_buffer</span>(3)</span>,
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3)</span>.