Net-IPv6Addr-0.2/0000755000175000017500000000000010525407550012123 5ustar bartbartNet-IPv6Addr-0.2/README0000644000175000017500000000204707524040436013007 0ustar bartbart========================= Net::IPv6Addr Version 0.1 ========================= Net::IPv6Addr provides functions for parsing IPv6 addresses in all formats described by RFC1884. If Math::Base85 is installed, formats described in RFC1924 are also valid. It will generate "IP6.INT." strings (as described in RFC1886) if you are inclined to play with DNS records. This module needs Net::IPv4Addr to function properly. The usual installation instructions apply: /path/to/perl Makefile.PL make make test make install Documentation is included in pod format. Please send bug reports and suggestions to the author at . --------------------- Copyright and License --------------------- This distribution (with the exception of included RFC's) 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. $Id: README,v 1.5 2002/08/06 21:35:26 tony Exp $ Net-IPv6Addr-0.2/t/0000755000175000017500000000000007524040451012364 5ustar bartbartNet-IPv6Addr-0.2/t/parse.t0000644000175000017500000000124607326061041013664 0ustar bartbartuse strict; use Test; BEGIN { plan tests => 12; } use Net::IPv6Addr; ok(1); # Yeah, so I was listening to it when I wrote the test. eval { Net::IPv6Addr::ipv6_parse("sunshine of your love"); }; ok($@); ok($@, qr/invalid IPv6 address/); eval { Net::IPv6Addr::ipv6_parse("::/x"); }; ok($@); ok($@, qr/non-numeric prefix length/); eval { Net::IPv6Addr::ipv6_parse("::/-19325"); }; ok($@); ok($@, qr/non-numeric prefix length/); eval { Net::IPv6Addr::ipv6_parse("::/65389"); }; ok($@); ok($@, qr/invalid prefix length/); ok(scalar(Net::IPv6Addr::ipv6_parse("a:b:c:d:0:1:2:3")), "a:b:c:d:0:1:2:3"); my ($x, $y) = Net::IPv6Addr::ipv6_parse("a::/24"); ok($x, "a::"); ok($y, 24); Net-IPv6Addr-0.2/t/chkip.t0000644000175000017500000001031107325701272013647 0ustar bartbartuse strict; use Test; BEGIN { plan tests => 34; } use Net::IPv6Addr; ok(1); 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'); Net-IPv6Addr-0.2/t/string.t0000644000175000017500000000446307326120442014065 0ustar bartbartuse strict; use Test; BEGIN { plan test => 35; } use Net::IPv6Addr; ok(1); my $w = new Net::IPv6Addr("ab:cd:ef:01:23:45:67:89"); ok($w->to_string_preferred(), "ab:cd:ef:1:23:45:67:89"); ok($w->to_string_compressed(), "ab:cd:ef:1:23:45:67:89"); eval { $w->to_string_ipv4(); }; ok($@); ok($@, qr/not originally an IPv4 address/); eval { $w->to_string_ipv4_compressed(); }; ok($@); ok($@, qr/not originally an IPv4 address/); ok($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("::"); ok($x->to_string_preferred(), "0:0:0:0:0:0:0:0"); ok($x->to_string_compressed(), "::"); ok($x->to_string_ipv4(), "0:0:0:0:0:0:0.0.0.0"); ok($x->to_string_ipv4_compressed(), "::0.0.0.0"); ok($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"); ok($y->to_string_preferred(), "0:0:0:0:0:0:0:1"); ok($y->to_string_compressed(), "::1"); ok($y->to_string_ipv4(), "0:0:0:0:0:0:0.0.0.1"); ok($y->to_string_ipv4_compressed(), "::0.0.0.1"); ok($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"); ok($z->to_string_preferred(), "abcd:ef12:0:0:0:0:3456:789a"); ok($z->to_string_compressed(), "abcd:ef12::3456:789a"); eval { $w->to_string_ipv4(); }; ok($@); ok($@, qr/not originally an IPv4 address/); eval { $w->to_string_ipv4_compressed(); }; ok($@); ok($@, qr/not originally an IPv4 address/); ok($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."); my $p = new Net::IPv6Addr("::ffff:10.0.0.1"); ok($p->to_string_preferred(), "0:0:0:0:0:ffff:a00:1"); ok($p->to_string_compressed(), "::ffff:a00:1"); ok($p->to_string_ipv4(), "0:0:0:0:0:ffff:10.0.0.1"); ok($p->to_string_ipv4_compressed(), "::ffff:10.0.0.1"); ok($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 = new Net::IPv6Addr("0:0:0:0:0:0:10.0.0.1"); ok($q->to_string_preferred(), "0:0:0:0:0:0:a00:1"); ok($q->to_string_compressed(), "::a00:1"); ok($q->to_string_ipv4(), "0:0:0:0:0:0:10.0.0.1"); ok($q->to_string_ipv4_compressed(), "::10.0.0.1"); ok($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."); Net-IPv6Addr-0.2/t/new.t0000644000175000017500000001121007326077450013346 0ustar bartbartuse 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.2/t/ipv4.t0000644000175000017500000000361407326060726013446 0ustar bartbartuse 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.2/t/ipv4comp.t0000644000175000017500000000444007326066241014321 0ustar bartbartuse 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.2/t/compressed.t0000644000175000017500000000200007325713363014715 0ustar bartbartuse 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.2/t/base85.t0000644000175000017500000000303307326074060013642 0ustar bartbartuse strict; use Test; BEGIN { eval { require Math::Base85; }; if ($@) { print "1..0 # Math::Base85 is not installed\n"; exit 0; } } BEGIN { plan test => 29; } use Net::IPv6Addr; ok(1); # Test ipv6_parse_base85 with garbage. eval { Net::IPv6Addr::ipv6_parse_base85("\n"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_base85 with a bad character. eval { Net::IPv6Addr::ipv6_parse_base85("abcdefghi klmnopqrst"); }; ok($@); ok($@, qr/invalid address/); # Test ipv6_parse_base85 with a bad length. eval { Net::IPv6Addr::ipv6_parse_base85("abcdefghijklmnopqrs"); }; ok($@); ok($@, 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"); ok($pieces[0], 0x1080); ok($pieces[1], 0); ok($pieces[2], 0); ok($pieces[3], 0); ok($pieces[4], 0x8); ok($pieces[5], 0x800); ok($pieces[6], 0x200C); ok($pieces[7], 0x417A); my $x; # Test new with bad base85 digits. eval { $x = new Net::IPv6Addr("0123456789ABCDEF GHI"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with bad base85 length. eval { $x = new Net::IPv6Addr("0123456789ABCDEFGHI"); }; ok($@); ok($@, qr/invalid IPv6 address/); # Test new with good base85. $x = new Net::IPv6Addr("4)+k&C#VzJ4br>0wv%Yp"); ok(ref $x, 'Net::IPv6Addr'); ok($x->[0], 0x1080); ok($x->[1], 0); ok($x->[2], 0); ok($x->[3], 0); ok($x->[4], 8); ok($x->[5], 0x800); ok($x->[6], 0x200C); ok($x->[7], 0x417A); # Test to_string_base85. ok($x->to_string_base85(), "4)+k&C#VzJ4br>0wv%Yp"); Net-IPv6Addr-0.2/t/preferred.t0000644000175000017500000000256707326066754014557 0ustar bartbartuse 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.2/MANIFEST0000644000175000017500000000027307524037240013256 0ustar bartbartChangeLog IPv6Addr.pm MANIFEST Makefile.PL README t/base85.t t/chkip.t t/compressed.t t/ipv4.t t/ipv4comp.t t/new.t t/parse.t t/preferred.t t/string.t rfc1886.txt rfc1924.txt rfc2373.txt Net-IPv6Addr-0.2/IPv6Addr.pm0000644000175000017500000004315207524036575014057 0ustar bartbartpackage Net::IPv6Addr; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); use Carp; use Net::IPv4Addr; BEGIN { eval { require Math::BigInt; require Math::Base85; }; } =pod =head1 NAME Net::IPv6Addr -- check validity of IPv6 addresses =head1 SYNOPSIS use Net::IPv6Addr; Net::IPv6Addr::ipv6_parse($addr); $x = new Net::IPv6Addr("dead:beef:cafe:babe::f0ad"); print $x->to_string_preferred(), "\n"; =head1 DESCRIPTION C checks strings for valid IPv6 addresses, as specified in RFC1884. You throw possible addresses at it, it either accepts them or throws an exception. If C is installed, then this module is able to process addresses formatted in the style referenced by RFC1924. The public interface of this module is rather small. =cut @ISA = qw(Exporter); @EXPORT = qw(); @EXPORT_OK = qw(); $VERSION = '0.2'; # We get these formats from rfc1884: # # preferred form: x:x:x:x:x:x:x:x # # zero-compressed form: the infamous double-colon. # Too many pattern matches to describe in this margin. # # mixed IPv4/IPv6 format: x:x:x:x:x:x:d.d.d.d # # mixed IPv4/IPv6 with compression: ::d.d.d.d or ::FFFF:d.d.d.d # # And we get these from rfc1924: # # base-85-encoded: [0-9A-Za-z!#$%&()*+-;<=>?@^_`{|}~]{20} # my %ipv6_patterns = ( 'preferred' => [ qr/^(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}$/i, \&ipv6_parse_preferred, ], 'compressed' => [ ## No, this isn't pretty. qr/^[a-f0-9]{0,4}::$/i, qr/^:(?::[a-f0-9]{1,4}){1,6}$/i, qr/^(?:[a-f0-9]{1,4}:){1,6}:$/i, qr/^(?:[a-f0-9]{1,4}:)(?::[a-f0-9]{1,4}){1,6}$/i, qr/^(?:[a-f0-9]{1,4}:){2}(?::[a-f0-9]{1,4}){1,5}$/i, qr/^(?:[a-f0-9]{1,4}:){3}(?::[a-f0-9]{1,4}){1,4}$/i, qr/^(?:[a-f0-9]{1,4}:){4}(?::[a-f0-9]{1,4}){1,3}$/i, qr/^(?:[a-f0-9]{1,4}:){5}(?::[a-f0-9]{1,4}){1,2}$/i, qr/^(?:[a-f0-9]{1,4}:){6}(?::[a-f0-9]{1,4})$/i, \&ipv6_parse_compressed, ], 'ipv4' => [ qr/^(?:0:){5}ffff:(?:\d{1,3}\.){3}\d{1,3}$/i, qr/^(?:0:){6}(?:\d{1,3}\.){3}\d{1,3}$/, \&ipv6_parse_ipv4, ], 'ipv4 compressed' => [ qr/^::(?:ffff:)?(?:\d{1,3}\.){3}\d{1,3}$/i, \&ipv6_parse_ipv4_compressed, ], ); # base-85 if (defined $Math::Base85::base85_digits) { my $digits; ($digits = $Math::Base85::base85_digits) =~ s/-//; my $x = "[" . $digits . "-]"; my $n = "{20}"; $ipv6_patterns{'base85'} = [ qr/$x$n/, \&ipv6_parse_base85, ]; } =pod =head1 new =head2 Parameters A string to be interpreted as an IPv6 address. =head2 Returns A C object if successful. =head2 Notes Throws an exception if the string isn't a valid address. =cut 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') { croak __PACKAGE__, "::new -- invalid IPv6 address $maybe_ip"; } my @hexadecets = $parser->($maybe_ip); my $self = \@hexadecets; bless $self, $class; return $self; } =pod =head1 ipv6_parse =head2 Parameters A string containing an IPv6 address string. Optionally, it may also include a C character, and a numeric prefix length, in that order. -or- An IPv6 address string. Optionally, a numeric prefix length. =head2 Returns What you gave it, more or less, if it does parse out correctly. =head2 Notes Throws an exception on malformed input. This is not an object method or class method; it's just a subroutine. =cut sub ipv6_parse { my ($ip, $pfx); if (@_ == 2) { ($ip, $pfx) = @_; } else { ($ip, $pfx) = split(m!/!, $_[0]) } unless (ipv6_chkip($ip)) { croak __PACKAGE__, "::ipv6_parse -- invalid IPv6 address $ip\n"; } $pfx =~ s/\s+//g if defined($pfx); if (defined $pfx) { if ($pfx =~ /^\d+$/) { if (($pfx < 0) || ($pfx > 128)) { croak __PACKAGE__, "::ipv6_parse -- invalid prefix length $pfx\n"; } } else { croak __PACKAGE__, "::ipv6_parse -- non-numeric prefix length $pfx\n"; } } else { return $ip; } wantarray ? ($ip, $pfx) : "$ip/$pfx"; } =pod =head1 is_ipv6 =head2 Parameters A string containing an IPv6 address string. Optionally, it may also include a C character, and a numeric prefix length, in that order. -or- An IPv6 address string. Optionally, a numeric prefix length. =head2 Returns What you gave it, more or less, if it does parse out correctly, otherwise returns undef. =head2 Notes This is not an object method or class method; it is just a subroutine. =cut sub is_ipv6 { my ($ip, $pfx); if (@_ == 2) { ($ip, $pfx) = @_; } else { ($ip, $pfx) = split(m!/!, $_[0]) } unless (ipv6_chkip($ip)) { return undef; } if (defined $pfx) { $pfx =~ s/s+//g; if ($pfx =~ /^\d+$/) { if (($pfx < 0) || ($pfx > 128)) { return undef; } } else { return undef; } } else { return $ip; } wantarray ? ($ip, $pfx) : "$ip/$pfx"; } =pod =head1 ipv6_chkip =head2 Parameters An IPv6 address string. =head2 Returns Something true if it's a valid address; something false otherwise. =cut sub ipv6_chkip { my $ip = shift; my ($pattern, $parser); my @patlist; $parser = undef; TYPE: for my $k (keys %ipv6_patterns) { @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_preferred { my $ip = shift; my @patterns = @{$ipv6_patterns{'preferred'}}; for my $p (@patterns) { if (ref($p) eq 'CODE') { croak __PACKAGE__, "::ipv6_parse_preferred -- invalid address"; } last if ($ip =~ $p); } my @pieces = split(/:/, $ip); splice(@pieces, 8); return map { hex } @pieces; } sub ipv6_parse_compressed { my $ip = shift; my @patterns = @{$ipv6_patterns{'compressed'}}; for my $p (@patterns) { if (ref($p) eq 'CODE') { croak __PACKAGE__, "::ipv6_parse_compressed -- invalid address"; } last if ($ip =~ $p); } my $colons; $colons = ($ip =~ tr/:/:/); my $expanded = ':' x (9 - $colons); $ip =~ s/::/$expanded/; my @pieces = split(/:/, $ip, 8); return map { hex } @pieces; } sub ipv6_parse_ipv4 { my $ip = shift; my @patterns = @{$ipv6_patterns{'ipv4'}}; for my $p (@patterns) { if (ref($p) eq 'CODE') { croak __PACKAGE__, "::ipv6_parse_ipv4 -- invalid address"; } last if ($ip =~ $p); } 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; } sub ipv6_parse_ipv4_compressed { my $ip = shift; my @patterns = @{$ipv6_patterns{'ipv4 compressed'}}; for my $p (@patterns) { if (ref($p) eq 'CODE') { croak __PACKAGE__, "::ipv6_parse_ipv4_compressed -- invalid address"; } last if ($ip =~ $p); } 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; } sub ipv6_parse_base85 { croak __PACKAGE__, "::ipv6_parse_base85 -- Math::Base85 not loaded" unless defined $Math::Base85::base85_digits; my $ip = shift; my $r; my @patterns = @{$ipv6_patterns{'base85'}}; for my $p (@patterns) { if (ref($p) eq 'CODE') { croak __PACKAGE__, "::ipv6_parse_base85 -- invalid address"; } last if ($ip =~ $p); } 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; } =pod =head1 to_string_preferred =head2 Parameters If used as an object method, none; if used as a plain old subroutine, an IPv6 address string in any format. =head2 Returns The IPv6 address, formatted in the "preferred" way (as detailed by RFC1884). =head2 Notes Invalid input will generate an exception. =cut sub to_string_preferred { my $self = shift; if (ref $self eq __PACKAGE__) { return join(":", map { sprintf("%x", $_) } @$self); } return Net::IPv6Addr->new($self)->to_string_preferred(); } =pod =head1 to_string_compressed =head2 Parameters If used as an object method, none; if used as a plain old subroutine, an IPv6 address string in any format. =head2 Returns The IPv6 address in "compresed" format (as detailed by RFC1884). =head2 Notes Invalid input will generate an exception. =cut sub to_string_compressed { my $self = shift; if (ref $self ne __PACKAGE__) { return Net::IPv6Addr->new($self)->to_string_compressed(); } my $expanded = join(":", map { sprintf("%x", $_) } @$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; } =pod =head1 to_string_ipv4 =head2 Parameters If used as an object method, none; if used as a plain old subroutine, an IPv6 address string in any format. =head2 Returns The IPv6 address in IPv4 format (as detailed by RFC1884). =head2 Notes Invalid input (such as an address that was not originally IPv4) will generate an exception. =cut sub to_string_ipv4 { my $self = shift; if (ref $self ne __PACKAGE__) { return Net::IPv6Addr->new($self)->to_string_ipv4(); } if ($self->[0] | $self->[1] | $self->[2] | $self->[3] | $self->[4]) { croak __PACKAGE__, "::to_string_ipv4 -- not originally an IPv4 address"; } if (($self->[5] != 0xffff) && $self->[5]) { croak __PACKAGE__, "::to_string_ipv4 -- not originally an IPv4 address"; } my $v6part = join(':', map { sprintf("%x", $_) } @$self[0..5]); my $v4part = join('.', $self->[6] >> 8, $self->[6] & 0xff, $self->[7] >> 8, $self->[7] & 0xff); return "$v6part:$v4part"; } =pod =head1 to_string_ipv4_compressed =head2 Parameters If used as an object method, none; if used as a plain old subroutine, an IPv6 address string in any format. =head2 Returns The IPv6 address in compressed IPv4 format (as detailed by RFC1884). =head2 Notes Invalid input (such as an address that was not originally IPv4) will generate an exception. =cut sub to_string_ipv4_compressed { my $self = shift; if (ref $self ne __PACKAGE__) { return Net::IPv6Addr->new($self)->to_string_ipv4_compressed(); } if ($self->[0] | $self->[1] | $self->[2] | $self->[3] | $self->[4]) { croak __PACKAGE__, "::to_string_ipv4 -- not originally an IPv4 address"; } if (($self->[5] != 0xffff) && $self->[5]) { croak __PACKAGE__, "::to_string_ipv4 -- not originally an IPv4 address"; } my $v6part; if ($self->[5]) { $v6part = sprintf("::%x", $self->[5]); } else { $v6part = ":"; } my $v4part = join('.', $self->[6] >> 8, $self->[6] & 0xff, $self->[7] >> 8, $self->[7] & 0xff); return "$v6part:$v4part"; } =pod =head1 to_string_base85 =head2 Parameters If used as an object method, none; if used as a plain old subroutine, an IPv6 address string in any format. =head2 Returns The IPv6 address in the style detailed by RFC1924. =head2 Notes Invalid input will generate an exception. =cut sub to_string_base85 { croak __PACKAGE__, "::to_string_base85 -- Math::Base85 not loaded" unless defined $Math::Base85::base85_digits; my $self = shift; if (ref $self ne __PACKAGE__) { return Net::IPv6Addr->new($self)->to_string_base85(); } 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); } =pod =head1 to_bigint =head2 Parameters If used as an object method, none; if used as a plain old subroutine, an IPv6 address string in any format. =head2 Returns The BigInt representation of IPv6 address. =head2 Notes Invalid input will generate an exception. =cut sub to_bigint { croak __PACKAGE__, "::to_bigint -- Math::BigInt not loaded" unless defined &Math::BigInt::new; my $self = shift; if (ref $self ne __PACKAGE__) { return Net::IPv6Addr->new($self)->to_bigint(); } 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; } =pod =head1 to_array =head2 Parameters If used as an object method, none; if used as a plain old subroutine, an IPv6 address string in any format. =head2 Returns An array [0..7] of 16 bit hexadecimal numbers. =head2 Notes Invalid input will generate an exception. =cut sub to_array { my $self = shift; if (ref $self ne __PACKAGE__) { return Net::IPv6Addr->new($self)->to_array(); } return map {sprintf "%04x", $_} @$self; } =pod =head1 to_intarray =head2 Parameters If used as an object method, none; if used as a plain old subroutine, an IPv6 address string in any format. =head2 Returns An array [0..7] of decimal numbers. =head2 Notes Invalid input will generate an exception. =cut sub to_intarray { my $self = shift; if (ref $self ne __PACKAGE__) { return Net::IPv6Addr->new($self)->to_intarray(); } return @$self; } =pod =head1 to_string_ip6_int =head2 Parameters If used as an object method, none; if used as a plain old subroutine, an IPv6 address string in any format. =head2 Returns The reverse-address pointer as defined by RFC1886. =head2 Notes Invalid input will generate an exception. =cut sub to_string_ip6_int { my $self = shift; if (ref $self ne __PACKAGE__) { return Net::IPv6Addr->new($self)->to_string_ip6_int(); } my $hexdigits = sprintf("%04x" x 8, @$self); my @nibbles = ('INT', 'IP6', split(//, $hexdigits)); my $ptr = join('.', reverse @nibbles); return $ptr . "."; } =pod =head1 in_network_of_size =head2 Parameters If used as an object method, network size in bits If used as a plain old subroutine, an IPv6 address string in any format and network size in bits. Network size may be given with / notation. =head2 Returns Network IPv6Addr of given size. =head2 Notes Invalid input will generate an exception. =cut sub in_network_of_size { my $self = shift; if (ref $self ne __PACKAGE__) { if ($self =~ m!(.+)/(.+)!) { unshift @_, $2; return Net::IPv6Addr->new($1)->in_network_of_size(@_)->to_string_preferred; } return Net::IPv6Addr->new($self)->in_network_of_size(@_)->to_string_preferred; } my $netsize = shift; if (!defined $netsize) { croak __PACKAGE__, "::in_network_of_size -- not network size given"; } $netsize =~ s!/!!; if ($netsize !~ /^\d+$/ or $netsize < 0 or $netsize > 128) { croak __PACKAGE__, "::in_network_of_size -- not valid network size $netsize"; } my @parts = @$self; my $i = $netsize / 16; unless ($i == 8) { # netsize was 128 bits; the whole address my $j = $netsize % 16; $parts[$i] &= unpack("C4",pack("B16", '1' x $j . '0000000000000000')); foreach $j (++$i..$#parts) { $parts[$j] = 0; } } return Net::IPv6Addr->new(join(':', @parts)); } =pod =head1 in_network =head2 Parameters If used as an object method, network and its size in bits If used as a plain old subroutine, an IPv6 address string in any format network address string and size in bits. Network size may be given with / notation. =head2 Returns Something true, if address is member of the network, false otherwise. =head2 Notes Invalid input will generate an exception. =cut sub in_network { my $self = shift; if (ref $self ne __PACKAGE__) { return Net::IPv6Addr->new($self)->in_network(@_); } my ($net,$netsize) = (@_); if ($net =~ m!/!) { $net =~ s!(.*)/(.*)!$1!; $netsize = $2; } unless (defined $netsize) { croak __PACKAGE__, "::in_network -- not enough parameters"; } $netsize =~ s!/!!; if ($netsize !~ /^\d+$/ or $netsize < 0 or $netsize > 128) { croak __PACKAGE__, "::in_network -- not valid network size $netsize"; } my @s = $self->in_network_of_size($netsize)->to_intarray; $net = Net::IPv6Addr->new($net) unless (ref $net); my @n = $net->in_network_of_size($netsize)->to_intarray; my $i = int($netsize / 16); $i++; $i = $#s if ($i > $#s); for (0..$i) { return 0 unless ($s[$_] == $n[$_]); } return 1; } 1; __END__ =pod =head1 BUGS probably exist in this module. Please report them. =head1 AUTHOR Tony Monroe Etmonroe plus perl at nog dot netE. The module's interface probably looks like it vaguely resembles Net::IPv4Addr 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. =head1 HISTORY This was originally written to simplify the task of maintaining DNS records after I set myself up with Freenet6. Interesting that there's really only one DNS-related subroutine in here. =head1 SEE ALSO RFC1884, RFC1886, RFC1924, L, L, L, L =cut Net-IPv6Addr-0.2/Makefile.PL0000644000175000017500000000047307326123327014103 0ustar bartbartuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Net::IPv6Addr', 'VERSION_FROM' => 'IPv6Addr.pm', # finds $VERSION 'PREREQ_PM' => { 'Net::IPv4Addr' => 0, 'Math::Base85' => 0 }, ); Net-IPv6Addr-0.2/ChangeLog0000644000175000017500000000072007464533216013703 0ustar bartbart2002-05-03 Tony Monroe (0.2) * Many patches from Jyrki Soini , fixing bugs and adding features! 2001-07-20 Tony Monroe (0.1) * 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).