diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-05-07 12:30:32 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-05-07 12:30:32 +0300 |
commit | c4e539cf7b31c8938ea471419e42f79a87cfb4ea (patch) | |
tree | 91871e9ab571886deb471241adbf06b454c8f0dd | |
parent | 95c82ca2a5562e60463a38519157ae1a8b60ac1a (diff) | |
download | acmeman-c4e539cf7b31c8938ea471419e42f79a87cfb4ea.tar.gz acmeman-c4e539cf7b31c8938ea471419e42f79a87cfb4ea.tar.bz2 |
Use gethostbyname + Socket::inet_ntoa instead of Net::DNS
-rw-r--r-- | Makefile.PL | 2 | ||||
-rwxr-xr-x | acmeman | 38 |
2 files changed, 7 insertions, 33 deletions
diff --git a/Makefile.PL b/Makefile.PL index 53ed39a..1fad0ba 100644 --- a/Makefile.PL +++ b/Makefile.PL | |||
@@ -31,7 +31,7 @@ my %makefile_args = ( | |||
31 | 'Pod::Man' => 2.25, | 31 | 'Pod::Man' => 2.25, |
32 | 'Text::ParseWords' => 3.27, | 32 | 'Text::ParseWords' => 3.27, |
33 | 'Data::Dumper' => 0, | 33 | 'Data::Dumper' => 0, |
34 | 'Net::DNS' => 0.68, | 34 | 'Socket' => 0, |
35 | 'Sys::Hostname' => 1.16 | 35 | 'Sys::Hostname' => 1.16 |
36 | }, | 36 | }, |
37 | 37 | ||
@@ -29,7 +29,7 @@ use File::Path qw(make_path); | |||
29 | use DateTime::Format::Strptime; | 29 | use DateTime::Format::Strptime; |
30 | use LWP::UserAgent; | 30 | use LWP::UserAgent; |
31 | use LWP::Protocol::https; | 31 | use LWP::Protocol::https; |
32 | use Net::DNS; | 32 | use Socket qw(inet_ntoa); |
33 | use Sys::Hostname; | 33 | use Sys::Hostname; |
34 | use Pod::Usage; | 34 | use Pod::Usage; |
35 | use Pod::Man; | 35 | use Pod::Man; |
@@ -934,38 +934,12 @@ sub coalesce { | |||
934 | 934 | ||
935 | sub resolve { | 935 | sub resolve { |
936 | my $host = shift; | 936 | my $host = shift; |
937 | state $res; | 937 | if (my @addrs = gethostbyname($host)) { |
938 | unless ($res) { | 938 | return map { inet_ntoa($_) } @addrs[4 .. $#addrs]; |
939 | $res = new Net::DNS::Resolver(); | 939 | } else { |
940 | } | 940 | error("$host doesn't resolve"); |
941 | my $q = $res->query($host,'ANY'); | ||
942 | unless ($q) { | ||
943 | if ($res->errorstring eq 'NXDOMAIN') { | ||
944 | debug(1, "$host: no such host"); | ||
945 | } elsif ($res->errorstring eq 'NOERROR') { | ||
946 | debug(1, "$host: no A record"); | ||
947 | } else { | ||
948 | error("$host: " . $res->errorstring); | ||
949 | # FIXME: bail out? | ||
950 | } | ||
951 | return (); | ||
952 | } | ||
953 | my %res; | ||
954 | my %cnames; | ||
955 | my @answer = $q->answer(); | ||
956 | while (my $ans = shift @answer) { | ||
957 | if ($ans->type eq 'A') { | ||
958 | $res{$ans->rdatastr} = 1; | ||
959 | } elsif ($ans->type eq 'CNAME') { | ||
960 | unless ($cnames{$ans->cname}) { # Avoid eventual loops | ||
961 | $cnames{$ans->cname} = 1; | ||
962 | if (my $q = $res->query($ans->cname, 'A')) { | ||
963 | push @answer, ($q->answer()); | ||
964 | } | ||
965 | } | ||
966 | } | ||
967 | } | 941 | } |
968 | keys %res; | 942 | return (); |
969 | } | 943 | } |
970 | 944 | ||
971 | sub myip { | 945 | sub myip { |