1LWRES(3) BIND9 LWRES(3)
2
3
4
6 lwres - introduction to the lightweight resolver library
7
9 #include <lwres/lwres.h>
10
12 The BIND 9 lightweight resolver library is a simple, name service
13 independent stub resolver library. It provides hostname-to-address and
14 address-to-hostname lookup services to applications by transmitting
15 lookup requests to a resolver daemon lwresd running on the local host.
16 The resolver daemon performs the lookup using the DNS or possibly other
17 name service protocols, and returns the results to the application
18 through the library. The library and resolver daemon communicate using
19 a simple UDP-based protocol.
20
22 The lwresd library implements multiple name service APIs. The standard
23 gethostbyname(), gethostbyaddr(), gethostbyname_r(), gethostbyaddr_r(),
24 getaddrinfo(), getipnodebyname(), and getipnodebyaddr() functions are
25 all supported. To allow the lwres library to coexist with system
26 libraries that define functions of the same name, the library defines
27 these functions with names prefixed by lwres_. To define the standard
28 names, applications must include the header file <lwres/netdb.h> which
29 contains macro definitions mapping the standard function names into
30 lwres_ prefixed ones. Operating system vendors who integrate the lwres
31 library into their base distributions should rename the functions in
32 the library proper so that the renaming macros are not needed.
33
34 The library also provides a native API consisting of the functions
35 lwres_getaddrsbyname() and lwres_getnamebyaddr(). These may be called
36 by applications that require more detailed control over the lookup
37 process than the standard functions provide.
38
39 In addition to these name service independent address lookup functions,
40 the library implements a new, experimental API for looking up arbitrary
41 DNS resource records, using the lwres_getaddrsbyname() function.
42
43 Finally, there is a low-level API for converting lookup requests and
44 responses to and from raw lwres protocol packets. This API can be used
45 by clients requiring nonblocking operation, and is also used when
46 implementing the server side of the lwres protocol, for example in the
47 lwresd resolver daemon. The use of this low-level API in clients and
48 servers is outlined in the following sections.
49
51 When a client program wishes to make an lwres request using the native
52 low-level API, it typically performs the following sequence of actions.
53
54 (1) Allocate or use an existing lwres_packet_t, called pkt below.
55
56 (2) Set pkt.recvlength to the maximum length we will accept. This is
57 done so the receiver of our packets knows how large our receive buffer
58 is. The "default" is a constant in lwres.h: LWRES_RECVLENGTH = 4096.
59
60 (3) Set pkt.serial to a unique serial number. This value is echoed back
61 to the application by the remote server.
62
63 (4) Set pkt.pktflags. Usually this is set to 0.
64
65 (5) Set pkt.result to 0.
66
67 (6) Call lwres_*request_render(), or marshall in the data using the
68 primitives such as lwres_packet_render() and storing the packet data.
69
70 (7) Transmit the resulting buffer.
71
72 (8) Call lwres_*response_parse() to parse any packets received.
73
74 (9) Verify that the opcode and serial match a request, and process the
75 packet specific information contained in the body.
76
78 When implementing the server side of the lightweight resolver protocol
79 using the lwres library, a sequence of actions like the following is
80 typically involved in processing each request packet.
81
82 Note that the same lwres_packet_t is used in both the _parse() and
83 _render() calls, with only a few modifications made to the packet
84 header's contents between uses. This method is recommended as it keeps
85 the serial, opcode, and other fields correct.
86
87 (1) When a packet is received, call lwres_*request_parse() to
88 unmarshall it. This returns a lwres_packet_t (also called pkt, below)
89 as well as a data specific type, such as lwres_gabnrequest_t.
90
91 (2) Process the request in the data specific type.
92
93 (3) Set the pkt.result, pkt.recvlength as above. All other fields can
94 be left untouched since they were filled in by the *_parse() call
95 above. If using lwres_*response_render(), pkt.pktflags will be set up
96 properly. Otherwise, the LWRES_LWPACKETFLAG_RESPONSE bit should be set.
97
98 (4) Call the data specific rendering function, such as
99 lwres_gabnresponse_render().
100
101 (5) Send the resulting packet to the client.
102
104 lwres_gethostent(3), lwres_getipnode(3), lwres_getnameinfo(3),
105 lwres_noop(3), lwres_gabn(3), lwres_gnba(3), lwres_context(3),
106 lwres_config(3), resolver(5), lwresd(8).
107
109 Internet Systems Consortium, Inc.
110
112 Copyright © 2000, 2001, 2004, 2005, 2007, 2014-2016, 2018 Internet
113 Systems Consortium, Inc. ("ISC")
114
115
116
117ISC 2007-06-18 LWRES(3)