]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/lib/lwres/man/lwres.html
MFC r363988:
[FreeBSD/stable/9.git] / contrib / bind9 / lib / lwres / man / lwres.html
1 <!--
2  - Copyright (C) 2004, 2005, 2007, 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
3  - Copyright (C) 2000, 2001 Internet Software Consortium.
4  - 
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.
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 <html>
18 <head>
19 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
20 <title>lwres</title>
21 <meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
22 </head>
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">
26 <h2>Name</h2>
27 <p>lwres &#8212; introduction to the lightweight resolver library</p>
28 </div>
29 <div class="refsynopsisdiv">
30 <h2>Synopsis</h2>
31 <div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;lwres/lwres.h&gt;</pre></div>
32 </div>
33 <div class="refsection">
34 <a name="id-1.7"></a><h2>DESCRIPTION</h2>
35 <p>
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
45       UDP-based protocol.
46     </p>
47 </div>
48 <div class="refsection">
49 <a name="id-1.8"></a><h2>OVERVIEW</h2>
50 <p>
51       The lwresd library implements multiple name service APIs.
52       The standard
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>,
59       and
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
66       header file
67       <code class="filename">&lt;lwres/netdb.h&gt;</code>
68       which contains macro definitions mapping the standard function names
69       into
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.
74     </p>
75 <p>
76       The library also provides a native API consisting of the functions
77       <code class="function">lwres_getaddrsbyname()</code>
78       and
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
82       provide.
83     </p>
84 <p>
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>
89       function.
90     </p>
91 <p>
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.
100     </p>
101 </div>
102 <div class="refsection">
103 <a name="id-1.9"></a><h2>CLIENT-SIDE LOW-LEVEL API CALL FLOW</h2>
104 <p>
105       When a client program wishes to make an lwres request using the
106       native low-level API, it typically performs the following
107       sequence of actions.
108     </p>
109 <p>
110       (1) Allocate or use an existing <span class="type">lwres_packet_t</span>,
111       called <code class="varname">pkt</code> below.
112     </p>
113 <p>
114       (2) Set <code class="varname">pkt.recvlength</code> to the maximum length
115       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 <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.
124     </p>
125 <p>
126       (4) Set <code class="varname">pkt.pktflags</code>.  Usually this is set to
127       0.
128     </p>
129 <p>
130       (5) Set <code class="varname">pkt.result</code> to 0.
131     </p>
132 <p>
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.
137     </p>
138 <p>
139       (7) Transmit the resulting buffer.
140     </p>
141 <p>
142       (8) Call <code class="function">lwres_*response_parse()</code>
143       to parse any packets received.
144     </p>
145 <p>
146       (9) Verify that the opcode and serial match a request, and process the
147       packet specific information contained in the body.
148     </p>
149 </div>
150 <div class="refsection">
151 <a name="id-1.10"></a><h2>SERVER-SIDE LOW-LEVEL API CALL FLOW</h2>
152 <p>
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.
156     </p>
157 <p>
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
162       recommended
163       as it keeps the serial, opcode, and other fields correct.
164     </p>
165 <p>
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>.
169     </p>
170 <p>
171       (2) Process the request in the data specific type.
172     </p>
173 <p>
174       (3) Set the <code class="varname">pkt.result</code>,
175       <code class="varname">pkt.recvlength</code> as above.  All other fields
176       can
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
181       set.
182     </p>
183 <p>
184       (4) Call the data specific rendering function, such as
185       <code class="function">lwres_gabnresponse_render()</code>.
186     </p>
187 <p>
188       (5) Send the resulting packet to the client.
189     </p>
190 <p></p>
191 </div>
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>,
195
196       <span class="citerefentry"><span class="refentrytitle">lwres_getipnode</span>(3)</span>,
197
198       <span class="citerefentry"><span class="refentrytitle">lwres_getnameinfo</span>(3)</span>,
199
200       <span class="citerefentry"><span class="refentrytitle">lwres_noop</span>(3)</span>,
201
202       <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3)</span>,
203
204       <span class="citerefentry"><span class="refentrytitle">lwres_gnba</span>(3)</span>,
205
206       <span class="citerefentry"><span class="refentrytitle">lwres_context</span>(3)</span>,
207
208       <span class="citerefentry"><span class="refentrytitle">lwres_config</span>(3)</span>,
209
210       <span class="citerefentry"><span class="refentrytitle">resolver</span>(5)</span>,
211
212       <span class="citerefentry"><span class="refentrytitle">lwresd</span>(8)</span>.
213
214     </p>
215 </div>
216 </div></body>
217 </html>