]> git.ipfire.org Git - people/ms/strongswan.git/blob - lib/liblwres/man/lwres.docbook
15378e908ae65f5eb9e2f1f231aa96781ea3daca
[people/ms/strongswan.git] / lib / liblwres / man / lwres.docbook
1 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
2 <!--
3 - Copyright (C) 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 INTERNET SOFTWARE CONSORTIUM
10 - DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
11 - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
12 - INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
13 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
14 - FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 - NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
16 - WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 -->
18
19 <!-- $Id: lwres.docbook,v 1.1 2004/03/15 20:35:25 as Exp $ -->
20
21 <refentry>
22 <refentryinfo>
23
24 <date>Jun 30, 2000</date>
25 </refentryinfo>
26 <refmeta>
27 <refentrytitle>lwres</refentrytitle>
28 <manvolnum>3</manvolnum>
29 <refmiscinfo>BIND9</refmiscinfo>
30 </refmeta>
31 <refnamediv>
32 <refname>lwres</refname>
33 <refpurpose>introduction to the lightweight resolver library</refpurpose>
34 </refnamediv>
35
36 <refsynopsisdiv>
37 <funcsynopsis>
38 <funcsynopsisinfo>#include &lt;lwres/lwres.h&gt;</funcsynopsisinfo>
39 </funcsynopsis>
40 </refsynopsisdiv>
41
42 <refsect1>
43 <title>DESCRIPTION</title>
44 <para>
45 The BIND 9 lightweight resolver library is a simple, name service
46 independent stub resolver library. It provides hostname-to-address
47 and address-to-hostname lookup services to applications by
48 transmitting lookup requests to a resolver daemon
49 <command>lwresd</command>
50 running on the local host. The resover daemon performs the
51 lookup using the DNS or possibly other name service protocols,
52 and returns the results to the application through the library.
53 The library and resolver daemon communicate using a simple
54 UDP-based protocol.
55 </para>
56 </refsect1>
57
58 <refsect1>
59 <title>OVERVIEW</title>
60 <para>
61 The lwresd library implements multiple name service APIs.
62 The standard
63 <function>gethostbyname()</function>,
64 <function>gethostbyaddr()</function>,
65 <function>gethostbyname_r()</function>,
66 <function>gethostbyaddr_r()</function>,
67 <function>getaddrinfo()</function>,
68 <function>getipnodebyname()</function>,
69 and
70 <function>getipnodebyaddr()</function>
71 functions are all supported. To allow the lwres library to coexist
72 with system libraries that define functions of the same name,
73 the library defines these functions with names prefixed by
74 <literal>lwres_</literal>.
75 To define the standard names, applications must include the
76 header file
77 <filename>&lt;lwres/netdb.h&gt;</filename>
78 which contains macro definitions mapping the standard function names
79 into
80 <literal>lwres_</literal>
81 prefixed ones. Operating system vendors who integrate the lwres
82 library into their base distributions should rename the functions
83 in the library proper so that the renaming macros are not needed.
84 </para>
85 <para>
86 The library also provides a native API consisting of the functions
87 <function>lwres_getaddrsbyname()</function>
88 and
89 <function>lwres_getnamebyaddr()</function>.
90 These may be called by applications that require more detailed
91 control over the lookup process than the standard functions
92 provide.
93 </para>
94 <para>
95 In addition to these name service independent address lookup
96 functions, the library implements a new, experimental API
97 for looking up arbitrary DNS resource records, using the
98 <function>lwres_getaddrsbyname()</function>
99 function.
100 </para>
101 <para>
102 Finally, there is a low-level API for converting lookup
103 requests and responses to and from raw lwres protocol packets.
104 This API can be used by clients requiring nonblocking operation,
105 and is also used when implementing the server side of the lwres
106 protocol, for example in the
107 <command>lwresd</command>
108 resolver daemon. The use of this low-level API in clients
109 and servers is outlined in the following sections.
110 </para>
111 </refsect1>
112 <refsect1>
113 <title>CLIENT-SIDE LOW-LEVEL API CALL FLOW</title>
114 <para>
115 When a client program wishes to make an lwres request using the
116 native low-level API, it typically performs the following
117 sequence of actions.
118 </para>
119 <para>
120 (1) Allocate or use an existing <type>lwres_packet_t</type>,
121 called <varname>pkt</varname> below.
122 </para>
123 <para>
124 (2) Set <structfield>pkt.recvlength</structfield> to the maximum length we will accept.
125 This is done so the receiver of our packets knows how large our receive
126 buffer is. The "default" is a constant in
127 <filename>lwres.h</filename>: <constant>LWRES_RECVLENGTH = 4096</constant>.
128 </para>
129 <para>
130 (3) Set <structfield>pkt.serial</structfield>
131 to a unique serial number. This value is echoed
132 back to the application by the remote server.
133 </para>
134 <para>
135 (4) Set <structfield>pkt.pktflags</structfield>. Usually this is set to 0.
136 </para>
137 <para>
138 (5) Set <structfield>pkt.result</structfield> to 0.
139 </para>
140 <para>
141 (6) Call <function>lwres_*request_render()</function>,
142 or marshall in the data using the primitives
143 such as <function>lwres_packet_render()</function>
144 and storing the packet data.
145 </para>
146 <para>
147 (7) Transmit the resulting buffer.
148 </para>
149 <para>
150 (8) Call <function>lwres_*response_parse()</function>
151 to parse any packets received.
152 </para>
153 <para>
154 (9) Verify that the opcode and serial match a request, and process the
155 packet specific information contained in the body.
156 </para>
157 </refsect1>
158 <refsect1>
159 <title>SERVER-SIDE LOW-LEVEL API CALL FLOW</title>
160 <para>
161 When implementing the server side of the lightweight resolver
162 protocol using the lwres library, a sequence of actions like the
163 following is typically involved in processing each request packet.
164 </para>
165 <para>
166 Note that the same <type>lwres_packet_t</type> is used
167 in both the <function>_parse()</function> and <function>_render()</function> calls,
168 with only a few modifications made
169 to the packet header's contents between uses. This method is recommended
170 as it keeps the serial, opcode, and other fields correct.
171 </para>
172 <para>
173 (1) When a packet is received, call <function>lwres_*request_parse()</function> to
174 unmarshall it. This returns a <type>lwres_packet_t</type> (also called <varname>pkt</varname>, below)
175 as well as a data specific type, such as <type>lwres_gabnrequest_t</type>.
176 </para>
177 <para>
178 (2) Process the request in the data specific type.
179 </para>
180 <para>
181 (3) Set the <structfield>pkt.result</structfield>,
182 <structfield>pkt.recvlength</structfield> as above. All other fields can
183 be left untouched since they were filled in by the <function>*_parse()</function> call
184 above. If using <function>lwres_*response_render()</function>,
185 <structfield>pkt.pktflags</structfield> will be set up
186 properly. Otherwise, the <constant>LWRES_LWPACKETFLAG_RESPONSE</constant> bit should be
187 set.
188 </para>
189 <para>
190 (4) Call the data specific rendering function, such as
191 <function>lwres_gabnresponse_render()</function>.
192 </para>
193 <para>
194 (5) Send the resulting packet to the client.
195 </para>
196 <para>
197 </para>
198 </refsect1>
199 <refsect1>
200 <title>SEE ALSO</title>
201 <para>
202 <citerefentry>
203 <refentrytitle>lwres_gethostent</refentrytitle><manvolnum>3</manvolnum>
204 </citerefentry>,
205
206 <citerefentry>
207 <refentrytitle>lwres_getipnode</refentrytitle><manvolnum>3</manvolnum>
208 </citerefentry>,
209
210 <citerefentry>
211 <refentrytitle>lwres_getnameinfo</refentrytitle><manvolnum>3</manvolnum>
212 </citerefentry>,
213
214 <citerefentry>
215 <refentrytitle>lwres_noop</refentrytitle><manvolnum>3</manvolnum>
216 </citerefentry>,
217
218 <citerefentry>
219 <refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum>
220 </citerefentry>,
221
222 <citerefentry>
223 <refentrytitle>lwres_gnba</refentrytitle><manvolnum>3</manvolnum>
224 </citerefentry>,
225
226 <citerefentry>
227 <refentrytitle>lwres_context</refentrytitle><manvolnum>3</manvolnum>
228 </citerefentry>,
229
230 <citerefentry>
231 <refentrytitle>lwres_config</refentrytitle><manvolnum>3</manvolnum>
232 </citerefentry>,
233
234 <citerefentry>
235 <refentrytitle>resolver</refentrytitle><manvolnum>5</manvolnum>
236 </citerefentry>,
237
238 <citerefentry>
239 <refentrytitle>lwresd</refentrytitle><manvolnum>8</manvolnum>
240 </citerefentry>.
241
242 </para>
243 </refsect1>
244 </refentry>