xref: /minix/external/bsd/bind/dist/lib/lwres/man/lwres.html (revision 00b67f09)
1<!--
2 - Copyright (C) 2004, 2005, 2007, 2014 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<!-- Id -->
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.71.1">
23</head>
24<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
25<a name="id2476275"></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="id2543357"></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 resolver 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="id2543370"></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="id2543434"></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
116      we will accept.
117      This is done so the receiver of our packets knows how large our receive
118      buffer is.  The "default" is a constant in
119      <code class="filename">lwres.h</code>: <code class="constant">LWRES_RECVLENGTH = 4096</code>.
120    </p>
121<p>
122      (3) Set <em class="structfield"><code>pkt.serial</code></em>
123      to a unique serial number.  This value is echoed
124      back to the application by the remote server.
125    </p>
126<p>
127      (4) Set <em class="structfield"><code>pkt.pktflags</code></em>.  Usually this is set to
128      0.
129    </p>
130<p>
131      (5) Set <em class="structfield"><code>pkt.result</code></em> to 0.
132    </p>
133<p>
134      (6) Call <code class="function">lwres_*request_render()</code>,
135      or marshall in the data using the primitives
136      such as <code class="function">lwres_packet_render()</code>
137      and storing the packet data.
138    </p>
139<p>
140      (7) Transmit the resulting buffer.
141    </p>
142<p>
143      (8) Call <code class="function">lwres_*response_parse()</code>
144      to parse any packets received.
145    </p>
146<p>
147      (9) Verify that the opcode and serial match a request, and process the
148      packet specific information contained in the body.
149    </p>
150</div>
151<div class="refsect1" lang="en">
152<a name="id2543582"></a><h2>SERVER-SIDE LOW-LEVEL API CALL FLOW</h2>
153<p>
154      When implementing the server side of the lightweight resolver
155      protocol using the lwres library, a sequence of actions like the
156      following is typically involved in processing each request packet.
157    </p>
158<p>
159      Note that the same <span class="type">lwres_packet_t</span> is used
160      in both the <code class="function">_parse()</code> and <code class="function">_render()</code> calls,
161      with only a few modifications made
162      to the packet header's contents between uses.  This method is
163      recommended
164      as it keeps the serial, opcode, and other fields correct.
165    </p>
166<p>
167      (1) When a packet is received, call <code class="function">lwres_*request_parse()</code> to
168      unmarshall it.  This returns a <span class="type">lwres_packet_t</span> (also called <code class="varname">pkt</code>, below)
169      as well as a data specific type, such as <span class="type">lwres_gabnrequest_t</span>.
170    </p>
171<p>
172      (2) Process the request in the data specific type.
173    </p>
174<p>
175      (3) Set the <em class="structfield"><code>pkt.result</code></em>,
176      <em class="structfield"><code>pkt.recvlength</code></em> as above.  All other fields
177      can
178      be left untouched since they were filled in by the <code class="function">*_parse()</code> call
179      above.  If using <code class="function">lwres_*response_render()</code>,
180      <em class="structfield"><code>pkt.pktflags</code></em> will be set up
181      properly.  Otherwise, the <code class="constant">LWRES_LWPACKETFLAG_RESPONSE</code> bit should be
182      set.
183    </p>
184<p>
185      (4) Call the data specific rendering function, such as
186      <code class="function">lwres_gabnresponse_render()</code>.
187    </p>
188<p>
189      (5) Send the resulting packet to the client.
190    </p>
191<p></p>
192</div>
193<div class="refsect1" lang="en">
194<a name="id2543666"></a><h2>SEE ALSO</h2>
195<p><span class="citerefentry"><span class="refentrytitle">lwres_gethostent</span>(3)</span>,
196
197      <span class="citerefentry"><span class="refentrytitle">lwres_getipnode</span>(3)</span>,
198
199      <span class="citerefentry"><span class="refentrytitle">lwres_getnameinfo</span>(3)</span>,
200
201      <span class="citerefentry"><span class="refentrytitle">lwres_noop</span>(3)</span>,
202
203      <span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3)</span>,
204
205      <span class="citerefentry"><span class="refentrytitle">lwres_gnba</span>(3)</span>,
206
207      <span class="citerefentry"><span class="refentrytitle">lwres_context</span>(3)</span>,
208
209      <span class="citerefentry"><span class="refentrytitle">lwres_config</span>(3)</span>,
210
211      <span class="citerefentry"><span class="refentrytitle">resolver</span>(5)</span>,
212
213      <span class="citerefentry"><span class="refentrytitle">lwresd</span>(8)</span>.
214
215    </p>
216</div>
217</div></body>
218</html>
219