fix poking into DNS HOSTS
This commit is contained in:
@@ -8,6 +8,13 @@ use Net::DNS;
|
||||
use AnyEvent::DNS;
|
||||
use NetAddr::IP::Lite ':lower';
|
||||
|
||||
# AE::DNS::EtcHosts only works for A/AAAA/SRV, but we want PTR.
|
||||
# this loads+parses /etc/hosts file using AE. dirty hack.
|
||||
use AnyEvent::Socket 'format_address';
|
||||
use AnyEvent::DNS::EtcHosts;
|
||||
AnyEvent::DNS::EtcHosts::_load_hosts_unless(sub{},AE::cv);
|
||||
no AnyEvent::DNS::EtcHosts; # unimport
|
||||
|
||||
use base 'Exporter';
|
||||
our @EXPORT = ();
|
||||
our @EXPORT_OK = qw/
|
||||
@@ -94,26 +101,15 @@ addresses which resolved.
|
||||
|
||||
=cut
|
||||
|
||||
# AE::DNS::EtcHosts only works for A/AAAA/SRV, but we want PTR.
|
||||
# this loads+parses /etc/hosts file using AE. dirty hack.
|
||||
|
||||
BEGIN {
|
||||
use AnyEvent::Socket 'format_address';
|
||||
|
||||
use AnyEvent::DNS::EtcHosts;
|
||||
AnyEvent::DNS::EtcHosts::_load_hosts_unless(sub{},AE::cv);
|
||||
no AnyEvent::DNS::EtcHosts; # unimport
|
||||
|
||||
$AnyEvent::DNS::EtcHosts::HOSTS{$_}
|
||||
= [ map { [ format_address $_->[0] ] }
|
||||
@{$AnyEvent::DNS::EtcHosts::HOSTS{$_}} ]
|
||||
for keys %AnyEvent::DNS::EtcHosts::HOSTS;
|
||||
}
|
||||
|
||||
sub hostnames_resolve_async {
|
||||
my $ips = shift;
|
||||
|
||||
my $resolver = AnyEvent::DNS->new();
|
||||
|
||||
my %HOSTS = ();
|
||||
$HOSTS{$_} = [ map { [ format_address $_->[0] ] }
|
||||
@{$AnyEvent::DNS::EtcHosts::HOSTS{$_}} ]
|
||||
for keys %AnyEvent::DNS::EtcHosts::HOSTS;
|
||||
|
||||
# Set up the condvar
|
||||
my $done = AE::cv;
|
||||
@@ -124,8 +120,8 @@ sub hostnames_resolve_async {
|
||||
next IP if no_resolve($ip);
|
||||
|
||||
# check /etc/hosts file and short-circuit if found
|
||||
foreach my $name (reverse sort keys %AnyEvent::DNS::EtcHosts::HOSTS) {
|
||||
if ($AnyEvent::DNS::EtcHosts::HOSTS{$name}->[0]->[0] eq $ip) {
|
||||
foreach my $name (reverse sort keys %HOSTS) {
|
||||
if ($HOSTS{$name}->[0]->[0] eq $ip) {
|
||||
$hash_ref->{'dns'} = $name;
|
||||
next IP;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user