Net-IPv6Addr-0.96/000755 001751 001751 00000000000 13356050322 013126 5ustar00benben000000 000000 Net-IPv6Addr-0.96/t/000755 001751 001751 00000000000 13356050322 013371 5ustar00benben000000 000000 Net-IPv6Addr-0.96/examples/000755 001751 001751 00000000000 13356050322 014744 5ustar00benben000000 000000 Net-IPv6Addr-0.96/lib/000755 001751 001751 00000000000 13356050322 013674 5ustar00benben000000 000000 Net-IPv6Addr-0.96/Changes000644 001751 001751 00000004252 13356050135 014426 0ustar00benben000000 000000 Revision history for Perl module Net::IPv6Addr 0.96 2018-10-06 * Requirement on Math::BigInt changed to add version 0.95 2018-10-06 * "from_bigint" method added * Documentation updated to reflect the current RFCs * Tests of "to_bigint", rfc compliance; fix broken string test * Any valid ipv6 value can now be output as mixed ipv6 and ipv4 0.94 2018-10-06 Ben Bullock * Pod error fixed * EXPORTS_OK corrected 0.93 2018-10-05 Ben Bullock * Remove README and use generated one * Fix bad links in documentation 0.92 2018-10-05 Ben Bullock * Documentation expanded with working examples * UTF-8 in Makefile.PL marked * to_* routines exported on demand * Repetition in error messages removed * Parsing of mixed IPv6/IPv4 now OK 0.91 2017-10-06 Ben Bullock * Documentation (esp. SEE ALSO, BUGS) * Better validation of IPv4 addresses in ipv6_chkip 0.9 2017-09-30 Ben Bullock * in_network / in_network_of_size bug fix 0.8 2017-09-30 Ben Bullock * Export some functions * Documentation corrected 0.7 2017-08-26 Ben Bullock * Documentation rewrite 0.6 2017-08-25 Ben Bullock * Changed format of ChangeLog to follow CPAN::Changes::Spec, which means it will be displayed nicely by MetaCPAN. 0.5 2017-08-24 Ben Bullock * Add licence information to POD documentation 0.4 2017-08-24 Ben Bullock * Add contributors and licence information * Add documentation * Remove RFCs from distro 0.3 2017-08-24 Ben Bullock * Add meta files to distribution * in_network altered * Documentation updates 0.2 2002-08-06 Tony Monroe * Many patches from Jyrki Soini , fixing bugs and adding features! 0.1 2001-07-21 Tony Monroe * Based on Net::IPv4Addr version 0.10. Author: Francis J. Lacoste * Passes all basic tests. * Takes any input or output format described by RFC1884 or RFC1924. * Automatically generates those pesky IP6.INT. strings (RFC1886). Net-IPv6Addr-0.96/MANIFEST000644 001751 001751 00000001330 13356050322 014254 0ustar00benben000000 000000 Changes examples/array.pl examples/bigint.pl examples/compressed.pl examples/from-bigint.pl examples/inet.pl examples/inos.pl examples/intarray.pl examples/preferred.pl examples/string-ip6-int.pl examples/synopsis.pl examples/to-string-ipv4-comp.pl examples/to-string-ipv4.pl lib/Net/IPv6Addr.pm lib/Net/IPv6Addr.pod Makefile.PL MANIFEST This list of files MANIFEST.SKIP README t/base85.t t/bigint.t t/chkip.t t/compressed.t t/in-network.t t/ipv4.t t/ipv4comp.t t/new.t t/parse.t t/preferred.t t/Regexp-IPv6.t t/rfc5952.t t/string.t t/synopsis.t t/vietnam.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Net-IPv6Addr-0.96/Makefile.PL000644 001751 001751 00000002321 13356050210 015072 0ustar00benben000000 000000 use utf8; use ExtUtils::MakeMaker; my $pm = 'lib/Net/IPv6Addr.pm'; my $pod = 'lib/Net/IPv6Addr.pod'; my $github = 'github.com/benkasminbullock/net-ipv6addr'; my $repo = "https://$github"; WriteMakefile( # 'AUTHOR' => 'Tony Monroe', # This is set for documentation generation. Tony Monroe is the # author of the module. 'AUTHOR' => 'Ben Bullock ', 'NAME' => 'Net::IPv6Addr', 'VERSION_FROM' => $pm, 'ABSTRACT_FROM' => $pod, 'PREREQ_PM' => { 'Net::IPv4Addr' => '0.10', 'Math::Base85' => '0.2', 'Carp' => '0', 'Math::BigInt' => '1.999813', }, LICENSE => 'perl', META_MERGE => { 'meta-spec' => { version => 2, }, resources => { repository => { type => 'git', url => "git://$github.git", web => $repo, }, bugtracker => { web => "https://rt.cpan.org/Dist/Display.html?Name=Net-IPv6Addr", }, }, x_contributors => [ 'Jyrki Soini', 'Joacim Haggmark', 'Ben Bullock ', 'Neil Bowers ', 'Salvador Fandiño García ', ], }, # http://matrix.cpantesters.org/?dist=Net-IPv6Addr%200.8 gives # 5.6.2 as valid. MIN_PERL_VERSION => '5.006000', ); Net-IPv6Addr-0.96/README000644 001751 001751 00000007732 13356050321 014016 0ustar00benben000000 000000 _ _ _ ___ ____ __ _ _ _ | \ | | ___| |_ _ _ |_ _| _ \__ __/ /_ / \ __| | __| |_ __ | \| |/ _ \ __| (_|_) | || |_) \ \ / / '_ \ / _ \ / _` |/ _` | '__| | |\ | __/ |_ _ _ | || __/ \ V /| (_) / ___ \ (_| | (_| | | |_| \_|\___|\__| (_|_) |___|_| \_/ \___/_/ \_\__,_|\__,_|_| This is the README for Net::IPv6Addr version 0.96. Net::IPv6Addr is a "module" for the Perl computer programming language, a library of computer code to install on a computer. This document contains four sections: 1. About - what the module does 2. Documentation - how to learn more about the module 3. Installation - how to install this module on a computer 4. Help - what to do if you get stuck ----------------------------------------------------------------------------- 1. ABOUT Net::IPv6Addr - Check and manipulate IPv6 addresses "Net::IPv6Addr" can check whether strings contain valid IPv6 addresses, and convert them into various formats. All of "new", "is_ipv6", and "ipv6_parse" can process the following formats: Preferred form: x:x:x:x:x:x:x:x "2001:db8:0:0:0:ff00:42:8329" This is the form described as the "preferred form" in section 2.2 of "RFC1884" et al. Output with "to_string_preferred". Compressed form with double colon: x::x etc. "2001:db8::ff00:42:8329" This is the "canonical text representation format" of "RFC5952". Output with "to_string_compressed". Mixed IPv4/IPv6 format: x:x:x:x:x:x:d.d.d.d "2001:db8:0:0:0:ff00:0.66.131.41" Output with "to_string_ipv4". Mixed IPv4/IPv6 with compression: x::x:d.d.d.d, etc. "2001:db8::ff00:0.66.131.41" Output with "to_string_ipv4_compressed". Base-85-encoded: [0-9A-Za-z!#$%&()*+;<=>?@^_`{|}~-]{20} "9R}vSQ9RqiCvG6zn?Zyh" This encoding was given in "RFC1924" as an April Fool's joke. Output with "to_string_base85". In addition, the following formats can be output: Big integers An IPv6 can be changed to a "Math::BigInt" object or a digit string using "to_bigint". Big integers can also be input with "from_bigint". Arrays An IPv6 can be processed into its component pieces with "to_array" or "to_intarray". Reverse-address pointer An IPv6 can be processed into its reverse-address pointer, as defined by "RFC1886", using "to_string_ip6_int". ----------------------------------------------------------------------------- 2. DOCUMENTATION You can read the documentation for the module online at the following website: * http://metacpan.org/release/Net-IPv6Addr (This link goes to the latest version of the module.) After installing the module, you can read the documentation on your computer using perldoc Net::IPv6Addr ----------------------------------------------------------------------------- 3. INSTALLATION This module requires Perl version 5.6.0 or later. To install the module from CPAN, use cpan Net::IPv6Addr If you have the App::cpanminus installer, you may prefer cpanm Net::IPv6Addr To install the module from the source file, Net-IPv6Addr-0.96.tar.gz, follow this sequence of commands: tar xfz Net-IPv6Addr-0.96.tar.gz cd Net-IPv6Addr-0.96 perl Makefile.PL make make install If you want to test the module before installing it, use "make test" after "make" and before "make install". ----------------------------------------------------------------------------- 4. HELP To get help with the module, you can email the author, Ben Bullock, at . If you think there is a problem in the module, you can report a bug at , or if you want to alter the source code of Net::IPv6Addr, try the public repository on github at . ----------------------------------------------------------------------------- This README was written on Sat Oct 6 15:06:09 2018. ----------------------------------------------------------------------------- Net-IPv6Addr-0.96/MANIFEST.SKIP000644 001751 001751 00000000373 13355514341 015034 0ustar00benben000000 000000 ^pm_to_blib$ ^MYMETA\..* ^Net-IPv6Addr-[0-9].*$ ^(build|make-pod)\.pl$ ^Makefile(?:\.(?:old|bak))?$ ^\.git/.* ^\.gitignore$ .*~$ ^#.* ^blib/.* ^MANIFEST\.bak$ ^xt/.*\.t$ ^examples/.*-out\.txt$ ^lib/Net/IPv6Addr\.pod\.tmpl$ ^research/.*$ ^cover_db/.*$ Net-IPv6Addr-0.96/META.yml000644 001751 001751 00000001702 13356050322 014377 0ustar00benben000000 000000 --- abstract: 'Check and manipulate IPv6 addresses' author: - 'Ben Bullock ' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Net-IPv6Addr no_index: directory: - t - inc requires: Carp: '0' Math::Base85: '0.2' Math::BigInt: '1.999813' Net::IPv4Addr: '0.10' perl: '5.006000' resources: bugtracker: https://rt.cpan.org/Dist/Display.html?Name=Net-IPv6Addr repository: git://github.com/benkasminbullock/net-ipv6addr.git version: '0.96' x_contributors: - 'Jyrki Soini' - 'Joacim Haggmark' - 'Ben Bullock ' - 'Neil Bowers ' - 'Salvador Fandiño García ' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Net-IPv6Addr-0.96/META.json000644 001751 001751 00000003104 13356050322 014545 0ustar00benben000000 000000 { "abstract" : "Check and manipulate IPv6 addresses", "author" : [ "Ben Bullock " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Net-IPv6Addr", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Math::Base85" : "0.2", "Math::BigInt" : "1.999813", "Net::IPv4Addr" : "0.10", "perl" : "5.006000" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://rt.cpan.org/Dist/Display.html?Name=Net-IPv6Addr" }, "repository" : { "type" : "git", "url" : "git://github.com/benkasminbullock/net-ipv6addr.git", "web" : "https://github.com/benkasminbullock/net-ipv6addr" } }, "version" : "0.96", "x_contributors" : [ "Jyrki Soini", "Joacim Haggmark", "Ben Bullock ", "Neil Bowers ", "Salvador Fandiño García " ], "x_serialization_backend" : "JSON::PP version 2.97001" } Net-IPv6Addr-0.96/lib/Net/000755 001751 001751 00000000000 13356050322 014422 5ustar00benben000000 000000 Net-IPv6Addr-0.96/lib/Net/IPv6Addr.pm000644 001751 001751 00000032063 13356050170 016344 0ustar00benben000000 000000 package Net::IPv6Addr; use strict; use warnings; our @ISA = qw(Exporter); our @EXPORT = qw(); our @EXPORT_OK = qw( in_network in_network_of_size ipv6_chkip ipv6_parse is_ipv6 to_string_preferred to_string_compressed to_bigint to_intarray to_array to_string_ip6_int to_string_base85 to_string_ipv4 to_string_ipv4_compressed from_bigint ); our %EXPORT_TAGS = (all => \@EXPORT_OK); our $VERSION = '0.96'; use Carp; use Net::IPv4Addr; use Math::BigInt '1.999813'; use Math::Base85; # ____ _ _ # | _ \ __ _| |_| |_ ___ _ __ _ __ ___ # | |_) / _` | __| __/ _ \ '__| '_ \/ __| # | __/ (_| | |_| || __/ | | | | \__ \ # |_| \__,_|\__|\__\___|_| |_| |_|___/ # # Match one to four digits of hexadecimal my $h = qr/[a-f0-9]{1,4}/i; # Match one to three digits #my $d = qr/[0-9]{1,3}/; my $ipv4 = "((25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}))"; # base-85 my $digits = $Math::Base85::base85_digits; $digits =~ s/-//; my $x = "[" . $digits . "-]"; my $n = "{20}"; my %ipv6_patterns = ( 'preferred' => [ qr/^(?:$h:){7}$h$/i, \&ipv6_parse_preferred, ], 'compressed' => [ qr/^[a-f0-9]{0,4}::$/i, qr/^:(?::$h){1,7}$/i, qr/^(?:$h:){1,}:$/i, qr/^(?:$h:)(?::$h){1,6}$/i, qr/^(?:$h:){2}(?::$h){1,5}$/i, qr/^(?:$h:){3}(?::$h){1,4}$/i, qr/^(?:$h:){4}(?::$h){1,3}$/i, qr/^(?:$h:){5}(?::$h){1,2}$/i, qr/^(?:$h:){6}(?::$h)$/i, \&ipv6_parse_compressed, ], 'ipv4' => [ qr/^(?:0:){5}ffff:$ipv4$/i, qr/^(?:0:){6}$ipv4$/, \&ipv6_parse_ipv4, ], 'ipv4 compressed' => [ qr/^::(?:ffff:)?$ipv4$/i, \&ipv6_parse_ipv4_compressed, ], 'ipv6v4' => [ qr/^[a-f0-9]{0,4}::$ipv4$/i, # ::1:2:3:4:1.2.3.4 qr/^::(?:$h:){1,5}$ipv4$/i, qr/^(?:$h:):(?:$h:){1,4}$ipv4$/i, qr/^(?:$h:){2}:(?:$h:){1,3}$ipv4$/i, qr/^(?:$h:){3}:(?:$h:){1,2}$ipv4$/i, qr/^(?:$h:){4}:(?:$h:){1}$ipv4$/i, # 1:2:3:4:5::1.2.3.4 qr/^(?:$h:){1,5}:$ipv4$/i, # 1:2:3:4:5:6:1.2.3.4 qr/^(?:$h:){6}$ipv4$/i, \&parse_mixed_ipv6v4_compressed, ], 'base85' => [ qr/$x$n/, \&ipv6_parse_base85, ], ); # ____ _ _ # | _ \ _ __(_)_ ____ _| |_ ___ # | |_) | '__| \ \ / / _` | __/ _ \ # | __/| | | |\ V / (_| | || __/ # |_| |_| |_| \_/ \__,_|\__\___| # # Errors which include the package name and the subroutine name. This # is for consistency with earlier versions of the module. sub mycroak { my ($message) = @_; my @caller = caller (1); croak $caller[3] . ' -- ' . $message; } # Given one argument with a slash or two arguments, return them as two # arguments, and check there are one or two arguments. sub getargs { my ($ip, $pfx); if (@_ == 2) { ($ip, $pfx) = @_; } elsif (@_ == 1) { ($ip, $pfx) = split(m!/!, $_[0]) } else { mycroak "wrong number of arguments (need 1 or 2)"; } return ($ip, $pfx); } # Match $ip against the regexes of type $type, or die. sub match_or_die { my ($ip, $type) = @_; # Instead of trying to construct a gigantic regex which only # allows two colons in a row, just check here. if ($ip =~ /:::/) { mycroak "invalid address $ip for type $type"; } my $patterns = $ipv6_patterns{$type}; for my $p (@$patterns) { # The last thing in the pattern is a code reference, so this # match indicates no matches were found. if (ref($p) eq 'CODE') { mycroak "invalid address $ip for type $type"; } if ($ip =~ $p) { return; } } } # Make the bit mask for "in_network_of_size". sub bitmask { my ($j) = @_; my $bitmask = '1' x $j . '0' x (16 - $j); my $k = unpack("n",pack("B16", $bitmask)); return $k; } # ____ # | _ \ __ _ _ __ ___ ___ _ __ ___ # | |_) / _` | '__/ __|/ _ \ '__/ __| # | __/ (_| | | \__ \ __/ | \__ \ # |_| \__,_|_| |___/\___|_| |___/ # # Private parser sub ipv6_parse_preferred { my $ip = shift; match_or_die ($ip, 'preferred'); my @pieces = split(/:/, $ip); splice(@pieces, 8); return map { hex } @pieces; } # Private parser sub ipv6_parse_compressed { my $ip = shift; my $type = 'compressed'; match_or_die ($ip, $type); my $colons = ($ip =~ tr/:/:/); my $expanded = ':' x (9 - $colons); $ip =~ s/::/$expanded/; my @pieces = split(/:/, $ip, 8); return map { hex } @pieces; } sub parse_mixed_ipv6v4_compressed { my $ip = shift; match_or_die ($ip, 'ipv6v4'); my @result; my $v4addr; my $colons; $colons = ($ip =~ tr/:/:/); my $expanded = ':' x (8 - $colons); $ip =~ s/::/$expanded/; my @v6pcs = split(/:/, $ip, 7); $v4addr = $v6pcs[-1]; splice(@v6pcs, 6); push @result, map { hex } @v6pcs; Net::IPv4Addr::ipv4_parse($v4addr); my @v4pcs = split(/\./, $v4addr); splice(@v4pcs, 4); push @result, unpack("n", pack("CC", @v4pcs[0,1])); push @result, unpack("n", pack("CC", @v4pcs[2,3])); return @result; } # Private parser sub ipv6_parse_ipv4 { my $ip = shift; match_or_die ($ip, 'ipv4'); my @result; my $v4addr; my @v6pcs = split(/:/, $ip); $v4addr = $v6pcs[-1]; splice(@v6pcs, 6); push @result, map { hex } @v6pcs; Net::IPv4Addr::ipv4_parse($v4addr); my @v4pcs = split(/\./, $v4addr); push @result, unpack("n", pack("CC", @v4pcs[0,1])); push @result, unpack("n", pack("CC", @v4pcs[2,3])); return @result; } # Private parser sub ipv6_parse_ipv4_compressed { my $ip = shift; match_or_die ($ip, 'ipv4 compressed'); my @result; my $v4addr; my $colons; $colons = ($ip =~ tr/:/:/); my $expanded = ':' x (8 - $colons); $ip =~ s/::/$expanded/; my @v6pcs = split(/:/, $ip, 7); $v4addr = $v6pcs[-1]; splice(@v6pcs, 6); push @result, map { hex } @v6pcs; Net::IPv4Addr::ipv4_parse($v4addr); my @v4pcs = split(/\./, $v4addr); splice(@v4pcs, 4); push @result, unpack("n", pack("CC", @v4pcs[0,1])); push @result, unpack("n", pack("CC", @v4pcs[2,3])); return @result; } # Private parser sub ipv6_parse_base85 { my $ip = shift; match_or_die ($ip, 'base85'); my $r; my $bigint = Math::Base85::from_base85($ip); my @result; while ($bigint > 0) { $r = $bigint & 0xffff; unshift @result, sprintf("%d", $r); $bigint = $bigint >> 16; } foreach $r ($#result+1..7) { $result[$r] = 0; } return @result; } # ____ _ _ _ # | _ \ _ _| |__ | (_) ___ # | |_) | | | | '_ \| | |/ __| # | __/| |_| | |_) | | | (__ # |_| \__,_|_.__/|_|_|\___| # sub new { my $proto = shift; my $class = ref($proto) || $proto; my $maybe_ip = shift; my $parser = ipv6_chkip($maybe_ip); if (ref $parser ne 'CODE') { mycroak "invalid IPv6 address $maybe_ip"; } my @hexadecets = $parser->($maybe_ip); my $self = \@hexadecets; bless $self, $class; return $self; } sub ipv6_chkip { my $ip = shift; my $parser = undef; TYPE: for my $k (keys %ipv6_patterns) { my @patlist = @{$ipv6_patterns{$k}}; PATTERN: for my $pattern (@patlist) { last PATTERN if (ref($pattern) eq 'CODE'); if ($ip =~ $pattern) { $parser = $patlist[-1]; last TYPE; } } } return $parser; } sub ipv6_parse { my ($ip, $pfx) = getargs (@_); if (! ipv6_chkip($ip)) { mycroak "invalid IPv6 address $ip"; } if (! defined $pfx) { return $ip; } $pfx =~ s/\s+//g; if ($pfx =~ /^[0-9]+$/) { if ($pfx > 128) { mycroak "invalid prefix length $pfx"; } } else { mycroak "non-numeric prefix length $pfx"; } if (wantarray ()) { return ($ip, $pfx); } return "$ip/$pfx"; } sub is_ipv6 { my $r; eval { $r = ipv6_parse (@_); }; if ($@) { return undef; } return $r; } sub to_string_preferred { my $self = shift; if (ref $self ne __PACKAGE__) { $self = Net::IPv6Addr->new ($self); } return v6part (@$self); } sub to_string_compressed { my $self = shift; if (ref $self ne __PACKAGE__) { $self = Net::IPv6Addr->new ($self); } my $expanded = v6part (@$self); $expanded =~ s/^0:/:/; $expanded =~ s/:0/:/g; if ($expanded =~ s/:::::::/_/ or $expanded =~ s/::::::/_/ or $expanded =~ s/:::::/_/ or $expanded =~ s/::::/_/ or $expanded =~ s/:::/_/ or $expanded =~ s/::/_/ ) { $expanded =~ s/:(?=:)/:0/g; $expanded =~ s/^:(?=[0-9a-f])/0:/; $expanded =~ s/([0-9a-f]):$/$1:0/; $expanded =~ s/_/::/; } return $expanded; } sub bytes { my ($in) = @_; my $low = $in & 0xff; my $high = $in >> 8; return ($high, $low); } sub v4part { my ($t, $b) = @_; return join('.', bytes ($t), bytes ($b)); } sub v6part { return join(':', map { sprintf("%x", $_) } @_); } sub to_string_ipv4 { my $self = shift; if (ref $self ne __PACKAGE__) { $self = Net::IPv6Addr->new ($self); } my $v6part = v6part (@$self[0..5]); my $v4part = v4part (@$self[6, 7]); return "$v6part:$v4part"; } sub to_string_ipv4_compressed { my $self = shift; if (ref $self ne __PACKAGE__) { $self = Net::IPv6Addr->new ($self); } my $v6part = v6part (@$self[0..5]); $v6part .= ':'; $v6part =~ s/(^|:)(0:)+/::/; my $v4part = v4part (@$self[6, 7]); return "$v6part$v4part"; } sub to_string_base85 { my $self = shift; if (ref $self ne __PACKAGE__) { $self = Net::IPv6Addr->new ($self); } my $bigint = new Math::BigInt("0"); for my $i (@{$self}[0..6]) { $bigint = $bigint + $i; $bigint = $bigint << 16; } $bigint = $bigint + $self->[7]; return Math::Base85::to_base85($bigint); } sub to_bigint { my $self = shift; if (ref $self ne __PACKAGE__) { $self = Net::IPv6Addr->new ($self); } my $bigint = new Math::BigInt("0"); for my $i (@{$self}[0..6]) { $bigint = $bigint + $i; $bigint = $bigint << 16; } $bigint = $bigint + $self->[7]; $bigint =~ s/\+//; return $bigint; } sub to_array { my $self = shift; if (ref $self ne __PACKAGE__) { $self = Net::IPv6Addr->new ($self); } return map {sprintf "%04x", $_} @$self; } sub to_intarray { my $self = shift; if (ref $self ne __PACKAGE__) { $self = Net::IPv6Addr->new ($self); } return @$self; } sub to_string_ip6_int { my $self = shift; if (ref $self ne __PACKAGE__) { $self = Net::IPv6Addr->new ($self); } my $hexdigits = sprintf("%04x" x 8, @$self); my @nibbles = ('INT', 'IP6', split(//, $hexdigits)); my $ptr = join('.', reverse @nibbles); return $ptr . "."; } # Private - validate a given netsize sub validate_netsize { my ($netsize) = @_; if ($netsize !~ /^[0-9]+$/ || $netsize > 128) { mycroak "invalid network size $netsize"; } } sub in_network_of_size { my $self = shift; if (ref $self ne __PACKAGE__) { if ($self =~ m!(.+)/(.+)!) { unshift @_, $2; $self = $1; } $self = Net::IPv6Addr->new($self); } my $netsize = shift; if (! defined $netsize) { mycroak "network size not given"; } $netsize =~ s!/!!; validate_netsize ($netsize); my @parts = @$self; my $i = int ($netsize / 16); if ($i < 8) { my $j = $netsize % 16; if ($j) { # If $netsize is not a multiple of 16, truncate the lowest # 16-$j bits of the $ith element of @parts. $parts[$i] &= bitmask ($j); # Jump over this element. $i++; } # Set all the remaining lower parts to zero. for ($i..$#parts) { $parts[$_] = 0; } } return bless \@parts; } sub in_network { my $self = shift; if (ref $self ne __PACKAGE__) { $self = Net::IPv6Addr->new ($self); } my ($net, $netsize) = getargs (@_); unless (defined $netsize) { mycroak "not enough parameters, need netsize"; } $netsize =~ s!/!!; validate_netsize ($netsize); if (! ref $net) { $net = Net::IPv6Addr->new($net); } my @s = $self->in_network_of_size($netsize)->to_intarray; my @n = $net->in_network_of_size($netsize)->to_intarray; my $i = int ($netsize / 16) + 1; if ($i > $#s) { $i = $#s; } for (0..$i) { if ($s[$_] != $n[$_]) { return undef; } } return 1; } sub from_bigint { my ($big) = @_; # Input is a scalar or a Math::BigInt object. if (! ref ($big)) { $big = Math::BigInt->new ($big); } if (ref ($big) ne 'Math::BigInt') { mycroak "Cannot process non-scalar, non-Math::BigInt input"; } # Convert the number to a hexadecimal string my $hex = $big->to_hex (); # Pad if necessary for the colon placement if (length ($hex) < 32) { my $leading = '0' x (32 - length ($hex)); $hex = $leading . $hex; } # Reversing the string makes adding colons with a substitution # operator easier. my $ipr = reverse $hex; $ipr =~ s/(....)/$1:/g; $ipr = reverse $ipr; # Remove the excess colon. $ipr =~ s/^://; # Should be OK now, let "new" handle any further issues. return Net::IPv6Addr->new ($ipr); } 1; Net-IPv6Addr-0.96/lib/Net/IPv6Addr.pod000444 001751 001751 00000047227 13356050317 016523 0ustar00benben000000 000000 =encoding UTF-8 =head1 NAME Net::IPv6Addr - Check and manipulate IPv6 addresses =head1 VERSION This documents version 0.96 of Net::IPv6Addr corresponding to L released on Sat Oct 6 15:05:27 2018 +0900. =head1 SYNOPSIS use Net::IPv6Addr; my $addr = "dead:beef:cafe:babe::f0ad"; Net::IPv6Addr::ipv6_parse($addr); my $x = Net::IPv6Addr->new($addr); print $x->to_string_preferred(), "\n"; produces output dead:beef:cafe:babe:0:0:0:f0ad (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/synopsis.pl> in the distribution.) =head1 DESCRIPTION C can check whether strings contain valid IPv6 addresses, and convert them into various formats. All of L, L, and L can process the following formats: =over =item Preferred form: x:x:x:x:x:x:x:x C<2001:db8:0:0:0:ff00:42:8329> This is the form described as the "preferred form" in section 2.2 of L et al. Output with L. =item Compressed form with double colon: x::x etc. C<2001:db8::ff00:42:8329> This is the "canonical text representation format" of L. Output with L. =item Mixed IPv4/IPv6 format: x:x:x:x:x:x:d.d.d.d C<2001:db8:0:0:0:ff00:0.66.131.41> Output with L. =item Mixed IPv4/IPv6 with compression: x::x:d.d.d.d, etc. C<2001:db8::ff00:0.66.131.41> Output with L. =item Base-85-encoded: [0-9A-Za-z!#$%&()*+;<=>?@^_`{|}~-]{20} C<9R}vSQ9RqiCvG6zn?Zyh> This encoding was given in L as an April Fool's joke. Output with L. =back In addition, the following formats can be output: =over =item Big integers An IPv6 can be changed to a L object or a digit string using L. Big integers can also be input with L. =item Arrays An IPv6 can be processed into its component pieces with L or L. =item Reverse-address pointer An IPv6 can be processed into its reverse-address pointer, as defined by L, using L. =back =head1 METHODS AND FUNCTIONS All of the following except L serve as both object methods and standalone functions. =head2 new my $ni = Net::IPv6Addr->new ('dead:beef:cafe:babe::f0ad'); Create a new Net::IPv6Addr object from a string. Internally, the object is a blessed array reference containing the eight parts of the address as integers. =head3 Parameters A string to be interpreted as an IPv6 address. =head3 Returns A C object if successful. =head3 Notes Throws an exception if the string isn't a valid address. =head2 ipv6_parse my ($ni, $pl) = ipv6_parse ('dead:beef:cafe:babe::f0ad'); =head3 Parameters Either a string containing an IPv6 address string, which may also include a C character and a numeric prefix length, my ($x, $y) = ipv6_parse ("a::/24"); or an IPv6 address string, with an optional second argument consisting of a numeric prefix length: my ($x, $y) = ipv6_parse('a::', '24'); =head3 Returns Called in array context, the return value is a list consisting of the address string and the prefix, if it parses correctly. Called in scalar context, the address and prefix are concatenated with "/". =head3 Notes Throws an exception on malformed input. =head2 is_ipv6 my $niok = is_ipv6 ('dead:beef:cafe:babe::f0ad'); =head3 Parameters Identical to L. =head3 Returns This returns the return value of L, called in scalar context, if it does parse out correctly, otherwise it returns C. Unlike L, C does not throw exceptions. =head2 ipv6_chkip my $niok = ipv6_chkip ('dead:beef:cafe:babe::f0ad'); =head3 Parameters An IPv6 address string, without a prefix. =head3 Returns A true value if it's a valid address; a false value if not. =head2 to_string_preferred use Net::IPv6Addr 'to_string_preferred'; print to_string_preferred ('dead:beef:cafe:babe::f0ad'); produces output dead:beef:cafe:babe:0:0:0:f0ad (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/preferred.pl> in the distribution.) =head3 Parameters If used as an object method, none; if used as a subroutine, an IPv6 address string in any format. =head3 Returns The IPv6 address, formatted in the "preferred" way (as detailed by L et al). =head3 Notes Invalid input will generate an exception. =head2 to_string_compressed use Net::IPv6Addr 'to_string_compressed'; print to_string_compressed ('dead:beef:0000:0000:0000:0000:cafe:babe'); produces output dead:beef::cafe:babe (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/compressed.pl> in the distribution.) This provides the "canonical text representation format" of L. =head3 Parameters If used as an object method, none; if used as a subroutine, an IPv6 address string in any format. =head3 Returns The IPv6 address in the "compressed" (L et al.) or "canonical" (L) format. Hexadecimal numbers are reduced to lower case, consecutive zero elements are reduced to double colons, and leading zeros are removed from strings of hexadecimal digits. All treatment of ambiguities is as per RFC5952. (See L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/t/rfc5952.t> for tests.) =head3 Notes Invalid input will generate an exception. =head2 to_string_ipv4 use Net::IPv6Addr ':all'; print to_string_ipv4_compressed ('dead:beef:0:3:2:1:cafe:babe'); produces output dead:beef::3:2:1:202.254.186.190 (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/to-string-ipv4.pl> in the distribution.) =head3 Parameters If used as an object method, none; if used as a subroutine, an IPv6 address string in any format. =head3 Returns The IPv6 address in the IPv4 format detailed by L et al. =head3 Notes When used as a subroutine, invalid input will generate an exception. From version L, this allows any IPv6 address to be produced, not just the restricted forms allowed previously. =head2 to_string_ipv4_compressed use Net::IPv6Addr ':all'; print to_string_ipv4_compressed ('dead:beef:0:3:2:1:cafe:babe'); produces output dead:beef::3:2:1:202.254.186.190 (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/to-string-ipv4-comp.pl> in the distribution.) =head3 Parameters If used as an object method, none; if used as a subroutine, an IPv6 address string in any format. =head3 Returns The IPv6 address in the compressed IPv4 format detailed by L et al. =head3 Notes When used as a subroutine, invalid input will generate an exception. From version L, this allows any IPv6 address to be produced, not just the restricted forms allowed previously. =head2 to_string_base85 =head3 Parameters If used as an object method, none; if used as a subroutine, an IPv6 address string in any format. =head3 Returns The IPv6 address in the style detailed by L. =head3 Notes Invalid input will generate an exception. The base 85 encoding described in L was an April Fool's joke. =head2 to_bigint use Net::IPv6Addr 'to_bigint'; my $int = to_bigint ('dead::beef'); my $ipobj = Net::IPv6Addr->new ('dead::beef'); my $int2 = $ipobj->to_bigint (); print "$int\n$int2\n"; produces output 295986882420777848964380943247191621359 295986882420777848964380943247191621359 (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/bigint.pl> in the distribution.) Convert an IPv6 address into a L object containing the IP address as a single number. =head3 Parameters If used as an object method, none; if used as a subroutine, an IPv6 address string in any format. =head3 Returns The BigInt representation of the given IPv6 address. =head3 Notes Invalid input will generate an exception. See also L, L and L. =head2 to_array use Net::IPv6Addr 'to_array'; my @int = to_array ('dead::beef'); my $ipobj = Net::IPv6Addr->new ('dead::beef'); my @int2 = $ipobj->to_array (); print "@int\n@int2\n"; produces output dead 0000 0000 0000 0000 0000 0000 beef dead 0000 0000 0000 0000 0000 0000 beef (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/array.pl> in the distribution.) Convert an IPv6 address into an array of eight hexadecimal numbers. =head3 Parameters If used as an object method, none; if used as a subroutine, an IPv6 address string in any format. =head3 Returns An array [0..7] of 16-bit hexadecimal numbers (strings). =head3 Notes Invalid input will generate an exception. See also L and L. =head2 to_intarray use Net::IPv6Addr 'to_array'; my @int = to_array ('dead::beef'); my $ipobj = Net::IPv6Addr->new ('dead::beef'); my @int2 = $ipobj->to_array (); print "@int\n@int2\n"; produces output dead 0000 0000 0000 0000 0000 0000 beef dead 0000 0000 0000 0000 0000 0000 beef (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/array.pl> in the distribution.) Convert an IPv6 address into an array of eight integer numbers. =head3 Parameters If used as an object method, none; if used as a subroutine, an IPv6 address string in any format. =head3 Returns An array [0..7] of numbers. =head3 Notes Invalid input will generate an exception. See also L and L. =head2 to_string_ip6_int use Net::IPv6Addr 'to_string_ip6_int'; my $s = to_string_ip6_int ('dead::beef'); my $ipobj = Net::IPv6Addr->new ('dead::beef'); my $s2 = $ipobj->to_string_ip6_int (); print "$s\n$s2\n"; produces output f.e.e.b.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.a.e.d.IP6.INT. f.e.e.b.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.a.e.d.IP6.INT. (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/string-ip6-int.pl> in the distribution.) =head3 Parameters If used as an object method, none; if used as a subroutine, an IPv6 address string in any format. =head3 Returns The reverse-address pointer as defined by L. =head3 Notes Invalid input will generate an exception. The reverse process of converting these into Net::IPv6Addr objects is not supported. =head2 in_network_of_size use Net::IPv6Addr 'in_network_of_size'; my $obj = in_network_of_size ('dead:beef:cafe:babe:dead:beef:cafe:babe', 42); print $obj->to_string_compressed (); produces output dead:beef:cac0:: (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/inos.pl> in the distribution.) Given an input IPv6 address $x, this returns the C<$n> most-significant bits of C<$x> as a new Net::IPv6Addr object. =head3 Parameters If used as an object method, network size in bits: my $obj = $x->in_network_of_size (64); If used as a subroutine, an IPv6 address string in any format and a network size in bits: my $obj = in_network_of_size ($addr, 64); Network size may also be given with C notation: my $obj = in_network_of_size ("$addr/64"); =head3 Returns The C<$n> most-significant bits of C<$x> as a new Net::IPv6Addr object. =head3 Notes Invalid input will generate an exception. Prior to version L, this did not work correctly unless the net size was a multiple of sixteen. =head2 in_network use Net::IPv6Addr; my $obj = Net::IPv6Addr->new ('dead:beef:cafe:babe:dead:beef:cafe:babe'); if ($obj->in_network ('dead:beef:ca0::/21')) { print $obj->to_string_compressed, " is in network.\n"; } produces output dead:beef:cafe:babe:dead:beef:cafe:babe is in network. (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/inet.pl> in the distribution.) =head3 Parameters If used as an object method, a network and its size in bits my $ok = $x->in_network ("aa:bb:cc:dd::", 64); If used as a subroutine, an IPv6 address string in any format, followed by a network address string and its size in bits. my $addr = 'fd00::54:20c:29fe:fe14:ab4b'; my $ok = Net::IPv6Addr::in_network ($addr, "aa:bb:cc:dd::", 64); The network size may also be given with the / notation after the network address string: my $ok = $x->in_network("aa:bb:cc:dd::/64"); =head3 Returns A true value if the address C<$x> is a member of the network given as the argument, or false otherwise. =head3 Notes Invalid input will generate an exception. Prior to version L, this did not work correctly unless the net size was a multiple of sixteen. =head2 from_bigint use Net::IPv6Addr 'from_bigint'; print from_bigint ('12345678901234567890')->to_string_compressed (); produces output ::ab54:a98c:eb1f:ad2 (This example is included as L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/examples/from-bigint.pl> in the distribution.) Given a string or a L object containing a number, this converts it into a Net::IPv6Addr object. =head3 Parameters A string or a Math::BigInt object. If the input is a scalar, it's converted into a Math::BigInt object. =head3 Returns A Net::IPv6Addr object =head3 Notes Invalid input will generate an exception. This function was added in L. =head1 EXPORTS As of version 0.96, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L may be exported on demand. All the exported functions may be exported using use Net::IPv6Addr ':all'; =head1 DEPENDENCIES =over =item L This is used to parse IPv4 addresses. =item L This is used to parse L (April Fool's) addresses. =item L This is used by the L (April Fool's) address routines and by L and L. =back =head2 Reverse dependencies L =head1 SEE ALSO =head2 RFCs The following RFCs (requests for comment, internet standards documentation) contain information on IPv6. =head3 Addressing Architecture series These are all the same standard, with updates. The most recent one is the active one. =over =item L I - December 1995 =item L I - July 1998 =item L I - April 2003 =item L I - February 2006 =back =head3 Other =over =item L I - December 1995 =item L I - 1 April 1996 This was an April Fool's joke. =item L I - August 2010 This contains a "recommendation for a canonical text representation format of IPv6 addresses" which corresponds to the output of L in this module. =back The links go to the plain text online versions of the RFCs. =head2 Other CPAN modules There are a very large number of CPAN modules which deal with IPv6 addresses. The following list gives all the ones I know about which overlap with this module, in alphabetical order. =over =item L This module uses L to validate IP addresses. It offers a number of facilities for special-purpose sub networks, like C, which are not offered in Net::IPv6Addr. =item L Its description says "A pure Perl IPv6 address manipulation library. Emphasis on manipulation of prefixes and addresses." It insists on having a prefix with the IP address, so my $ipv6 = IPv6::Address->new ('2001:0:0:1:0:0:0:1'); actually fails, you have to use my $ipv6 = IPv6::Address->new ('2001:0:0:1:0:0:0:1/64'); =item L Features binary IPs (strings like '101001'), etc. =item L It's a simplified version of L. =item L It's a "Version-agnostic representation of an IP address". I have not tried this module. =item L This module is broken and strongly not recommended. =item L =item L These are two things in the same distribution. The documentation is quite offputting, but there are a lot of users of the module and stars on metacpan. =item L This module consists of a regex for validating IPv6s. Because this module had a lot more and better tests than Net::IPv6Addr, I included the tests and one regex from C in this module. (See L|https://fastapi.metacpan.org/source/BKB/Net-IPv6Addr-0.96/t/Regexp-IPv6.t>) Unlike C, C disallows C<::>, "the unspecified addresses". See the module's documentation for details. =back =head2 Other =over =item Online validator L =back =head1 HISTORY This module was originally written by Tony Monroe in 2001 to simplify the task of maintaining DNS records after he set himself up with Freenet6. In 2017 the module was adopted by Ben Bullock with the help of Neil Bowers as part of "CPAN day". Significant changes to the module since then include the following: =over =item 0.8 Exporting of some functions was added. Prior to this, everything had to be done fully-qualified, as in C. =item 0.9 L and L were fixed to allow more kinds of previxes. =item 0.92 The valid format consisting of a compressed-but-non-zero six-element IPv6 followed by an IPv4, such as C, is accepted by the module. =item 0.95 The L method was added and the documentation updated to reflect the current internet standards. The restriction on mixed address inputs removed in L was also removed in the output routines L and L. =back =head1 AUTHOR Tony Monroe(*) The module's interface resembles L by Francis J. Lacoste Efrancis dot lacoste at iNsu dot COME. Some fixes and subroutines from Jyrki Soini Ejyrki dot soini at sonera dot comE. (*) The current module maintainer (BKB) does not have any contact information for Tony Monroe. Those wishing to contact him can do so via Neil Bowers (see L). =head1 LICENSE This distribution is copyright (c) 2001-2002 Tony Monroe. All rights reserved. This software is distributed under the same license terms as Perl itself. This software comes with NO WARRANTIES WHATSOEVER, express, implied, or otherwise. Net-IPv6Addr-0.96/examples/string-ip6-int.pl000644 001751 001751 00000000372 13355515465 020112 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr 'to_string_ip6_int'; my $s = to_string_ip6_int ('dead::beef'); my $ipobj = Net::IPv6Addr->new ('dead::beef'); my $s2 = $ipobj->to_string_ip6_int (); print "$s\n$s2\n"; Net-IPv6Addr-0.96/examples/preferred.pl000644 001751 001751 00000000242 13355516505 017266 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr 'to_string_preferred'; print to_string_preferred ('dead:beef:cafe:babe::f0ad'); Net-IPv6Addr-0.96/examples/bigint.pl000644 001751 001751 00000000352 13355514574 016572 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr 'to_bigint'; my $int = to_bigint ('dead::beef'); my $ipobj = Net::IPv6Addr->new ('dead::beef'); my $int2 = $ipobj->to_bigint (); print "$int\n$int2\n"; Net-IPv6Addr-0.96/examples/intarray.pl000644 001751 001751 00000000360 13355514633 017142 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr 'to_intarray'; my @int = to_intarray ('dead::beef'); my $ipobj = Net::IPv6Addr->new ('dead::beef'); my @int2 = $ipobj->to_intarray (); print "@int\n@int2\n"; Net-IPv6Addr-0.96/examples/compressed.pl000644 001751 001751 00000000262 13355516356 017462 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr 'to_string_compressed'; print to_string_compressed ('dead:beef:0000:0000:0000:0000:cafe:babe'); Net-IPv6Addr-0.96/examples/from-bigint.pl000644 001751 001751 00000000247 13356021777 017535 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr 'from_bigint'; print from_bigint ('12345678901234567890')->to_string_compressed (); Net-IPv6Addr-0.96/examples/to-string-ipv4.pl000644 001751 001751 00000000233 13356032610 020105 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr ':all'; print to_string_ipv4_compressed ('dead:beef:0:3:2:1:cafe:babe'); Net-IPv6Addr-0.96/examples/inos.pl000644 001751 001751 00000000333 13356036741 016261 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr 'in_network_of_size'; my $obj = in_network_of_size ('dead:beef:cafe:babe:dead:beef:cafe:babe', 42); print $obj->to_string_compressed (); Net-IPv6Addr-0.96/examples/to-string-ipv4-comp.pl000644 001751 001751 00000000233 13356032570 021046 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr ':all'; print to_string_ipv4_compressed ('dead:beef:0:3:2:1:cafe:babe'); Net-IPv6Addr-0.96/examples/array.pl000644 001751 001751 00000000347 13355514723 016434 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr 'to_array'; my @int = to_array ('dead::beef'); my $ipobj = Net::IPv6Addr->new ('dead::beef'); my @int2 = $ipobj->to_array (); print "@int\n@int2\n"; Net-IPv6Addr-0.96/examples/inet.pl000644 001751 001751 00000000413 13356037600 016242 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr; my $obj = Net::IPv6Addr->new ('dead:beef:cafe:babe:dead:beef:cafe:babe'); if ($obj->in_network ('dead:beef:ca0::/21')) { print $obj->to_string_compressed, " is in network.\n"; } Net-IPv6Addr-0.96/examples/synopsis.pl000644 001751 001751 00000000347 13150117446 017177 0ustar00benben000000 000000 #!/home/ben/software/install/bin/perl use warnings; use strict; use Net::IPv6Addr; my $addr = "dead:beef:cafe:babe::f0ad"; Net::IPv6Addr::ipv6_parse($addr); my $x = Net::IPv6Addr->new($addr); print $x->to_string_preferred(), "\n"; Net-IPv6Addr-0.96/t/vietnam.t000644 001751 001751 00000000713 13177706176 015242 0ustar00benben000000 000000 use warnings; use strict; use utf8; use FindBin '$Bin'; use Test::More; my $builder = Test::More->builder; binmode $builder->output, ":utf8"; binmode $builder->failure_output, ":utf8"; binmode $builder->todo_output, ":utf8"; binmode STDOUT, ":encoding(utf8)"; binmode STDERR, ":encoding(utf8)"; use Net::IPv6Addr; my $addr = Net::IPv6Addr->new ('2405:4800:56a7:b16:21bd:e851:60b6:202d'); ok ($addr->in_network ('2405:4800::/32')); done_testing (); Net-IPv6Addr-0.96/t/in-network.t000644 001751 001751 00000002003 13163710512 015646 0ustar00benben000000 000000 use warnings; use strict; use utf8; use FindBin '$Bin'; use Test::More; use Net::IPv6Addr; my $addr = 'fd00::54:20c:29fe:fe14:ab4b'; my $x = new Net::IPv6Addr($addr); my $in; eval { $in = $x->in_network("aa:bb:cc:dd::/64"); }; ok (! $@, "no error with address $addr"); ok (! $in, "not in network OK"); $in = $x->in_network ($addr, 64); ok ($in, "network is in itself for 64 bits"); $in = $x->in_network ($addr, 68); ok ($in, "network is in itself for 68 bits"); eval { $in = $x->in_network ($addr, 68888); }; ok ($@, "Too-big network gives error"); my $abcd = 'abcd:' x 7 . 'abcd'; my $y = Net::IPv6Addr->new ($abcd); my $obj = $y->in_network_of_size (64); my @ints = $obj->to_intarray (); my $h = hex ('abcd'); my $trunk = [$h, $h, $h, $h, 0, 0, 0, 0]; is_deeply (\@ints, $trunk, "Truncated to sixty-four bits"); my $obj2 = $y->in_network_of_size (68); my @ints2 = $obj2->to_intarray (); my $trunk2 = [$h, $h, $h, $h, $h & 0xF000, 0, 0, 0]; is_deeply (\@ints2, $trunk2, "Truncated to sixty-eight bits"); done_testing (); Net-IPv6Addr-0.96/t/Regexp-IPv6.t000644 001751 001751 00000012140 13356005756 015603 0ustar00benben000000 000000 # These tests of IPv6 addresses were poached from Regexp::IPv6. use Test::More; #use Regexp::IPv6 qw($IPv6_re); use Net::IPv6Addr 'ipv6_chkip'; # True or false depending on whether this test is supposed to match or not. my $good; #my $re = qr/^$IPv6_re$/; #my $nare = qr/($IPv6_re)/; while () { chomp; s/\s*#.*//; next if m/^$/; if (/^GOOD/) { $good = 1; next; } if (/^TODOGOOD/) { $todogood = 1; next; } if (/^BAD/) { $good = 0; next; } if ($good) { if ($todogood) { TODO: { local $TODO = 'compressed + ipv4'; ok (ipv6_chkip ($_), "good $_"); }; } else { ok (ipv6_chkip ($_), "good $_"); } } else { ok (! ipv6_chkip ($_), "bad $_"); } } done_testing (); exit; # most of the samples below were taken from the validate_ipv6.rb # script by Christoph Petschnig (Michael Erickson pointed me there). # some samples are from the Wikipedia. # some samples contributed by Michael G. Schwern __DATA__ GOOD: ::127.0.0.1 ::1 2001:0db8:85a3:0000:0000:8a2e:0370:7334 2001:db8:85a3:0:0:8a2e:370:7334 2001:db8:85a3::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 ::ffff:12.34.56.78 ::ffff:0c22:384e 2001:0db8:1234:ffff:ffff:ffff:ffff:ffff 2001:0db8:1234:0000:0000:0000:0000:0000 2001:db8:a::123 fc00:: ::ffff:0:0 2001:: 2001:10:: 2001:db8:: 2001:0000:1234:0000:0000:C1C0:ABCD:0876 3ffe:0b00:0000:0000:0001:0000:0000:000a FF02:0000:0000:0000:0000:0000:0000:0001 0000:0000:0000:0000:0000:0000:0000:0001 0000:0000:0000:0000:0000:0000:0000:0000 ::ffff:192.168.1.26 2::10 ff02::1 fe80:: 2002:: 2001:db8:: 2001:0db8:1234:: ::ffff:0:0 ::1 ::ffff:192.168.1.1 1:2:3:4:5:6:7:8 1:2:3:4:5:6::8 1:2:3:4:5::8 1:2:3:4::8 1:2:3::8 1:2::8 1::8 1::2:3:4:5:6:7 1::2:3:4:5:6 1::2:3:4:5 1::2:3:4 1::2:3 1::8 ::2:3:4:5:6:7:8 ::2:3:4:5:6:7 ::2:3:4:5:6 ::2:3:4:5 ::2:3:4 ::2:3 ::8 1:2:3:4:5:6:: 1:2:3:4:5:: 1:2:3:4:: 1:2:3:: 1:2:: 1:: 1:2:3:4:5::7:8 2001:0000:1234:0000:0000:C1C0:ABCD:0876 1:2:3:4::7:8 1:2:3::7:8 1:2::7:8 1::7:8 fe80::217:f2ff:fe07:ed62 2001:DB8:0:0:8:800:200C:417A # unicast, full FF01:0:0:0:0:0:0:101 # multicast, full 0:0:0:0:0:0:0:1 # loopback, full 0:0:0:0:0:0:0:0 # unspecified, full 2001:DB8::8:800:200C:417A # unicast, compressed FF01::101 # multicast, compressed ::1 # loopback, compressed, non-routable 0:0:0:0:0:0:13.1.68.3 # IPv4-compatible IPv6 address, full, deprecated 0:0:0:0:0:FFFF:129.144.52.38 # IPv4-mapped IPv6 address, full ::13.1.68.3 # IPv4-compatible IPv6 address, compressed, deprecated ::FFFF:129.144.52.38 # IPv4-mapped IPv6 address, compressed fe80:0000:0000:0000:0204:61ff:fe9d:f156 fe80:0:0:0:204:61ff:fe9d:f156 fe80::204:61ff:fe9d:f156 fe80:: fe80::1 0000:0000:0000:0000:0000:0000:0000:0001 ::1 ::ffff:192.0.2.128 ::ffff:c000:280 # Double colon is a valid address, so this was moved from BAD: to here. # See also # https://metacpan.org/pod/release/SALVA/Regexp-IPv6-0.03/lib/Regexp/IPv6.pm#DESCRIPTION # https://rt.cpan.org/Public/Bug/Display.html?id=62125 :: # These are valid addresses, but the original Tony Monroe # Net::IPv6Addr did not recognise them. From version 0.92, these are # accepted by the module, so the disqualifier is no longer here. 1:2:3:4:5:6:1.2.3.4 1:2:3:4:5::1.2.3.4 1:2:3:4::1.2.3.4 1:2:3::1.2.3.4 1:2::1.2.3.4 1::1.2.3.4 1:2:3:4::5:1.2.3.4 1:2:3::5:1.2.3.4 1:2::5:1.2.3.4 1::5:1.2.3.4 1::5:11.22.33.44 fe80::217:f2ff:254.7.237.98 fe80:0:0:0:204:61ff:254.157.241.86 fe80::204:61ff:254.157.241.86 BAD: 127.0.0.1 : 2001:0000:1234:0000:0000:C1C0:ABCD:0876 0 2001:0000:1234: 0000:0000:C1C0:ABCD:0876 02001:0000:1234:0000:0000:C1C0:ABCD:0876 # extra 0 not allowed! 2001:0000:1234:0000:00001:C1C0:ABCD:0876 # extra 0 not allowed! 3ffe:0b00:0000:0001:0000:0000:000a FF02:0000:0000:0000:0000:0000:0000:0000:0001 3ffe:b00::1::a ::1111:2222:3333:4444:5555:6666:: 1:2:3::4:5::7:8 12345::6:7:8 1::5:400.2.3.4 1::5:260.2.3.4 1::5:256.2.3.4 1::5:1.256.3.4 1::5:1.2.256.4 1::5:1.2.3.256 1::5:300.2.3.4 1::5:1.300.3.4 1::5:1.2.300.4 1::5:1.2.3.300 1::5:900.2.3.4 1::5:1.900.3.4 1::5:1.2.900.4 1::5:1.2.3.900 1::5:300.300.300.300 1::5:3000.30.30.30 1::400.2.3.4 1::260.2.3.4 1::256.2.3.4 1::1.256.3.4 1::1.2.256.4 1::1.2.3.256 1::300.2.3.4 1::1.300.3.4 1::1.2.300.4 1::1.2.3.300 1::900.2.3.4 1::1.900.3.4 1::1.2.900.4 1::1.2.3.900 1::300.300.300.300 1::3000.30.30.30 ::400.2.3.4 ::260.2.3.4 ::256.2.3.4 ::1.256.3.4 ::1.2.256.4 ::1.2.3.256 ::300.2.3.4 ::1.300.3.4 ::1.2.300.4 ::1.2.3.300 ::900.2.3.4 ::1.900.3.4 ::1.2.900.4 ::1.2.3.900 ::300.300.300.300 ::3000.30.30.30 2001:DB8:0:0:8:800:200C:417A:221 # unicast, full FF01::101::2 # multicast, compressed 1111:2222:3333:4444::5555: 1111:2222:3333::5555: 1111:2222::5555: 1111::5555: ::5555: ::: 1111: : :1111:2222:3333:4444::5555 :1111:2222:3333::5555 :1111:2222::5555 :1111::5555 :::5555 ::: 1.2.3.4:1111:2222:3333:4444::5555 1.2.3.4:1111:2222:3333::5555 1.2.3.4:1111:2222::5555 1.2.3.4:1111::5555 1.2.3.4::5555 1.2.3.4:: 123 ldkfj 2001::FFD3::57ab 2001:db8:85a3::8a2e:37023:7334 2001:db8:85a3::8a2e:370k:7334 1:2:3:4:5:6:7:8:9 1::2::3 1:::3:4:5 1:2:3::4:5:6:7:8:9 ::ffff:2.3.4 ::ffff:257.1.2.3 1.2.3.4 Net-IPv6Addr-0.96/t/ipv4.t000644 001751 001751 00000003614 07326060726 014455 0ustar00benben000000 000000 use strict; use Test; BEGIN { plan test => 31; } use Net::IPv6Addr; ok(1); my @x; # Test ipv6_parse_ipv4, garbage. eval { @x = Net::IPv6Addr::ipv6_parse_ipv4("absolute and utter garbage"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4, bad ipv6 digits. eval { @x = Net::IPv6Addr::ipv6_parse_ipv4("x:0:0:0:0:0:10.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4, bad ipv4 digits. eval { @x = Net::IPv6Addr::ipv6_parse_ipv4("0:0:0:0:0:0:x.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4, adjacent : eval { @x = Net::IPv6Addr::ipv6_parse_ipv4("0:0:0:0:0::0:10.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4, too many ipv6 digits. eval { @x = Net::IPv6Addr::ipv6_parse_ipv4("00000:0:0:0:0:0:10.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4, too many ipv4 digits. eval { @x = Net::IPv6Addr::ipv6_parse_ipv4("0:0:0:0:0:0:10.0.0.1000"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4, too many : eval { @x = Net::IPv6Addr::ipv6_parse_ipv4("0:0:0:0:0:0:0:10.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4, not enough : eval { @x = Net::IPv6Addr::ipv6_parse_ipv4("0:0:0:0:0:10.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4, too many . eval { @x = Net::IPv6Addr::ipv6_parse_ipv4("0:0:0:0:0:0:10.0.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4, not enough . eval { @x = Net::IPv6Addr::ipv6_parse_ipv4("0:0:0:0:0:0:10.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4, adjacent . eval { @x = Net::IPv6Addr::ipv6_parse_ipv4("0:0:0:0:0:0:10.0.0..1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4, good stuff. @x = Net::IPv6Addr::ipv6_parse_ipv4("0:0:0:0:0:0:10.0.0.1"); ok($x[0], 0); ok($x[1], 0); ok($x[2], 0); ok($x[3], 0); ok($x[4], 0); ok($x[5], 0); ok($x[6], 0xa00); ok($x[7], 1); Net-IPv6Addr-0.96/t/string.t000644 001751 001751 00000004323 13356030540 015066 0ustar00benben000000 000000 use warnings; use strict; use Test::More; use Net::IPv6Addr; my $w = new Net::IPv6Addr("ab:cd:ef:01:23:45:67:89"); is($w->to_string_preferred(), "ab:cd:ef:1:23:45:67:89"); is($w->to_string_compressed(), "ab:cd:ef:1:23:45:67:89"); is ($w->to_string_ipv4(), "ab:cd:ef:1:23:45:0.103.0.137"); is ($w->to_string_ipv4_compressed(), "ab:cd:ef:1:23:45:0.103.0.137"); is($w->to_string_ip6_int(), "9.8.0.0.7.6.0.0.5.4.0.0.3.2.0.0.1.0.0.0.f.e.0.0.d.c.0.0.b.a.0.0.IP6.INT."); my $x = new Net::IPv6Addr("::"); is($x->to_string_preferred(), "0:0:0:0:0:0:0:0"); is($x->to_string_compressed(), "::"); is($x->to_string_ipv4(), "0:0:0:0:0:0:0.0.0.0"); is($x->to_string_ipv4_compressed(), "::0.0.0.0"); is($x->to_string_ip6_int(), "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.INT."); my $y = new Net::IPv6Addr("::1"); is($y->to_string_preferred(), "0:0:0:0:0:0:0:1"); is($y->to_string_compressed(), "::1"); is($y->to_string_ipv4(), "0:0:0:0:0:0:0.0.0.1"); is($y->to_string_ipv4_compressed(), "::0.0.0.1"); is($y->to_string_ip6_int(), "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.INT."); my $z = new Net::IPv6Addr("abcd:ef12::3456:789a"); is($z->to_string_preferred(), "abcd:ef12:0:0:0:0:3456:789a"); is($z->to_string_compressed(), "abcd:ef12::3456:789a"); is ($z->to_string_ipv4, 'abcd:ef12:0:0:0:0:52.86.120.154'); is($z->to_string_ip6_int(), "a.9.8.7.6.5.4.3.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.1.f.e.d.c.b.a.IP6.INT."); is ($z->to_string_ipv4_compressed, 'abcd:ef12::52.86.120.154'); my $p = new Net::IPv6Addr("::ffff:10.0.0.1"); is($p->to_string_preferred(), "0:0:0:0:0:ffff:a00:1"); is($p->to_string_compressed(), "::ffff:a00:1"); is($p->to_string_ipv4(), "0:0:0:0:0:ffff:10.0.0.1"); is($p->to_string_ipv4_compressed(), "::ffff:10.0.0.1"); is($p->to_string_ip6_int(), "1.0.0.0.0.0.a.0.f.f.f.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.INT."); my $q; $q = new Net::IPv6Addr("0:0:0:0:0:0:10.0.0.1"); is($q->to_string_preferred(), "0:0:0:0:0:0:a00:1"); is($q->to_string_compressed(), "::a00:1"); is($q->to_string_ipv4(), "0:0:0:0:0:0:10.0.0.1"); is($q->to_string_ipv4_compressed(), "::10.0.0.1"); is($q->to_string_ip6_int(), "1.0.0.0.0.0.a.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.INT."); done_testing (); Net-IPv6Addr-0.96/t/parse.t000644 001751 001751 00000003117 13165570065 014703 0ustar00benben000000 000000 use strict; use Test::More; use Net::IPv6Addr qw/ipv6_parse is_ipv6/; # Yeah, so I was listening to it when I wrote the test. my $input = "sunshine of your love"; eval { Net::IPv6Addr::ipv6_parse($input); }; ok($@, "Error with bad address"); like($@, qr/invalid IPv6 address/, "correct error message"); ok (! is_ipv6 ($input), "Bad address not accepted"); $input = "::/x"; eval { Net::IPv6Addr::ipv6_parse($input); }; ok($@, "Error with $input"); like($@, qr/non-numeric prefix length/, "Reject non-numeric prefix length"); ok (! is_ipv6 ($input), "Reject non-numeric prefix length"); $input = "::/-19325"; eval { Net::IPv6Addr::ipv6_parse($input); }; ok($@, "error with negative prefix"); like($@, qr/non-numeric prefix length/, "Reject negative prefix length"); ok (! is_ipv6 ($input), "Reject negative prefix length"); $input = "::/65389"; eval { Net::IPv6Addr::ipv6_parse($input); }; ok($@, "error with $input"); like($@, qr/invalid prefix length/, "Reject excessive prefix length"); ok (! is_ipv6 ($input), "Reject excessive prefix length"); $input = "a:b:c:d:0:1:2:3"; is(scalar(Net::IPv6Addr::ipv6_parse($input)), $input, "Valid address OK (ipv6_parse)"); ok (is_ipv6 ($input), "Valid address OK (is_ipv6)"); $input = "a::/24"; my ($x, $y) = Net::IPv6Addr::ipv6_parse($input); is($x, "a::", "Valid address OK"); is($y, 24, "Valid address OK"); ok (is_ipv6 ($input), "Valid address OK"); my @inputs = ('a::', '24'); my ($x2, $y2) = Net::IPv6Addr::ipv6_parse(@inputs); is($x2, "a::", "Valid address OK"); is($y2, 24, "Valid address OK"); ok (is_ipv6 (@inputs), "Valid address OK"); done_testing (); Net-IPv6Addr-0.96/t/synopsis.t000644 001751 001751 00000000407 13150122366 015446 0ustar00benben000000 000000 use warnings; use strict; use FindBin '$Bin'; use Test::More; my $synopsis; open my $in, "<", "$Bin/../examples/synopsis.pl" or die $!; while (<$in>) { $synopsis .= $_; } close $in or die $!; eval $synopsis; ok (! $@); if ($@) { diag ($@); } done_testing (); Net-IPv6Addr-0.96/t/rfc5952.t000644 001751 001751 00000004007 13356031607 014663 0ustar00benben000000 000000 # This tests the module's compliance with RFC 5952. The tests here are # directly copy-pasted from the document itself. See # https://tools.ietf.org/rfc/rfc5952.txt. No alterations to the # module were necessary, since it already complied with the # requirements described. use warnings; use strict; use utf8; use FindBin '$Bin'; use Test::More; my $builder = Test::More->builder; binmode $builder->output, ":utf8"; binmode $builder->failure_output, ":utf8"; binmode $builder->todo_output, ":utf8"; binmode STDOUT, ":encoding(utf8)"; binmode STDERR, ":encoding(utf8)"; use Net::IPv6Addr ':all'; my @same = qw! 2001:db8:0:0:1:0:0:1 2001:0db8:0:0:1:0:0:1 2001:db8::1:0:0:1 2001:db8::0:1:0:0:1 2001:0db8::1:0:0:1 2001:db8:0:0:1::1 2001:db8:0000:0:1::1 2001:DB8:0:0:1::1 !; my @same2 = qw! 2001:db8:aaaa:bbbb:cccc:dddd:eeee:0001 2001:db8:aaaa:bbbb:cccc:dddd:eeee:001 2001:db8:aaaa:bbbb:cccc:dddd:eeee:01 2001:db8:aaaa:bbbb:cccc:dddd:eeee:1 !; my @same3 = qw! 2001:db8:aaaa:bbbb:cccc:dddd::1 2001:db8:aaaa:bbbb:cccc:dddd:0:1 !; my @same4 = qw! 2001:db8::aaaa:0:0:1 2001:db8:0:0:aaaa::1 !; my @same5 = qw! 2001:db8:aaaa:bbbb:cccc:dddd:eeee:aaaa 2001:db8:aaaa:bbbb:cccc:dddd:eeee:AAAA 2001:db8:aaaa:bbbb:cccc:dddd:eeee:AaAa !; # Base for comparison. for my $array (\@same, \@same2, \@same3, \@same4, \@same5) { my $comp; for my $ip (@$array) { my $ni = Net::IPv6Addr->new ($ip); my $s = $ni->to_string_preferred (); if (! $comp) { $comp = $s; } else { is ($s, $comp, "Identical outputs for $ip"); } } } is (to_string_compressed ('2001:0db8::0001'), '2001:db8::1', "Section 4.1"); is (to_string_compressed ('2001:db8:0:0:0:0:2:1'), '2001:db8::2:1', "Section 4.2.1"); is (to_string_compressed ('2001:0:0:1:0:0:0:1'), '2001:0:0:1::1', "Section 4.2.3"); is (to_string_compressed ('2001:db8:0:0:1:0:0:1'), '2001:db8::1:0:0:1', "Section 4.2.3"); done_testing (); Net-IPv6Addr-0.96/t/preferred.t000644 001751 001751 00000002567 07326066754 015566 0ustar00benben000000 000000 use strict; use Test; BEGIN { plan test => 25; } use Net::IPv6Addr; ok(1); my @x; # Test ipv6_parse_preferred, garbage input. eval { @x = Net::IPv6Addr::ipv6_parse_preferred("nathan jones"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_preferred, too many : eval { @x = Net::IPv6Addr::ipv6_parse_preferred("0:1:2:3:4:5:6:7:8"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_preferred, not enough : eval { @x = Net::IPv6Addr::ipv6_parse_preferred("0:1:2:3:4:5:6"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_preferred, bad digits. eval { @x = Net::IPv6Addr::ipv6_parse_preferred("0:1:2:3:4:5:6:x"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_preferred, adjacent : eval { @x = Net::IPv6Addr::ipv6_parse_preferred("0:1:2:3:4:5:6::7"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_preferred, too many digits. eval { @x = Net::IPv6Addr::ipv6_parse_preferred("0:1:2:3:4:5:6:789ab"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_preferred, : on boundary. eval { @x = Net::IPv6Addr::ipv6_parse_preferred(":0:1:2:3:4:5:6"); }; ok($@); ok($@, qr/invalid address/); eval { @x = Net::IPv6Addr::ipv6_parse_preferred("0:1:2:3:4:5:6:"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_preferred, with good stuff. @x = Net::IPv6Addr::ipv6_parse_preferred("0:1:2:3:4:5:6:7"); for my $i (0..7) { ok($x[$i], $i); } Net-IPv6Addr-0.96/t/chkip.t000644 001751 001751 00000010557 13355520603 014667 0ustar00benben000000 000000 use strict; use Test::More; use Net::IPv6Addr; my $x; # Test ipv6_chkip with garbage. $x = Net::IPv6Addr::ipv6_chkip("Obvious Garbage"); ok(not defined $x); # Test ipv6_chkip with preferred style, too many : $x = Net::IPv6Addr::ipv6_chkip("0:1:2:3:4:5:6:7:8"); ok(not defined $x); # Test ipv6_chkip with preferred style, not enough : $x = Net::IPv6Addr::ipv6_chkip("0:1:2:3:4:5:6"); ok(not defined $x); # Test ipv6_chkip with preferred style, bad digits. $x = Net::IPv6Addr::ipv6_chkip("0:1:2:3:4:5:6:x"); ok(not defined $x); # Test ipv6_chkip with preferred style, adjacent : $x = Net::IPv6Addr::ipv6_chkip("0:1:2:3:4:5:6::7"); ok(not defined $x); # Test ipv6_chkip with preferred style, too many digits. $x = Net::IPv6Addr::ipv6_chkip("0:1:2:3:4:5:6:789abcdef"); ok(not defined $x); # Test ipv6_chkip with preferred style. $x = Net::IPv6Addr::ipv6_chkip("0:1:2:3:4:5:6:789a"); ok(ref $x, 'CODE'); # Test ipv6_chkip with compressed style, bad digits. $x = Net::IPv6Addr::ipv6_chkip("0:1:2:3::x"); ok(not defined $x); # Test ipv6_chkip with compressed style, too many adjacent : $x = Net::IPv6Addr::ipv6_chkip("0:1:2:::3"); ok(not defined $x); # Test ipv6_chkip with compressed style, too many digits. $x = Net::IPv6Addr::ipv6_chkip("0:1:2:3::abcde"); ok(not defined $x); # Test ipv6_chkip with compressed style, too many : $x = Net::IPv6Addr::ipv6_chkip("0:1:2:3:4:5:6:7:8"); ok(not defined $x); # Test ipv6_chkip with compressed style, not enough : $x = Net::IPv6Addr::ipv6_chkip("0:1"); ok(not defined $x); # Test ipv6_chkip with compressed style. $x = Net::IPv6Addr::ipv6_chkip("0:1:2:3::f"); ok(ref $x, 'CODE'); # Test ipv6_chkip with ipv4 style, bad ipv6 digits. $x = Net::IPv6Addr::ipv6_chkip("0:0:0:0:0:x:10.0.0.1"); ok(not defined $x); # Test ipv6_chkip with ipv4 style, bad ipv4 digits. $x = Net::IPv6Addr::ipv6_chkip("0:0:0:0:0:0:10.0.0.x"); ok(not defined $x); # Test ipv6_chkip with ipv4 style, adjacent : $x = Net::IPv6Addr::ipv6_chkip("0:0:0:0:0::0:10.0.0.1"); ok(not defined $x); # Test ipv6_chkip with ipv4 style, too many ipv6 digits. $x = Net::IPv6Addr::ipv6_chkip("0:0:0:0:0:00000:10.0.0.1"); ok(not defined $x); # Test ipv6_chkip with ipv4 style, too many : $x = Net::IPv6Addr::ipv6_chkip("0:0:0:0:0:0:0:10.0.0.1"); ok(not defined $x); # Test ipv6_chkip with ipv4 style, not enough : $x = Net::IPv6Addr::ipv6_chkip("0:0:0:0:0:10.0.0.1"); ok(not defined $x); # Test ipv6_chkip with ipv4 style, too many . $x = Net::IPv6Addr::ipv6_chkip("0:0:0:0:0:0:10.0.0.0.1"); ok(not defined $x); # Test ipv6_chkip with ipv4 style, not enough . $x = Net::IPv6Addr::ipv6_chkip("0:0:0:0:0:0:10.0.1"); ok(not defined $x); # Test ipv6_chkip with ipv4 style, adjacent . $x = Net::IPv6Addr::ipv6_chkip("0:0:0:0:0:0:10..0.0.1"); ok(not defined $x); # Test ipv6_chkip with ipv4 style. $x = Net::IPv6Addr::ipv6_chkip("0:0:0:0:0:0:10.0.0.1"); ok(ref $x, 'CODE'); # Test ipv6_chkip with compressed ipv4 style, bad ipv6 digits. $x = Net::IPv6Addr::ipv6_chkip("::fffx:192.168.0.1"); ok(not defined $x); # Test ipv6_chkip with compressed ipv4 style, bad ipv4 digits. $x = Net::IPv6Addr::ipv6_chkip("::ffff:192.168.0.x"); ok(not defined $x); # Test ipv6_chkip with compressed ipv4 style, too many adjacent : $x = Net::IPv6Addr::ipv6_chkip(":::ffff:192.168.0.1"); ok(not defined $x); # Test ipv6_chkip with compressed ipv4 style, too many ipv6 digits. $x = Net::IPv6Addr::ipv6_chkip("::fffff:192.168.0.1"); ok(not defined $x); # Test ipv6_chkip with compressed ipv4 style, too many ipv4 digits. $x = Net::IPv6Addr::ipv6_chkip("::ffff:1923.168.0.1"); ok(not defined $x); # Test ipv6_chkip with compressed ipv4 style, not enough : $x = Net::IPv6Addr::ipv6_chkip(":ffff:192.168.0.1"); ok(not defined $x); # Test ipv6_chkip with compressed ipv4 style, too many . $x = Net::IPv6Addr::ipv6_chkip("::ffff:192.168.0.1.2"); ok(not defined $x); # Test ipv6_chkip with compressed ipv4 style, not enough . $x = Net::IPv6Addr::ipv6_chkip("::ffff:192.168.0"); ok(not defined $x); # Test ipv6_chkip with compressed ipv4 style, adjacent . $x = Net::IPv6Addr::ipv6_chkip("::ffff:192.168..0.1"); ok(not defined $x); # Test ipv6_chkip with compressed ipv4 style. $x = Net::IPv6Addr::ipv6_chkip("::ffff:192.168.0.1"); ok(ref $x, 'CODE'); eval { Net::IPv6Addr::ipv6_parse ('failburger'); }; ok ($@, "failed to parse nonsense"); unlike ($@, qr!Net::IPv6Addr::Net::IPv6Addr!, "Did not get Clement Freud output"); done_testing (); Net-IPv6Addr-0.96/t/new.t000644 001751 001751 00000011210 07326077450 014355 0ustar00benben000000 000000 use strict; use Test; BEGIN { plan test => 63; } use Net::IPv6Addr; ok(1); my $x; # Test new with garbage. eval { $x = new Net::IPv6Addr("Obvious Garbage"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with preferred style, too many : eval { $x = new Net::IPv6Addr("0:1:2:3:4:5:6:7:8"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with preferred style, not enough : eval { $x = new Net::IPv6Addr("0:1:2:3:4:5:6"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with preferred style, bad digits. eval { $x = new Net::IPv6Addr("0:1:2:3:4:5:6:x"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with preferred style, adjacent : eval { $x = new Net::IPv6Addr("0:1:2:3:4:5:6::7"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with preferred style, too many digits. eval { $x = new Net::IPv6Addr("0:1:2:3:4:5:6:789abcdef"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with preferred style. $x = new Net::IPv6Addr("0:1:2:3:4:5:6:789a"); ok(ref $x, 'Net::IPv6Addr'); # Test new with compressed style, bad digits. eval { $x = new Net::IPv6Addr("0:1:2:3::x"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed style, too many adjacent : eval { $x = new Net::IPv6Addr("0:1:2:::3"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed style, too many digits. eval { $x = new Net::IPv6Addr("0:1:2:3::abcde"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed style, too many : eval { $x = new Net::IPv6Addr("0:1:2:3:4:5:6:7:8"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed style, not enough : eval { $x = new Net::IPv6Addr("0:1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed style. $x = new Net::IPv6Addr("0:1:2:3::f"); ok(ref $x, 'Net::IPv6Addr'); # Test new with ipv4 style, bad ipv6 digits. eval { $x = new Net::IPv6Addr("0:0:0:0:0:x:10.0.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with ipv4 style, bad ipv4 digits. eval { $x = new Net::IPv6Addr("0:0:0:0:0:0:10.0.0.x"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with ipv4 style, adjacent : eval { $x = new Net::IPv6Addr("0:0:0:0:0::0:10.0.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with ipv4 style, too many ipv6 digits. eval { $x = new Net::IPv6Addr("0:0:0:0:0:00000:10.0.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with ipv4 style, too many : eval { $x = new Net::IPv6Addr("0:0:0:0:0:0:0:10.0.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with ipv4 style, not enough : eval { $x = new Net::IPv6Addr("0:0:0:0:0:10.0.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with ipv4 style, too many . eval { $x = new Net::IPv6Addr("0:0:0:0:0:0:10.0.0.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with ipv4 style, not enough . eval { $x = new Net::IPv6Addr("0:0:0:0:0:0:10.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with ipv4 style, adjacent . eval { $x = new Net::IPv6Addr("0:0:0:0:0:0:10..0.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with ipv4 style. $x = new Net::IPv6Addr("0:0:0:0:0:0:10.0.0.1"); ok(ref $x, 'Net::IPv6Addr'); # Test new with compressed ipv4 style, bad ipv6 digits. eval { $x = new Net::IPv6Addr("::fffx:192.168.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed ipv4 style, bad ipv4 digits. eval { $x = new Net::IPv6Addr("::ffff:192.168.0.x"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed ipv4 style, too many adjacent : eval { $x = new Net::IPv6Addr(":::ffff:192.168.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed ipv4 style, too many ipv6 digits. eval { $x = new Net::IPv6Addr("::fffff:192.168.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed ipv4 style, too many ipv4 digits. eval { $x = new Net::IPv6Addr("::ffff:1923.168.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed ipv4 style, not enough : eval { $x = new Net::IPv6Addr(":ffff:192.168.0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed ipv4 style, too many . eval { $x = new Net::IPv6Addr("::ffff:192.168.0.1.2"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed ipv4 style, not enough . eval { $x = new Net::IPv6Addr("::ffff:192.168.0"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed ipv4 style, adjacent . eval { $x = new Net::IPv6Addr("::ffff:192.168..0.1"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with compressed ipv4 style. $x = new Net::IPv6Addr("::ffff:192.168.0.1"); ok(ref $x, 'Net::IPv6Addr'); Net-IPv6Addr-0.96/t/compressed.t000644 001751 001751 00000002000 07325713363 015724 0ustar00benben000000 000000 use strict; use Test; BEGIN { plan test => 19; } use Net::IPv6Addr; ok(1); my @x; # Test ipv6_parse_compressed, bad digits. eval { @x = Net::IPv6Addr::ipv6_parse_compressed("::x"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_compressed, too many adjacent : eval { @x = Net::IPv6Addr::ipv6_parse_compressed(":::1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_compressed, too many digits. eval { @x = Net::IPv6Addr::ipv6_parse_compressed("::11111"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_compressed, too many : eval { @x = Net::IPv6Addr::ipv6_parse_compressed("0:1:2:3:4:5:6::7"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_compressed, not enough : eval { @x = Net::IPv6Addr::ipv6_parse_compressed(":1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_compressed, with good stuff. @x = Net::IPv6Addr::ipv6_parse_compressed("::1"); ok($x[0], 0); ok($x[1], 0); ok($x[2], 0); ok($x[3], 0); ok($x[4], 0); ok($x[5], 0); ok($x[6], 0); ok($x[7], 1); Net-IPv6Addr-0.96/t/bigint.t000644 001751 001751 00000007643 13356013051 015042 0ustar00benben000000 000000 # Test a list of weird IPs against various round trips through # to_bigint, to_array, and to_intarray. use warnings; use strict; use utf8; use FindBin '$Bin'; use Test::More; my $builder = Test::More->builder; binmode $builder->output, ":utf8"; binmode $builder->failure_output, ":utf8"; binmode $builder->todo_output, ":utf8"; binmode STDOUT, ":encoding(utf8)"; binmode STDERR, ":encoding(utf8)"; use Net::IPv6Addr ':all'; use Math::BigInt; my ($good, $todogood); while () { chomp; s/\s*#.*//; next if m/^$/; if (/^GOOD/) { $good = 1; next; } if (/^TODOGOOD/) { $todogood = 1; next; } if (/^BAD/) { $good = 0; next; } if ($good) { if ($todogood) { TODO: { local $TODO = 'fails'; big_round ($_); }; } else { big_round ($_); } } else { die "I'm bad, I'm bad, you know it, I'm really really bad"; } } done_testing (); # Round trip big int test sub big_round { my ($ipv6) = @_; my $o = Net::IPv6Addr->new ($ipv6); my $can = $o->to_string_compressed (); my $big = $o->to_bigint (); my @ia = $o->to_intarray (); my @ha = $o->to_array (); my $ipr = from_bigint ($big); my $iar = join (':', map {sprintf ("%04X", $_)} @ia); my $har = join (':', @ha); my $iarr = to_string_compressed ($iar); my $harr = to_string_compressed ($har); my $canr = $ipr->to_string_compressed (); is ($canr, $can, "Round trip of $ipv6 thru to/from_bigint"); is ($iarr, $can, "Round trip of $ipv6 thru to_intarray"); is ($harr, $can, "Round trip of $ipv6 thru to_array"); } __DATA__ GOOD ::127.0.0.1 ::1 2001:0db8:85a3:0000:0000:8a2e:0370:7334 2001:db8:85a3:0:0:8a2e:370:7334 2001:db8:85a3::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 ::ffff:12.34.56.78 ::ffff:0c22:384e 2001:0db8:1234:ffff:ffff:ffff:ffff:ffff 2001:0db8:1234:0000:0000:0000:0000:0000 2001:db8:a::123 fc00:: ::ffff:0:0 2001:: 2001:10:: 2001:db8:: 2001:0000:1234:0000:0000:C1C0:ABCD:0876 3ffe:0b00:0000:0000:0001:0000:0000:000a FF02:0000:0000:0000:0000:0000:0000:0001 0000:0000:0000:0000:0000:0000:0000:0001 0000:0000:0000:0000:0000:0000:0000:0000 ::ffff:192.168.1.26 2::10 ff02::1 fe80:: 2002:: 2001:db8:: 2001:0db8:1234:: ::ffff:0:0 ::1 ::ffff:192.168.1.1 1:2:3:4:5:6:7:8 1:2:3:4:5:6::8 1:2:3:4:5::8 1:2:3:4::8 1:2:3::8 1:2::8 1::8 1::2:3:4:5:6:7 1::2:3:4:5:6 1::2:3:4:5 1::2:3:4 1::2:3 1::8 ::2:3:4:5:6:7:8 ::2:3:4:5:6:7 ::2:3:4:5:6 ::2:3:4:5 ::2:3:4 ::2:3 ::8 1:2:3:4:5:6:: 1:2:3:4:5:: 1:2:3:4:: 1:2:3:: 1:2:: 1:: 1:2:3:4:5::7:8 2001:0000:1234:0000:0000:C1C0:ABCD:0876 1:2:3:4::7:8 1:2:3::7:8 1:2::7:8 1::7:8 fe80::217:f2ff:fe07:ed62 2001:DB8:0:0:8:800:200C:417A # unicast, full FF01:0:0:0:0:0:0:101 # multicast, full 0:0:0:0:0:0:0:1 # loopback, full 0:0:0:0:0:0:0:0 # unspecified, full 2001:DB8::8:800:200C:417A # unicast, compressed FF01::101 # multicast, compressed ::1 # loopback, compressed, non-routable 0:0:0:0:0:0:13.1.68.3 # IPv4-compatible IPv6 address, full, deprecated 0:0:0:0:0:FFFF:129.144.52.38 # IPv4-mapped IPv6 address, full ::13.1.68.3 # IPv4-compatible IPv6 address, compressed, deprecated ::FFFF:129.144.52.38 # IPv4-mapped IPv6 address, compressed fe80:0000:0000:0000:0204:61ff:fe9d:f156 fe80:0:0:0:204:61ff:fe9d:f156 fe80::204:61ff:fe9d:f156 fe80:: fe80::1 0000:0000:0000:0000:0000:0000:0000:0001 ::1 ::ffff:192.0.2.128 ::ffff:c000:280 # Double colon is a valid address, so this was moved from BAD: to here. # See also # https://metacpan.org/pod/release/SALVA/Regexp-IPv6-0.03/lib/Regexp/IPv6.pm#DESCRIPTION # https://rt.cpan.org/Public/Bug/Display.html?id=62125 :: 1:2:3:4:5:6:1.2.3.4 1:2:3:4:5::1.2.3.4 1:2:3:4::1.2.3.4 1:2:3::1.2.3.4 1:2::1.2.3.4 1::1.2.3.4 1:2:3:4::5:1.2.3.4 1:2:3::5:1.2.3.4 1:2::5:1.2.3.4 1::5:1.2.3.4 1::5:11.22.33.44 fe80::217:f2ff:254.7.237.98 fe80:0:0:0:204:61ff:254.157.241.86 fe80::204:61ff:254.157.241.86 Net-IPv6Addr-0.96/t/ipv4comp.t000644 001751 001751 00000004440 07326066241 015330 0ustar00benben000000 000000 use strict; use Test; BEGIN { plan test => 39; } use Net::IPv6Addr; ok(1); my @x; # Test ipv6_parse_ipv4_compressed, with garbage. eval { @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed("life, in a nutshell"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4_compressed, bad ipv6 digits. eval { @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed("::fffe:10.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4_compressed, bad ipv4 digits. eval { @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed("::ffff:10.0.0.x"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4_compressed, too many adjacent : eval { @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed(":::ffff:10.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4_compressed, too many ipv6 digits. eval { @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed("::fffff:10.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4_compressed, too many ipv4 digits. eval { @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed("::ffff:10.0.0.9999"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4_compressed, too many : eval { @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed("::0:ffff:10.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4_compressed, not enough : eval { @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed(":ffff:10.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4_compressed, too many . eval { @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed("::ffff:10.0.0.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4_compressed, not enough . eval { @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed("::ffff:10.0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4_compressed, adjacent . eval { @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed("::ffff:10.0..0.1"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_ipv4_compressed, with good stuff. @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed("::ffff:10.0.0.1"); ok($x[0], 0); ok($x[1], 0); ok($x[2], 0); ok($x[3], 0); ok($x[4], 0); ok($x[5], 0xffff); ok($x[6], 0xa00); ok($x[7], 1); @x = Net::IPv6Addr::ipv6_parse_ipv4_compressed("::10.0.0.1"); ok($x[0], 0); ok($x[1], 0); ok($x[2], 0); ok($x[3], 0); ok($x[4], 0); ok($x[5], 0); ok($x[6], 0xa00); ok($x[7], 1); Net-IPv6Addr-0.96/t/base85.t000644 001751 001751 00000002664 13152205505 014654 0ustar00benben000000 000000 use strict; use Test::More; use Net::IPv6Addr; # Test ipv6_parse_base85 with garbage. eval { Net::IPv6Addr::ipv6_parse_base85("\n"); }; ok($@); like ($@, qr/invalid address/); # Test ipv6_parse_base85 with a bad character. eval { Net::IPv6Addr::ipv6_parse_base85("abcdefghi klmnopqrst"); }; ok($@); like ($@, qr/invalid address/); # Test ipv6_parse_base85 with a bad length. eval { Net::IPv6Addr::ipv6_parse_base85("abcdefghijklmnopqrs"); }; ok($@); like ($@, qr/invalid address/); # Test ipv6_parse_base85 with good stuff. # Example stolen from rfc1924.txt my @pieces = Net::IPv6Addr::ipv6_parse_base85("4)+k&C#VzJ4br>0wv%Yp"); is ($pieces[0], 0x1080); is ($pieces[1], 0); is ($pieces[2], 0); is ($pieces[3], 0); is ($pieces[4], 0x8); is ($pieces[5], 0x800); is ($pieces[6], 0x200C); is ($pieces[7], 0x417A); my $x; # Test new with bad base85 digits. eval { $x = new Net::IPv6Addr("0123456789ABCDEF GHI"); }; ok($@); like ($@, qr/invalid IPv6 address/); # Test new with bad base85 length. eval { $x = new Net::IPv6Addr("0123456789ABCDEFGHI"); }; ok($@); like ($@, qr/invalid IPv6 address/); # Test new with good base85. $x = new Net::IPv6Addr("4)+k&C#VzJ4br>0wv%Yp"); is (ref $x, 'Net::IPv6Addr'); is ($x->[0], 0x1080); is ($x->[1], 0); is ($x->[2], 0); is ($x->[3], 0); is ($x->[4], 8); is ($x->[5], 0x800); is ($x->[6], 0x200C); is ($x->[7], 0x417A); # Test to_string_base85. is ($x->to_string_base85(), "4)+k&C#VzJ4br>0wv%Yp"); done_testing ();