1LWRES_RESUTIL(3) BIND9 LWRES_RESUTIL(3)
2
3
4
6 lwres_string_parse, lwres_addr_parse, lwres_getaddrsbyname,
7 lwres_getnamebyaddr - lightweight resolver utility functions
8
10 #include <lwres/lwres.h>
11
12 lwres_result_t lwres_string_parse(lwres_buffer_t *b, char **c,
13 lwres_uint16_t *len);
14
15 lwres_result_t lwres_addr_parse(lwres_buffer_t *b, lwres_addr_t *addr);
16
17 lwres_result_t lwres_getaddrsbyname(lwres_context_t *ctx,
18 const char *name,
19 lwres_uint32_t addrtypes,
20 lwres_gabnresponse_t **structp);
21
22 lwres_result_t lwres_getnamebyaddr(lwres_context_t *ctx,
23 lwres_uint32_t addrtype,
24 lwres_uint16_t addrlen,
25 const unsigned char *addr,
26 lwres_gnbaresponse_t **structp);
27
29 lwres_string_parse() retrieves a DNS-encoded string starting the
30 current pointer of lightweight resolver buffer b: i.e. b->current.
31 When the function returns, the address of the first byte of the encoded
32 string is returned via *c and the length of that string is given by
33 *len. The buffer's current pointer is advanced to point at the
34 character following the string length, the encoded string, and the
35 trailing NULL character.
36
37 lwres_addr_parse() extracts an address from the buffer b. The buffer's
38 current pointer b->current is presumed to point at an encoded address:
39 the address preceded by a 32-bit protocol family identifier and a
40 16-bit length field. The encoded address is copied to addr->address and
41 addr->length indicates the size in bytes of the address that was
42 copied. b->current is advanced to point at the next byte of available
43 data in the buffer following the encoded address.
44
45 lwres_getaddrsbyname() and lwres_getnamebyaddr() use the
46 lwres_gnbaresponse_t structure defined below:
47
48 typedef struct {
49 lwres_uint32_t flags;
50 lwres_uint16_t naliases;
51 lwres_uint16_t naddrs;
52 char *realname;
53 char **aliases;
54 lwres_uint16_t realnamelen;
55 lwres_uint16_t *aliaslen;
56 lwres_addrlist_t addrs;
57 void *base;
58 size_t baselen;
59 } lwres_gabnresponse_t;
60
61 The contents of this structure are not manipulated directly but they
62 are controlled through the lwres_gabn(3) functions.
63
64 The lightweight resolver uses lwres_getaddrsbyname() to perform forward
65 lookups. Hostname name is looked up using the resolver context ctx for
66 memory allocation. addrtypes is a bitmask indicating which type of
67 addresses are to be looked up. Current values for this bitmask are
68 LWRES_ADDRTYPE_V4 for IPv4 addresses and LWRES_ADDRTYPE_V6 for IPv6
69 addresses. Results of the lookup are returned in *structp.
70
71 lwres_getnamebyaddr() performs reverse lookups. Resolver context ctx is
72 used for memory allocation. The address type is indicated by addrtype:
73 LWRES_ADDRTYPE_V4 or LWRES_ADDRTYPE_V6. The address to be looked up is
74 given by addr and its length is addrlen bytes. The result of the
75 function call is made available through *structp.
76
78 Successful calls to lwres_string_parse() and lwres_addr_parse() return
79 LWRES_R_SUCCESS. Both functions return LWRES_R_FAILURE if the buffer
80 is corrupt or LWRES_R_UNEXPECTEDEND if the buffer has less space than
81 expected for the components of the encoded string or address.
82
83 lwres_getaddrsbyname() returns LWRES_R_SUCCESS on success and it
84 returns LWRES_R_NOTFOUND if the hostname name could not be found.
85
86 LWRES_R_SUCCESS is returned by a successful call to
87 lwres_getnamebyaddr().
88
89 Both lwres_getaddrsbyname() and lwres_getnamebyaddr() return
90 LWRES_R_NOMEMORY when memory allocation requests fail and
91 LWRES_R_UNEXPECTEDEND if the buffers used for sending queries and
92 receiving replies are too small.
93
95 lwres_buffer(3), lwres_gabn(3).
96
98 Internet Systems Consortium, Inc.
99
101 Copyright © 2000, 2001, 2004, 2005, 2007, 2014-2016, 2018 Internet
102 Systems Consortium, Inc. ("ISC")
103
104
105
106ISC 2007-06-18 LWRES_RESUTIL(3)