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, 2012 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.
25 <date>Jun 30, 2000</date>
29 <refentrytitle>lwres_resutil</refentrytitle>
30 <manvolnum>3</manvolnum>
31 <refmiscinfo>BIND9</refmiscinfo>
40 <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
45 <holder>Internet Software Consortium.</holder>
50 <refname>lwres_string_parse</refname>
51 <refname>lwres_addr_parse</refname>
52 <refname>lwres_getaddrsbyname</refname>
53 <refname>lwres_getnamebyaddr</refname>
54 <refpurpose>lightweight resolver utility functions</refpurpose>
58 <funcsynopsisinfo>#include <lwres/lwres.h></funcsynopsisinfo>
62 <function>lwres_string_parse</function></funcdef>
63 <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
64 <paramdef>char **<parameter>c</parameter></paramdef>
65 <paramdef>lwres_uint16_t *<parameter>len</parameter></paramdef>
70 <function>lwres_addr_parse</function></funcdef>
71 <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
72 <paramdef>lwres_addr_t *<parameter>addr</parameter></paramdef>
77 <function>lwres_getaddrsbyname</function></funcdef>
78 <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
79 <paramdef>const char *<parameter>name</parameter></paramdef>
80 <paramdef>lwres_uint32_t <parameter>addrtypes</parameter></paramdef>
81 <paramdef>lwres_gabnresponse_t **<parameter>structp</parameter></paramdef>
86 <function>lwres_getnamebyaddr</function></funcdef>
87 <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
88 <paramdef>lwres_uint32_t <parameter>addrtype</parameter></paramdef>
89 <paramdef>lwres_uint16_t <parameter>addrlen</parameter></paramdef>
90 <paramdef>const unsigned char *<parameter>addr</parameter></paramdef>
91 <paramdef>lwres_gnbaresponse_t **<parameter>structp</parameter></paramdef>
97 <title>DESCRIPTION</title>
99 <para><function>lwres_string_parse()</function>
100 retrieves a DNS-encoded string starting the current pointer of
101 lightweight resolver buffer <parameter>b</parameter>: i.e.
102 <constant>b->current</constant>. When the function returns,
103 the address of the first byte of the encoded string is returned
104 via <parameter>*c</parameter> and the length of that string is
105 given by <parameter>*len</parameter>. The buffer's current
106 pointer is advanced to point at the character following the
107 string length, the encoded string, and the trailing
108 <type>NULL</type> character.
111 <para><function>lwres_addr_parse()</function>
112 extracts an address from the buffer <parameter>b</parameter>.
113 The buffer's current pointer <constant>b->current</constant>
114 is presumed to point at an encoded address: the address preceded
115 by a 32-bit protocol family identifier and a 16-bit length
116 field. The encoded address is copied to
117 <constant>addr->address</constant> and
118 <constant>addr->length</constant> indicates the size in bytes
119 of the address that was copied.
120 <constant>b->current</constant> is advanced to point at the
121 next byte of available data in the buffer following the encoded
125 <para><function>lwres_getaddrsbyname()</function>
126 and <function>lwres_getnamebyaddr()</function> use the
127 <type>lwres_gnbaresponse_t</type> structure defined below:
130 <para><programlisting>
132 lwres_uint32_t flags;
133 lwres_uint16_t naliases;
134 lwres_uint16_t naddrs;
137 lwres_uint16_t realnamelen;
138 lwres_uint16_t *aliaslen;
139 lwres_addrlist_t addrs;
142 } lwres_gabnresponse_t;
143 </programlisting></para>
146 The contents of this structure are not manipulated directly but
147 they are controlled through the
149 <refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum>
155 The lightweight resolver uses
156 <function>lwres_getaddrsbyname()</function> to perform
158 Hostname <parameter>name</parameter> is looked up using the
160 context <parameter>ctx</parameter> for memory allocation.
161 <parameter>addrtypes</parameter> is a bitmask indicating
163 addresses are to be looked up. Current values for this bitmask are
164 <type>LWRES_ADDRTYPE_V4</type> for IPv4 addresses and
165 <type>LWRES_ADDRTYPE_V6</type> for IPv6 addresses. Results of the
166 lookup are returned in <parameter>*structp</parameter>.
169 <para><function>lwres_getnamebyaddr()</function>
170 performs reverse lookups. Resolver context
171 <parameter>ctx</parameter> is used for memory allocation. The
172 address type is indicated by <parameter>addrtype</parameter>:
173 <type>LWRES_ADDRTYPE_V4</type> or
174 <type>LWRES_ADDRTYPE_V6</type>. The address to be looked up is
175 given by <parameter>addr</parameter> and its length is
176 <parameter>addrlen</parameter> bytes. The result of the
177 function call is made available through
178 <parameter>*structp</parameter>.
183 <title>RETURN VALUES</title>
186 <function>lwres_string_parse()</function>
188 <function>lwres_addr_parse()</function>
190 <errorcode>LWRES_R_SUCCESS.</errorcode>
191 Both functions return
192 <errorcode>LWRES_R_FAILURE</errorcode>
193 if the buffer is corrupt or
194 <errorcode>LWRES_R_UNEXPECTEDEND</errorcode>
195 if the buffer has less space than expected for the components of the
196 encoded string or address.
199 <para><function>lwres_getaddrsbyname()</function>
200 returns <errorcode>LWRES_R_SUCCESS</errorcode> on success and it
201 returns <errorcode>LWRES_R_NOTFOUND</errorcode> if the hostname
202 <parameter>name</parameter> could not be found.
204 <para><errorcode>LWRES_R_SUCCESS</errorcode>
205 is returned by a successful call to
206 <function>lwres_getnamebyaddr()</function>.
211 <function>lwres_getaddrsbyname()</function>
213 <function>lwres_getnamebyaddr()</function>
215 <errorcode>LWRES_R_NOMEMORY</errorcode>
216 when memory allocation requests fail and
217 <errorcode>LWRES_R_UNEXPECTEDEND</errorcode>
218 if the buffers used for sending queries and receiving replies are too
224 <title>SEE ALSO</title>
226 <refentrytitle>lwres_buffer</refentrytitle><manvolnum>3</manvolnum>
230 <refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum>