1Net::DNS::Resolver::ProUgsrearmmCaobnlter(i3b)uted PerlNDeotc:u:mDeNnSt:a:tRieosnolver::Programmable(3)
2
3
4
6 Net::DNS::Resolver::Programmable - programmable DNS resolver class for
7 offline emulation of DNS
8
10 use Net::DNS::Resolver::Programmable;
11 use Net::DNS::RR;
12
13 my $resolver = Net::DNS::Resolver::Programmable->new(
14 records => {
15 'example.com' => [
16 Net::DNS::RR->new('example.com. NS ns.example.org.'),
17 Net::DNS::RR->new('example.com. A 192.168.0.1')
18 ],
19 'ns.example.org' => [
20 Net::DNS::RR->new('ns.example.org. A 192.168.1.1')
21 ]
22 },
23
24 resolver_code => sub {
25 my ($domain, $rr_type, $class) = @_;
26 ...
27 return ($result, $aa, @rrs);
28 }
29 );
30
32 Net::DNS::Resolver::Programmable is a Net::DNS::Resolver descendant
33 class that allows a virtual DNS to be emulated instead of querying the
34 real DNS. A set of static DNS records may be supplied, or arbitrary
35 code may be specified as a means for retrieving DNS records, or even
36 generating them on the fly.
37
38 Constructor
39 The following constructor is provided:
40
41 new(%options): returns Net::DNS::Resolver::Programmable
42 Creates a new programmed DNS resolver object.
43
44 %options is a list of key/value pairs representing any of the
45 following options:
46
47 records
48 A reference to a hash of arrays containing a static set of
49 Net::DNS::RR objects. The hash entries must be indexed by
50 fully qualified domain names (lower-case, without any trailing
51 dots), and the entries themselves must be arrays of the RR
52 objects pertaining to these domain names. For example:
53
54 records => {
55 'example.com' => [
56 Net::DNS::RR->new('example.com. NS ns.example.org.'),
57 Net::DNS::RR->new('example.com. A 192.168.0.1')
58 ],
59 'www.example.com' => [
60 Net::DNS::RR->new('www.example.com. A 192.168.0.2')
61 ],
62 'ns.example.org' => [
63 Net::DNS::RR->new('ns.example.org. A 192.168.1.1')
64 ]
65 }
66
67 If this option is specified, the resolver retrieves requested
68 RRs from this data structure.
69
70 resolver_code
71 A code reference used as a call-back for dynamically retrieving
72 requested RRs.
73
74 The code must take the following query parameters as arguments:
75 the domain, RR type, and class.
76
77 It must return a list composed of: the response's RCODE (by
78 name, as returned by Net::DNS::Header->rcode), the "aa"
79 (authoritative answer) flag (boolean, use undef if you don't
80 care), and the Net::DNS::RR answer objects. If an error string
81 is returned instead of a valid RCODE, a Net::DNS::Packet object
82 is not constructed but an error condition for the resolver is
83 signaled instead.
84
85 For example:
86
87 resolver_code => sub {
88 my ($domain, $rr_type, $class) = @_;
89 ...
90 return ($result, $aa, @rrs);
91 }
92
93 If both this and the "records" option are specified, then
94 statically programmed records are used in addition to any that
95 are returned by the configured resolver code.
96
97 defnames
98 dnsrch
99 domain
100 searchlist
101 debug
102 These Net::DNS::Resolver options are also meaningful with
103 Net::DNS::Resolver::Programmable. See Net::DNS::Resolver for
104 their descriptions.
105
106 Instance methods
107 The following instance methods of Net::DNS::Resolver are also supported
108 by Net::DNS::Resolver::Programmable:
109
110 search: returns Net::DNS::Packet
111 query: returns Net::DNS::Packet
112 send: returns Net::DNS::Packet
113 Performs an offline DNS query, using the statically programmed DNS
114 RRs and/or the configured dynamic resolver code. See the "new"
115 constructor's "records" and "resolver_code" options. See the
116 descriptions of search, query, and send for details about the
117 calling syntax of these methods.
118
119 print
120 string: returns string
121 searchlist: returns list of string
122 defnames: returns boolean
123 dnsrch: returns boolean
124 debug: returns boolean
125 errorstring: returns string
126 answerfrom: returns string
127 answersize: returns integer
128 See "METHODS" in Net::DNS::Resolver.
129
130 Currently the following methods of Net::DNS::Resolver are not
131 supported: axfr, axfr_start, axfr_next, nameservers, port, srcport,
132 srcaddr, bgsend, bgread, bgisready, tsig, retrans, retry, recurse,
133 usevc, tcp_timeout, udp_timeout, persistent_tcp, persistent_udp, igntc,
134 dnssec, cdflag, udppacketsize. The effects of using these on
135 Net::DNS::Resolver::Programmable objects are undefined.
136
138 Net::DNS::Resolver
139
140 For availability, support, and license information, see the README file
141 included with Net::DNS::Resolver::Programmable.
142
144 David Precious (BIGPRESH) "<davidp@preshweb.co.uk>" took on
145 maintainership in July 2017
146
147 Original author Julian Mehnle "<julian@mehnle.net>"
148
150 Dick Franks (rwfranks)
151
152 (This section was added by BIGPRESH in July 2017, so currently omits
153 acknowledgements for those who contributed things in the past; I may
154 retrospectively add them in future.)
155
156
157
158perl v5.34.0 2022-01-21Net::DNS::Resolver::Programmable(3)