$cb->(map $_->[3], @_);
});
}
sub any($$) {
my ($domain, $cb) = @_;
resolver->resolve ($domain => "*", $cb);
}
# convert textual ip address into reverse lookup form
sub _munge_ptr($) {
my $ipn = $_[0]
or return;
my $ptr;
my $af = AnyEvent::Socket::address_family ($ipn);
if ($af == AF_INET6) {
$ipn = substr $ipn, 0, 16; # anticipate future expansion
# handle v4mapped and v4compat
if ($ipn =~ s/^\x00{10}(?:\xff\xff|\x00\x00)//) {
$af = AF_INET;
} else {
$ptr = join ".", (reverse split //, unpack "H32", $ipn), "ip6.arpa.";
}
}
if ($af == AF_INET) {
$ptr = join ".", (reverse unpack "C4", $ipn), "in-addr.arpa.";
}
$ptr
}
sub reverse_lookup($$) {
my ($ip, $cb) = @_;
$ip = _munge_ptr AnyEvent::Socket::parse_address ($ip)
or return $cb->();
resolver->resolve ($ip => "ptr", sub {
$cb->(map $_->[3], @_);
});
}
sub reverse_verify($$) {
my ($ip, $cb) = @_;
my $ipn = AnyEvent::Socket::parse_address ($ip)
or return $cb->();
my $af = AnyEvent::Socket::address_family ($ipn);
my @res;
my $cnt;
my $ptr = _munge_ptr $ipn
or return $cb->();
$ip = AnyEvent::Socket::format_address ($ipn); # normalise into the same form
ptr $ptr, sub {
for my $name (@_) {
++$cnt;
# () around AF_INET to work around bug in 5.8
resolver->resolve ("$name." => ($af == (AF_INET) ? "a" : "aaaa"), sub {
for (@_) {
push @res, $name
if $_->[3] eq $ip;
}
$cb->(@res) unless --$cnt;
});
}
$cb->() unless $cnt;
};
}
#################################################################################
=back
=head2 LOW-LEVEL DNS EN-/DECODING FUNCTIONS
=over 4
=item $AnyEvent::DNS::EDNS0
This variable decides whether dns_pack automatically enables EDNS0
support. By default, this is disabled (C<0>), unless overridden by
C<$ENV{PERL_ANYEVENT_EDNS0}>, but when set to C<1>, AnyEvent::DNS will use
EDNS0 in all requests.
=cut
our $EDNS0 = $ENV{PERL_ANYEVENT_EDNS0} * 1; # set to 1 to enable (partial) edns0
=3= |