2 - Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2000, 2001 Internet Software Consortium.
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.
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.
20 <meta http-equiv=
"Content-Type" content=
"text/html; charset=ISO-8859-1">
22 <meta name=
"generator" content=
"DocBook XSL Stylesheets V1.71.1">
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">
28 <p>lwres
— introduction to the lightweight resolver library
</p>
30 <div class=
"refsynopsisdiv">
32 <div class=
"funcsynopsis"><pre class=
"funcsynopsisinfo">#include
<lwres/lwres.h
></pre></div>
34 <div class=
"refsect1" lang=
"en">
35 <a name=
"id2543357"></a><h2>DESCRIPTION
</h2>
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
49 <div class=
"refsect1" lang=
"en">
50 <a name=
"id2543370"></a><h2>OVERVIEW
</h2>
52 The lwresd library implements multiple name service APIs.
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>,
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
68 <code class=
"filename"><lwres/netdb.h
></code>
69 which contains macro definitions mapping the standard function names
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.
77 The library also provides a native API consisting of the functions
78 <code class=
"function">lwres_getaddrsbyname()
</code>
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
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>
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.
103 <div class=
"refsect1" lang=
"en">
104 <a name=
"id2543434"></a><h2>CLIENT-SIDE LOW-LEVEL API CALL FLOW
</h2>
106 When a client program wishes to make an lwres request using the
107 native low-level API, it typically performs the following
111 (
1) Allocate or use an existing
<span class=
"type">lwres_packet_t
</span>,
112 called
<code class=
"varname">pkt
</code> below.
115 (
2) Set
<em class=
"structfield"><code>pkt.recvlength
</code></em> to the maximum length
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>.
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.
127 (
4) Set
<em class=
"structfield"><code>pkt.pktflags
</code></em>. Usually this is set to
131 (
5) Set
<em class=
"structfield"><code>pkt.result
</code></em> to
0.
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.
140 (
7) Transmit the resulting buffer.
143 (
8) Call
<code class=
"function">lwres_*response_parse()
</code>
144 to parse any packets received.
147 (
9) Verify that the opcode and serial match a request, and process the
148 packet specific information contained in the body.
151 <div class=
"refsect1" lang=
"en">
152 <a name=
"id2543582"></a><h2>SERVER-SIDE LOW-LEVEL API CALL FLOW
</h2>
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.
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
164 as it keeps the serial, opcode, and other fields correct.
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>.
172 (
2) Process the request in the data specific type.
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
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
185 (
4) Call the data specific rendering function, such as
186 <code class=
"function">lwres_gabnresponse_render()
</code>.
189 (
5) Send the resulting packet to the client.
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>,
197 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_getipnode
</span>(
3)
</span>,
199 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_getnameinfo
</span>(
3)
</span>,
201 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_noop
</span>(
3)
</span>,
203 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_gabn
</span>(
3)
</span>,
205 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_gnba
</span>(
3)
</span>,
207 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_context
</span>(
3)
</span>,
209 <span class=
"citerefentry"><span class=
"refentrytitle">lwres_config
</span>(
3)
</span>,
211 <span class=
"citerefentry"><span class=
"refentrytitle">resolver
</span>(
5)
</span>,
213 <span class=
"citerefentry"><span class=
"refentrytitle">lwresd
</span>(
8)
</span>.