diff --git a/lib/SNMP/Info.pm b/lib/SNMP/Info.pm index 7e7d7dee..177a809d 100644 --- a/lib/SNMP/Info.pm +++ b/lib/SNMP/Info.pm @@ -3756,14 +3756,17 @@ sub munge_e_type { Takes the SNMP::Session C argument and determines if it is an 'IPv4' or 'IPv6' host. 'IPv6' hosts are prefixed with the C C as required by the undelying C library. -If unable to determine the type of address or resolve a DNS name, 'undef' -will be returned causing the session creation to fail. +If unable to determine the type of address or resolve a DNS name, dies with +C. =cut sub resolve_desthost { 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); if ($ip and $ip->bits == 32) { @@ -3773,7 +3776,7 @@ sub resolve_desthost { return 'udp6:' . $ip->addr; } else { - return; + croak "Unable to resolve DestHost: $desthost to an IP\n"; } } @@ -4548,7 +4551,6 @@ sub snmp_connect_ip { return if $self->{Offline}; $ip = resolve_desthost($ip); - return unless $ip; return if ( $ip eq '0.0.0.0' ) or ( $ip =~ /^127\./ ); # Create session object diff --git a/xt/lib/Test/SNMP/Info.pm b/xt/lib/Test/SNMP/Info.pm index 71fe4791..e423ac35 100644 --- a/xt/lib/Test/SNMP/Info.pm +++ b/xt/lib/Test/SNMP/Info.pm @@ -781,7 +781,7 @@ sub munge_e_type : Tests(3) { '.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; can_ok($test->{info}, 'resolve_desthost'); @@ -792,11 +792,19 @@ sub resolve_desthost : Tests(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)); + 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( SNMP::Info::resolve_desthost('fe80::2d0:b7ff:fe21:c6c0'), 'udp6:fe80:0:0:0:2d0:b7ff:fe21:c6c0', 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) {