2 - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2000, 2001 Internet Software Consortium.
5 - Permission to use, copy, modify, and distribute this software for any
6 - purpose with or without fee is hereby granted, provided that the above
7 - copyright notice and this permission notice appear in all copies.
9 - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 - PERFORMANCE OF THIS SOFTWARE.
17 <!-- $Id: lwres_resutil.html,v 1.8.2.1.4.11 2006/06/29 13:02:31 marka Exp $ -->
20 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
21 <title>lwres_resutil</title>
22 <meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
24 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
25 <a name="id2482688"></a><div class="titlepage"></div>
26 <div class="refnamediv">
28 <p>lwres_string_parse, lwres_addr_parse, lwres_getaddrsbyname, lwres_getnamebyaddr — lightweight resolver utility functions</p>
30 <div class="refsynopsisdiv">
32 <div class="funcsynopsis">
33 <pre class="funcsynopsisinfo">#include <lwres/lwres.h></pre>
34 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
36 <td><code class="funcdef">
38 <b class="fsfunc">lwres_string_parse</b>(</code></td>
59 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
61 <td><code class="funcdef">
63 <b class="fsfunc">lwres_addr_parse</b>(</code></td>
79 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
81 <td><code class="funcdef">
83 <b class="fsfunc">lwres_getaddrsbyname</b>(</code></td>
109 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0">
111 <td><code class="funcdef">
113 <b class="fsfunc">lwres_getnamebyaddr</b>(</code></td>
146 <div class="refsect1" lang="en">
147 <a name="id2549485"></a><h2>DESCRIPTION</h2>
149 <code class="function">lwres_string_parse()</code> retrieves a DNS-encoded
150 string starting the current pointer of lightweight resolver buffer
151 <em class="parameter"><code>b</code></em>: i.e. <code class="constant">b->current</code>.
152 When the function returns, the address of the first byte of the
153 encoded string is returned via <em class="parameter"><code>*c</code></em> and the
154 length of that string is given by <em class="parameter"><code>*len</code></em>. The
155 buffer's current pointer is advanced to point at the character
156 following the string length, the encoded string, and the trailing
157 <span class="type">NULL</span> character.
160 <code class="function">lwres_addr_parse()</code> extracts an address from the
161 buffer <em class="parameter"><code>b</code></em>. The buffer's current pointer
162 <code class="constant">b->current</code> is presumed to point at an encoded
163 address: the address preceded by a 32-bit protocol family identifier
164 and a 16-bit length field. The encoded address is copied to
165 <code class="constant">addr->address</code> and
166 <code class="constant">addr->length</code> indicates the size in bytes of
167 the address that was copied. <code class="constant">b->current</code> is
168 advanced to point at the next byte of available data in the buffer
169 following the encoded address.
172 <code class="function">lwres_getaddrsbyname()</code>
174 <code class="function">lwres_getnamebyaddr()</code>
176 <span class="type">lwres_gnbaresponse_t</span>
177 structure defined below:
179 <pre class="programlisting">
181 lwres_uint32_t flags;
182 lwres_uint16_t naliases;
183 lwres_uint16_t naddrs;
186 lwres_uint16_t realnamelen;
187 lwres_uint16_t *aliaslen;
188 lwres_addrlist_t addrs;
191 } lwres_gabnresponse_t;
194 The contents of this structure are not manipulated directly but
195 they are controlled through the
196 <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3
201 The lightweight resolver uses
202 <code class="function">lwres_getaddrsbyname()</code> to perform foward lookups.
203 Hostname <em class="parameter"><code>name</code></em> is looked up using the resolver
204 context <em class="parameter"><code>ctx</code></em> for memory allocation.
205 <em class="parameter"><code>addrtypes</code></em> is a bitmask indicating which type of
206 addresses are to be looked up. Current values for this bitmask are
207 <span class="type">LWRES_ADDRTYPE_V4</span> for IPv4 addresses and
208 <span class="type">LWRES_ADDRTYPE_V6</span> for IPv6 addresses. Results of the
209 lookup are returned in <em class="parameter"><code>*structp</code></em>.
212 <code class="function">lwres_getnamebyaddr()</code> performs reverse lookups.
213 Resolver context <em class="parameter"><code>ctx</code></em> is used for memory
214 allocation. The address type is indicated by
215 <em class="parameter"><code>addrtype</code></em>: <span class="type">LWRES_ADDRTYPE_V4</span> or
216 <span class="type">LWRES_ADDRTYPE_V6</span>. The address to be looked up is given
217 by <em class="parameter"><code>addr</code></em> and its length is
218 <em class="parameter"><code>addrlen</code></em> bytes. The result of the function call
219 is made available through <em class="parameter"><code>*structp</code></em>.
222 <div class="refsect1" lang="en">
223 <a name="id2549693"></a><h2>RETURN VALUES</h2>
226 <code class="function">lwres_string_parse()</code>
228 <code class="function">lwres_addr_parse()</code>
230 <span class="errorcode">LWRES_R_SUCCESS.</span>
231 Both functions return
232 <span class="errorcode">LWRES_R_FAILURE</span>
233 if the buffer is corrupt or
234 <span class="errorcode">LWRES_R_UNEXPECTEDEND</span>
235 if the buffer has less space than expected for the components of the
236 encoded string or address.
239 <code class="function">lwres_getaddrsbyname()</code>
241 <span class="errorcode">LWRES_R_SUCCESS</span>
242 on success and it returns
243 <span class="errorcode">LWRES_R_NOTFOUND</span>
245 <em class="parameter"><code>name</code></em>
249 <span class="errorcode">LWRES_R_SUCCESS</span>
250 is returned by a successful call to
251 <code class="function">lwres_getnamebyaddr()</code>.
255 <code class="function">lwres_getaddrsbyname()</code>
257 <code class="function">lwres_getnamebyaddr()</code>
259 <span class="errorcode">LWRES_R_NOMEMORY</span>
260 when memory allocation requests fail and
261 <span class="errorcode">LWRES_R_UNEXPECTEDEND</span>
262 if the buffers used for sending queries and receiving replies are too
266 <div class="refsect1" lang="en">
267 <a name="id2549763"></a><h2>SEE ALSO</h2>
269 <span class="citerefentry"><span class="refentrytitle">lwres_buffer</span>(3)</span>,
271 <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3)</span>.