Data-Validate-IP-0.22/0000755000175000017500000000000012250201072014172 5ustar autarchautarchData-Validate-IP-0.22/dist.ini0000644000175000017500000000144612250201072015643 0ustar autarchautarchname = Data-Validate-IP author = Neil Neely author = Dave Rolsky license = Perl_5 copyright_holder = Neil Neely version = 0.22 [NextRelease] format = %-5v %{EEE MMM dd yyyy}d [@Basic] [Authority] authority = cpan:NEELY [InstallGuide] [MetaJSON] [MetaResources] bugtracker.web = http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Validate-IP bugtracker.mailto = bug-data-validate-ip@rt.cpan.org repository.url = https://github.com/neilneely/Data-Validate-IP.git repository.web = https://github.com/neilneely/Data-Validate-IP.git repository.type = git [SurgicalPodWeaver] [PkgVersion] [EOLTests] [NoTabsTests] [PodSyntaxTests] [Test::CPAN::Changes] [Test::Pod::LinkCheck] [Test::Pod::No404s] [AutoPrereqs] skip = Socket [CheckPrereqsIndexed] [@Git] Data-Validate-IP-0.22/perltidyrc0000644000175000017500000000032612250201072016277 0ustar autarchautarch-l=78 -i=4 -ci=4 -se -b -bar -boc -nolq -pt=2 -it=2 --blank-lines-before-packages=0 --no-outdent-long-comments -wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=" Data-Validate-IP-0.22/README0000644000175000017500000000045312250201072015054 0ustar autarchautarch This archive contains the distribution Data-Validate-IP, version 0.22: IPv4 and IPv6 validation methods This software is copyright (c) 2013 by Neil Neely. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Data-Validate-IP-0.22/bench/0000755000175000017500000000000012250201072015251 5ustar autarchautarchData-Validate-IP-0.22/bench/socket-vs-perl0000644000175000017500000000175712250201072020064 0ustar autarchautarchuse strict; use warnings; use Benchmark qw( cmpthese ); use Data::Validate::IP; unless ($Data::Validate::IP::HAS_SOCKET) { warn "Cannot load inet_pton from Socket\n"; exit; } my @bad = ('a' .. 'z', undef, 0); my @ipv4 = @bad; for (1 .. 500) { push @ipv4, _random_ipv4(); } my @ipv6 = @bad; push @ipv6, '::', '::0'; for (1 .. 500) { push @ipv6, _random_ipv6(); } cmpthese( 10000, { 'pure Perl ipv4' => sub { Data::Validate::IP::_slow_is_ipv4($_) for @ipv4 }, 'Socket ipv4' => sub { Data::Validate::IP::_fast_is_ipv4($_) for @ipv4 }, } ); cmpthese( 10000, { 'pure Perl ipv6' => sub { Data::Validate::IP::_slow_is_ipv6($_) for @ipv6 }, 'Socket ipv6' => sub { Data::Validate::IP::_fast_is_ipv6($_) for @ipv6 }, } ); sub _random_ipv4 { return join '.', map { int(rand(256)) } 1 .. 4; } sub _random_ipv6 { return join '::', map { sprintf('%4x', int(rand(2**16))) } 1 .. 8; } Data-Validate-IP-0.22/t/0000755000175000017500000000000012250201072014435 5ustar autarchautarchData-Validate-IP-0.22/t/Untaint.t0000644000175000017500000000416412250201072016251 0ustar autarchautarch#!perl -T use strict; use warnings; use Test::More 0.88; use Test::Requires { 'Test::Taint' => 0, }; use Data::Validate::IP; taint_checking_ok('taint is enabled') or BAIL_OUT('Cannot continue unless taint is enabled'); _test_good_data('is_ipv4', '1.2.3.4'); _test_bad_data('is_ipv4', '1.2.3.999'); _test_good_data( 'is_innet_ipv4', [ '216.17.184.1', '216.17.184.0/24' ], '216.17.184.1' ); _test_bad_data( 'is_innet_ipv4', [ '127.0.0.1', '216.17.184.0/24' ], ); _test_good_data('is_private_ipv4', '10.0.0.1'); _test_bad_data('is_private_ipv4', '1.2.3.4'); _test_good_data('is_public_ipv4', '1.2.3.4'); _test_bad_data('is_public_ipv4', '10.0.0.1'); _test_good_data('is_loopback_ipv4', '127.0.0.1'); _test_bad_data('is_loopback_ipv4', '10.0.0.1'); _test_good_data('is_testnet_ipv4', '192.0.2.9'); _test_bad_data('is_testnet_ipv4', '10.0.0.1'); _test_good_data('is_multicast_ipv4', '224.0.0.1'); _test_bad_data('is_multicast_ipv4', '10.0.0.1'); _test_good_data('is_linklocal_ipv4', '169.254.0.1'); _test_bad_data('is_linklocal_ipv4', '10.0.0.1'); _test_good_data('is_ipv6', '::'); _test_good_data('is_ipv6', 'fff0:1234::'); _test_bad_data('is_ipv6', 'fffff::'); _test_good_data('is_linklocal_ipv6', 'fe80:db8::4'); _test_bad_data('is_linklocal_ipv6', 'fffff::'); sub _test_good_data { my $meth = shift; my $good = shift; my $expect = shift || $good; my @args = _args($good); tainted_ok_deeply(\@args, 'all arguments are tainted'); my $return = Data::Validate::IP->new()->$meth(@args); is($return, $expect, "$meth(@args) returns $expect with tainted value"); untainted_ok( $return, "$meth() returns untained value when value is valid" ); } sub _test_bad_data { my $meth = shift; my $bad = shift; my @args = _args($bad); tainted_ok_deeply(\@args, 'all arguments are tainted'); my $return = Data::Validate::IP->new()->$meth(@args); is($return, undef, "$meth(@args) returns undef with tainted value"); } sub _args { my $args = shift; my @args = ref $args ? @{$args} : $args; taint(@args); return @args; } done_testing(); Data-Validate-IP-0.22/t/Data-Validate-IP-slow.t0000644000175000017500000000024712250201072020515 0ustar autarchautarchuse strict; use warnings; use lib 't/lib'; BEGIN { $ENV{DVI_NO_SOCKET} = 1; } use Test::Data::Validate::IP; use Test::More 0.88; run_tests(); done_testing(); Data-Validate-IP-0.22/t/release-pod-no404s.t0000644000175000017500000000076512250201072020057 0ustar autarchautarch#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; foreach my $env_skip ( qw( SKIP_POD_NO404S AUTOMATED_TESTING ) ){ plan skip_all => "\$ENV{$env_skip} is set, skipping" if $ENV{$env_skip}; } eval "use Test::Pod::No404s"; if ( $@ ) { plan skip_all => 'Test::Pod::No404s required for testing POD'; } else { all_pod_files_ok(); } Data-Validate-IP-0.22/t/release-pod-spell.t0000644000175000017500000000136012250201072020137 0ustar autarchautarch BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::Spelling; my @stopwords; for () { chomp; push @stopwords, $_ unless /\A (?: \# | \s* \z)/msx; # skip comments, whitespace } add_stopwords(@stopwords); set_spell_cmd('aspell list -l en'); # This prevents a weird segfault from the aspell command - see # https://bugs.launchpad.net/ubuntu/+source/aspell/+bug/71322 local $ENV{LC_ALL} = 'C'; all_pod_files_spelling_ok; __DATA__ CIDR IETF IP IPv Neely OO Rolsky Sonnen TEREDO anycast functoins ip ipv loopback multicast namespace routable subnet testnet unicast unroutable validator Data-Validate-IP-0.22/t/Data-Validate-IP.t0000644000175000017500000000017712250201072017535 0ustar autarchautarchuse strict; use warnings; use lib 't/lib'; use Test::Data::Validate::IP; use Test::More 0.88; run_tests(); done_testing(); Data-Validate-IP-0.22/t/release-pod-syntax.t0000644000175000017500000000045012250201072020345 0ustar autarchautarch#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); Data-Validate-IP-0.22/t/release-no-tabs.t0000644000175000017500000000045012250201072017602 0ustar autarchautarch BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; eval 'use Test::NoTabs'; plan skip_all => 'Test::NoTabs required' if $@; all_perl_files_ok(); Data-Validate-IP-0.22/t/release-pod-linkcheck.t0000644000175000017500000000077512250201072020764 0ustar autarchautarch#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; foreach my $env_skip ( qw( SKIP_POD_LINKCHECK ) ){ plan skip_all => "\$ENV{$env_skip} is set, skipping" if $ENV{$env_skip}; } eval "use Test::Pod::LinkCheck"; if ( $@ ) { plan skip_all => 'Test::Pod::LinkCheck required for testing POD'; } else { Test::Pod::LinkCheck->new->all_pod_ok; } Data-Validate-IP-0.22/t/release-cpan-changes.t0000644000175000017500000000052112250201072020565 0ustar autarchautarch#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More 0.96 tests => 2; use_ok('Test::CPAN::Changes'); subtest 'changes_ok' => sub { changes_file_ok('Changes'); }; done_testing(); Data-Validate-IP-0.22/t/lib/0000755000175000017500000000000012250201072015203 5ustar autarchautarchData-Validate-IP-0.22/t/lib/Test/0000755000175000017500000000000012250201072016122 5ustar autarchautarchData-Validate-IP-0.22/t/lib/Test/Data/0000755000175000017500000000000012250201072016773 5ustar autarchautarchData-Validate-IP-0.22/t/lib/Test/Data/Validate/0000755000175000017500000000000012250201072020524 5ustar autarchautarchData-Validate-IP-0.22/t/lib/Test/Data/Validate/IP.pm0000644000175000017500000002035712250201072021401 0ustar autarchautarchpackage # hide from PAUSE Test::Data::Validate::IP; use strict; use warnings; use Data::Validate::IP; use Exporter qw( import ); use Test::More 0.88; our @EXPORT = 'run_tests'; my $object = Data::Validate::IP->new(); my %ipv4_types = ( private => [qw(10.0.0.1 172.16.0.1 192.168.0.1)], public => [qw(1.2.3.4 123.123.44.55 216.17.184.1)], loopback => [qw(127.0.0.1)], testnet => [qw(192.0.2.9 198.51.100.33 203.0.113.44)], multicast => [qw(224.0.0.1)], anycast => [qw(192.88.99.45)], linklocal => [qw(169.254.0.1)], unroutable => [ qw( 0.0.0.1 100.64.1.2 192.0.0.4 198.18.0.55 240.0.0.4 255.255.255.254 255.255.255.255 ) ], ); my %ipv6_types = ( private => [ qw( fc00:: fc01::1234 fdef:: fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff ) ], public => [ qw( ::abcd:1234 1:: 2:: 1:1:1:1:: 2001:abcd:: abcd:: ) ], loopback => [qw(::1)], ipv4_mapped => [ qw( ::ffff:0:0 ::ffff:0:1234 ::ffff:1.2.3.4 ::ffff:ffff:ffff ) ], discard => [ qw( 100:: 100::1234 100:0000:0000:0000:ffff:ffff:ffff:ffff ) ], multicast => [ qw( ff00:: ffff:: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff ) ], linklocal => [ qw( fe80:: fe89:: febf:: febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff ) ], special => [ [ '2001::' => [qw( teredo )] ], [ '2001::1234' => [qw( teredo )] ], qw( 2001:1ff:ffff:ffff:ffff:ffff:ffff:ffff ) ], teredo => [ qw( 2001:: 2001::1234 2001:0:ffff:ffff:ffff:ffff:ffff:ffff ) ], orchid => [ qw( 2001:10:: 2001:10::1234 2001:001F:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF ) ], documentation => [ qw( 2001:db8:: 2001:db8::1234 2001:0db8:ffff:ffff:ffff:ffff:ffff:ffff ) ], ); sub run_tests { _ipv4_basic_tests(); _type_tests(\%ipv4_types, 4); _ipv4_innet_tests(); _ipv6_basic_tests(); _type_tests(\%ipv6_types, 6); } sub _ipv4_basic_tests { my @valid_ipv4 = qw( 0.0.0.0 1.2.3.4 216.17.184.1 255.255.255.255 ); for my $ip (@valid_ipv4) { is(is_ipv4($ip), $ip, "is_ipv4($ip) returns $ip"); is($object->is_ipv4($ip), $ip, "->is_ipv4($ip) returns $ip"); } my @invalid_ipv4 = qw( www.neely.cx 216.17.184.G 216.17.184.1. 216.17.184 216.17.184. 256.17.184.1 216.017.184.1 016.17.184.1 ); for my $ip (@invalid_ipv4) { is(is_ipv4($ip), undef, "is_ipv4($ip) returns undef"); is($object->is_ipv4($ip), undef, "->is_ipv4($ip) returns undef"); for my $type (sort keys %ipv4_types) { my ($is_sub_name, $is_sub) = _sub_for_type($type, 4); is($is_sub->($ip), undef, "$is_sub_name($ip) returns undef"); is( $object->$is_sub_name($ip), undef, "->$is_sub_name($ip) returns undef" ); } } } sub _ipv4_innet_tests { my @tests = ( [ '216.17.184.1', '216.17.184.0/24', 1 ], [ '127.0.0.1', '216.17.184.0/24', 0 ], [ 'invalid', '216.17.184.0/24', 0 ], [ '0.0.0.0', 'default', 1 ], [ '1.2.3.4', 'default', 1 ], [ '216.240.32.1', '216.240.32.1', 1 ], ); # These are accepted for backwards compatibility with the time when we # used Net::Netmask. my @deprecated = ( [ '216.240.32.1', '216.240.32/24', 1, 1 ], [ '216.240.32.1', '216.240/16', 1, 1 ], [ '216.240.32.1', '216.240.32.0:255.255.255.0', 1, 1 ], [ '216.240.32.1', '216.240.32.0-255.255.255.0', 1, 1 ], [ '216.240.32.1', '216.240.32', 1, 1 ], [ '216.240.32.1', '216.240', 1, 1 ], [ '216.240.32.1', '216', 1, 1 ], [ '216.240.32.1', '216.240.32.0#0.0.31.255', 1, 1 ], ); my @warnings; for my $triplet (@tests, @deprecated) { my ($ip, $network, $is_member, $is_deprecated) = @{$triplet}; my $expect = $is_member ? $ip : undef; my $expect_string = $expect || 'undef'; local $SIG{__WARN__} = sub { push @warnings, @_ } if $is_deprecated; is( is_innet_ipv4($ip, $network), $expect, "is_innet_ipv4($ip, $network) returns $expect_string" ); } is( scalar @warnings, 1, 'got one warning from is_innet_ipv4' ); like( $warnings[0], qr/\QUse of non-CIDR notation for networks with is_innet_ipv4() is deprecated/, 'got expected deprecation warning' ); like( $warnings[0], qr/at line \d+ of Test::Data::Validate::IP in sub Test::Data::Validate::IP::_ipv4_innet_tests/, 'deprecation warning identifies caller' ); } sub _ipv6_basic_tests { my @valid = qw( 2067:fa88::0 2067:FA88::1 2607:fa88::8a2e:370:7334 2001:0db8:0000:0000:0000:0000:1428:57ab 2001:0db8:0000:0000:0000::1428:57ab 2001:0db8:0:0:0:0:1428:57ab 2001:0db8:0:0::1428:57ab 2001:0db8::1428:57ab 2001:db8::1428:57ab :: ::0 ::1 ::ffff:12.34.56.78 0:0:0:0:0:ffff:12.34.56.78 ); for my $ip (@valid) { is(is_ipv6($ip), $ip, "is_ipv6($ip) returns $ip"); is($object->is_ipv6($ip), $ip, "->is_ipv6($ip) returns $ip"); } my @invalid = qw( 2067:fa88 2067:FA88 2067::: 2067:::1 2067::1: 216.17.184.1 bbb.bbb.bbb ::: g123::1234 ); for my $ip (@invalid) { is(is_ipv6($ip), undef, "is_ipv6($ip) returns undef"); is($object->is_ipv6($ip), undef, "->is_ipv6($ip) returns undef"); } } sub _type_tests { my $types = shift; my $ip_number = shift; my @types = sort keys %{$types}; for my $type (@types) { for my $test (@{ $types->{$type} }) { my ($ip, $is_also) = ref $test ? @{$test} : ($test, []); my ($is_sub_name, $is_sub) = _sub_for_type($type, $ip_number); is($is_sub->($ip), $ip, "$is_sub_name($ip) returns $ip"); is( $object->$is_sub_name($ip), $ip, "->$is_sub_name($ip) returns $ip" ); for my $other (sort grep { $_ ne $type } @types) { next if grep { $_ eq $other } @{$is_also}; my ($other_sub_name, $other_sub) = _sub_for_type($other, $ip_number); if (Data::Validate::IP::_network_is_subnet_of($type, $other)) { is( $other_sub->($ip), $ip, "$other_sub_name($ip) returns $ip" ); is( $object->$other_sub_name($ip), $ip, "->$other_sub_name($ip) returns $ip" ); } else { is( $other_sub->($ip), undef, "$other_sub_name($ip) returns undef" ); is( $object->$other_sub_name($ip), undef, "->$other_sub_name($ip) returns undef" ); } } } } } sub _sub_for_type { my $type = shift; my $ip_number = shift; my $sub_name = 'is_' . $type . '_ipv' . $ip_number; my $sub = do { no strict 'refs'; \&{$sub_name}; } or die "No sub named $sub_name was imported"; return ($sub_name, $sub); } 1; Data-Validate-IP-0.22/t/release-eol.t0000644000175000017500000000047612250201072017026 0ustar autarchautarch BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; use Test::More; eval 'use Test::EOL'; plan skip_all => 'Test::EOL required' if $@; all_perl_files_ok({ trailing_whitespace => 1 }); Data-Validate-IP-0.22/Makefile.PL0000644000175000017500000000303412250201072016144 0ustar autarchautarch use strict; use warnings; use 5.008; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "IPv4 and IPv6 validation methods", "AUTHOR" => "Neil Neely , Dave Rolsky ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Data-Validate-IP", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Data::Validate::IP", "PREREQ_PM" => { "Exporter" => 0, "NetAddr::IP" => 4, "Scalar::Util" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Test::More" => "0.88", "Test::Requires" => 0, "lib" => 0 }, "VERSION" => "0.22", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { my $tr = delete $WriteMakefileArgs{TEST_REQUIRES}; my $br = $WriteMakefileArgs{BUILD_REQUIRES}; for my $mod ( keys %$tr ) { if ( exists $br->{$mod} ) { $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod}; } else { $br->{$mod} = $tr->{$mod}; } } } unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Data-Validate-IP-0.22/META.yml0000644000175000017500000000136012250201072015443 0ustar autarchautarch--- abstract: 'IPv4 and IPv6 validation methods' author: - 'Neil Neely ' - 'Dave Rolsky ' build_requires: Test::More: 0.88 Test::Requires: 0 lib: 0 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300039, CPAN::Meta::Converter version 2.131560' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Data-Validate-IP requires: Exporter: 0 NetAddr::IP: 4 Scalar::Util: 0 perl: 5.008 strict: 0 warnings: 0 resources: bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Validate-IP repository: https://github.com/neilneely/Data-Validate-IP.git version: 0.22 x_authority: cpan:NEELY Data-Validate-IP-0.22/LICENSE0000644000175000017500000004364512250201072015213 0ustar autarchautarchThis software is copyright (c) 2013 by Neil Neely. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2013 by Neil Neely. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2013 by Neil Neely. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Data-Validate-IP-0.22/lib/0000755000175000017500000000000012250201072014740 5ustar autarchautarchData-Validate-IP-0.22/lib/Data/0000755000175000017500000000000012250201072015611 5ustar autarchautarchData-Validate-IP-0.22/lib/Data/Validate/0000755000175000017500000000000012250201072017342 5ustar autarchautarchData-Validate-IP-0.22/lib/Data/Validate/IP.pm0000644000175000017500000004771612250201072020227 0ustar autarchautarchpackage Data::Validate::IP; { $Data::Validate::IP::VERSION = '0.22'; } BEGIN { $Data::Validate::IP::AUTHORITY = 'cpan:NEELY'; } use strict; use warnings; use 5.008; use NetAddr::IP 4; use Scalar::Util qw( blessed ); require Exporter; our $HAS_SOCKET; BEGIN { local $@; $HAS_SOCKET = (!$ENV{DVI_NO_SOCKET}) && eval { require Socket; Socket->import(qw( AF_INET AF_INET6 inet_pton )); # On some platforms, Socket.pm exports an inet_pton that just dies # when it is called. On others, inet_pton accepts various forms of # invalid input. defined &Socket::inet_pton && !defined inet_pton(Socket::AF_INET(), '016.17.184.1') && !defined inet_pton(Socket::AF_INET6(), '2067::1:'); }; if ($HAS_SOCKET) { *is_ipv4 = \&_fast_is_ipv4; *is_ipv6 = \&_fast_is_ipv6; } else { *is_ipv4 = \&_slow_is_ipv4; *is_ipv6 = \&_slow_is_ipv6; } } our @ISA = qw(Exporter); our @EXPORT = qw( is_ipv4 is_ipv6 is_innet_ipv4 ); sub new { my $class = shift; return bless {}, $class; } sub _fast_is_ipv4 { shift if ref $_[0]; my $value = shift; return unless defined $value && defined inet_pton(Socket::AF_INET(), $value); $value =~ /(.+)/; return $1; } sub _slow_is_ipv4 { shift if ref $_[0]; my $value = shift; return unless defined($value); my (@octets) = $value =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; return unless (@octets == 4); foreach (@octets) { #return unless ($_ >= 0 && $_ <= 255); return unless ($_ >= 0 && $_ <= 255 && $_ !~ /^0\d{1,2}$/); } return join('.', @octets); } sub _fast_is_ipv6 { shift if ref $_[0]; my $value = shift; return unless defined $value && defined inet_pton(Socket::AF_INET6(), $value); $value =~ /(.+)/; return $1; } sub _slow_is_ipv6 { shift if ref $_[0]; my $value = shift; return unless defined($value); # This is valid but the algorithm below won't do the right thing with it. return '::' if $value eq '::'; # 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; my $expected_chunks = 8; if (@chunks > 1 && is_ipv4($chunks[-1])) { $ipv4 = pop(@chunks); $expected_chunks--; } my $empty = 0; #Workaround to handle trailing :: being valid if ($value =~ /[0123456789abcdef]{1,4}::$/) { $empty++; } elsif ($value =~ /:$/) { #single trailing ':' is invalid return; } 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 == $expected_chunks || @chunks < $expected_chunks && $empty); my $return = join(':', @chunks); #Explicitly untaint the data $return =~ /(.+)/; $return = $1; #Need to handle the exception of trailing :: being valid return $return . '::' if ($value =~ /::$/); return $return; } # This is just a quick test - we'll let NetAddr::IP decide if the address is # valid. my $ip_re = qr/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/; my $partial_ip_re = qr/\d{1,3}(?:\.\d{1,3}){0,2}/; sub is_innet_ipv4 { shift if ref $_[0]; my $value = shift; my $network = shift; return unless defined($value); my $ip = is_ipv4($value); return unless defined $ip; # Backwards compatibility hacks to make it accept things that Net::Netmask # accepts. if ( $network eq 'default' || $network =~ /^$ip_re$/ || $network =~ m{^$ip_re/\d\d?$}) { $network = NetAddr::IP->new($network) or return; } elsif (!(blessed $network && $network->isa('NetAddr::IP'))) { my $orig = $network; if ($network =~ /^($ip_re)[:\-]($ip_re)$/) { my ($net, $netmask) = ($1, $2); my $bits = _netmask_to_bits($netmask) or return; $network = "$net/$bits"; } elsif ($network =~ /^($ip_re)\#($ip_re)$/) { my ($net, $hostmask) = ($1, $2); my $bits = _hostmask_to_bits($hostmask) or return; $network = "$net/$bits"; } elsif ($network =~ m{^($partial_ip_re)/(\d\d?)$}) { my ($net, $bits) = ($1, $2); # This is a hack to avoid a deprecation warning (Use of implicit # split to @_ is deprecated) that shows up on 5.10.1 but not on # newer Perls. my $octets = scalar(my @tmp = split /\./, $net); $network = $net; $network .= '.0' x (4 - $octets); $network .= "/$bits"; } elsif ($network =~ /^$partial_ip_re$/) { my $octets = scalar(my @tmp = split /\./, $network); if ($octets < 4) { $network .= '.0' x (4 - $octets); $network .= '/' . $octets * 8; } } if ($orig ne $network) { _deprecation_warn( 'Use of non-CIDR notation for networks with is_innet_ipv4() is deprecated' ); } $network = NetAddr::IP->new($network) or return; } my $netaddr_ip = NetAddr::IP->new($ip) or return; return $ip if $network->contains($netaddr_ip); return; } { my %netmasks = ( '128.0.0.0' => '1', '192.0.0.0' => '2', '224.0.0.0' => '3', '240.0.0.0' => '4', '248.0.0.0' => '5', '252.0.0.0' => '6', '254.0.0.0' => '7', '255.0.0.0' => '8', '255.128.0.0' => '9', '255.192.0.0' => '10', '255.224.0.0' => '11', '255.240.0.0' => '12', '255.248.0.0' => '13', '255.252.0.0' => '14', '255.254.0.0' => '15', '255.255.0.0' => '16', '255.255.128.0' => '17', '255.255.192.0' => '18', '255.255.224.0' => '19', '255.255.240.0' => '20', '255.255.248.0' => '21', '255.255.252.0' => '22', '255.255.254.0' => '23', '255.255.255.0' => '24', '255.255.255.128' => '25', '255.255.255.192' => '26', '255.255.255.224' => '27', '255.255.255.240' => '28', '255.255.255.248' => '29', '255.255.255.252' => '30', '255.255.255.254' => '31', '255.255.255.255' => '32', ); sub _netmask_to_bits { return $netmasks{$_[0]}; } } { my %hostmasks = ( '255.255.255.255' => 0, '127.255.255.255' => 1, '63.255.255.255' => 2, '31.255.255.255' => 3, '15.255.255.255' => 4, '7.255.255.255' => 5, '3.255.255.255' => 6, '1.255.255.255' => 7, '0.255.255.255' => 8, '0.127.255.255' => 9, '0.63.255.255' => 10, '0.31.255.255' => 11, '0.15.255.255' => 12, '0.7.255.255' => 13, '0.3.255.255' => 14, '0.1.255.255' => 15, '0.0.255.255' => 16, '0.0.127.255' => 17, '0.0.63.255' => 18, '0.0.31.255' => 19, '0.0.15.255' => 20, '0.0.7.255' => 21, '0.0.3.255' => 22, '0.0.1.255' => 23, '0.0.0.255' => 24, '0.0.0.127' => 25, '0.0.0.63' => 26, '0.0.0.31' => 27, '0.0.0.15' => 28, '0.0.0.7' => 29, '0.0.0.3' => 30, '0.0.0.1' => 31, '0.0.0.0' => 32, ); sub _hostmask_to_bits { return $hostmasks{ $_[0] }; } } { my %warned_at; sub _deprecation_warn { my $warning = shift; my @caller = caller(2); my $caller_info = "at line $caller[2] of $caller[0] in sub $caller[3]"; return if $warned_at{$warning}{$caller_info}++; warn "$warning $caller_info\n"; } } { my %ipv4_networks = ( loopback => { networks => '127.0.0.0/8' }, private => { networks => [ qw( 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 ) ], }, testnet => { networks => [ qw( 192.0.2.0/24 198.51.100.0/24 203.0.113.0/24 ) ], }, anycast => { networks => '192.88.99.0/24' }, multicast => { networks => '224.0.0.0/4' }, linklocal => { networks => '169.254.0.0/16' }, unroutable => { networks => [ qw( 0.0.0.0/8 100.64.0.0/10 192.0.0.0/29 198.18.0.0/15 240.0.0.0/4 ) ], }, ); _build_is_X_ip_subs(\%ipv4_networks, 4); } { my %ipv6_networks = ( loopback => { networks => '::1/128' }, ipv4_mapped => { networks => '::ffff:0:0/96' }, discard => { networks => '100::/64' }, special => { networks => '2001::/23' }, teredo => { networks => '2001::/32', subnet_of => 'special', }, orchid => { networks => '2001:10::/28', subnet_of => 'special', }, documentation => { networks => '2001:db8::/32' }, private => { networks => 'fc00::/7' }, linklocal => { networks => 'fe80::/10' }, multicast => { networks => 'ff00::/8' }, ); _build_is_X_ip_subs(\%ipv6_networks, 6); # This exists for the benefit of the test code. sub _network_is_subnet_of { my $network = shift; my $other = shift; return ($ipv6_networks{$network}{subnet_of} || q{}) eq $other; } } sub _build_is_X_ip_subs { my $networks = shift; my $ip_number = shift; my $is_ip_sub = $ip_number == 4 ? 'is_ipv4' : 'is_ipv6'; my $netaddr_new = $ip_number == 4 ? 'new' : 'new6'; my @all_nets; local $@; for my $type (keys %{$networks}) { my @nets = map { NetAddr::IP->$netaddr_new($_) } ref $networks->{$type}{networks} ? @{ $networks->{$type}{networks} } : $networks->{$type}{networks}; # Some IPv6 networks (like TEREDO) are a subset of the special block # so there's no point in checking for them in the is_public_ipv6() # sub. unless ($networks->{$type}{subnet_of}) { push @all_nets, @nets; } # We're using code gen rather than just making an anon sub outright so # we don't have to pay the cost of derefencing the $is_ip_sub and the # dynamic dispatch cost for $netaddr_new my $sub = eval sprintf( <<'EOF', $is_ip_sub, $netaddr_new ); sub { shift if ref $_[0]; my $value = shift; return unless defined $value; my $ip = %s($value); return unless defined $ip; my $netaddr_ip = NetAddr::IP->%s($ip); for my $net (@nets) { return $ip if $net->contains($netaddr_ip); } return; } EOF die $@ if $@; my $sub_name = 'is_' . $type . '_ipv' . $ip_number; no strict 'refs'; *{$sub_name} = $sub; push @EXPORT, $sub_name; } my $sub = eval sprintf( <<'EOF', $is_ip_sub, $netaddr_new ); sub { shift if ref $_[0]; my $value = shift; return unless defined($value); my $ip = %s($value); return unless defined $ip; my $netaddr_ip = NetAddr::IP->%s($ip); for my $net (@all_nets) { return if $net->contains($netaddr_ip); } return $ip; } EOF die $@ if $@; my $sub_name = 'is_public_ipv' . $ip_number; no strict 'refs'; *{$sub_name} = $sub; push @EXPORT, $sub_name; } 1; # ABSTRACT: IPv4 and IPv6 validation methods __END__ =pod =head1 NAME Data::Validate::IP - IPv4 and IPv6 validation methods =head1 VERSION version 0.22 =head1 SYNOPSIS use Data::Validate::IP qw(is_ipv4 is_ipv6); if (is_ipv4($suspect)) { print "Looks like an IPv4 address"; } else { 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 IPv4 ip" unless ($v->is_ipv4('domain.com')); die "not an IPv6 ip" unless ($v->is_ipv6('domain.com')); =head1 DESCRIPTION This module provides a number IP address validation subs that both validate and untaint their input. This includes both basic validation (C and C) and special cases like checking whether an address belongs to a specific network or whether an address is public or private (reserved). =head1 FUNCTIONS All of the functions below are exported by default. All functions return an untainted value if the test passes and undef if it fails. In theory, this means that you should always check for a defined status explicitly but in practice there are no valid IP addresses where the string form evaluates to false in Perl. Note that none of these functions actually attempt to test whether the given IP address is routable from your device; they are purely semantic checks. =head2 is_ipv4($ip) and is_ipv6($ip) These functions simply check whether the address is a valid IPv4 or IPv6 address. =head2 is_innet_ipv4($ip, $network) This subroutine checks whether the address belongs to the given IPv4 network. The C<$network> argument can either be a string in CIDR notation like "15.0.15.0/24" or a L object. This subroutine used to accept many more forms of network specifications (anything L accepts) but this has been deprecated. =head2 is_unroutable_ipv4($ip) This subroutine checks whether the address belongs to any of several special use IPv4 networks - C<0.0.0.0/8>, C<100.64.0.0/10>, C<192.0.0.0/29>, C<198.18.0.0/15>, C<240.0.0.0/4> - as defined by L, L, and L. Arguably, these should be broken down further but this subroutine will always exist for backwards compatibility. =head2 is_private_ipv4($ip) This subroutine checks whether the address belongs to any of the private IPv4 networks - C<10.0.0.0/8>, C<172.16.0.0/12>, C<192.168.0.0/16> - as defined by L. =head2 is_loopback_ipv4($ip) This subroutine checks whether the address belongs to the IPv4 loopback network - C<127.0.0.0/8> - as defined by L. =head2 is_linklocal_ipv4($ip) This subroutine checks whether the address belongs to the IPv4 link local network - C<169.254.0.0/16> - as defined by L. =head2 is_testnet_ipv4($ip) This subroutine checks whether the address belongs to any of the IPv4 TEST-NET networks for use in documentation and example code - C<192.0.2.0/24>, C<198.51.100.0/24>, and C<203.0.113.0/24> - as defined by L. =head2 is_anycast_ipv4($ip) This subroutine checks whether the address belongs to the 6to4 relay anycast network - C<192.88.99.0/24> - as defined by L. =head2 is_multicast_ipv4($ip) This subroutine checks whether the address belongs to the IPv4 multicast network - C<224.0.0.0/4> - as defined by L. =head2 is_loopback_ipv6($ip) This subroutine checks whether the address is the IPv6 loopback address - C<::1/128> - as defined by L. =head2 is_ipv4_mapped_ipv6($ip) This subroutine checks whether the address belongs to the IPv6 IPv4-mapped address network - C<::ffff:0:0/96> - as defined by L. =head2 is_discard_ipv6($ip) This subroutine checks whether the address belongs to the IPv6 discard prefix network - C<100::/64> - as defined by L. =head2 is_special_ipv6($ip) This subroutine checks whether the address belongs to the IPv6 special network - C<2001::/23> - as defined by L. =head2 is_teredo_ipv6($ip) This subroutine checks whether the address belongs to the IPv6 TEREDO network - C<2001::/32> - as defined by L. Note that this network is a subnet of the larger special network at C<2001::/23>. =head2 is_orchid_ipv6($ip) This subroutine checks whether the address belongs to the IPv6 ORCHID network - C<2001::/32> - as defined by L. Note that this network is a subnet of the larger special network at C<2001::/23>. This network is currently scheduled to be returned to the special pool in March of 2014 unless the IETF extends its use. If that happens this subroutine will continue to exist but will always return false. =head2 is_documentation_ipv6($ip) This subroutine checks whether the address belongs to the IPv6 documentation network - C<2001:DB8::/32> - as defined by L. =head2 is_private_ipv6($ip) This subroutine checks whether the address belongs to the IPv6 private network - C - as defined by L. =head2 is_linklocal_ipv6($ip) This subroutine checks whether the address belongs to the IPv6 link-local unicast network - C - as defined by L. =head2 is_multicast_ipv6($ip) This subroutine checks whether the address belongs to the IPv6 multicast network - C - as defined by L. =head2 is_public_ipv4($ip) and is_public_ipv6($ip) These subroutines check whether the given IP address belongs to any of the special case networks defined previously. Note that this is B simply the opposite of checking C or C. The private networks are a subset of all the special case networks. =head1 OBJECT-ORIENTED INTERFACE This module can also be used as a class. You can call C<< Data::Validate::IP->new() >> to get an object and then call any of the validation subroutines as methods on that object. This is somewhat pointless since the object will never contain any state but this interface is kept for backwards compatibility. =head1 SEE ALSO IPv4 B<[RFC 5735] [RFC 1918]> IPv6 B<[RFC 2460] [RFC 4193] [RFC 4291] [RFC 6434]> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 ACKNOWLEDGEMENTS Thanks to Richard Sonnen > for writing the Data::Validate module. Thanks to Matt Dainty > for adding the C and C code. =head1 AUTHORS =over 4 =item * Neil Neely =item * Dave Rolsky =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2013 by Neil Neely. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Data-Validate-IP-0.22/META.json0000644000175000017500000000310112250201072015606 0ustar autarchautarch{ "abstract" : "IPv4 and IPv6 validation methods", "author" : [ "Neil Neely ", "Dave Rolsky " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300039, CPAN::Meta::Converter version 2.131560", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Data-Validate-IP", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "develop" : { "requires" : { "Test::CPAN::Changes" : "0.19", "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "Exporter" : "0", "NetAddr::IP" : "4", "Scalar::Util" : "0", "perl" : "5.008", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "0.88", "Test::Requires" : "0", "lib" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-data-validate-ip@rt.cpan.org", "web" : "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Validate-IP" }, "repository" : { "type" : "git", "url" : "https://github.com/neilneely/Data-Validate-IP.git", "web" : "https://github.com/neilneely/Data-Validate-IP.git" } }, "version" : "0.22", "x_authority" : "cpan:NEELY" } Data-Validate-IP-0.22/Changes0000644000175000017500000001145012250201072015466 0ustar autarchautarch0.22 Thu Dec 05 2013 - Fixed some small doc typo/formatting issues. 0.21 Thu Dec 05 2013 - The 198.51.100.0/24 and 203.0.113.0/24 networks were mistakenly put in the unroutable list, rather than the testnet list. This has been fixed. Note that if you've just been using is_public_ipv4 in your code, there are no changes in the results. - Added the 6to4 anycast network - 192.88.99.0/24. Addresses in this network are not considered public and there is now a new is_anycast_ipv4() subroutine exported. - Added a number of missing reserved IPv6 networks. These are the IPv4-mapped block (::ffff:0:0/96), the discard prefix (100::/64), TEREDO (2001::/32), ORCHID (2001:10::/28), and documentation (2001:db8::/32) IPv6 networks. There are now is_ipv4_mapped_ipv6(), is_discard_ipv6(), is_teredo_ipv6(), is_orchid_ipv6(), and is_documentation_ipv6() subs. Note that the TEREDO and ORCHID networks are both subnets of the larger special network, and as such were already excluded by is_public_ipv6(), though arguably the TEREDO addresses _should_ be considered public. - Rewrote most of the docs to greatly reduce the amount of text and to improve the ToC on MetaCPAN and search.cpan.org. 0.20 Sat Jul 13 2013 - Add docs for the is_public_ipv6() sub that was added in 0.15. Reported by Greg Oschwald. 0.19 Wed Mar 13 2013 - Fix a deprecation warning that showed up with Perl 5.10.1, but not with newer Perls. Reported by Iosif Fettich. 0.18 Tue Feb 19 2013 - Versions 0.15 - 0.17 still had $VERSION set to 0.14. Reported by Greg Oschwald. 0.17 Tue Feb 19 2013 - Previous releases broke is_innet_ipv4 for many network formats. This support has been restored, but only the "a.b.c.d/nn" CIDR form will be documented going forward. All other forms are deprecated, and support for them will be removed in a future release. 0.16 Wed Feb 06 2013 - Made the check for Socket.pm stricter. On some platforms it exports an inet_pton() that just dies when called. On other platforms it accepts invalid input like '016.17.184.1' or '2067::1:'. 0.15 Mon Feb 04 2013 - If your installed version of Socket.pm provides an inet_pton subroutine we use that to do validation. This is about 5x faster for IPv4 addresses and 20 times faster for IPv6. - Various unroutable networks are now recognized as non-public addresses. Based on a patch by Greg Oschwald. (Bug#83081). - Added is_unroutable_ipv4 exported sub. - Added is_public_ipv6, is_private_ipv6, is_loopback_ipv6, is_multicast_ipv6, and is_special_ipv6 subroutines. - Fixed the is_linklocal_ipv6 method. It didn't recognize the full link-local range properly. - Fixed bug where '::' was not recognized as a valid IPv6 address. (Bug#81700) - Fixed bug where ipv6 related subroutines were not untainting their return value. 0.14 Thu Jan 06 2011 - Cleaned up test suite (no code changes) 0.13 Thu Jan 06 2011 - Fixed unshorted ipv6 check when ipv4 address is trailing. (Bug#64532) Thanks to Milan Matlak for patch 0.12 Wed Dec 29 2010 - Fixed parsing of trailing :: (such as 2001::), as that is valid This address bug#58991 - Thanks to Alan.Chester@tekelec.com for identifying the problem - Also fixed incorrectly treating 2001::1: as a valid IPv6 address when it isn't 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" 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 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 for submitting the patch 0.07 Wed May 17 2007 - Added POD testing, and minor cleanup related to that 0.06 Wed May 16 2007 - Updated contact information to be neil@neely.cx, this is a purely cosmetic change 0.05 Tue Mar 6 12:42:11 2007 - added is_multicast_ipv4 and is_linklocal_ipv4 Thanks to Matt Dainty for doing all the work 0.04 Thu Apr 28 09:07:29 2005 - Removed perl version dependency in Makefile.PL 0.03 Fri Mar 4 12:58:10 2005 - Minor fix to pod markup 0.02 Fri Mar 4 09:43:14 2005 - added is_private_ipv4 is_loopback_ipv4 is_testnet_ipv4 is_public_ipv4 0.01 Thu Mar 3 15:15:46 2005 - original version; created by h2xs 1.23 with options -AXn Data::Validate::IP Data-Validate-IP-0.22/MANIFEST0000644000175000017500000000057512250201072015332 0ustar autarchautarchChanges INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README bench/socket-vs-perl dist.ini lib/Data/Validate/IP.pm perltidyrc t/Data-Validate-IP-slow.t t/Data-Validate-IP.t t/Untaint.t t/lib/Test/Data/Validate/IP.pm t/release-cpan-changes.t t/release-eol.t t/release-no-tabs.t t/release-pod-linkcheck.t t/release-pod-no404s.t t/release-pod-spell.t t/release-pod-syntax.t Data-Validate-IP-0.22/INSTALL0000644000175000017500000000173212250201072015226 0ustar autarchautarch This is the Perl distribution Data-Validate-IP. Installing Data-Validate-IP is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm Data::Validate::IP If you are installing into a system-wide directory, you may need to pass the "-S" flag to cpanm, which uses sudo to install the module: % cpanm -S Data::Validate::IP ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Data::Validate::IP ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Makefile.PL % make && make test Then install it: % make install If you are installing into a system-wide directory, you may need to run: % sudo make install ## Documentation Data-Validate-IP documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc Data::Validate::IP