fix poking into DNS HOSTS
This commit is contained in:
@@ -8,6 +8,13 @@ use Net::DNS;
|
|||||||
use AnyEvent::DNS;
|
use AnyEvent::DNS;
|
||||||
use NetAddr::IP::Lite ':lower';
|
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';
|
use base 'Exporter';
|
||||||
our @EXPORT = ();
|
our @EXPORT = ();
|
||||||
our @EXPORT_OK = qw/
|
our @EXPORT_OK = qw/
|
||||||
@@ -94,27 +101,16 @@ addresses which resolved.
|
|||||||
|
|
||||||
=cut
|
=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 {
|
sub hostnames_resolve_async {
|
||||||
my $ips = shift;
|
my $ips = shift;
|
||||||
|
|
||||||
my $resolver = AnyEvent::DNS->new();
|
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
|
# Set up the condvar
|
||||||
my $done = AE::cv;
|
my $done = AE::cv;
|
||||||
$done->begin( sub { shift->send } );
|
$done->begin( sub { shift->send } );
|
||||||
@@ -124,8 +120,8 @@ sub hostnames_resolve_async {
|
|||||||
next IP if no_resolve($ip);
|
next IP if no_resolve($ip);
|
||||||
|
|
||||||
# check /etc/hosts file and short-circuit if found
|
# check /etc/hosts file and short-circuit if found
|
||||||
foreach my $name (reverse sort keys %AnyEvent::DNS::EtcHosts::HOSTS) {
|
foreach my $name (reverse sort keys %HOSTS) {
|
||||||
if ($AnyEvent::DNS::EtcHosts::HOSTS{$name}->[0]->[0] eq $ip) {
|
if ($HOSTS{$name}->[0]->[0] eq $ip) {
|
||||||
$hash_ref->{'dns'} = $name;
|
$hash_ref->{'dns'} = $name;
|
||||||
next IP;
|
next IP;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user