1 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
3 [<!ENTITY mdash "—">]>
5 - Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
6 - Copyright (C) 2000, 2001 Internet Software Consortium.
8 - Permission to use, copy, modify, and/or distribute this software for any
9 - purpose with or without fee is hereby granted, provided that the above
10 - copyright notice and this permission notice appear in all copies.
12 - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
13 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14 - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16 - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
17 - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18 - PERFORMANCE OF THIS SOFTWARE.
24 <date>June 18, 2007</date>
28 <refentrytitle>lwres_resutil</refentrytitle>
29 <manvolnum>3</manvolnum>
30 <refmiscinfo>BIND9</refmiscinfo>
39 <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
44 <holder>Internet Software Consortium.</holder>
49 <refname>lwres_string_parse</refname>
50 <refname>lwres_addr_parse</refname>
51 <refname>lwres_getaddrsbyname</refname>
52 <refname>lwres_getnamebyaddr</refname>
53 <refpurpose>lightweight resolver utility functions</refpurpose>
57 <funcsynopsisinfo>#include <lwres/lwres.h></funcsynopsisinfo>
61 <function>lwres_string_parse</function></funcdef>
62 <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
63 <paramdef>char **<parameter>c</parameter></paramdef>
64 <paramdef>lwres_uint16_t *<parameter>len</parameter></paramdef>
69 <function>lwres_addr_parse</function></funcdef>
70 <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
71 <paramdef>lwres_addr_t *<parameter>addr</parameter></paramdef>
76 <function>lwres_getaddrsbyname</function></funcdef>
77 <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
78 <paramdef>const char *<parameter>name</parameter></paramdef>
79 <paramdef>lwres_uint32_t <parameter>addrtypes</parameter></paramdef>
80 <paramdef>lwres_gabnresponse_t **<parameter>structp</parameter></paramdef>
85 <function>lwres_getnamebyaddr</function></funcdef>
86 <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
87 <paramdef>lwres_uint32_t <parameter>addrtype</parameter></paramdef>
88 <paramdef>lwres_uint16_t <parameter>addrlen</parameter></paramdef>
89 <paramdef>const unsigned char *<parameter>addr</parameter></paramdef>
90 <paramdef>lwres_gnbaresponse_t **<parameter>structp</parameter></paramdef>
96 <title>DESCRIPTION</title>
98 <para><function>lwres_string_parse()</function>
99 retrieves a DNS-encoded string starting the current pointer of
100 lightweight resolver buffer <parameter>b</parameter>: i.e.
101 <constant>b->current</constant>. When the function returns,
102 the address of the first byte of the encoded string is returned
103 via <parameter>*c</parameter> and the length of that string is
104 given by <parameter>*len</parameter>. The buffer's current
105 pointer is advanced to point at the character following the
106 string length, the encoded string, and the trailing
107 <type>NULL</type> character.
110 <para><function>lwres_addr_parse()</function>
111 extracts an address from the buffer <parameter>b</parameter>.
112 The buffer's current pointer <constant>b->current</constant>
113 is presumed to point at an encoded address: the address preceded
114 by a 32-bit protocol family identifier and a 16-bit length
115 field. The encoded address is copied to
116 <constant>addr->address</constant> and
117 <constant>addr->length</constant> indicates the size in bytes
118 of the address that was copied.
119 <constant>b->current</constant> is advanced to point at the
120 next byte of available data in the buffer following the encoded
124 <para><function>lwres_getaddrsbyname()</function>
125 and <function>lwres_getnamebyaddr()</function> use the
126 <type>lwres_gnbaresponse_t</type> structure defined below:
129 <para><programlisting>
131 lwres_uint32_t flags;
132 lwres_uint16_t naliases;
133 lwres_uint16_t naddrs;
136 lwres_uint16_t realnamelen;
137 lwres_uint16_t *aliaslen;
138 lwres_addrlist_t addrs;
141 } lwres_gabnresponse_t;
142 </programlisting></para>
145 The contents of this structure are not manipulated directly but
146 they are controlled through the
148 <refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum>
154 The lightweight resolver uses
155 <function>lwres_getaddrsbyname()</function> to perform
157 Hostname <parameter>name</parameter> is looked up using the
159 context <parameter>ctx</parameter> for memory allocation.
160 <parameter>addrtypes</parameter> is a bitmask indicating
162 addresses are to be looked up. Current values for this bitmask are
163 <type>LWRES_ADDRTYPE_V4</type> for IPv4 addresses and
164 <type>LWRES_ADDRTYPE_V6</type> for IPv6 addresses. Results of the
165 lookup are returned in <parameter>*structp</parameter>.
168 <para><function>lwres_getnamebyaddr()</function>
169 performs reverse lookups. Resolver context
170 <parameter>ctx</parameter> is used for memory allocation. The
171 address type is indicated by <parameter>addrtype</parameter>:
172 <type>LWRES_ADDRTYPE_V4</type> or
173 <type>LWRES_ADDRTYPE_V6</type>. The address to be looked up is
174 given by <parameter>addr</parameter> and its length is
175 <parameter>addrlen</parameter> bytes. The result of the
176 function call is made available through
177 <parameter>*structp</parameter>.
182 <title>RETURN VALUES</title>
185 <function>lwres_string_parse()</function>
187 <function>lwres_addr_parse()</function>
189 <errorcode>LWRES_R_SUCCESS.</errorcode>
190 Both functions return
191 <errorcode>LWRES_R_FAILURE</errorcode>
192 if the buffer is corrupt or
193 <errorcode>LWRES_R_UNEXPECTEDEND</errorcode>
194 if the buffer has less space than expected for the components of the
195 encoded string or address.
198 <para><function>lwres_getaddrsbyname()</function>
199 returns <errorcode>LWRES_R_SUCCESS</errorcode> on success and it
200 returns <errorcode>LWRES_R_NOTFOUND</errorcode> if the hostname
201 <parameter>name</parameter> could not be found.
203 <para><errorcode>LWRES_R_SUCCESS</errorcode>
204 is returned by a successful call to
205 <function>lwres_getnamebyaddr()</function>.
210 <function>lwres_getaddrsbyname()</function>
212 <function>lwres_getnamebyaddr()</function>
214 <errorcode>LWRES_R_NOMEMORY</errorcode>
215 when memory allocation requests fail and
216 <errorcode>LWRES_R_UNEXPECTEDEND</errorcode>
217 if the buffers used for sending queries and receiving replies are too
223 <title>SEE ALSO</title>
225 <refentrytitle>lwres_buffer</refentrytitle><manvolnum>3</manvolnum>
229 <refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum>