Merge from vendor branch NETGRAPH:
[dragonfly.git] / contrib / bind-9.3 / lib / lwres / man / lwres.html
1 <!--
2  - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3  - Copyright (C) 2000, 2001 Internet Software Consortium.
4  - 
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.
8  - 
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.
16 -->
17 <!-- $Id: lwres.html,v 1.4.2.1.4.12 2006/06/29 13:02:31 marka Exp $ -->
18 <html>
19 <head>
20 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
21 <title>lwres</title>
22 <meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
23 </head>
24 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
25 <a name="id2482688"></a><div class="titlepage"></div>
26 <div class="refnamediv">
27 <h2>Name</h2>
28 <p>lwres &#8212; introduction to the lightweight resolver library</p>
29 </div>
30 <div class="refsynopsisdiv">
31 <h2>Synopsis</h2>
32 <div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;lwres/lwres.h&gt;</pre></div>
33 </div>
34 <div class="refsect1" lang="en">
35 <a name="id2549397"></a><h2>DESCRIPTION</h2>
36 <p>
37 The BIND 9 lightweight resolver library is a simple, name service
38 independent stub resolver library.  It provides hostname-to-address
39 and address-to-hostname lookup services to applications by
40 transmitting lookup requests to a resolver daemon
41 <span><strong class="command">lwresd</strong></span>
42 running on the local host. The resover daemon performs the
43 lookup using the DNS or possibly other name service protocols,
44 and returns the results to the application through the library.  
45 The library and resolver daemon communicate using a simple
46 UDP-based protocol.
47 </p>
48 </div>
49 <div class="refsect1" lang="en">
50 <a name="id2549410"></a><h2>OVERVIEW</h2>
51 <p>
52 The lwresd library implements multiple name service APIs.
53 The standard
54 <code class="function">gethostbyname()</code>,
55 <code class="function">gethostbyaddr()</code>,
56 <code class="function">gethostbyname_r()</code>,
57 <code class="function">gethostbyaddr_r()</code>,
58 <code class="function">getaddrinfo()</code>,
59 <code class="function">getipnodebyname()</code>,
60 and
61 <code class="function">getipnodebyaddr()</code>
62 functions are all supported.  To allow the lwres library to coexist
63 with system libraries that define functions of the same name,
64 the library defines these functions with names prefixed by
65 <code class="literal">lwres_</code>.
66 To define the standard names, applications must include the
67 header file
68 <code class="filename">&lt;lwres/netdb.h&gt;</code>
69 which contains macro definitions mapping the standard function names
70 into
71 <code class="literal">lwres_</code>
72 prefixed ones.  Operating system vendors who integrate the lwres
73 library into their base distributions should rename the functions
74 in the library proper so that the renaming macros are not needed.
75 </p>
76 <p>
77 The library also provides a native API consisting of the functions
78 <code class="function">lwres_getaddrsbyname()</code>
79 and
80 <code class="function">lwres_getnamebyaddr()</code>.
81 These may be called by applications that require more detailed
82 control over the lookup process than the standard functions
83 provide.
84 </p>
85 <p>
86 In addition to these name service independent address lookup
87 functions, the library implements a new, experimental API
88 for looking up arbitrary DNS resource records, using the
89 <code class="function">lwres_getaddrsbyname()</code>
90 function.
91 </p>
92 <p>
93 Finally, there is a low-level API for converting lookup
94 requests and responses to and from raw lwres protocol packets.  
95 This API can be used by clients requiring nonblocking operation, 
96 and is also used when implementing the server side of the lwres
97 protocol, for example in the
98 <span><strong class="command">lwresd</strong></span>
99 resolver daemon.  The use of this low-level API in clients
100 and servers is outlined in the following sections.
101 </p>
102 </div>
103 <div class="refsect1" lang="en">
104 <a name="id2549474"></a><h2>CLIENT-SIDE LOW-LEVEL API CALL FLOW</h2>
105 <p>
106 When a client program wishes to make an lwres request using the
107 native low-level API, it typically performs the following 
108 sequence of actions.
109 </p>
110 <p>
111 (1) Allocate or use an existing <span class="type">lwres_packet_t</span>,
112 called <code class="varname">pkt</code> below.
113 </p>
114 <p>
115 (2) Set <em class="structfield"><code>pkt.recvlength</code></em> to the maximum length we will accept.  
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>.
119 </p>
120 <p>
121 (3) Set <em class="structfield"><code>pkt.serial</code></em>
122 to a unique serial number.  This value is echoed
123 back to the application by the remote server.
124 </p>
125 <p>
126 (4) Set <em class="structfield"><code>pkt.pktflags</code></em>.  Usually this is set to 0.
127 </p>
128 <p>
129 (5) Set <em class="structfield"><code>pkt.result</code></em> to 0.
130 </p>
131 <p>
132 (6) Call <code class="function">lwres_*request_render()</code>, 
133 or marshall in the data using the primitives
134 such as <code class="function">lwres_packet_render()</code>
135 and storing the packet data.
136 </p>
137 <p>
138 (7) Transmit the resulting buffer.
139 </p>
140 <p>
141 (8) Call <code class="function">lwres_*response_parse()</code>
142 to parse any packets received.
143 </p>
144 <p>
145 (9) Verify that the opcode and serial match a request, and process the
146 packet specific information contained in the body.
147 </p>
148 </div>
149 <div class="refsect1" lang="en">
150 <a name="id2549689"></a><h2>SERVER-SIDE LOW-LEVEL API CALL FLOW</h2>
151 <p>
152 When implementing the server side of the lightweight resolver
153 protocol using the lwres library, a sequence of actions like the
154 following is typically involved in processing each request packet.
155 </p>
156 <p>
157 Note that the same <span class="type">lwres_packet_t</span> is used
158 in both the <code class="function">_parse()</code> and <code class="function">_render()</code> calls,
159 with only a few modifications made
160 to the packet header's contents between uses.  This method is recommended
161 as it keeps the serial, opcode, and other fields correct.
162 </p>
163 <p>
164 (1) When a packet is received, call <code class="function">lwres_*request_parse()</code> to
165 unmarshall it.  This returns a <span class="type">lwres_packet_t</span> (also called <code class="varname">pkt</code>, below)
166 as well as a data specific type, such as <span class="type">lwres_gabnrequest_t</span>.
167 </p>
168 <p>
169 (2) Process the request in the data specific type.
170 </p>
171 <p>
172 (3) Set the <em class="structfield"><code>pkt.result</code></em>,
173 <em class="structfield"><code>pkt.recvlength</code></em> as above.  All other fields can
174 be left untouched since they were filled in by the <code class="function">*_parse()</code> call
175 above.  If using <code class="function">lwres_*response_render()</code>,
176 <em class="structfield"><code>pkt.pktflags</code></em> will be set up
177 properly.  Otherwise, the <code class="constant">LWRES_LWPACKETFLAG_RESPONSE</code> bit should be
178 set.
179 </p>
180 <p>
181 (4) Call the data specific rendering function, such as
182 <code class="function">lwres_gabnresponse_render()</code>.
183 </p>
184 <p>
185 (5) Send the resulting packet to the client.
186 </p>
187 <p>
188 </p>
189 </div>
190 <div class="refsect1" lang="en">
191 <a name="id2549774"></a><h2>SEE ALSO</h2>
192 <p>
193 <span class="citerefentry"><span class="refentrytitle">lwres_gethostent</span>(3)</span>,
194
195 <span class="citerefentry"><span class="refentrytitle">lwres_getipnode</span>(3)</span>,
196
197 <span class="citerefentry"><span class="refentrytitle">lwres_getnameinfo</span>(3)</span>,
198
199 <span class="citerefentry"><span class="refentrytitle">lwres_noop</span>(3)</span>,
200
201 <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3)</span>,
202
203 <span class="citerefentry"><span class="refentrytitle">lwres_gnba</span>(3)</span>,
204
205 <span class="citerefentry"><span class="refentrytitle">lwres_context</span>(3)</span>,
206
207 <span class="citerefentry"><span class="refentrytitle">lwres_config</span>(3)</span>,
208
209 <span class="citerefentry"><span class="refentrytitle">resolver</span>(5)</span>,
210
211 <span class="citerefentry"><span class="refentrytitle">lwresd</span>(8)</span>.
212
213 </p>
214 </div>
215 </div></body>
216 </html>