1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#use diagnostics;
use NetAddr::IP::Lite;
$| = 1;
sub ok() {
print 'ok ',$test++,"\n";
}
print "1..10\n";
$test = 1;
############## test new6
my $exp = '0:0:0:0:0:0:0:3039/1';
my $ip = NetAddr::IP::Lite->new6(12345,1);
my $got = $ip->cidr();
print "got: $got\nexp: $exp\nnot "
unless $got eq $exp;
&ok;
$ip = NetAddr::IP::Lite->new6('12345',1);
$got = $ip->cidr();
print "got: $got\nexp: $exp\nnot "
unless $got eq $exp;
&ok;
$ip = NetAddr::IP::Lite->new6('12345/1');
$got = $ip->cidr();
print "got: $got\nexp: $exp\nnot "
unless $got eq $exp;
&ok;
# 2^127 170141183460469231731687303715884105728
$exp = '8000:0:0:0:0:0:0:0/1';
$ip = NetAddr::IP::Lite->new6('170141183460469231731687303715884105728/1');
$got = $ip->cidr();
print "got: $got\nexp: $exp\nnot "
unless $got eq $exp;
&ok;
# 2^128 340282366920938463463374607431768211456
# minus one
$exp = 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF/1';
$ip = NetAddr::IP::Lite->new6('340282366920938463463374607431768211455/1');
$got = $ip->cidr();
print "got: $got\nexp: $exp\nnot "
unless $got eq $exp;
&ok;
############# test new
$exp = '0.0.48.57/1';
$ip = NetAddr::IP::Lite->new(12345,1);
$got = $ip->cidr();
print "got: $got\nexp: $exp\nnot "
unless $got eq $exp;
&ok;
$ip = NetAddr::IP::Lite->new('12345',1);
$got = $ip->cidr();
print "got: $got\nexp: $exp\nnot "
unless $got eq $exp;
&ok;
$ip = NetAddr::IP::Lite->new('12345/1');
$got = $ip->cidr();
print "got: $got\nexp: $exp\nnot "
unless $got eq $exp;
&ok;
# 2^127 170141183460469231731687303715884105728
$exp = '8000:0:0:0:0:0:0:0/1';
$ip = NetAddr::IP::Lite->new('170141183460469231731687303715884105728/1');
$got = $ip->cidr();
print "got: $got\nexp: $exp\nnot "
unless $got eq $exp;
&ok;
# 2^128 340282366920938463463374607431768211456
# minus one
$exp = 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF/1';
$ip = NetAddr::IP::Lite->new('340282366920938463463374607431768211455/1');
$got = $ip->cidr();
print "got: $got\nexp: $exp\nnot "
unless $got eq $exp;
&ok;
|