AnyEvent
view release on metacpan or search on metacpan
lib/AnyEvent/DNS.pm view on Meta::CPAN
resource record decoders.
Since this is experimental, it can change, as anything can change, but
this interface is expe ctedc to be relatively stable and was stable during
the whole existance of C<AnyEvent::DNS> so far.
Note that, since changing the decoder or encoder might break existing
code, you should either be sure to control for this, or only temporarily
change these values, e.g. like so:
my $decoded = do {
local $AnyEvent::DNS::opcode_str{7} = "yxrrset";
AnyEvent::DNS::dns_unpack $mypkt
};
=over 4
=item %AnyEvent::DNS::opcode_id, %AnyEvent::DNS::opcode_str
Two hashes that map lowercase opcode strings to numerical id's (For the
encoder), or vice versa (for the decoder). Example: add a new opcode
lib/AnyEvent/DNS.pm view on Meta::CPAN
Same as above, but for resource record class names/values.
=item %AnyEvent::DNS::type_id, %AnyEvent::DNS::type_str
Same as above, but for resource record type names/values.
=item %AnyEvent::DNS::dec_rr
This hash maps resource record type values to code references. When
decoding, they are called with C<$_> set to the undecoded data portion and
C<$ofs> being the current byte offset. of the record. You should have a
look at the existing implementations to understand how it works in detail,
but here are two examples:
Decode an A record. A records are simply four bytes with one byte per
address component, so the decoder simply unpacks them and joins them with
dots in between:
$AnyEvent::DNS::dec_rr{1} = sub { join ".", unpack "C4", $_ };
lib/AnyEvent/DNS.pm view on Meta::CPAN
This is the main low-level workhorse for sending DNS requests.
This function sends a single request (a hash-ref formated as specified
for C<dns_pack>) to the configured nameservers in turn until it gets a
response. It handles timeouts, retries and automatically falls back to
virtual circuit mode (TCP) when it receives a truncated reply. It does not
handle anything else, such as the domain searchlist or relative names -
use C<< ->resolve >> for that.
Calls the callback with the decoded response packet if a reply was
received, or no arguments in case none of the servers answered.
=cut
sub request($$) {
my ($self, $req, $cb) = @_;
# _enc_name barfs on names that are too long, which is often outside
# program control, so check for too long names here.
for (@{ $req->{qd} }) {
lib/AnyEvent/DNS.pm view on Meta::CPAN
The callback will be invoked with arraryefs of the form C<[$name,
$type, $class, $ttl, @data>], where C<$name> is the domain name,
C<$type> a type string or number, C<$class> a class name, C<$ttl> is the
remaining time-to-live and C<@data> is resource-record-dependent data, in
seconds. For C<a> records, this will be the textual IPv4 addresses, for
C<ns> or C<cname> records this will be a domain name, for C<txt> records
these are all the strings and so on.
All types mentioned in RFC 1035, C<aaaa>, C<srv>, C<naptr> and C<spf> are
decoded. All resource records not known to this module will have the raw
C<rdata> field as fifth array element.
Note that this resolver is just a stub resolver: it requires a name server
supporting recursive queries, will not do any recursive queries itself and
is not secure when used against an untrusted name server.
The following options are supported:
=over 4
lib/AnyEvent/Handle.pm view on Meta::CPAN
}
}
};
=item storable => $cb->($handle, $ref)
Deserialises a L<Storable> frozen representation as written by the
C<storable> write type (BER-encoded length prefix followed by nfreeze'd
data).
Raises C<EBADMSG> error if the data could not be decoded.
=cut
register_read_type storable => sub {
my ($self, $cb) = @_;
require Storable unless $Storable::VERSION;
sub {
# when we can use 5.10 we can use ".", but for 5.8 we use the re-pack method
( run in 0.245 second using v1.01-cache-2.11-cpan-26ccb49234f )