File: v4-cidr.t

package info (click to toggle)
libnetaddr-ip-perl 4.079%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 1,580 kB
  • ctags: 251
  • sloc: perl: 1,417; cpp: 67; sh: 51; makefile: 9
file content (28 lines) | stat: -rw-r--r-- 487 bytes parent folder | download | duplicates (6)
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
use NetAddr::IP::Lite;

$| = 1;

my @addr = (qw(
	       0.0.0.0/0
	       1.0.0.0/1
	       2.0.0.0/2
	       10.0.0.0/8
	       10.0.120.0/24
	       161.196.66.0/25
	       255.255.255.255/32
	       ));

print '1..', scalar @addr, "\n";

my $count = 1;

for my $a (@addr) {
    my $ip = new NetAddr::IP::Lite $a;
    if ($ip->cidr eq $a) {
	print "ok ", $count ++, "\n";
    }
    else {
	print "not ok ", $count ++, "\n";
	print "$a -> ", $ip->cidr, " [", $ip->mask, "]\n";
    }
}