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.9 2005/10/13 02:33:58 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.69.1">
24 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
25 <a name="id2463721"></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>
54 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
56 <td><code class="funcdef">
58 <b class="fsfunc">lwres_addr_parse</b>(</code></td>
69 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
71 <td><code class="funcdef">
73 <b class="fsfunc">lwres_getaddrsbyname</b>(</code></td>
94 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0">
96 <td><code class="funcdef">
98 <b class="fsfunc">lwres_getnamebyaddr</b>(</code></td>
126 <div class="refsect1" lang="en">
127 <a name="id2525921"></a><h2>DESCRIPTION</h2>
129 <code class="function">lwres_string_parse()</code> retrieves a DNS-encoded
130 string starting the current pointer of lightweight resolver buffer
131 <em class="parameter"><code>b</code></em>: i.e. <code class="constant">b->current</code>.
132 When the function returns, the address of the first byte of the
133 encoded string is returned via <em class="parameter"><code>*c</code></em> and the
134 length of that string is given by <em class="parameter"><code>*len</code></em>. The
135 buffer's current pointer is advanced to point at the character
136 following the string length, the encoded string, and the trailing
137 <span class="type">NULL</span> character.
140 <code class="function">lwres_addr_parse()</code> extracts an address from the
141 buffer <em class="parameter"><code>b</code></em>. The buffer's current pointer
142 <code class="constant">b->current</code> is presumed to point at an encoded
143 address: the address preceded by a 32-bit protocol family identifier
144 and a 16-bit length field. The encoded address is copied to
145 <code class="constant">addr->address</code> and
146 <code class="constant">addr->length</code> indicates the size in bytes of
147 the address that was copied. <code class="constant">b->current</code> is
148 advanced to point at the next byte of available data in the buffer
149 following the encoded address.
152 <code class="function">lwres_getaddrsbyname()</code>
154 <code class="function">lwres_getnamebyaddr()</code>
156 <span class="type">lwres_gnbaresponse_t</span>
157 structure defined below:
159 <pre class="programlisting">
161 lwres_uint32_t flags;
162 lwres_uint16_t naliases;
163 lwres_uint16_t naddrs;
166 lwres_uint16_t realnamelen;
167 lwres_uint16_t *aliaslen;
168 lwres_addrlist_t addrs;
171 } lwres_gabnresponse_t;
174 The contents of this structure are not manipulated directly but
175 they are controlled through the
176 <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3
181 The lightweight resolver uses
182 <code class="function">lwres_getaddrsbyname()</code> to perform foward lookups.
183 Hostname <em class="parameter"><code>name</code></em> is looked up using the resolver
184 context <em class="parameter"><code>ctx</code></em> for memory allocation.
185 <em class="parameter"><code>addrtypes</code></em> is a bitmask indicating which type of
186 addresses are to be looked up. Current values for this bitmask are
187 <span class="type">LWRES_ADDRTYPE_V4</span> for IPv4 addresses and
188 <span class="type">LWRES_ADDRTYPE_V6</span> for IPv6 addresses. Results of the
189 lookup are returned in <em class="parameter"><code>*structp</code></em>.
192 <code class="function">lwres_getnamebyaddr()</code> performs reverse lookups.
193 Resolver context <em class="parameter"><code>ctx</code></em> is used for memory
194 allocation. The address type is indicated by
195 <em class="parameter"><code>addrtype</code></em>: <span class="type">LWRES_ADDRTYPE_V4</span> or
196 <span class="type">LWRES_ADDRTYPE_V6</span>. The address to be looked up is given
197 by <em class="parameter"><code>addr</code></em> and its length is
198 <em class="parameter"><code>addrlen</code></em> bytes. The result of the function call
199 is made available through <em class="parameter"><code>*structp</code></em>.
202 <div class="refsect1" lang="en">
203 <a name="id2526060"></a><h2>RETURN VALUES</h2>
206 <code class="function">lwres_string_parse()</code>
208 <code class="function">lwres_addr_parse()</code>
210 <span class="errorcode">LWRES_R_SUCCESS.</span>
211 Both functions return
212 <span class="errorcode">LWRES_R_FAILURE</span>
213 if the buffer is corrupt or
214 <span class="errorcode">LWRES_R_UNEXPECTEDEND</span>
215 if the buffer has less space than expected for the components of the
216 encoded string or address.
219 <code class="function">lwres_getaddrsbyname()</code>
221 <span class="errorcode">LWRES_R_SUCCESS</span>
222 on success and it returns
223 <span class="errorcode">LWRES_R_NOTFOUND</span>
225 <em class="parameter"><code>name</code></em>
229 <span class="errorcode">LWRES_R_SUCCESS</span>
230 is returned by a successful call to
231 <code class="function">lwres_getnamebyaddr()</code>.
235 <code class="function">lwres_getaddrsbyname()</code>
237 <code class="function">lwres_getnamebyaddr()</code>
239 <span class="errorcode">LWRES_R_NOMEMORY</span>
240 when memory allocation requests fail and
241 <span class="errorcode">LWRES_R_UNEXPECTEDEND</span>
242 if the buffers used for sending queries and receiving replies are too
246 <div class="refsect1" lang="en">
247 <a name="id2526130"></a><h2>SEE ALSO</h2>
249 <span class="citerefentry"><span class="refentrytitle">lwres_buffer</span>(3)</span>,
251 <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3)</span>.