If we were given an IPv6 transport-specifier strip it before trying to resolve it
Since DestHost defaults to 'localhost' die instead of returning undef from resolve_desthost()
This commit is contained in:
@@ -3756,14 +3756,17 @@ sub munge_e_type {
|
|||||||
Takes the SNMP::Session C<DestHost> argument and determines if it is an
|
Takes the SNMP::Session C<DestHost> argument and determines if it is an
|
||||||
'IPv4' or 'IPv6' host. 'IPv6' hosts are prefixed with the C<udp6:>
|
'IPv4' or 'IPv6' host. 'IPv6' hosts are prefixed with the C<udp6:>
|
||||||
C<transport-specifier> as required by the undelying C<Net-SNMP> library.
|
C<transport-specifier> as required by the undelying C<Net-SNMP> library.
|
||||||
If unable to determine the type of address or resolve a DNS name, 'undef'
|
If unable to determine the type of address or resolve a DNS name, dies with
|
||||||
will be returned causing the session creation to fail.
|
C<croak>.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub resolve_desthost {
|
sub resolve_desthost {
|
||||||
my $desthost = shift;
|
my $desthost = shift;
|
||||||
|
|
||||||
|
# If we have an IPv6 transport-specifier strip it
|
||||||
|
$desthost =~ s/^(?:udp6:|udpv6:|udpipv6:)//x;
|
||||||
|
|
||||||
my $ip = NetAddr::IP::Lite->new($desthost);
|
my $ip = NetAddr::IP::Lite->new($desthost);
|
||||||
|
|
||||||
if ($ip and $ip->bits == 32) {
|
if ($ip and $ip->bits == 32) {
|
||||||
@@ -3773,7 +3776,7 @@ sub resolve_desthost {
|
|||||||
return 'udp6:' . $ip->addr;
|
return 'udp6:' . $ip->addr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return;
|
croak "Unable to resolve DestHost: $desthost to an IP\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4548,7 +4551,6 @@ sub snmp_connect_ip {
|
|||||||
return if $self->{Offline};
|
return if $self->{Offline};
|
||||||
|
|
||||||
$ip = resolve_desthost($ip);
|
$ip = resolve_desthost($ip);
|
||||||
return unless $ip;
|
|
||||||
return if ( $ip eq '0.0.0.0' ) or ( $ip =~ /^127\./ );
|
return if ( $ip eq '0.0.0.0' ) or ( $ip =~ /^127\./ );
|
||||||
|
|
||||||
# Create session object
|
# Create session object
|
||||||
|
|||||||
@@ -781,7 +781,7 @@ sub munge_e_type : Tests(3) {
|
|||||||
'.100.3.6.1.2.1.11.4', 'OID returned when unable to translate');
|
'.100.3.6.1.2.1.11.4', 'OID returned when unable to translate');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub resolve_desthost : Tests(4) {
|
sub resolve_desthost : Tests(6) {
|
||||||
my $test = shift;
|
my $test = shift;
|
||||||
|
|
||||||
can_ok($test->{info}, 'resolve_desthost');
|
can_ok($test->{info}, 'resolve_desthost');
|
||||||
@@ -792,11 +792,19 @@ sub resolve_desthost : Tests(4) {
|
|||||||
is(SNMP::Info::resolve_desthost('::1.2.3.4'),
|
is(SNMP::Info::resolve_desthost('::1.2.3.4'),
|
||||||
'udp6:0:0:0:0:0:0:102:304', q(IPv6 address returns with 'udp6:' prefix));
|
'udp6:0:0:0:0:0:0:102:304', q(IPv6 address returns with 'udp6:' prefix));
|
||||||
|
|
||||||
|
is(
|
||||||
|
SNMP::Info::resolve_desthost('udp6:fe80::2d0:b7ff:fe21:c6c0'),
|
||||||
|
'udp6:fe80:0:0:0:2d0:b7ff:fe21:c6c0',
|
||||||
|
q(Net-SNMP example with 'udp6:' prefix returns expected string)
|
||||||
|
);
|
||||||
|
|
||||||
is(
|
is(
|
||||||
SNMP::Info::resolve_desthost('fe80::2d0:b7ff:fe21:c6c0'),
|
SNMP::Info::resolve_desthost('fe80::2d0:b7ff:fe21:c6c0'),
|
||||||
'udp6:fe80:0:0:0:2d0:b7ff:fe21:c6c0',
|
'udp6:fe80:0:0:0:2d0:b7ff:fe21:c6c0',
|
||||||
q(Net-SNMP example IPv6 address returns with 'udp6:' prefix)
|
q(Net-SNMP example IPv6 address returns with 'udp6:' prefix)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
dies_ok { SNMP::Info::resolve_desthost('1.2.3.4.5') } 'Bad IP dies';
|
||||||
}
|
}
|
||||||
|
|
||||||
sub init : Tests(3) {
|
sub init : Tests(3) {
|
||||||
|
|||||||
Reference in New Issue
Block a user