allow override of Net::DNS::Resolver timeout options
This commit is contained in:
@@ -25,16 +25,31 @@ subroutines.
|
|||||||
|
|
||||||
=head1 EXPORT_OK
|
=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.
|
Given an IP address (either IPv4 or IPv6), return the canonical hostname.
|
||||||
|
|
||||||
|
C<< %opts >> can override the various timeouts available in
|
||||||
|
L<Net::DNS::Resolver>:
|
||||||
|
|
||||||
|
=over 4
|
||||||
|
|
||||||
|
=item C<tcp_timeout>: 120 (seconds)
|
||||||
|
|
||||||
|
=item C<udp_timeout>: 30 (seconds)
|
||||||
|
|
||||||
|
=item C<retry>: 4 (attempts)
|
||||||
|
|
||||||
|
=item C<retrans>: 5 (timeout)
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
Returns C<undef> if no PTR record exists for the IP.
|
Returns C<undef> if no PTR record exists for the IP.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub hostname_from_ip {
|
sub hostname_from_ip {
|
||||||
my $ip = shift;
|
my ($ip, $opts) = @_;
|
||||||
return unless $ip;
|
return unless $ip;
|
||||||
my $ETCHOSTS = setting('dns')->{'ETCHOSTS'};
|
my $ETCHOSTS = setting('dns')->{'ETCHOSTS'};
|
||||||
|
|
||||||
@@ -46,6 +61,10 @@ 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);
|
my $query = $res->search($ip);
|
||||||
|
|
||||||
if ($query) {
|
if ($query) {
|
||||||
|
|||||||
Reference in New Issue
Block a user