5887N/A - Copyright (C) 2000, 2001, 2004, 2005, 2007, 2014-2016 Internet Systems Consortium, Inc. ("ISC") 5887N/A - This Source Code Form is subject to the terms of the Mozilla Public 5887N/A - License, v. 2.0. If a copy of the MPL was not distributed with this 5887N/A<
meta http-
equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5887N/A<
meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
5887N/A<
body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><
div class="refentry">
5887N/A<
a name="id-1"></
a><
div class="titlepage"></
div>
5887N/A<
p>lwres — introduction to the lightweight resolver library</
p>
5887N/A<
div class="refsynopsisdiv">
5887N/A<
div class="funcsynopsis"><
pre class="funcsynopsisinfo">#include <
lwres/
lwres.h></
pre></
div>
5887N/A<
a name="id-1.7"></
a><
h2>DESCRIPTION</
h2>
5887N/A The BIND 9 lightweight resolver library is a simple, name service
5887N/A independent stub resolver library. It provides hostname-to-address
5887N/A and address-to-hostname lookup services to applications by
5887N/A transmitting lookup requests to a resolver daemon
5887N/A <
span class="command"><
strong>lwresd</
strong></
span>
5887N/A running on the local host. The resolver daemon performs the
5887N/A lookup using the DNS or possibly other name service protocols,
5887N/A and returns the results to the application through the library.
5887N/A The library and resolver daemon communicate using a simple
5887N/A<
a name="id-1.8"></
a><
h2>OVERVIEW</
h2>
5887N/A The lwresd library implements multiple name service APIs.
5887N/A <
code class="function">gethostbyname()</
code>,
5887N/A <
code class="function">gethostbyaddr()</
code>,
5887N/A <
code class="function">gethostbyname_r()</
code>,
5887N/A <
code class="function">gethostbyaddr_r()</
code>,
5887N/A <
code class="function">getaddrinfo()</
code>,
5887N/A <
code class="function">getipnodebyname()</
code>,
5887N/A <
code class="function">getipnodebyaddr()</
code>
5887N/A functions are all supported. To allow the lwres library to coexist
5887N/A with system libraries that define functions of the same name,
5887N/A the library defines these functions with names prefixed by
5887N/A <
code class="literal">lwres_</
code>.
5887N/A To define the standard names, applications must include the
5887N/A which contains macro definitions mapping the standard function names
5887N/A <
code class="literal">lwres_</
code>
5887N/A prefixed ones. Operating system vendors who integrate the lwres
5887N/A library into their base distributions should rename the functions
5887N/A in the library proper so that the renaming macros are not needed.
5887N/A The library also provides a native API consisting of the functions
5887N/A <
code class="function">lwres_getaddrsbyname()</
code>
5887N/A <
code class="function">lwres_getnamebyaddr()</
code>.
5887N/A These may be called by applications that require more detailed
5887N/A control over the lookup process than the standard functions
5887N/A In addition to these name service independent address lookup
5887N/A functions, the library implements a new, experimental API
5887N/A for looking up arbitrary DNS resource records, using the
5887N/A <
code class="function">lwres_getaddrsbyname()</
code>
5887N/A Finally, there is a low-level API for converting lookup
5887N/A requests and responses to and from raw lwres protocol packets.
5887N/A This API can be used by clients requiring nonblocking operation,
5887N/A and is also used when implementing the server side of the lwres
5887N/A protocol, for example in the
5887N/A <
span class="command"><
strong>lwresd</
strong></
span>
5887N/A resolver daemon. The use of this low-level API in clients
5887N/A and servers is outlined in the following sections.
5887N/A<
a name="id-1.9"></
a><
h2>CLIENT-SIDE LOW-LEVEL API CALL FLOW</
h2>
5887N/A When a client program wishes to make an lwres request using the
5887N/A native low-level API, it typically performs the following
5887N/A (1) Allocate or use an existing <
span class="type">lwres_packet_t</
span>,
5887N/A called <
code class="varname">pkt</
code> below.
5887N/A This is done so the receiver of our packets knows how large our receive
5887N/A buffer is. The "default" is a constant in
5887N/A <
code class="filename">
lwres.h</
code>: <
code class="constant">LWRES_RECVLENGTH = 4096</
code>.
5887N/A to a unique serial number. This value is echoed
5887N/A back to the application by the remote server.
5887N/A (6) Call <
code class="function">lwres_*request_render()</
code>,
5887N/A or marshall in the data using the primitives
5887N/A such as <
code class="function">lwres_packet_render()</
code>
5887N/A and storing the packet data.
5887N/A (7) Transmit the resulting buffer.
5887N/A (8) Call <
code class="function">lwres_*response_parse()</
code>
5887N/A to parse any packets received.
5887N/A (9) Verify that the opcode and serial match a request, and process the
5887N/A packet specific information contained in the body.
5887N/A<
a name="id-1.10"></
a><
h2>SERVER-SIDE LOW-LEVEL API CALL FLOW</
h2>
5887N/A When implementing the server side of the lightweight resolver
5887N/A protocol using the lwres library, a sequence of actions like the
5887N/A following is typically involved in processing each request packet.
5887N/A Note that the same <
span class="type">lwres_packet_t</
span> is used
5887N/A in both the <
code class="function">_parse()</
code> and <
code class="function">_render()</
code> calls,
5887N/A with only a few modifications made
5887N/A to the packet header's contents between uses. This method is
5887N/A as it keeps the serial, opcode, and other fields correct.
5887N/A (1) When a packet is received, call <
code class="function">lwres_*request_parse()</
code> to
5887N/A unmarshall it. This returns a <
span class="type">lwres_packet_t</
span> (also called <
code class="varname">pkt</
code>, below)
5887N/A as well as a data specific type, such as <
span class="type">lwres_gabnrequest_t</
span>.
5887N/A (2) Process the request in the data specific type.
5887N/A be left untouched since they were filled in by the <
code class="function">*_parse()</
code> call
5887N/A above. If using <
code class="function">lwres_*response_render()</
code>,
5887N/A properly. Otherwise, the <
code class="constant">LWRES_LWPACKETFLAG_RESPONSE</
code> bit should be
5887N/A (4) Call the data specific rendering function, such as
5887N/A <
code class="function">lwres_gabnresponse_render()</
code>.
5887N/A (5) Send the resulting packet to the client.
<
a name="id-1.11"></
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>.