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</refentrytitle>
29 <manvolnum>3</manvolnum>
30 <refmiscinfo>BIND9</refmiscinfo>
33 <refname>lwres</refname>
34 <refpurpose>introduction to the lightweight resolver library</refpurpose>
43 <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
48 <holder>Internet Software Consortium.</holder>
54 <funcsynopsisinfo>#include <lwres/lwres.h></funcsynopsisinfo>
59 <title>DESCRIPTION</title>
61 The BIND 9 lightweight resolver library is a simple, name service
62 independent stub resolver library. It provides hostname-to-address
63 and address-to-hostname lookup services to applications by
64 transmitting lookup requests to a resolver daemon
65 <command>lwresd</command>
66 running on the local host. The resolver daemon performs the
67 lookup using the DNS or possibly other name service protocols,
68 and returns the results to the application through the library.
69 The library and resolver daemon communicate using a simple
75 <title>OVERVIEW</title>
77 The lwresd library implements multiple name service APIs.
79 <function>gethostbyname()</function>,
80 <function>gethostbyaddr()</function>,
81 <function>gethostbyname_r()</function>,
82 <function>gethostbyaddr_r()</function>,
83 <function>getaddrinfo()</function>,
84 <function>getipnodebyname()</function>,
86 <function>getipnodebyaddr()</function>
87 functions are all supported. To allow the lwres library to coexist
88 with system libraries that define functions of the same name,
89 the library defines these functions with names prefixed by
90 <literal>lwres_</literal>.
91 To define the standard names, applications must include the
93 <filename><lwres/netdb.h></filename>
94 which contains macro definitions mapping the standard function names
96 <literal>lwres_</literal>
97 prefixed ones. Operating system vendors who integrate the lwres
98 library into their base distributions should rename the functions
99 in the library proper so that the renaming macros are not needed.
102 The library also provides a native API consisting of the functions
103 <function>lwres_getaddrsbyname()</function>
105 <function>lwres_getnamebyaddr()</function>.
106 These may be called by applications that require more detailed
107 control over the lookup process than the standard functions
111 In addition to these name service independent address lookup
112 functions, the library implements a new, experimental API
113 for looking up arbitrary DNS resource records, using the
114 <function>lwres_getaddrsbyname()</function>
118 Finally, there is a low-level API for converting lookup
119 requests and responses to and from raw lwres protocol packets.
120 This API can be used by clients requiring nonblocking operation,
121 and is also used when implementing the server side of the lwres
122 protocol, for example in the
123 <command>lwresd</command>
124 resolver daemon. The use of this low-level API in clients
125 and servers is outlined in the following sections.
129 <title>CLIENT-SIDE LOW-LEVEL API CALL FLOW</title>
131 When a client program wishes to make an lwres request using the
132 native low-level API, it typically performs the following
136 (1) Allocate or use an existing <type>lwres_packet_t</type>,
137 called <varname>pkt</varname> below.
140 (2) Set <structfield>pkt.recvlength</structfield> to the maximum length
142 This is done so the receiver of our packets knows how large our receive
143 buffer is. The "default" is a constant in
144 <filename>lwres.h</filename>: <constant>LWRES_RECVLENGTH = 4096</constant>.
147 (3) Set <structfield>pkt.serial</structfield>
148 to a unique serial number. This value is echoed
149 back to the application by the remote server.
152 (4) Set <structfield>pkt.pktflags</structfield>. Usually this is set to
156 (5) Set <structfield>pkt.result</structfield> to 0.
159 (6) Call <function>lwres_*request_render()</function>,
160 or marshall in the data using the primitives
161 such as <function>lwres_packet_render()</function>
162 and storing the packet data.
165 (7) Transmit the resulting buffer.
168 (8) Call <function>lwres_*response_parse()</function>
169 to parse any packets received.
172 (9) Verify that the opcode and serial match a request, and process the
173 packet specific information contained in the body.
177 <title>SERVER-SIDE LOW-LEVEL API CALL FLOW</title>
179 When implementing the server side of the lightweight resolver
180 protocol using the lwres library, a sequence of actions like the
181 following is typically involved in processing each request packet.
184 Note that the same <type>lwres_packet_t</type> is used
185 in both the <function>_parse()</function> and <function>_render()</function> calls,
186 with only a few modifications made
187 to the packet header's contents between uses. This method is
189 as it keeps the serial, opcode, and other fields correct.
192 (1) When a packet is received, call <function>lwres_*request_parse()</function> to
193 unmarshall it. This returns a <type>lwres_packet_t</type> (also called <varname>pkt</varname>, below)
194 as well as a data specific type, such as <type>lwres_gabnrequest_t</type>.
197 (2) Process the request in the data specific type.
200 (3) Set the <structfield>pkt.result</structfield>,
201 <structfield>pkt.recvlength</structfield> as above. All other fields
203 be left untouched since they were filled in by the <function>*_parse()</function> call
204 above. If using <function>lwres_*response_render()</function>,
205 <structfield>pkt.pktflags</structfield> will be set up
206 properly. Otherwise, the <constant>LWRES_LWPACKETFLAG_RESPONSE</constant> bit should be
210 (4) Call the data specific rendering function, such as
211 <function>lwres_gabnresponse_render()</function>.
214 (5) Send the resulting packet to the client.
219 <title>SEE ALSO</title>
221 <refentrytitle>lwres_gethostent</refentrytitle><manvolnum>3</manvolnum>
225 <refentrytitle>lwres_getipnode</refentrytitle><manvolnum>3</manvolnum>
229 <refentrytitle>lwres_getnameinfo</refentrytitle><manvolnum>3</manvolnum>
233 <refentrytitle>lwres_noop</refentrytitle><manvolnum>3</manvolnum>
237 <refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum>
241 <refentrytitle>lwres_gnba</refentrytitle><manvolnum>3</manvolnum>
245 <refentrytitle>lwres_context</refentrytitle><manvolnum>3</manvolnum>
249 <refentrytitle>lwres_config</refentrytitle><manvolnum>3</manvolnum>
253 <refentrytitle>resolver</refentrytitle><manvolnum>5</manvolnum>
257 <refentrytitle>lwresd</refentrytitle><manvolnum>8</manvolnum>