1 |
NAME |
2 |
EV::ADNS - lightweight asynchronous dns queries using EV and libadns |
3 |
|
4 |
SYNOPSIS |
5 |
use EV; |
6 |
use EV::ADNS; |
7 |
|
8 |
EV::ADNS::submit "example.com", EV::ADNS::r_a, 0, sub { |
9 |
my ($status, $expires, @a) = @_; |
10 |
warn $a[0]; # "127.13.166.3" etc. |
11 |
}; |
12 |
|
13 |
EV::loop; |
14 |
|
15 |
DESCRIPTION |
16 |
This is a simple interface to libadns (asynchronous dns) that integrates |
17 |
well and automatically into the EV event loop. The documentation for |
18 |
libadns is vital to understand this module, see |
19 |
<http://www.chiark.greenend.org.uk/~ian/adns/>. |
20 |
|
21 |
You can use it only with EV (directly or indirectly, e.g. via Glib::EV). |
22 |
Apart from loading and using the "submit" function you need not do |
23 |
anything (except run an EV event loop). |
24 |
|
25 |
OVERVIEW |
26 |
All the constants/enums from adns.h are available in the EV::ADNS |
27 |
namespace, without the "adns_" prefix, e.g. "adns_r_a" becomes |
28 |
"EV::ADNS::r_a", "adns__qtf_deref" becomes "EV::ADNS::_qtf_deref" and so |
29 |
on. |
30 |
|
31 |
FUNCTIONS |
32 |
$query = EV::ADNS::submit "domain", $rrtype, $flags, $cb |
33 |
Submits a new request to be handled. See the "adns_submit" C |
34 |
function description for more details. The function optionally |
35 |
returns a query object which can be used to cancel an in-progress |
36 |
request. You do not need to store the query object, even if you |
37 |
ignore it the query will proceed. |
38 |
|
39 |
The callback will be invoked with a result status, the time the |
40 |
resource record validity expires and zero or more resource records, |
41 |
one scalar per result record. Example: |
42 |
|
43 |
sub adns_cb { |
44 |
my ($status, $expires, @rr) = @_; |
45 |
if ($status == EV::ADNS::s_ok) { |
46 |
use JSON::XS; |
47 |
warn encode_json \@rr; |
48 |
} |
49 |
} |
50 |
|
51 |
The format of result records varies considerably, here is some |
52 |
cursory documentation of how each record will look like, depending |
53 |
on the query type: |
54 |
|
55 |
EV::ADNS::rr_a |
56 |
An IPv4 address in dotted quad (string) form. |
57 |
|
58 |
EV::ADNS::r_ns_raw, EV::ADNS::r_cname, EV::ADNS::r_ptr, |
59 |
EV::ADNS::r_ptr_raw |
60 |
The resource record as a simple string. |
61 |
|
62 |
EV::ADNS::r_txt |
63 |
An arrayref of strings. |
64 |
|
65 |
EV::ADNS::r_ns |
66 |
A "host address", a hostname with any number of addresses (hint |
67 |
records). |
68 |
|
69 |
Currently only the hostname will be stored, so this is alway an |
70 |
arrayref with a single element of the hostname. Future versions |
71 |
might add additional address entries. |
72 |
|
73 |
EV::ADNS::r_hinfo |
74 |
An arrayref consisting of the two strings. |
75 |
|
76 |
EV::ADNS::r_rp, EV::ADNS::r_rp_raw |
77 |
An arrayref with two strings. |
78 |
|
79 |
EV::ADNS::r_mx |
80 |
An arrayref consisting of the priority and a "host address" (see |
81 |
"EV::ADNS::r_ns"). Example: |
82 |
|
83 |
[10, "mail10.example.com"] |
84 |
|
85 |
EV::ADNS::r_mx_raw |
86 |
An arrayref consisting of the priority and the hostname, e.g. |
87 |
"[10, "mail.example.com"]". |
88 |
|
89 |
EV::ADNS::r_soa, EV::ADNS::r_soa_raw |
90 |
An arrayref consisting of the primary nameserver, admin name, |
91 |
serial, refresh, retry expire and minimum times, e.g.: |
92 |
|
93 |
["ns.example.net", "hostmaster@example.net", 2000001102, 86400, 21600, 2592000, 172800] |
94 |
|
95 |
The "raw" form doesn't mangle the e-mail address. |
96 |
|
97 |
EV::ADNS::r_srv_raw |
98 |
An arrayref consisting of the priority, weight, port and |
99 |
hostname, e.g.: |
100 |
|
101 |
[10, 10, 5060, "sip1.example.net"] |
102 |
|
103 |
EV::ADNS::r_srv |
104 |
The same as "EV::ADNS::r_srv_raw", but the hostname is replaced |
105 |
by a "host address" (see "EV::ADNS::r_ns"). |
106 |
|
107 |
EV::ADNS::r_unknown |
108 |
A single octet string with the raw contents. |
109 |
|
110 |
anything else |
111 |
Currently "undef". |
112 |
|
113 |
$query->cancel |
114 |
Cancels a request that is in progress. |
115 |
|
116 |
SEE ALSO |
117 |
EV, Net::ADNS another interface to adns, maybe better, but without real |
118 |
support to integrate it into other event loops. |
119 |
|
120 |
AUTHOR |
121 |
Marc Lehmann <schmorp@schmorp.de> |
122 |
http://home.schmorp.de/ |
123 |
|