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