128N/A - Copyright (C) 2000, 2001, 2004, 2005, 2007, 2014-2016 Internet Systems Consortium, Inc. ("ISC") 128N/A - This Source Code Form is subject to the terms of the Mozilla Public 128N/A - License, v. 2.0. If a copy of the MPL was not distributed with this 128N/A<
meta http-
equiv="Content-Type" content="text/html; charset=ISO-8859-1">
128N/A<
title>lwres_resutil</
title>
128N/A<
meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
128N/A<
body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><
div class="refentry">
128N/A<
a name="id-1"></
a><
div class="titlepage"></
div>
618N/A — lightweight resolver utility functions
4068N/A <
div class="refsynopsisdiv">
4068N/A<
table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
5680N/A<
b class="fsfunc">lwres_string_parse</
b>(</
code></
td>
5680N/A<
td>lwres_buffer_t *<
var class="pdparam">b</
var>, </
td>
128N/A<
td>char **<
var class="pdparam">c</
var>, </
td>
3955N/A<
td>lwres_uint16_t *<
var class="pdparam">len</
var><
code>)</
code>;</
td>
3955N/A<
div class="funcprototype-spacer">�</
div>
3955N/A<
table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
4068N/A<
b class="fsfunc">lwres_addr_parse</
b>(</
code></
td>
4068N/A<
td>lwres_buffer_t *<
var class="pdparam">b</
var>, </
td>
3955N/A<
td>lwres_addr_t *<
var class="pdparam">addr</
var><
code>)</
code>;</
td>
3955N/A<
div class="funcprototype-spacer">�</
div>
3955N/A<
table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
3955N/A<
b class="fsfunc">lwres_getaddrsbyname</
b>(</
code></
td>
6047N/A<
td>lwres_context_t *<
var class="pdparam">ctx</
var>, </
td>
128N/A<
td>const char *<
var class="pdparam">name</
var>, </
td>
128N/A<
td>lwres_uint32_t <
var class="pdparam">addrtypes</
var>, </
td>
128N/A<
td>lwres_gabnresponse_t **<
var class="pdparam">structp</
var><
code>)</
code>;</
td>
128N/A<
div class="funcprototype-spacer">�</
div>
4068N/A<
table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
181N/A<
td><
code class="funcdef">
6047N/A<
b class="fsfunc">lwres_getnamebyaddr</
b>(</
code></
td>
6047N/A<
td>lwres_context_t *<
var class="pdparam">ctx</
var>, </
td>
3817N/A<
td>lwres_uint32_t <
var class="pdparam">addrtype</
var>, </
td>
6047N/A<
td>lwres_uint16_t <
var class="pdparam">addrlen</
var>, </
td>
6047N/A<
td>const unsigned char *<
var class="pdparam">addr</
var>, </
td>
<
td>lwres_gnbaresponse_t **<
var class="pdparam">structp</
var><
code>)</
code>;</
td>
<
div class="funcprototype-spacer">�</
div>
<
a name="id-1.7"></
a><
h2>DESCRIPTION</
h2>
<
p><
code class="function">lwres_string_parse()</
code>
retrieves a DNS-encoded string starting the current pointer of
lightweight resolver buffer <
em class="parameter"><
code>b</
code></
em>:
i.e. <
code class="constant">b->current</
code>. When the function returns,
the address of the first byte of the encoded string is returned
via <
em class="parameter"><
code>*c</
code></
em> and the length of that string is
given by <
em class="parameter"><
code>*len</
code></
em>. The buffer's current
pointer is advanced to point at the character following the
string length, the encoded string, and the trailing
<
span class="type">NULL</
span> character.
<
p><
code class="function">lwres_addr_parse()</
code>
extracts an address from the buffer <
em class="parameter"><
code>b</
code></
em>.
The buffer's current pointer <
code class="constant">b->current</
code>
is presumed to point at an encoded address: the address preceded
by a 32-bit protocol family identifier and a 16-bit length
field. The encoded address is copied to
<
code class="constant">addr->address</
code> and
<
code class="constant">addr->length</
code> indicates the size in bytes
of the address that was copied.
<
code class="constant">b->current</
code> is advanced to point at the
next byte of available data in the buffer following the encoded
<
p><
code class="function">lwres_getaddrsbyname()</
code>
and <
code class="function">lwres_getnamebyaddr()</
code> use the
<
span class="type">lwres_gnbaresponse_t</
span> structure defined below:
<
pre class="programlisting">
lwres_uint16_t realnamelen;
lwres_uint16_t *aliaslen;
The contents of this structure are not manipulated directly but
they are controlled through the
<
span class="citerefentry">
<
span class="refentrytitle">lwres_gabn</
span>(3)
The lightweight resolver uses
<
code class="function">lwres_getaddrsbyname()</
code> to perform
Hostname <
em class="parameter"><
code>name</
code></
em> is looked up using the
context <
em class="parameter"><
code>ctx</
code></
em> for memory allocation.
<
em class="parameter"><
code>addrtypes</
code></
em> is a bitmask indicating
addresses are to be looked up. Current values for this bitmask are
<
span class="type">LWRES_ADDRTYPE_V4</
span> for IPv4 addresses and
<
span class="type">LWRES_ADDRTYPE_V6</
span> for IPv6 addresses. Results of the
lookup are returned in <
em class="parameter"><
code>*structp</
code></
em>.
<
p><
code class="function">lwres_getnamebyaddr()</
code>
performs reverse lookups. Resolver context
<
em class="parameter"><
code>ctx</
code></
em> is used for memory allocation. The
address type is indicated by <
em class="parameter"><
code>addrtype</
code></
em>:
<
span class="type">LWRES_ADDRTYPE_V4</
span> or
<
span class="type">LWRES_ADDRTYPE_V6</
span>. The address to be looked up is
given by <
em class="parameter"><
code>addr</
code></
em> and its length is
<
em class="parameter"><
code>addrlen</
code></
em> bytes. The result of the
function call is made available through
<
em class="parameter"><
code>*structp</
code></
em>.
<
a name="id-1.8"></
a><
h2>RETURN VALUES</
h2>
<
code class="function">lwres_string_parse()</
code>
<
code class="function">lwres_addr_parse()</
code>
<
span class="errorcode">LWRES_R_SUCCESS.</
span>
<
span class="errorcode">LWRES_R_FAILURE</
span>
if the buffer is corrupt or
<
span class="errorcode">LWRES_R_UNEXPECTEDEND</
span>
if the buffer has less space than expected for the components of the
encoded string or address.
<
p><
code class="function">lwres_getaddrsbyname()</
code>
returns <
span class="errorcode">LWRES_R_SUCCESS</
span> on success and it
returns <
span class="errorcode">LWRES_R_NOTFOUND</
span> if the hostname
<
em class="parameter"><
code>name</
code></
em> could not be found.
<
p><
span class="errorcode">LWRES_R_SUCCESS</
span>
is returned by a successful call to
<
code class="function">lwres_getnamebyaddr()</
code>.
<
code class="function">lwres_getaddrsbyname()</
code>
<
code class="function">lwres_getnamebyaddr()</
code>
<
span class="errorcode">LWRES_R_NOMEMORY</
span>
when memory allocation requests fail and
<
span class="errorcode">LWRES_R_UNEXPECTEDEND</
span>
if the buffers used for sending queries and receiving replies are too
<
a name="id-1.9"></
a><
h2>SEE ALSO</
h2>
<
p><
span class="citerefentry">
<
span class="refentrytitle">lwres_buffer</
span>(3)
<
span class="citerefentry">
<
span class="refentrytitle">lwres_gabn</
span>(3)