2 - Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2000, 2001 Internet Software Consortium.
5 - Permission to use, copy, modify, and/or 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.
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.71.1">
24 <body bgcolor=
"white" text=
"black" link=
"#0000FF" vlink=
"#840084" alink=
"#0000FF"><div class=
"refentry" lang=
"en">
25 <a name=
"id2476275"></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>
39 <td>lwres_buffer_t *
</td>
41 <var class=
"pdparam">b
</var>,
</td>
47 <var class=
"pdparam">c
</var>,
</td>
51 <td>lwres_uint16_t *
</td>
53 <var class=
"pdparam">len
</var><code>)
</code>;
</td>
56 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
58 <td><code class=
"funcdef">
60 <b class=
"fsfunc">lwres_addr_parse
</b>(
</code></td>
61 <td>lwres_buffer_t *
</td>
63 <var class=
"pdparam">b
</var>,
</td>
67 <td>lwres_addr_t *
</td>
69 <var class=
"pdparam">addr
</var><code>)
</code>;
</td>
72 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
74 <td><code class=
"funcdef">
76 <b class=
"fsfunc">lwres_getaddrsbyname
</b>(
</code></td>
77 <td>lwres_context_t *
</td>
79 <var class=
"pdparam">ctx
</var>,
</td>
83 <td>const char *
</td>
85 <var class=
"pdparam">name
</var>,
</td>
89 <td>lwres_uint32_t
</td>
91 <var class=
"pdparam">addrtypes
</var>,
</td>
95 <td>lwres_gabnresponse_t **
</td>
97 <var class=
"pdparam">structp
</var><code>)
</code>;
</td>
100 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0">
102 <td><code class=
"funcdef">
104 <b class=
"fsfunc">lwres_getnamebyaddr
</b>(
</code></td>
105 <td>lwres_context_t *
</td>
107 <var class=
"pdparam">ctx
</var>,
</td>
111 <td>lwres_uint32_t
</td>
113 <var class=
"pdparam">addrtype
</var>,
</td>
117 <td>lwres_uint16_t
</td>
119 <var class=
"pdparam">addrlen
</var>,
</td>
123 <td>const unsigned char *
</td>
125 <var class=
"pdparam">addr
</var>,
</td>
129 <td>lwres_gnbaresponse_t **
</td>
131 <var class=
"pdparam">structp
</var><code>)
</code>;
</td>
136 <div class=
"refsect1" lang=
"en">
137 <a name=
"id2543476"></a><h2>DESCRIPTION
</h2>
138 <p><code class=
"function">lwres_string_parse()
</code>
139 retrieves a DNS-encoded string starting the current pointer of
140 lightweight resolver buffer
<em class=
"parameter"><code>b
</code></em>: i.e.
141 <code class=
"constant">b-
>current
</code>. When the function returns,
142 the address of the first byte of the encoded string is returned
143 via
<em class=
"parameter"><code>*c
</code></em> and the length of that string is
144 given by
<em class=
"parameter"><code>*len
</code></em>. The buffer's current
145 pointer is advanced to point at the character following the
146 string length, the encoded string, and the trailing
147 <span class=
"type">NULL
</span> character.
149 <p><code class=
"function">lwres_addr_parse()
</code>
150 extracts an address from the buffer
<em class=
"parameter"><code>b
</code></em>.
151 The buffer's current pointer
<code class=
"constant">b-
>current
</code>
152 is presumed to point at an encoded address: the address preceded
153 by a
32-bit protocol family identifier and a
16-bit length
154 field. The encoded address is copied to
155 <code class=
"constant">addr-
>address
</code> and
156 <code class=
"constant">addr-
>length
</code> indicates the size in bytes
157 of the address that was copied.
158 <code class=
"constant">b-
>current
</code> is advanced to point at the
159 next byte of available data in the buffer following the encoded
162 <p><code class=
"function">lwres_getaddrsbyname()
</code>
163 and
<code class=
"function">lwres_getnamebyaddr()
</code> use the
164 <span class=
"type">lwres_gnbaresponse_t
</span> structure defined below:
166 <pre class=
"programlisting">
168 lwres_uint32_t flags;
169 lwres_uint16_t naliases;
170 lwres_uint16_t naddrs;
173 lwres_uint16_t realnamelen;
174 lwres_uint16_t *aliaslen;
175 lwres_addrlist_t addrs;
178 } lwres_gabnresponse_t;
181 The contents of this structure are not manipulated directly but
182 they are controlled through the
183 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_gabn
</span>(
3)
</span>
187 The lightweight resolver uses
188 <code class=
"function">lwres_getaddrsbyname()
</code> to perform
190 Hostname
<em class=
"parameter"><code>name
</code></em> is looked up using the
192 context
<em class=
"parameter"><code>ctx
</code></em> for memory allocation.
193 <em class=
"parameter"><code>addrtypes
</code></em> is a bitmask indicating
195 addresses are to be looked up. Current values for this bitmask are
196 <span class=
"type">LWRES_ADDRTYPE_V4
</span> for IPv4 addresses and
197 <span class=
"type">LWRES_ADDRTYPE_V6
</span> for IPv6 addresses. Results of the
198 lookup are returned in
<em class=
"parameter"><code>*structp
</code></em>.
200 <p><code class=
"function">lwres_getnamebyaddr()
</code>
201 performs reverse lookups. Resolver context
202 <em class=
"parameter"><code>ctx
</code></em> is used for memory allocation. The
203 address type is indicated by
<em class=
"parameter"><code>addrtype
</code></em>:
204 <span class=
"type">LWRES_ADDRTYPE_V4
</span> or
205 <span class=
"type">LWRES_ADDRTYPE_V6
</span>. The address to be looked up is
206 given by
<em class=
"parameter"><code>addr
</code></em> and its length is
207 <em class=
"parameter"><code>addrlen
</code></em> bytes. The result of the
208 function call is made available through
209 <em class=
"parameter"><code>*structp
</code></em>.
212 <div class=
"refsect1" lang=
"en">
213 <a name=
"id2543614"></a><h2>RETURN VALUES
</h2>
216 <code class=
"function">lwres_string_parse()
</code>
218 <code class=
"function">lwres_addr_parse()
</code>
220 <span class=
"errorcode">LWRES_R_SUCCESS.
</span>
221 Both functions return
222 <span class=
"errorcode">LWRES_R_FAILURE
</span>
223 if the buffer is corrupt or
224 <span class=
"errorcode">LWRES_R_UNEXPECTEDEND
</span>
225 if the buffer has less space than expected for the components of the
226 encoded string or address.
228 <p><code class=
"function">lwres_getaddrsbyname()
</code>
229 returns
<span class=
"errorcode">LWRES_R_SUCCESS
</span> on success and it
230 returns
<span class=
"errorcode">LWRES_R_NOTFOUND
</span> if the hostname
231 <em class=
"parameter"><code>name
</code></em> could not be found.
233 <p><span class=
"errorcode">LWRES_R_SUCCESS
</span>
234 is returned by a successful call to
235 <code class=
"function">lwres_getnamebyaddr()
</code>.
239 <code class=
"function">lwres_getaddrsbyname()
</code>
241 <code class=
"function">lwres_getnamebyaddr()
</code>
243 <span class=
"errorcode">LWRES_R_NOMEMORY
</span>
244 when memory allocation requests fail and
245 <span class=
"errorcode">LWRES_R_UNEXPECTEDEND
</span>
246 if the buffers used for sending queries and receiving replies are too
250 <div class=
"refsect1" lang=
"en">
251 <a name=
"id2543686"></a><h2>SEE ALSO
</h2>
252 <p><span class=
"citerefentry"><span class=
"refentrytitle">lwres_buffer
</span>(
3)
</span>,
254 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_gabn
</span>(
3)
</span>.