r37475 - in /branches/upstream/libdata-validate-ip-perl/current: Changes META.yml README lib/Data/Validate/IP.pm t/Data-Validate-IP.t
ryan52-guest at users.alioth.debian.org
ryan52-guest at users.alioth.debian.org
Fri Jun 5 15:19:34 UTC 2009
Author: ryan52-guest
Date: Fri Jun 5 15:19:29 2009
New Revision: 37475
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=37475
Log:
[svn-upgrade] Integrating new upstream version, libdata-validate-ip-perl (0.10)
Modified:
branches/upstream/libdata-validate-ip-perl/current/Changes
branches/upstream/libdata-validate-ip-perl/current/META.yml
branches/upstream/libdata-validate-ip-perl/current/README
branches/upstream/libdata-validate-ip-perl/current/lib/Data/Validate/IP.pm
branches/upstream/libdata-validate-ip-perl/current/t/Data-Validate-IP.t
Modified: branches/upstream/libdata-validate-ip-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-validate-ip-perl/current/Changes?rev=37475&op=diff
==============================================================================
--- branches/upstream/libdata-validate-ip-perl/current/Changes (original)
+++ branches/upstream/libdata-validate-ip-perl/current/Changes Fri Jun 5 15:19:29 2009
@@ -1,5 +1,12 @@
Revision history for Perl extension Data::Validate::IP.
+0.10 Thu Jun 04 2009
+ - Added initial support for is_ipv6. ipv6 is new territory for me, so please send in your
+ bug reports to me so that I can make sure I get it done correctly.
+
+0.09 Fri Jan 30 2009
+ - Removed AUTOLOAD
+
0.08 Wed Dec 6 2007
- Fixed is_ipv4 to treat leading 0's in an ip as invalid, i.e.: 017.1.1.1 is invalid
Thanks to Joshua D. Abraham <jabra at spl0it.org> for submitting the patch
Modified: branches/upstream/libdata-validate-ip-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-validate-ip-perl/current/META.yml?rev=37475&op=diff
==============================================================================
--- branches/upstream/libdata-validate-ip-perl/current/META.yml (original)
+++ branches/upstream/libdata-validate-ip-perl/current/META.yml Fri Jun 5 15:19:29 2009
@@ -1,15 +1,21 @@
--- #YAML:1.0
-name: Data-Validate-IP
-version: 0.08
-abstract: ip validation methods
-license: perl
-generated_by: ExtUtils::MakeMaker version 6.36
-distribution_type: module
-requires:
- Net::Netmask: 0
- Test::More: 0
-meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.2.html
- version: 1.2
+name: Data-Validate-IP
+version: 0.10
+abstract: ip validation methods
author:
- Neil Neely <neil at neely.cx>
+license: perl
+distribution_type: module
+configure_requires:
+ ExtUtils::MakeMaker: 0
+requires:
+ Net::Netmask: 0
+ Test::More: 0
+no_index:
+ directory:
+ - t
+ - inc
+generated_by: ExtUtils::MakeMaker version 6.46
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
Modified: branches/upstream/libdata-validate-ip-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-validate-ip-perl/current/README?rev=37475&op=diff
==============================================================================
--- branches/upstream/libdata-validate-ip-perl/current/README (original)
+++ branches/upstream/libdata-validate-ip-perl/current/README Fri Jun 5 15:19:29 2009
@@ -64,6 +64,26 @@
actually exists. It only looks to see that the format is
appropriate.
+ is_ipv6 - does the value look like an ip v6 address?
+ is_ipv6($value);
+
+ *Description*
+ Returns the untainted ip address if the test value appears to be
+ a well-formed ip address.
+
+ *Arguments*
+
+ $value
+ The potential ip to test.
+
+ *Returns*
+ Returns the untainted ip on success, undef on failure.
+
+ *Notes, Exceptions, & Bugs*
+ The function does not make any attempt to check whether an ip
+ actually exists. It only looks to see that the format is
+ appropriate.
+
is_private_ipv4 - is it a valid private ipv4 address
is_private_ipv4($value);
or
@@ -209,6 +229,37 @@
addresses by auto-configuration, such as when a DHCP server may not
be found.
+ is_linklocal_ipv6 - is it a valid link-local ipv6 address
+ is_linklocal_ipv6($value);
+ or
+ $obj->is_linklocal_ipv6($value);
+
+ *Description*
+ Returns the untainted ip addres if the test value appears to be
+ a well-formed link-local ip address.
+
+ *Arguments*
+
+ $value
+ The potential ip to test.
+
+ *Returns*
+ Returns the untainted ip on success, undef on failure.
+
+ *Notes, Exceptions, & Bugs*
+ The function does not make any attempt to check whether an ip
+ actually exists.
+
+ *From RFC 2462*
+ A link-local address is formed by prepending the well-known link-
+ local prefix FE80::0 [ADDR-ARCH] (of appropriate length) to the
+ interface identifier. If the interface identifier has a length of N
+ bits, the interface identifier replaces the right-most N zero bits of
+ the link-local prefix. If the interface identifier is more than 118
+ bits in length, autoconfiguration fails and manual configuration is
+ required. Note that interface identifiers will typically be 64-bits
+ long and based on EUI-64 identifiers as described in [ADDR-ARCH].
+
is_public_ipv4 - is it a valid public ipv4 address
is_public_ipv4($value);
or
@@ -232,12 +283,18 @@
private/testnet/loopback ip.
SEE ALSO
+ IPv4
+
b<[RFC 3330] [RFC 1918] [RFC 1700]>
+ IPv6
+
+ b<[RFC 2460] [RFC 4291] [RFC 4294]>
+
Data::Validate(3)
-TODO
- Add in support for verifying IPv6 addresses.
+IPv6
+ IPv6 Support is new, please test it thoroughly and report any bugs.
AUTHOR
Neil Neely <neil at neely.cx>.
@@ -250,7 +307,7 @@
is_multicast_ipv4 and is_linklocal_ipv4 code.
COPYRIGHT AND LICENSE
- Copyright (c) 2005-2007 Neil Neely.
+ Copyright (c) 2005-2009 Neil Neely.
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself, either Perl version 5.8.2 or, at
Modified: branches/upstream/libdata-validate-ip-perl/current/lib/Data/Validate/IP.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-validate-ip-perl/current/lib/Data/Validate/IP.pm?rev=37475&op=diff
==============================================================================
--- branches/upstream/libdata-validate-ip-perl/current/lib/Data/Validate/IP.pm (original)
+++ branches/upstream/libdata-validate-ip-perl/current/lib/Data/Validate/IP.pm Fri Jun 5 15:19:29 2009
@@ -3,11 +3,10 @@
use strict;
use warnings;
use Net::Netmask;
-#use Net::IPv6Addr;
require Exporter;
-use AutoLoader 'AUTOLOAD';
+#use AutoLoader 'AUTOLOAD';
use constant LOOPBACK => [qw(127.0.0.0/8)];
use constant TESTNET => [qw(192.0.2.0/24)];
@@ -32,16 +31,17 @@
our @EXPORT = qw(
is_ipv4
+ is_ipv6
is_private_ipv4
is_loopback_ipv4
is_testnet_ipv4
is_public_ipv4
is_multicast_ipv4
is_linklocal_ipv4
+ is_linklocal_ipv6
);
-# is_ipv6
-
-our $VERSION = '0.08';
+
+our $VERSION = '0.10';
#Global, we store this only once
my %MASK;
@@ -49,8 +49,6 @@
# Preloaded methods go here.
-1;
-__END__
#
=head1 NAME
@@ -180,56 +178,85 @@
return join('.', @octets);
}
+
# -------------------------------------------------------------------------------
#
-#=pod
-#
-#=item B<is_ipv6> - does the value look like an ip v6 address?
-#
-# is_ipv6($value);
-#
-#=over 4
-#
-#=item I<Description>
-#
-#Returns the untainted ip address if the test value appears to be a well-formed
-#ip address.
-#
-#=item I<Arguments>
-#
-#=over 4
-#
-#=item $value
-#
-#The potential ip to test.
-#
-#=back
-#
-#=item I<Returns>
-#
-#Returns the untainted ip on success, undef on failure.
-#
-#=item I<Notes, Exceptions, & Bugs>
-#
-#The function does not make any attempt to check whether an ip
-#actually exists. It only looks to see that the format is appropriate.
-#All the real work for this is done by Net::IPv6Addr.
-#
-#=back
-#
-#=cut
-#
-#
-#
-#
-#sub is_ipv6 {
-# my $self = shift if ref($_[0]);
-# my $value = shift;
-#
-# return unless defined($value);
-# my $return = Net::IPv6Addr::is_ipv6($value);;
-# return $return;
-#}
+
+=pod
+
+=item B<is_ipv6> - does the value look like an ip v6 address?
+
+ is_ipv6($value);
+
+=over 4
+
+=item I<Description>
+
+Returns the untainted ip address if the test value appears to be a well-formed
+ip address.
+
+=item I<Arguments>
+
+=over 4
+
+=item $value
+
+The potential ip to test.
+
+=back
+
+=item I<Returns>
+
+Returns the untainted ip on success, undef on failure.
+
+=item I<Notes, Exceptions, & Bugs>
+
+The function does not make any attempt to check whether an ip
+actually exists. It only looks to see that the format is appropriate.
+
+=back
+
+=cut
+
+
+sub is_ipv6 {
+ my $self = shift if ref($_[0]);
+ my $value = shift;
+
+ return unless defined($value);
+
+ # if there is a :: then there must be only one ::
+ # and the length can be variable
+ # without it, the length must be 8 groups
+
+ my (@chunks) = split(':', $value);
+ #need to see if last chunk is an ipv4 address, if it is we pop it off and
+ #exempt it from the normal ipv6 checking and stick it back on at the end.
+ #if only one chunk and it matches it isn't ipv6 - it is a ipv4 address only
+ my $ipv4;
+ if (@chunks > 1 && is_ipv4($chunks[$#chunks])) {
+ $ipv4 = pop(@chunks);
+ }
+ my $empty = 0;
+ foreach (@chunks) {
+ return unless (/^[0123456789abcdef]{0,4}$/i);
+ $empty++ if /^$/;
+ }
+ #More than one :: block is bad, but if it starts with :: it will look like two, so we need an exception.
+ if ($empty == 2 && $value =~ /^::/) {
+ #This is ok
+ } elsif ($empty > 1) {
+ return;
+ }
+
+ if (defined $ipv4) {
+ push(@chunks, $ipv4);
+ }
+ #Need 8 chunks, or we need an empty section that could be filled to represent the missing '0' sections
+ return unless (@chunks == 8 || @chunks < 8 && $empty);
+
+ return join(':', @chunks);
+}
=pod
@@ -537,6 +564,71 @@
return unless Net::Netmask::findNetblock($ip,_mask('linklocal'));
return $ip;
}
+
+=pod
+
+=item B<is_linklocal_ipv6> - is it a valid link-local ipv6 address
+
+ is_linklocal_ipv6($value);
+ or
+ $obj->is_linklocal_ipv6($value);
+
+=over 4
+
+=item I<Description>
+
+Returns the untainted ip addres if the test value appears to be a well-formed
+link-local ip address.
+
+=item I<Arguments>
+
+=over 4
+
+=item $value
+
+The potential ip to test.
+
+=back
+
+=item I<Returns>
+
+Returns the untainted ip on success, undef on failure.
+
+=item I<Notes, Exceptions, & Bugs>
+
+The function does not make any attempt to check whether an ip
+actually exists.
+
+=item I<From RFC 2462>
+
+ A link-local address is formed by prepending the well-known link-
+ local prefix FE80::0 [ADDR-ARCH] (of appropriate length) to the
+ interface identifier. If the interface identifier has a length of N
+ bits, the interface identifier replaces the right-most N zero bits of
+ the link-local prefix. If the interface identifier is more than 118
+ bits in length, autoconfiguration fails and manual configuration is
+ required. Note that interface identifiers will typically be 64-bits
+ long and based on EUI-64 identifiers as described in [ADDR-ARCH].
+
+=back
+
+=cut
+
+
+sub is_linklocal_ipv6 {
+ my $self = shift if ref($_[0]);
+ my $value = shift;
+
+ return unless defined($value);
+
+ my $ip = is_ipv6($value);
+ return unless defined $ip;
+
+ return unless $ip =~ /^fe80:/i;
+ return $ip;
+}
+
+
@@ -628,23 +720,33 @@
}
+1;
+__END__
+
+
# -------------------------------------------------------------------------------
=back
=head1 SEE ALSO
+IPv4
+
b<[RFC 3330] [RFC 1918] [RFC 1700]>
+IPv6
+
+b<[RFC 2460] [RFC 4291] [RFC 4294]>
+
=over 4
=item L<Data::Validate(3)>
=back
-=head1 TODO
-
-Add in support for verifying IPv6 addresses.
+=head1 IPv6
+
+IPv6 Support is new, please test it thoroughly and report any bugs.
=head1 AUTHOR
@@ -658,7 +760,7 @@
=head1 COPYRIGHT AND LICENSE
-Copyright (c) 2005-2007 Neil Neely.
+Copyright (c) 2005-2009 Neil Neely.
Modified: branches/upstream/libdata-validate-ip-perl/current/t/Data-Validate-IP.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-validate-ip-perl/current/t/Data-Validate-IP.t?rev=37475&op=diff
==============================================================================
--- branches/upstream/libdata-validate-ip-perl/current/t/Data-Validate-IP.t (original)
+++ branches/upstream/libdata-validate-ip-perl/current/t/Data-Validate-IP.t Fri Jun 5 15:19:29 2009
@@ -5,8 +5,8 @@
# change 'tests => 1' to 'tests => last_test_to_print';
-use Test::More tests => 25;
-BEGIN { use_ok('Data::Validate::IP', qw(is_ipv4 is_private_ipv4 is_loopback_ipv4 is_testnet_ipv4 is_public_ipv4 is_multicast_ipv4 is_linklocal_ipv4) ) };
+use Test::More tests => 43;
+BEGIN { use_ok('Data::Validate::IP', qw(is_ipv4 is_ipv6 is_private_ipv4 is_loopback_ipv4 is_testnet_ipv4 is_public_ipv4 is_multicast_ipv4 is_linklocal_ipv4 is_linklocal_ipv6) ) };
#########################
@@ -41,6 +41,24 @@
isnt ('216.17.184.1', is_linklocal_ipv4('216.17.184.1'), 'is_linklocal_ipv4 216.17.184.1');
isnt ('169.254.0.1', is_public_ipv4('169.254.0.1'), 'is_public_ipv4 169.254.0.1');
-#Disabled ipv6 checks for now
-#is ('::216.17.184.1', is_ipv6('::216.17.184.1'), 'is_ipv6 ::216.17.184.1');
-#isnt ('216.17.184.1', is_ipv6('216.17.184.1'), 'is_ipv6 216.17.184.1');
+isnt ('2067:fa88', is_ipv6('2067:fa88'), 'is_ipv6 2067:fa88');
+isnt ('2067:FA88', is_ipv6('2067:FA88'), 'is_ipv6 2067:FA88');
+is ('2067:fa88::0', is_ipv6('2067:fa88::0'), 'is_ipv6 2067:fa88::0');
+is ('2067:FA88::1', is_ipv6('2067:FA88::1'), 'is_ipv6 2067:FA88::1');
+is ('2607:fa88::8a2e:370:7334', is_ipv6('2607:fa88::8a2e:370:7334'), 'is_ipv6 2607:fa88::8a2e:370:7334');
+is ('2001:0db8:0000:0000:0000:0000:1428:57ab', is_ipv6('2001:0db8:0000:0000:0000:0000:1428:57ab'), 'is_ipv6 2001:0db8:0000:0000:0000:0000:1428:57ab');
+is ('2001:0db8:0000:0000:0000::1428:57ab', is_ipv6('2001:0db8:0000:0000:0000::1428:57ab'), 'is_ipv6 2001:0db8:0000:0000:0000::1428:57ab');
+is ('2001:0db8:0:0:0:0:1428:57ab', is_ipv6('2001:0db8:0:0:0:0:1428:57ab'), 'is_ipv6 2001:0db8:0:0:0:0:1428:57ab');
+is ('2001:0db8:0:0::1428:57ab', is_ipv6('2001:0db8:0:0::1428:57ab'), 'is_ipv6 2001:0db8:0:0::1428:57ab');
+is ('2001:0db8::1428:57ab', is_ipv6('2001:0db8::1428:57ab'), 'is_ipv6 2001:0db8::1428:57ab');
+is ('2001:db8::1428:57ab', is_ipv6('2001:db8::1428:57ab'), 'is_ipv6 2001:db8::1428:57ab');
+is ('::0', is_ipv6('::0'), 'is_ipv6 ::0');
+is ('::1', is_ipv6('::1'), 'is_ipv6 ::1');
+is ('::ffff:12.34.56.78', is_ipv6('::ffff:12.34.56.78'), 'is_ipv6 ::ffff:12.34.56.78');
+
+isnt ('216.17.184.1', is_ipv6('216.17.184.1'), 'is_ipv6 216.17.184.1');
+isnt ('bbb.bbb.bbb', is_ipv6('bbb.bbb.bbb'), 'is_ipv6 bbb.bbb.bbb');
+
+isnt ('fe80:db8', is_linklocal_ipv6('fe80:db8'), 'is_linklocal_ipv6 fe80:db8');
+is ('fe80:db8::4', is_linklocal_ipv6('fe80:db8::4'), 'is_linklocal_ipv6 fe80:db8::4');
+
More information about the Pkg-perl-cvs-commits
mailing list