lwres_resutil.html revision fd2597f75693a2279fdf588bd40dfe2407c42028
b0e8629055a766d4555a005a283c2889a5974945Mark Andrews - Copyright (C) 2004, 2005, 2007, 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - Copyright (C) 2000, 2001 Internet Software Consortium.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews - Permission to use, copy, modify, and/or 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<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry">
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<a name="id-1"></a><div class="titlepage"></div>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<p>lwres_string_parse, lwres_addr_parse, lwres_getaddrsbyname, lwres_getnamebyaddr — lightweight resolver utility functions</p>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<pre class="funcsynopsisinfo">#include <lwres/lwres.h></pre>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewslwres_result_t
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<b class="fsfunc">lwres_string_parse</b>(</code></td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>lwres_uint16_t *<var class="pdparam">len</var><code>)</code>;</td>
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewslwres_result_t
b0e8629055a766d4555a005a283c2889a5974945Mark Andrews<b class="fsfunc">lwres_addr_parse</b>(</code></td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>lwres_addr_t *<var class="pdparam">addr</var><code>)</code>;</td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewslwres_result_t
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<b class="fsfunc">lwres_getaddrsbyname</b>(</code></td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>const char *<var class="pdparam">name</var>, </td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>lwres_uint32_t <var class="pdparam">addrtypes</var>, </td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>lwres_gabnresponse_t **<var class="pdparam">structp</var><code>)</code>;</td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewslwres_result_t
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<b class="fsfunc">lwres_getnamebyaddr</b>(</code></td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>lwres_uint32_t <var class="pdparam">addrtype</var>, </td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>lwres_uint16_t <var class="pdparam">addrlen</var>, </td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>const unsigned char *<var class="pdparam">addr</var>, </td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<td>lwres_gnbaresponse_t **<var class="pdparam">structp</var><code>)</code>;</td>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<p><code class="function">lwres_string_parse()</code>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews retrieves a DNS-encoded string starting the current pointer of
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews lightweight resolver buffer <em class="parameter"><code>b</code></em>: i.e.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <code class="constant">b->current</code>. When the function returns,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews the address of the first byte of the encoded string is returned
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews via <em class="parameter"><code>*c</code></em> and the length of that string is
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews given by <em class="parameter"><code>*len</code></em>. The buffer's current
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews pointer is advanced to point at the character following the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews string length, the encoded string, and the trailing
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<p><code class="function">lwres_addr_parse()</code>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews extracts an address from the buffer <em class="parameter"><code>b</code></em>.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews The buffer's current pointer <code class="constant">b->current</code>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews is presumed to point at an encoded address: the address preceded
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews by a 32-bit protocol family identifier and a 16-bit length
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews field. The encoded address is copied to
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews <code class="constant">addr->address</code> and
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews <code class="constant">addr->length</code> indicates the size in bytes
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews of the address that was copied.
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews <code class="constant">b->current</code> is advanced to point at the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews next byte of available data in the buffer following the encoded
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<p><code class="function">lwres_getaddrsbyname()</code>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews and <code class="function">lwres_getnamebyaddr()</code> use the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <span class="type">lwres_gnbaresponse_t</span> structure defined below:
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewstypedef struct {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews lwres_uint32_t flags;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews lwres_uint16_t naliases;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews lwres_uint16_t naddrs;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews char *realname;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews char **aliases;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews lwres_uint16_t realnamelen;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews lwres_uint16_t *aliaslen;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews lwres_addrlist_t addrs;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews size_t baselen;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews} lwres_gabnresponse_t;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews The contents of this structure are not manipulated directly but
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews they are controlled through the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3)</span>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews The lightweight resolver uses
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <code class="function">lwres_getaddrsbyname()</code> to perform
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews forward lookups.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews Hostname <em class="parameter"><code>name</code></em> is looked up using the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews context <em class="parameter"><code>ctx</code></em> for memory allocation.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <em class="parameter"><code>addrtypes</code></em> is a bitmask indicating
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews which type of
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews addresses are to be looked up. Current values for this bitmask are
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews <span class="type">LWRES_ADDRTYPE_V4</span> for IPv4 addresses and
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews <span class="type">LWRES_ADDRTYPE_V6</span> for IPv6 addresses. Results of the
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews lookup are returned in <em class="parameter"><code>*structp</code></em>.
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews<p><code class="function">lwres_getnamebyaddr()</code>
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews performs reverse lookups. Resolver context
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <em class="parameter"><code>ctx</code></em> is used for memory allocation. The
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews address type is indicated by <em class="parameter"><code>addrtype</code></em>:
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <span class="type">LWRES_ADDRTYPE_V6</span>. The address to be looked up is
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews given by <em class="parameter"><code>addr</code></em> and its length is
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <em class="parameter"><code>addrlen</code></em> bytes. The result of the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews function call is made available through
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <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>
285254345ce5ab270848f8c11f7be146793f1e00Mark Andrews Both functions return
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if the buffer is corrupt or
285254345ce5ab270848f8c11f7be146793f1e00Mark 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.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<p><code class="function">lwres_getaddrsbyname()</code>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews returns <span class="errorcode">LWRES_R_SUCCESS</span> on success and it
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews returns <span class="errorcode">LWRES_R_NOTFOUND</span> if the hostname
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <em class="parameter"><code>name</code></em> could not be found.
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews<p><span class="errorcode">LWRES_R_SUCCESS</span>
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews is returned by a successful call to
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews <code class="function">lwres_getnamebyaddr()</code>.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <code class="function">lwres_getaddrsbyname()</code>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <code class="function">lwres_getnamebyaddr()</code>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <span class="errorcode">LWRES_R_NOMEMORY</span>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews when memory allocation requests fail and
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <span class="errorcode">LWRES_R_UNEXPECTEDEND</span>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews 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>,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3)</span>.