From 1cdb6f7a634e1117d402f6850b3ffee43bed7c78 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 24 Jun 2017 14:34:52 +0100 Subject: [PATCH] allow override of Net::DNS::Resolver timeout options --- lib/App/Netdisco/Util/DNS.pm | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/App/Netdisco/Util/DNS.pm b/lib/App/Netdisco/Util/DNS.pm index cd8ed25f..978592b5 100644 --- a/lib/App/Netdisco/Util/DNS.pm +++ b/lib/App/Netdisco/Util/DNS.pm @@ -25,16 +25,31 @@ subroutines. =head1 EXPORT_OK -=head2 hostname_from_ip( $ip ) +=head2 hostname_from_ip( $ip, \%opts? ) Given an IP address (either IPv4 or IPv6), return the canonical hostname. +C<< %opts >> can override the various timeouts available in +L: + +=over 4 + +=item C: 120 (seconds) + +=item C: 30 (seconds) + +=item C: 4 (attempts) + +=item C: 5 (timeout) + +=back + Returns C if no PTR record exists for the IP. =cut sub hostname_from_ip { - my $ip = shift; + my ($ip, $opts) = @_; return unless $ip; my $ETCHOSTS = setting('dns')->{'ETCHOSTS'}; @@ -45,7 +60,11 @@ sub hostname_from_ip { } } - my $res = Net::DNS::Resolver->new; + my $res = Net::DNS::Resolver->new; + $res->tcp_timeout($opts->{tcp_timeout} || 120); + $res->udp_timeout($opts->{udp_timeout} || 30); + $res->retry($opts->{retry} || 4); + $res->retrans($opts->{retrans} || 5); my $query = $res->search($ip); if ($query) {