Merge from vendor branch BINUTILS:
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / lwres / man / lwres.3
1 .\" Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
2 .\" Copyright (C) 2000, 2001  Internet Software Consortium.
3 .\"
4 .\" Permission to use, copy, modify, and distribute this software for any
5 .\" purpose with or without fee is hereby granted, provided that the above
6 .\" copyright notice and this permission notice appear in all copies.
7 .\"
8 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 .\" AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 .\" PERFORMANCE OF THIS SOFTWARE.
15 .\"
16 .\" $Id: lwres.3,v 1.15.2.1 2004/03/15 04:45:00 marka Exp $
17 .\"
18 .TH "LWRES" "3" "Jun 30, 2000" "BIND9" ""
19 .SH NAME
20 lwres \- introduction to the lightweight resolver library
21 .SH SYNOPSIS
22 \fB#include <lwres/lwres.h>\fR
23 .SH "DESCRIPTION"
24 .PP
25 The BIND 9 lightweight resolver library is a simple, name service
26 independent stub resolver library. It provides hostname-to-address
27 and address-to-hostname lookup services to applications by
28 transmitting lookup requests to a resolver daemon
29 \fBlwresd\fR
30 running on the local host. The resover daemon performs the
31 lookup using the DNS or possibly other name service protocols,
32 and returns the results to the application through the library. 
33 The library and resolver daemon communicate using a simple
34 UDP-based protocol.
35 .SH "OVERVIEW"
36 .PP
37 The lwresd library implements multiple name service APIs.
38 The standard
39 \fBgethostbyname()\fR,
40 \fBgethostbyaddr()\fR,
41 \fBgethostbyname_r()\fR,
42 \fBgethostbyaddr_r()\fR,
43 \fBgetaddrinfo()\fR,
44 \fBgetipnodebyname()\fR,
45 and
46 \fBgetipnodebyaddr()\fR
47 functions are all supported. To allow the lwres library to coexist
48 with system libraries that define functions of the same name,
49 the library defines these functions with names prefixed by
50 lwres_.
51 To define the standard names, applications must include the
52 header file
53 \fI<lwres/netdb.h>\fR
54 which contains macro definitions mapping the standard function names
55 into
56 lwres_
57 prefixed ones. Operating system vendors who integrate the lwres
58 library into their base distributions should rename the functions
59 in the library proper so that the renaming macros are not needed.
60 .PP
61 The library also provides a native API consisting of the functions
62 \fBlwres_getaddrsbyname()\fR
63 and
64 \fBlwres_getnamebyaddr()\fR.
65 These may be called by applications that require more detailed
66 control over the lookup process than the standard functions
67 provide.
68 .PP
69 In addition to these name service independent address lookup
70 functions, the library implements a new, experimental API
71 for looking up arbitrary DNS resource records, using the
72 \fBlwres_getaddrsbyname()\fR
73 function.
74 .PP
75 Finally, there is a low-level API for converting lookup
76 requests and responses to and from raw lwres protocol packets. 
77 This API can be used by clients requiring nonblocking operation, 
78 and is also used when implementing the server side of the lwres
79 protocol, for example in the
80 \fBlwresd\fR
81 resolver daemon. The use of this low-level API in clients
82 and servers is outlined in the following sections.
83 .SH "CLIENT-SIDE LOW-LEVEL API CALL FLOW"
84 .PP
85 When a client program wishes to make an lwres request using the
86 native low-level API, it typically performs the following 
87 sequence of actions.
88 .PP
89 (1) Allocate or use an existing \fBlwres_packet_t\fR,
90 called pkt below.
91 .PP
92 (2) Set \fBpkt.recvlength\fR to the maximum length we will accept. 
93 This is done so the receiver of our packets knows how large our receive 
94 buffer is. The "default" is a constant in
95 \fIlwres.h\fR: LWRES_RECVLENGTH = 4096.
96 .PP
97 (3) Set \fBpkt.serial\fR
98 to a unique serial number. This value is echoed
99 back to the application by the remote server.
100 .PP
101 (4) Set \fBpkt.pktflags\fR. Usually this is set to 0.
102 .PP
103 (5) Set \fBpkt.result\fR to 0.
104 .PP
105 (6) Call \fBlwres_*request_render()\fR, 
106 or marshall in the data using the primitives
107 such as \fBlwres_packet_render()\fR
108 and storing the packet data.
109 .PP
110 (7) Transmit the resulting buffer.
111 .PP
112 (8) Call \fBlwres_*response_parse()\fR
113 to parse any packets received.
114 .PP
115 (9) Verify that the opcode and serial match a request, and process the
116 packet specific information contained in the body.
117 .SH "SERVER-SIDE LOW-LEVEL API CALL FLOW"
118 .PP
119 When implementing the server side of the lightweight resolver
120 protocol using the lwres library, a sequence of actions like the
121 following is typically involved in processing each request packet.
122 .PP
123 Note that the same \fBlwres_packet_t\fR is used
124 in both the \fB_parse()\fR and \fB_render()\fR calls,
125 with only a few modifications made
126 to the packet header's contents between uses. This method is recommended
127 as it keeps the serial, opcode, and other fields correct.
128 .PP
129 (1) When a packet is received, call \fBlwres_*request_parse()\fR to
130 unmarshall it. This returns a \fBlwres_packet_t\fR (also called pkt, below)
131 as well as a data specific type, such as \fBlwres_gabnrequest_t\fR.
132 .PP
133 (2) Process the request in the data specific type.
134 .PP
135 (3) Set the \fBpkt.result\fR,
136 \fBpkt.recvlength\fR as above. All other fields can
137 be left untouched since they were filled in by the \fB*_parse()\fR call
138 above. If using \fBlwres_*response_render()\fR,
139 \fBpkt.pktflags\fR will be set up
140 properly. Otherwise, the LWRES_LWPACKETFLAG_RESPONSE bit should be
141 set.
142 .PP
143 (4) Call the data specific rendering function, such as
144 \fBlwres_gabnresponse_render()\fR.
145 .PP
146 (5) Send the resulting packet to the client.
147 .PP
148 .SH "SEE ALSO"
149 .PP
150 \fBlwres_gethostent\fR(3),
151 \fBlwres_getipnode\fR(3),
152 \fBlwres_getnameinfo\fR(3),
153 \fBlwres_noop\fR(3),
154 \fBlwres_gabn\fR(3),
155 \fBlwres_gnba\fR(3),
156 \fBlwres_context\fR(3),
157 \fBlwres_config\fR(3),
158 \fBresolver\fR(5),
159 \fBlwresd\fR(8).