2 - Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2001 Internet Software Consortium.
5 - Permission to use, copy, modify, and 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.
18 <!-- $Id: lwres.html,v 1.4.2.2 2004/03/15 04:45:00 marka Exp $ -->
26 CONTENT="Modular DocBook HTML Stylesheet Version 1.73
47 >lwres -- introduction to the lightweight resolver library</DIV
49 CLASS="REFSYNOPSISDIV"
63 CLASS="FUNCSYNOPSISINFO"
64 >#include <lwres/lwres.h></PRE
77 >The BIND 9 lightweight resolver library is a simple, name service
78 independent stub resolver library. It provides hostname-to-address
79 and address-to-hostname lookup services to applications by
80 transmitting lookup requests to a resolver daemon
85 running on the local host. The resover daemon performs the
86 lookup using the DNS or possibly other name service protocols,
87 and returns the results to the application through the library.
88 The library and resolver daemon communicate using a simple
89 UDP-based protocol.</P
99 >The lwresd library implements multiple name service APIs.
111 >gethostbyname_r()</TT
115 >gethostbyaddr_r()</TT
123 >getipnodebyname()</TT
128 >getipnodebyaddr()</TT
130 functions are all supported. To allow the lwres library to coexist
131 with system libraries that define functions of the same name,
132 the library defines these functions with names prefixed by
137 To define the standard names, applications must include the
141 ><lwres/netdb.h></TT
143 which contains macro definitions mapping the standard function names
149 prefixed ones. Operating system vendors who integrate the lwres
150 library into their base distributions should rename the functions
151 in the library proper so that the renaming macros are not needed.</P
153 >The library also provides a native API consisting of the functions
156 >lwres_getaddrsbyname()</TT
161 >lwres_getnamebyaddr()</TT
163 These may be called by applications that require more detailed
164 control over the lookup process than the standard functions
167 >In addition to these name service independent address lookup
168 functions, the library implements a new, experimental API
169 for looking up arbitrary DNS resource records, using the
172 >lwres_getaddrsbyname()</TT
176 >Finally, there is a low-level API for converting lookup
177 requests and responses to and from raw lwres protocol packets.
178 This API can be used by clients requiring nonblocking operation,
179 and is also used when implementing the server side of the lwres
180 protocol, for example in the
185 resolver daemon. The use of this low-level API in clients
186 and servers is outlined in the following sections.</P
194 >CLIENT-SIDE LOW-LEVEL API CALL FLOW</H2
196 >When a client program wishes to make an lwres request using the
197 native low-level API, it typically performs the following
198 sequence of actions.</P
200 >(1) Allocate or use an existing <SPAN
202 >lwres_packet_t</SPAN
214 > to the maximum length we will accept.
215 This is done so the receiver of our packets knows how large our receive
216 buffer is. The "default" is a constant in
222 >LWRES_RECVLENGTH = 4096</TT
231 to a unique serial number. This value is echoed
232 back to the application by the remote server.</P
239 >. Usually this is set to 0.</P
250 >lwres_*request_render()</TT
252 or marshall in the data using the primitives
255 >lwres_packet_render()</TT
257 and storing the packet data.</P
259 >(7) Transmit the resulting buffer.</P
263 >lwres_*response_parse()</TT
265 to parse any packets received.</P
267 >(9) Verify that the opcode and serial match a request, and process the
268 packet specific information contained in the body.</P
276 >SERVER-SIDE LOW-LEVEL API CALL FLOW</H2
278 >When implementing the server side of the lightweight resolver
279 protocol using the lwres library, a sequence of actions like the
280 following is typically involved in processing each request packet.</P
282 >Note that the same <SPAN
284 >lwres_packet_t</SPAN
293 with only a few modifications made
294 to the packet header's contents between uses. This method is recommended
295 as it keeps the serial, opcode, and other fields correct.</P
297 >(1) When a packet is received, call <TT
299 >lwres_*request_parse()</TT
301 unmarshall it. This returns a <SPAN
303 >lwres_packet_t</SPAN
308 as well as a data specific type, such as <SPAN
310 >lwres_gabnrequest_t</SPAN
313 >(2) Process the request in the data specific type.</P
326 > as above. All other fields can
327 be left untouched since they were filled in by the <TT
333 >lwres_*response_render()</TT
341 properly. Otherwise, the <TT
343 >LWRES_LWPACKETFLAG_RESPONSE</TT
347 >(4) Call the data specific rendering function, such as
350 >lwres_gabnresponse_render()</TT
353 >(5) Send the resulting packet to the client.</P
368 CLASS="REFENTRYTITLE"
369 >lwres_gethostent</SPAN
376 CLASS="REFENTRYTITLE"
377 >lwres_getipnode</SPAN
384 CLASS="REFENTRYTITLE"
385 >lwres_getnameinfo</SPAN
392 CLASS="REFENTRYTITLE"
400 CLASS="REFENTRYTITLE"
408 CLASS="REFENTRYTITLE"
416 CLASS="REFENTRYTITLE"
424 CLASS="REFENTRYTITLE"
432 CLASS="REFENTRYTITLE"
440 CLASS="REFENTRYTITLE"