| 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_addr, EV::ADNS::qf_cname_loose, sub { |
| 9 |
my ($status, $expires, @a) = @_; |
| 10 |
warn $a[0]; # "127.13.166.3" etc. |
| 11 |
}; |
| 12 |
|
| 13 |
EV::run; |
| 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, i.e. "adns_r_a" becomes |
| 28 |
"EV::ADNS::r_a" and so on. |
| 29 |
|
| 30 |
FUNCTIONS |
| 31 |
$query = EV::ADNS::submit "domain", $rrtype, $flags, $cb |
| 32 |
Submits a new request to be handled. See the "adns_submit" C |
| 33 |
function description for more details. The function optionally |
| 34 |
returns a query object which can be used to cancel an in-progress |
| 35 |
request. You do not need to store the query object, even if you |
| 36 |
ignore it, the query will proceed. |
| 37 |
|
| 38 |
The callback will be invoked with a result status, the time the |
| 39 |
resource record validity expires and zero or more resource records, |
| 40 |
one scalar per result record. Example: |
| 41 |
|
| 42 |
sub adns_cb { |
| 43 |
my ($status, $expires, @rr) = @_; |
| 44 |
if ($status == EV::ADNS::s_ok) { |
| 45 |
use JSON::XS; |
| 46 |
warn encode_json \@rr; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
The format of result records varies considerably, here is some |
| 51 |
cursory documentation of how each record will look like, depending |
| 52 |
on the query type: |
| 53 |
|
| 54 |
EV::ADNS::r_a, EV::ADNS::r_addr |
| 55 |
An IPv4 address in dotted quad (string) form. |
| 56 |
|
| 57 |
EV::ADNS::r_ns_raw, EV::ADNS::r_cname, EV::ADNS::r_ptr, |
| 58 |
EV::ADNS::r_ptr_raw |
| 59 |
The resource record as a simple string. |
| 60 |
|
| 61 |
EV::ADNS::r_txt |
| 62 |
An arrayref of strings. |
| 63 |
|
| 64 |
EV::ADNS::r_ns |
| 65 |
A "host address", a hostname with any number of addresses (hint |
| 66 |
records). |
| 67 |
|
| 68 |
The record will be an arrayref with domainname, adns status and |
| 69 |
any number of associated addresses: "["domain", adns_status, |
| 70 |
addr...]". |
| 71 |
|
| 72 |
EV::ADNS::r_hinfo |
| 73 |
An arrayref consisting of the two strings. |
| 74 |
|
| 75 |
EV::ADNS::r_rp, EV::ADNS::r_rp_raw |
| 76 |
An arrayref with two strings. |
| 77 |
|
| 78 |
EV::ADNS::r_mx |
| 79 |
An arrayref consisting of the priority and a "host address" (see |
| 80 |
"EV::ADNS::r_ns"). Example: |
| 81 |
|
| 82 |
[10, [["alt3.aspmx.l.google.com", 0, "64.233.189.27", "2404:6800:4008:c07::1a"]]] |
| 83 |
|
| 84 |
EV::ADNS::r_mx_raw |
| 85 |
An arrayref consisting of the priority and the hostname, e.g. |
| 86 |
"[10, "mail.example.com"]". |
| 87 |
|
| 88 |
EV::ADNS::r_soa, EV::ADNS::r_soa_raw |
| 89 |
An arrayref consisting of the primary nameserver, admin name, |
| 90 |
serial, refresh, retry expire and minimum times, e.g.: |
| 91 |
|
| 92 |
["ns.example.net", "hostmaster@example.net", 2000001102, 86400, 21600, 2592000, 172800] |
| 93 |
|
| 94 |
The "raw" form doesn't mangle the e-mail address. |
| 95 |
|
| 96 |
EV::ADNS::r_srv_raw |
| 97 |
An arrayref consisting of the priority, weight, port and |
| 98 |
hostname, e.g.: |
| 99 |
|
| 100 |
[10, 10, 5060, "sip1.example.net"] |
| 101 |
|
| 102 |
EV::ADNS::r_srv |
| 103 |
The same as "EV::ADNS::r_srv_raw", but the hostname is replaced |
| 104 |
by a "host address" (see "EV::ADNS::r_ns"). |
| 105 |
|
| 106 |
EV::ADNS::r_unknown |
| 107 |
A single octet string with the raw contents. |
| 108 |
|
| 109 |
anything else |
| 110 |
Currently "undef". |
| 111 |
|
| 112 |
$query->cancel |
| 113 |
Cancels a request that is in progress. |
| 114 |
|
| 115 |
EV::ADNS::reinit undef, $resolvdata_or_undef |
| 116 |
Cancels all outstanding queries, frees all adns state and |
| 117 |
reinitialises it. It is highly recommended to only call this when |
| 118 |
there are no outstanding requests. |
| 119 |
|
| 120 |
The first argument must currently be specified as "undef". |
| 121 |
|
| 122 |
The second argument can be missing or "undef"; in which case the |
| 123 |
normal initialisation is done (such as reading the resolv.conf), or |
| 124 |
it might be a stirng, in which case no config files or environment |
| 125 |
variables will be read and the given string will be interpreted as |
| 126 |
the resolv.conf contents. |
| 127 |
|
| 128 |
SEE ALSO |
| 129 |
EV, Net::ADNS another interface to adns, maybe better, but without real |
| 130 |
support to integrate it into other event loops. |
| 131 |
|
| 132 |
AUTHOR |
| 133 |
Marc Lehmann <schmorp@schmorp.de> |
| 134 |
http://home.schmorp.de/ |
| 135 |
|