diff --git a/IP.pm b/IP.pm index de87e11..eab2564 100644 --- a/IP.pm +++ b/IP.pm @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -# $Id: IP.pm,v 1.4 2002/10/31 13:48:04 lem Exp $ +# $Id: IP.pm,v 1.5 2002/10/31 21:32:20 lem Exp $ package NetAddr::IP; @@ -45,7 +45,7 @@ use strict; use warnings; -our $VERSION = '3.13'; +our $VERSION = '3.14'; ############################################# # These are the overload methods, placed here @@ -411,6 +411,7 @@ my $present = shift; my $addr = ''; + my $a; if ($ip eq 'default' or $ip eq 'any') { vec($addr, 0, 32) = 0x0; @@ -567,8 +568,9 @@ vec($mask, 2, 8) = _obits $3, $7; vec($mask, 3, 8) = _obits $4, $8; } - elsif (my $a = gethostbyname($ip)) { - if (inet_ntoa($a) =~ m!^(\d+)\.(\d+)\.(\d+)\.(\d+)$!) { + elsif (($a = gethostbyname($ip)) and defined($a) + and ($a ne pack("C4", 0, 0, 0, 0))) { + if ($a and inet_ntoa($a) =~ m!^(\d+)\.(\d+)\.(\d+)\.(\d+)$!) { vec($addr, 0, 8) = $1; vec($addr, 1, 8) = $2; vec($addr, 2, 8) = $3; @@ -576,7 +578,6 @@ } } elsif (!$present and length($ip) == 4) { - my @o = unpack("C4", $ip); vec($addr, $_, 8) = $o[$_] for 0 .. 3; @@ -626,7 +627,7 @@ sub new ($$;$) { my $type = $_[0]; my $class = ref($type) || $type || "NetAddr::IP"; - my $ip = $_[1]; + my $ip = lc $_[1]; my $hasmask = 1; my $mask; @@ -637,7 +638,8 @@ $ip = $1; $mask = $2; } - elsif ($ip =~ m!^(default|any|broadcast|loopback)$!) { + elsif (grep { $ip eq $_ } (qw(default any broadcast loopback))) + { $mask = $ip; } } @@ -1221,7 +1223,7 @@ =head1 HISTORY -$Id: IP.pm,v 1.4 2002/10/31 13:48:04 lem Exp $ +$Id: IP.pm,v 1.5 2002/10/31 21:32:20 lem Exp $ =over @@ -1675,6 +1677,18 @@ =back +=item 3.14 + +=over + +=item * + +C in Solaris seems to behave a bit different +from other OSes. Reversed change in 3.13 and added code around this +difference. + +=back + =back =head1 AUTHOR diff --git a/TODO b/TODO index f5f98b8..7e25b7e 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,6 @@ -$Id: TODO,v 1.1 2002/10/31 04:30:23 lem Exp $ +$Id: TODO,v 1.2 2002/10/31 21:32:21 lem Exp $ o Definitely, support for IPv6 addresses. + +o Add support for other notations (when found).