1 .\" $NetBSD: lwres.3,v 1.5 2014/12/10 04:38:02 christos Exp $
3 .\" Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
4 .\" Copyright (C) 2000, 2001 Internet Software Consortium.
6 .\" Permission to use, copy, modify, and/or distribute this software for any
7 .\" purpose with or without fee is hereby granted, provided that the above
8 .\" copyright notice and this permission notice appear in all copies.
10 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 .\" PERFORMANCE OF THIS SOFTWARE.
24 .\" Generator: DocBook XSL Stylesheets v1.71.1 <http://docbook.sf.net/>
25 .\" Date: June 18, 2007
29 .TH "LWRES" "3" "June 18, 2007" "BIND9" "BIND9"
30 .\" disable hyphenation
32 .\" disable justification (adjust text to left margin only)
35 lwres \- introduction to the lightweight resolver library
38 #include <lwres/lwres.h>
42 The BIND 9 lightweight resolver library is a simple, name service independent stub resolver library. It provides hostname\-to\-address and address\-to\-hostname lookup services to applications by transmitting lookup requests to a resolver daemon
44 running on the local host. The resolver daemon performs the lookup using the DNS or possibly other name service protocols, and returns the results to the application through the library. The library and resolver daemon communicate using a simple UDP\-based protocol.
47 The lwresd library implements multiple name service APIs. The standard
48 \fBgethostbyname()\fR,
49 \fBgethostbyaddr()\fR,
50 \fBgethostbyname_r()\fR,
51 \fBgethostbyaddr_r()\fR,
53 \fBgetipnodebyname()\fR, and
54 \fBgetipnodebyaddr()\fR
55 functions are all supported. To allow the lwres library to coexist with system libraries that define functions of the same name, the library defines these functions with names prefixed by
56 lwres_. To define the standard names, applications must include the header file
58 which contains macro definitions mapping the standard function names into
60 prefixed ones. Operating system vendors who integrate the lwres library into their base distributions should rename the functions in the library proper so that the renaming macros are not needed.
62 The library also provides a native API consisting of the functions
63 \fBlwres_getaddrsbyname()\fR
65 \fBlwres_getnamebyaddr()\fR. These may be called by applications that require more detailed control over the lookup process than the standard functions provide.
67 In addition to these name service independent address lookup functions, the library implements a new, experimental API for looking up arbitrary DNS resource records, using the
68 \fBlwres_getaddrsbyname()\fR
71 Finally, there is a low\-level API for converting lookup requests and responses to and from raw lwres protocol packets. This API can be used by clients requiring nonblocking operation, and is also used when implementing the server side of the lwres protocol, for example in the
73 resolver daemon. The use of this low\-level API in clients and servers is outlined in the following sections.
74 .SH "CLIENT\-SIDE LOW\-LEVEL API CALL FLOW"
76 When a client program wishes to make an lwres request using the native low\-level API, it typically performs the following sequence of actions.
78 (1) Allocate or use an existing
79 \fBlwres_packet_t\fR, called
85 to the maximum length we will accept. This is done so the receiver of our packets knows how large our receive buffer is. The "default" is a constant in
87 \fBLWRES_RECVLENGTH = 4096\fR.
91 to a unique serial number. This value is echoed back to the application by the remote server.
94 pkt.pktflags. Usually this is set to 0.
101 \fBlwres_*request_render()\fR, or marshall in the data using the primitives such as
102 \fBlwres_packet_render()\fR
103 and storing the packet data.
105 (7) Transmit the resulting buffer.
108 \fBlwres_*response_parse()\fR
109 to parse any packets received.
111 (9) Verify that the opcode and serial match a request, and process the packet specific information contained in the body.
112 .SH "SERVER\-SIDE LOW\-LEVEL API CALL FLOW"
114 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.
122 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.
124 (1) When a packet is received, call
125 \fBlwres_*request_parse()\fR
126 to unmarshall it. This returns a
129 \fIpkt\fR, below) as well as a data specific type, such as
130 \fBlwres_gabnrequest_t\fR.
132 (2) Process the request in the data specific type.
137 as above. All other fields can be left untouched since they were filled in by the
140 \fBlwres_*response_render()\fR,
142 will be set up properly. Otherwise, the
143 \fBLWRES_LWPACKETFLAG_RESPONSE\fR
146 (4) Call the data specific rendering function, such as
147 \fBlwres_gabnresponse_render()\fR.
149 (5) Send the resulting packet to the client.
153 \fBlwres_gethostent\fR(3),
154 \fBlwres_getipnode\fR(3),
155 \fBlwres_getnameinfo\fR(3),
159 \fBlwres_context\fR(3),
160 \fBlwres_config\fR(3),
164 Copyright \(co 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
166 Copyright \(co 2000, 2001 Internet Software Consortium.