r53604 - in /branches/upstream/libdata-validate-ip-perl/current: Changes META.yml lib/Data/Validate/IP.pm t/Data-Validate-IP.t
gregoa at users.alioth.debian.org
gregoa at users.alioth.debian.org
Fri Mar 5 11:41:39 UTC 2010
Author: gregoa
Date: Fri Mar 5 11:41:33 2010
New Revision: 53604
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=53604
Log:
[svn-upgrade] Integrating new upstream version, libdata-validate-ip-perl (0.11)
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/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=53604&op=diff
==============================================================================
--- branches/upstream/libdata-validate-ip-perl/current/Changes (original)
+++ branches/upstream/libdata-validate-ip-perl/current/Changes Fri Mar 5 11:41:33 2010
@@ -1,4 +1,9 @@
Revision history for Perl extension Data::Validate::IP.
+
+0.11 Mon Mar 01 2010
+ - Added support for is_innet_ipv4 - simple check to see if IP is in network
+ Thanks to "BartÅomiej Syryjczyk" <bartlomiej at syryjczyk.name> for suggesting the function
+
0.10 Thu Jun 04 2009
- Added initial support for is_ipv6. ipv6 is new territory for me, so please send in your
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=53604&op=diff
==============================================================================
--- branches/upstream/libdata-validate-ip-perl/current/META.yml (original)
+++ branches/upstream/libdata-validate-ip-perl/current/META.yml Fri Mar 5 11:41:33 2010
@@ -1,7 +1,7 @@
--- #YAML:1.0
name: Data-Validate-IP
-version: 0.10
-abstract: ip validation methods
+version: 0.11
+abstract: ipv4 and ipv6 validation methods
author:
- Neil Neely <neil at neely.cx>
license: perl
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=53604&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 Mar 5 11:41:33 2010
@@ -6,7 +6,6 @@
require Exporter;
-#use AutoLoader 'AUTOLOAD';
use constant LOOPBACK => [qw(127.0.0.0/8)];
use constant TESTNET => [qw(192.0.2.0/24)];
@@ -32,6 +31,7 @@
our @EXPORT = qw(
is_ipv4
is_ipv6
+ is_innet_ipv4
is_private_ipv4
is_loopback_ipv4
is_testnet_ipv4
@@ -41,7 +41,7 @@
is_linklocal_ipv6
);
-our $VERSION = '0.10';
+our $VERSION = '0.11';
#Global, we store this only once
my %MASK;
@@ -53,23 +53,31 @@
=head1 NAME
-Data::Validate::IP - ip validation methods
+Data::Validate::IP - ipv4 and ipv6 validation methods
=head1 SYNOPSIS
- use Data::Validate::IP qw(is_ipv4);
+ use Data::Validate::IP qw(is_ipv4 is_ipv6);
if(is_ipv4($suspect)){
- print "Looks like an ip address";
+ print "Looks like an ipv4 address";
} else {
- print "Not an ip address\n";
+ print "Not an ipv4 address\n";
+ }
+
+ if(is_ipv6($suspect)){
+ print "Looks like an ipv6 address";
+ } else {
+ print "Not an ipv6 address\n";
}
# or as an object
my $v = Data::Validate::IP->new();
- die "not an ip" unless ($v->is_ipv4('domain.com'));
+ die "not an ipv4 ip" unless ($v->is_ipv4('domain.com'));
+
+ die "not an ipv6 ip" unless ($v->is_ipv6('domain.com'));
=head1 DESCRIPTION
@@ -260,6 +268,85 @@
=pod
+=item B<is_innet_ipv4> - is it a valid ipv4 address in the network specified
+
+ is_innet_ipv4($value,$network);
+ or
+ $obj->is_innet_ipv4($value,$network);
+
+=over 4
+
+=item I<Description>
+
+Returns the untainted ip address if the test value appears to be a well-formed
+ip address inside of the network specified
+
+=item I<Arguments>
+
+=over 4
+
+=item $value
+
+The potential ip to test.
+
+=item $network
+
+The potential network the IP must be a part of. Functionality uses Net::Netmask and should be in the form:
+
+ '216.240.32.0/24' The preferred form.
+
+ '216.240.32.0:255.255.255.0'
+ '216.240.32.0-255.255.255.0'
+ '216.240.32.0 - 216.240.32.255'
+ '216.240.32.4' A /32 block.
+
+ '216.240.32' Always a /24 block.
+
+ '216.240' Always a /16 block.
+
+ '140' Always a /8 block.
+
+ '216.240.32/24'
+ '216.240/16'
+ 'default' 0.0.0.0/0 (the default route)
+
+ '216.240.32.0#0.0.31.255' A hostmask (as used by Cisco
+ access-lists).
+
+Examples taken from Net::Netmask documentation. For more advanced network matching needs please see Net::Netmask.
+
+=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.
+
+=back
+
+=cut
+
+
+sub is_innet_ipv4 {
+ my $self = shift if ref($_[0]);
+ my $value = shift;
+ my $network = shift;
+
+ return unless defined($value);
+
+ my $ip = is_ipv4($value);
+ return unless defined $ip;
+
+ return unless Net::Netmask::findNetblock($ip,_mask($network));
+ return $ip;
+}
+
+=pod
+
=item B<is_private_ipv4> - is it a valid private ipv4 address
is_private_ipv4($value);
@@ -707,7 +794,10 @@
@masks = (MULTICAST);
} elsif ($type eq 'linklocal') {
@masks = (LINKLOCAL);
+ } else {
+ @masks = ([$type]);
}
+
my $mask = {};
foreach my $default (@masks) {
foreach my $range (@{$default}) {
@@ -742,6 +832,8 @@
=item L<Data::Validate(3)>
+=item L<Net::Netmask(3)>
+
=back
=head1 IPv6
@@ -760,7 +852,7 @@
=head1 COPYRIGHT AND LICENSE
-Copyright (c) 2005-2009 Neil Neely.
+Copyright (c) 2005-2010 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=53604&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 Mar 5 11:41:33 2010
@@ -5,8 +5,8 @@
# change 'tests => 1' to 'tests => last_test_to_print';
-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) ) };
+use Test::More tests => 45;
+BEGIN { use_ok('Data::Validate::IP', qw(is_ipv4 is_innet_ipv4 is_ipv6 is_private_ipv4 is_loopback_ipv4 is_testnet_ipv4 is_public_ipv4 is_multicast_ipv4 is_linklocal_ipv4 is_linklocal_ipv6) ) };
#########################
@@ -23,6 +23,9 @@
isnt ('256.17.184.1', is_ipv4('256.17.184.1'), 'is_ipv4 256.17.184.1');
isnt ('216.017.184.1', is_ipv4('216.017.184.1'), 'is_ipv4 216.017.184.1');
isnt ('016.17.184.1', is_ipv4('016.17.184.1'), 'is_ipv4 016.17.184.1');
+
+is ('216.17.184.1', is_innet_ipv4('216.17.184.1','216.17.184.0/24'), 'is_innet_ipv4 216.17.184.1 216.17.184.0/24');
+isnt ('216.17.184.1', is_innet_ipv4('127.0.0.1','216.17.184.0/24'), 'is_innet_ipv4 127.0.0.1 216.17.184.0/24');
is ('10.0.0.1', is_private_ipv4('10.0.0.1'), 'is_private_ipv4 10.0.0.1');
More information about the Pkg-perl-cvs-commits
mailing list