lwres.html revision 52ece689e0265f9a3e518de5b2539e749f6d35ac
905N/A<!--
905N/A - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
905N/A - Copyright (C) 2000, 2001 Internet Software Consortium.
905N/A -
905N/A - Permission to use, copy, modify, and distribute this software for any
905N/A - purpose with or without fee is hereby granted, provided that the above
905N/A - copyright notice and this permission notice appear in all copies.
905N/A -
905N/A - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
905N/A - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
905N/A - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
905N/A - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
905N/A - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
905N/A - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
905N/A - PERFORMANCE OF THIS SOFTWARE.
905N/A-->
905N/A<!-- $Id: lwres.html,v 1.19 2006/04/23 10:14:12 marka Exp $ -->
905N/A<html>
905N/A<head>
905N/A<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7049N/A<title>lwres</title>
905N/A<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
3996N/A</head>
905N/A<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
905N/A<a name="id2462968"></a><div class="titlepage"></div>
905N/A<div class="refnamediv">
4448N/A<h2>Name</h2>
905N/A<p>lwres &#8212; introduction to the lightweight resolver library</p>
4448N/A</div>
905N/A<div class="refsynopsisdiv">
4448N/A<h2>Synopsis</h2>
905N/A<div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;lwres/lwres.h&gt;</pre></div>
4448N/A</div>
4448N/A<div class="refsect1" lang="en">
4448N/A<a name="id2524474"></a><h2>DESCRIPTION</h2>
905N/A<p>
4448N/A The BIND 9 lightweight resolver library is a simple, name service
4448N/A independent stub resolver library. It provides hostname-to-address
4450N/A and address-to-hostname lookup services to applications by
4448N/A transmitting lookup requests to a resolver daemon
4450N/A <span><strong class="command">lwresd</strong></span>
4450N/A running on the local host. The resover daemon performs the
4448N/A lookup using the DNS or possibly other name service protocols,
4448N/A and returns the results to the application through the library.
4448N/A The library and resolver daemon communicate using a simple
4448N/A UDP-based protocol.
4448N/A </p>
4448N/A</div>
3661N/A<div class="refsect1" lang="en">
4448N/A<a name="id2524487"></a><h2>OVERVIEW</h2>
4448N/A<p>
4448N/A The lwresd library implements multiple name service APIs.
4448N/A The standard
4448N/A <code class="function">gethostbyname()</code>,
4448N/A <code class="function">gethostbyaddr()</code>,
4448N/A <code class="function">gethostbyname_r()</code>,
4448N/A <code class="function">gethostbyaddr_r()</code>,
4448N/A <code class="function">getaddrinfo()</code>,
4448N/A <code class="function">getipnodebyname()</code>,
4448N/A and
4448N/A <code class="function">getipnodebyaddr()</code>
4448N/A functions are all supported. To allow the lwres library to coexist
4448N/A with system libraries that define functions of the same name,
4448N/A the library defines these functions with names prefixed by
4448N/A <code class="literal">lwres_</code>.
4448N/A To define the standard names, applications must include the
4448N/A header file
4448N/A <code class="filename">&lt;lwres/netdb.h&gt;</code>
4448N/A which contains macro definitions mapping the standard function names
4448N/A into
4448N/A <code class="literal">lwres_</code>
4448N/A prefixed ones. Operating system vendors who integrate the lwres
4448N/A library into their base distributions should rename the functions
4448N/A in the library proper so that the renaming macros are not needed.
4448N/A </p>
4448N/A<p>
4448N/A The library also provides a native API consisting of the functions
4448N/A <code class="function">lwres_getaddrsbyname()</code>
905N/A and
905N/A <code class="function">lwres_getnamebyaddr()</code>.
4448N/A These may be called by applications that require more detailed
4448N/A control over the lookup process than the standard functions
4448N/A provide.
4448N/A </p>
4448N/A<p>
4448N/A In addition to these name service independent address lookup
905N/A functions, the library implements a new, experimental API
7049N/A for looking up arbitrary DNS resource records, using the
7049N/A <code class="function">lwres_getaddrsbyname()</code>
7049N/A function.
7049N/A </p>
905N/A<p>
905N/A Finally, there is a low-level API for converting lookup
905N/A requests and responses to and from raw lwres protocol packets.
905N/A This API can be used by clients requiring nonblocking operation,
905N/A and is also used when implementing the server side of the lwres
905N/A protocol, for example in the
905N/A <span><strong class="command">lwresd</strong></span>
4448N/A resolver daemon. The use of this low-level API in clients
4448N/A and servers is outlined in the following sections.
4448N/A </p>
4448N/A</div>
4448N/A<div class="refsect1" lang="en">
4448N/A<a name="id2525234"></a><h2>CLIENT-SIDE LOW-LEVEL API CALL FLOW</h2>
4448N/A<p>
4448N/A When a client program wishes to make an lwres request using the
4448N/A native low-level API, it typically performs the following
4448N/A sequence of actions.
905N/A </p>
4448N/A<p>
4448N/A (1) Allocate or use an existing <span class="type">lwres_packet_t</span>,
4448N/A called <code class="varname">pkt</code> below.
905N/A </p>
4448N/A<p>
4448N/A (2) Set <em class="structfield"><code>pkt.recvlength</code></em> to the maximum length
4448N/A we will accept.
4448N/A This is done so the receiver of our packets knows how large our receive
4448N/A buffer is. The "default" is a constant in
4448N/A <code class="filename">lwres.h</code>: <code class="constant">LWRES_RECVLENGTH = 4096</code>.
4448N/A </p>
4448N/A<p>
4448N/A (3) Set <em class="structfield"><code>pkt.serial</code></em>
4448N/A to a unique serial number. This value is echoed
4448N/A back to the application by the remote server.
905N/A </p>
4448N/A<p>
4448N/A (4) Set <em class="structfield"><code>pkt.pktflags</code></em>. Usually this is set to
4448N/A 0.
4448N/A </p>
905N/A<p>
905N/A (5) Set <em class="structfield"><code>pkt.result</code></em> to 0.
3319N/A </p>
905N/A<p>
3996N/A (6) Call <code class="function">lwres_*request_render()</code>,
4448N/A or marshall in the data using the primitives
3996N/A such as <code class="function">lwres_packet_render()</code>
4448N/A and storing the packet data.
3996N/A </p>
3996N/A<p>
3996N/A (7) Transmit the resulting buffer.
</p>
<p>
(8) Call <code class="function">lwres_*response_parse()</code>
to parse any packets received.
</p>
<p>
(9) Verify that the opcode and serial match a request, and process the
packet specific information contained in the body.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id2525382"></a><h2>SERVER-SIDE LOW-LEVEL API CALL FLOW</h2>
<p>
When implementing the server side of the lightweight resolver
protocol using the lwres library, a sequence of actions like the
following is typically involved in processing each request packet.
</p>
<p>
Note that the same <span class="type">lwres_packet_t</span> is used
in both the <code class="function">_parse()</code> and <code class="function">_render()</code> calls,
with only a few modifications made
to the packet header's contents between uses. This method is
recommended
as it keeps the serial, opcode, and other fields correct.
</p>
<p>
(1) When a packet is received, call <code class="function">lwres_*request_parse()</code> to
unmarshall it. This returns a <span class="type">lwres_packet_t</span> (also called <code class="varname">pkt</code>, below)
as well as a data specific type, such as <span class="type">lwres_gabnrequest_t</span>.
</p>
<p>
(2) Process the request in the data specific type.
</p>
<p>
(3) Set the <em class="structfield"><code>pkt.result</code></em>,
<em class="structfield"><code>pkt.recvlength</code></em> as above. All other fields
can
be left untouched since they were filled in by the <code class="function">*_parse()</code> call
above. If using <code class="function">lwres_*response_render()</code>,
<em class="structfield"><code>pkt.pktflags</code></em> will be set up
properly. Otherwise, the <code class="constant">LWRES_LWPACKETFLAG_RESPONSE</code> bit should be
set.
</p>
<p>
(4) Call the data specific rendering function, such as
<code class="function">lwres_gabnresponse_render()</code>.
</p>
<p>
(5) Send the resulting packet to the client.
</p>
<p></p>
</div>
<div class="refsect1" lang="en">
<a name="id2525465"></a><h2>SEE ALSO</h2>
<p><span class="citerefentry"><span class="refentrytitle">lwres_gethostent</span>(3)</span>,
<span class="citerefentry"><span class="refentrytitle">lwres_getipnode</span>(3)</span>,
<span class="citerefentry"><span class="refentrytitle">lwres_getnameinfo</span>(3)</span>,
<span class="citerefentry"><span class="refentrytitle">lwres_noop</span>(3)</span>,
<span class="citerefentry"><span class="refentrytitle">lwres_gabn</span>(3)</span>,
<span class="citerefentry"><span class="refentrytitle">lwres_gnba</span>(3)</span>,
<span class="citerefentry"><span class="refentrytitle">lwres_context</span>(3)</span>,
<span class="citerefentry"><span class="refentrytitle">lwres_config</span>(3)</span>,
<span class="citerefentry"><span class="refentrytitle">resolver</span>(5)</span>,
<span class="citerefentry"><span class="refentrytitle">lwresd</span>(8)</span>.
</p>
</div>
</div></body>
</html>