2 - Copyright (C) 2004, 2005, 2007, 2014, 2015 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.
19 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
21 <meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
23 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry">
24 <a name="id-1"></a><div class="titlepage"></div>
25 <div class="refnamediv">
27 <p>lwres — introduction to the lightweight resolver library</p>
29 <div class="refsynopsisdiv">
31 <div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <lwres/lwres.h></pre></div>
33 <div class="refsection">
34 <a name="id-1.7"></a><h2>DESCRIPTION</h2>
36 The BIND 9 lightweight resolver library is a simple, name service
37 independent stub resolver library. It provides hostname-to-address
38 and address-to-hostname lookup services to applications by
39 transmitting lookup requests to a resolver daemon
40 <span class="command"><strong>lwresd</strong></span>
41 running on the local host. The resolver daemon performs the
42 lookup using the DNS or possibly other name service protocols,
43 and returns the results to the application through the library.
44 The library and resolver daemon communicate using a simple
48 <div class="refsection">
49 <a name="id-1.8"></a><h2>OVERVIEW</h2>
51 The lwresd library implements multiple name service APIs.
53 <code class="function">gethostbyname()</code>,
54 <code class="function">gethostbyaddr()</code>,
55 <code class="function">gethostbyname_r()</code>,
56 <code class="function">gethostbyaddr_r()</code>,
57 <code class="function">getaddrinfo()</code>,
58 <code class="function">getipnodebyname()</code>,
60 <code class="function">getipnodebyaddr()</code>
61 functions are all supported. To allow the lwres library to coexist
62 with system libraries that define functions of the same name,
63 the library defines these functions with names prefixed by
64 <code class="literal">lwres_</code>.
65 To define the standard names, applications must include the
67 <code class="filename"><lwres/netdb.h></code>
68 which contains macro definitions mapping the standard function names
70 <code class="literal">lwres_</code>
71 prefixed ones. Operating system vendors who integrate the lwres
72 library into their base distributions should rename the functions
73 in the library proper so that the renaming macros are not needed.
76 The library also provides a native API consisting of the functions
77 <code class="function">lwres_getaddrsbyname()</code>
79 <code class="function">lwres_getnamebyaddr()</code>.
80 These may be called by applications that require more detailed
81 control over the lookup process than the standard functions
85 In addition to these name service independent address lookup
86 functions, the library implements a new, experimental API
87 for looking up arbitrary DNS resource records, using the
88 <code class="function">lwres_getaddrsbyname()</code>
92 Finally, there is a low-level API for converting lookup
93 requests and responses to and from raw lwres protocol packets.
94 This API can be used by clients requiring nonblocking operation,
95 and is also used when implementing the server side of the lwres
96 protocol, for example in the
97 <span class="command"><strong>lwresd</strong></span>
98 resolver daemon. The use of this low-level API in clients
99 and servers is outlined in the following sections.
102 <div class="refsection">
103 <a name="id-1.9"></a><h2>CLIENT-SIDE LOW-LEVEL API CALL FLOW</h2>
105 When a client program wishes to make an lwres request using the
106 native low-level API, it typically performs the following
110 (1) Allocate or use an existing <span class="type">lwres_packet_t</span>,
111 called <code class="varname">pkt</code> below.
114 (2) Set <code class="varname">pkt.recvlength</code> to the maximum length
116 This is done so the receiver of our packets knows how large our receive
117 buffer is. The "default" is a constant in
118 <code class="filename">lwres.h</code>: <code class="constant">LWRES_RECVLENGTH = 4096</code>.
121 (3) Set <code class="varname">pkt.serial</code>
122 to a unique serial number. This value is echoed
123 back to the application by the remote server.
126 (4) Set <code class="varname">pkt.pktflags</code>. Usually this is set to
130 (5) Set <code class="varname">pkt.result</code> to 0.
133 (6) Call <code class="function">lwres_*request_render()</code>,
134 or marshall in the data using the primitives
135 such as <code class="function">lwres_packet_render()</code>
136 and storing the packet data.
139 (7) Transmit the resulting buffer.
142 (8) Call <code class="function">lwres_*response_parse()</code>
143 to parse any packets received.
146 (9) Verify that the opcode and serial match a request, and process the
147 packet specific information contained in the body.
150 <div class="refsection">
151 <a name="id-1.10"></a><h2>SERVER-SIDE LOW-LEVEL API CALL FLOW</h2>
153 When implementing the server side of the lightweight resolver
154 protocol using the lwres library, a sequence of actions like the
155 following is typically involved in processing each request packet.
158 Note that the same <span class="type">lwres_packet_t</span> is used
159 in both the <code class="function">_parse()</code> and <code class="function">_render()</code> calls,
160 with only a few modifications made
161 to the packet header's contents between uses. This method is
163 as it keeps the serial, opcode, and other fields correct.
166 (1) When a packet is received, call <code class="function">lwres_*request_parse()</code> to
167 unmarshall it. This returns a <span class="type">lwres_packet_t</span> (also called <code class="varname">pkt</code>, below)
168 as well as a data specific type, such as <span class="type">lwres_gabnrequest_t</span>.
171 (2) Process the request in the data specific type.
174 (3) Set the <code class="varname">pkt.result</code>,
175 <code class="varname">pkt.recvlength</code> as above. All other fields
177 be left untouched since they were filled in by the <code class="function">*_parse()</code> call
178 above. If using <code class="function">lwres_*response_render()</code>,
179 <code class="varname">pkt.pktflags</code> will be set up
180 properly. Otherwise, the <code class="constant">LWRES_LWPACKETFLAG_RESPONSE</code> bit should be
184 (4) Call the data specific rendering function, such as
185 <code class="function">lwres_gabnresponse_render()</code>.
188 (5) Send the resulting packet to the client.
192 <div class="refsection">
193 <a name="id-1.11"></a><h2>SEE ALSO</h2>
194 <p><span class="citerefentry"><span class="refentrytitle">lwres_gethostent</span>(3)</span>,
196 <span class="citerefentry"><span class="refentrytitle">lwres_getipnode</span>(3)</span>,
198 <span class="citerefentry"><span class="refentrytitle">lwres_getnameinfo</span>(3)</span>,
200 <span class="citerefentry"><span class="refentrytitle">lwres_noop</span>(3)</span>,
202 <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3)</span>,
204 <span class="citerefentry"><span class="refentrytitle">lwres_gnba</span>(3)</span>,
206 <span class="citerefentry"><span class="refentrytitle">lwres_context</span>(3)</span>,
208 <span class="citerefentry"><span class="refentrytitle">lwres_config</span>(3)</span>,
210 <span class="citerefentry"><span class="refentrytitle">resolver</span>(5)</span>,
212 <span class="citerefentry"><span class="refentrytitle">lwresd</span>(8)</span>.