Subject: | No longer need USE_SOCKET_IP? |
Hi, now IO::Socket::IP is a requires, couldn't this patch be applied?
Subject: | dns.patch.txt |
diff --git a/lib/Net/DNS/Resolver/Base.pm b/lib/Net/DNS/Resolver/Base.pm
index 36e17514b..db93167ed 100644
--- a/lib/Net/DNS/Resolver/Base.pm
+++ b/lib/Net/DNS/Resolver/Base.pm
@@ -25,12 +25,6 @@ our $VERSION = (qw$LastChangedRevision: 1698 $)[1];
# Olaf Kolkman, RIPE NCC, December 2003.
# [Revised March 2016, June 2018]
-
-use constant USE_SOCKET_IP => defined eval 'use IO::Socket::IP 0.32; 1;';
-
-use constant IPv6 => USE_SOCKET_IP;
-
-
# If SOCKSified Perl, use TCP instead of UDP and keep the socket open.
use constant SOCKS => scalar eval 'require Config; $Config::Config{usesocks}';
@@ -47,6 +41,7 @@ use integer;
use Carp;
use IO::Select;
use IO::Socket;
+use IO::Socket::IP;
use Net::DNS::RR;
use Net::DNS::Packet;
@@ -84,7 +79,7 @@ use constant PACKETSZ => 512;
adflag => 0, # see RFC6840, 5.7
cdflag => 0, # see RFC6840, 5.9
udppacketsize => 0, # value bounded below by PACKETSZ
- force_v4 => ( IPv6 ? 0 : 1 ),
+ force_v4 => 0,
force_v6 => 0, # only relevant if IPv6 is supported
prefer_v4 => 0,
prefer_v6 => 0,
@@ -284,10 +279,8 @@ sub nameservers {
my $packet = $defres->search( $ns, 'A' );
my @iplist = _cname_addr( $packet, $names );
- if (IPv6) {
- $packet = $defres->search( $ns, 'AAAA' );
- push @iplist, _cname_addr( $packet, $names );
- }
+ $packet = $defres->search( $ns, 'AAAA' );
+ push @iplist, _cname_addr( $packet, $names );
my %unique = map( ( $_ => $_ ), @iplist );
@@ -862,7 +855,7 @@ sub _create_tcp_socket {
$self->_diag('socket disconnected (trying to connect)');
}
- my $ip6_addr = IPv6 && _ipv6($ip);
+ my $ip6_addr = _ipv6($ip);
$socket = IO::Socket::IP->new(
LocalAddr => $ip6_addr ? $self->{srcaddr6} : $self->{srcaddr4},
@@ -871,20 +864,7 @@ sub _create_tcp_socket {
PeerPort => $self->{port},
Proto => 'tcp',
Timeout => $self->{tcp_timeout},
- )
- if USE_SOCKET_IP;
-
- unless (USE_SOCKET_IP) {
- $socket = IO::Socket::INET->new(
- LocalAddr => $self->{srcaddr4},
- LocalPort => $self->{srcport} || undef,
- PeerAddr => $ip,
- PeerPort => $self->{port},
- Proto => 'tcp',
- Timeout => $self->{tcp_timeout},
- )
- unless $ip6_addr;
- }
+ );
$self->errorstring("no socket $sock_key $!") unless $socket;
$self->{persistent}{$sock_key} = $self->{persistent_tcp} ? $socket : undef;
@@ -896,8 +876,8 @@ sub _create_udp_socket {
my $self = shift;
my $ip = shift;
- my $ip6_addr = IPv6 && _ipv6($ip);
- my $sock_key = IPv6 && $ip6_addr ? 'UDP/IPv6' : 'UDP/IPv4';
+ my $ip6_addr = _ipv6($ip);
+ my $sock_key = $ip6_addr ? 'UDP/IPv6' : 'UDP/IPv4';
my $socket;
return $socket if $socket = $self->{persistent}{$sock_key};
@@ -906,18 +886,7 @@ sub _create_udp_socket {
LocalPort => $self->{srcport},
Proto => 'udp',
Type => SOCK_DGRAM
- )
- if USE_SOCKET_IP;
-
- unless (USE_SOCKET_IP) {
- $socket = IO::Socket::INET->new(
- LocalAddr => $self->{srcaddr4},
- LocalPort => $self->{srcport} || undef,
- Proto => 'udp',
- Type => SOCK_DGRAM
- )
- unless $ip6_addr;
- }
+ );
$self->errorstring("no socket $sock_key $!") unless $socket;
$self->{persistent}{$sock_key} = $self->{persistent_udp} ? $socket : undef;
@@ -933,18 +902,13 @@ sub _create_udp_socket {
socktype => SOCK_DGRAM
);
- my $ip4 = USE_SOCKET_IP ? {family => AF_INET, @udp} : {};
- my $ip6 = USE_SOCKET_IP ? {family => AF_INET6, @udp} : {};
+ my $ip4 = {family => AF_INET, @udp};
+ my $ip6 = {family => AF_INET6, @udp};
sub _create_dst_sockaddr { ## create UDP destination sockaddr structure
my ( $self, $ip, $port ) = @_;
- unless (USE_SOCKET_IP) {
- return sockaddr_in( $port, inet_aton($ip) ) unless _ipv6($ip);
- }
-
- ( grep ref, Socket::getaddrinfo( $ip, $port, _ipv6($ip) ? $ip6 : $ip4 ), {} )[0]->{addr}
- if USE_SOCKET_IP; # NB: errors raised in socket->send
+ return ( grep ref, Socket::getaddrinfo( $ip, $port, _ipv6($ip) ? $ip6 : $ip4 ), {} )[0]->{addr}; # NB: errors raised in socket->send
}
}