From 9ca88a753c7c1831ebfa17ab9b7e356a131874d1 Mon Sep 17 00:00:00 2001 From: Doug Freed Date: Thu, 14 Jan 2016 23:35:05 -0700 Subject: Fix async DNS resolution to handle things better - Handles CNAMEs now - Handles multiple IPs for a given host --- lib/ASM/Util.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/ASM/Util.pm') diff --git a/lib/ASM/Util.pm b/lib/ASM/Util.pm index dc10d64..55c49ab 100644 --- a/lib/ASM/Util.pm +++ b/lib/ASM/Util.pm @@ -7,6 +7,7 @@ use strict; use Term::ANSIColor qw (:constants); use Socket qw( inet_aton inet_ntoa ); use Data::Dumper; +use Net::DNS 0.55 qw(rrsort); no if $] >= 5.017011, warnings => 'experimental::smartmatch'; @@ -245,12 +246,17 @@ sub stripResp my @answer = $response->answer; if ($response->{header}->{rcode} ne "NOERROR") { dprint($module, Dumper($response), 'dns'); - return; + return undef; } - if ((!(@answer)) || ($answer[0]->{type} ne 'A')) { + if (!(@answer)) { return undef; } - return dottedQuadToInt($module, $answer[0]->{address}); + my @addresses = rrsort('A', @answer); + my @results = (); + foreach my $address (@addresses) { + push @results, dottedQuadToInt($module, $address->{address}); + } + return @results; } sub getHostIPFast -- cgit v1.2.3