| 1 | # Copyright (C) 1998-2006 David Muir Sharnoff <muir@idiom.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright (C) 2011-2013 Google, Inc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright (C) 2018-2021 Joelle Maslak <jmaslak@antelope.net> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | package Net::Netmask; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | $Net::Netmask::VERSION = '2.0001'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use 5.006_001; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Understand and manipulate IP netmasks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # Disable one-arg bless to preserve the existing interface. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ## no critic (ClassHierarchies::ProhibitOneArgBless) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | @EXPORT = qw(findNetblock findOuterNetblock findAllNetblock | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | cidrs2contiglists range2cidrlist sort_by_ip_address | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | dumpNetworkTable sort_network_blocks cidrs2cidrs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | cidrs2inverse); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | @EXPORT_OK = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | @EXPORT, qw(ascii2int int2quad quad2int %quadmask2bits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | %quadhostmask2bits imask i6mask int2ascii sameblock cmpblocks contains) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 8 | my $remembered = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 8 | my %imask2bits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | my %size2bits; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 8 | my @imask; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 8 | my @i6mask; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 8 | our $SHORTNET_DEFAULT = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 8 | ▶ | use vars qw($error $debug %quadmask2bits %quadhostmask2bits); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 8 | $debug = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | ▶ | use Math::BigInt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 8 | ▶ | use POSIX qw(floor); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | use overload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | '""' => \&desc, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | '<=>' => \&cmp_net_netmask_block, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 'cmp' => \&cmp_net_netmask_block, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | ▶ | 'fallback' => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1900 | ▶ | my ( $package, $net, @params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=68 SCAR=42.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1900 | my $mask = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1900 | ▶ | if (@params % 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 81 | $mask = shift(@params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 81 | ▶ | $mask = '' if !defined($mask); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1900 | my (%options) = @params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1900 | ▶ | my $shortnet = ( ( exists($options{shortnet}) && $options{shortnet} ) || $SHORTNET_DEFAULT ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
exists $options{'shortnet'} && $options{'shortnet'} || $Net::Netmask::SHORTNET_DEFAULT
exists $options{"shortnet"} and $options{"shortnet"}
MC/DC100%3/3
exists $options{'shortnet'} && $options{'shortnet'} || $Net::Netmask::SHORTNET_DEFAULT
exists $options{"shortnet"}
$options{"shortnet"}
$Net::Netmask::SHORTNET_DEFAULT
Truth table80%4/5
A and B || C
A= exists $options{"shortnet"}B= $options{"shortnet"}C= $Net::Netmask::SHORTNET_DEFAULT
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1900 | my $base; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | my $bits; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1900 | my $ibase; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1900 | my $proto = 'IPv4'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1900 | undef $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1900 | ▶ | if ( $net =~ m,^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/([0-9]+)$, ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 17 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 417 | ( $base, $bits ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } elsif ( $net =~ m,^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)[:/]([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$, ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | $base = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | my $quadmask = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | ▶ | if ( exists $quadmask2bits{$quadmask} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | $bits = $quadmask2bits{$quadmask}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | $error = "illegal netmask: $quadmask"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } elsif ( $net =~ m,^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)[#]([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$, ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | $base = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | my $hostmask = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | ▶ | if ( exists $quadhostmask2bits{$hostmask} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | $bits = $quadhostmask2bits{$hostmask}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | $error = "illegal hostmask: $hostmask"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ▶ | } elsif ( ( $net =~ m,^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$, ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ and $mask =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
MC/DC100%2/2
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ and $mask =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
$mask =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
Truth table100%3/3
A and B
A= $net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/B= $mask =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | && ( $mask =~ m,[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$, ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | $base = $net; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | ▶ | if ( exists $quadmask2bits{$mask} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 5 | $bits = $quadmask2bits{$mask}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | $error = "illegal netmask: $mask"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | ▶ | } elsif ( ( $net =~ m,^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$, ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ and $mask =~ /0x[a-f0-9]+/i
MC/DC100%2/2
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ and $mask =~ /0x[a-f0-9]+/i
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
$mask =~ /0x[a-f0-9]+/i
Truth table100%3/3
A and B
A= $net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/B= $mask =~ /0x[a-f0-9]+/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | && ( $mask =~ m,0x[a-f0-9]+,i ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | $base = $net; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | my $imask = hex($mask); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 6 | ▶ | if ( exists $imask2bits{$imask} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | $bits = $imask2bits{$imask}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | $error = "illegal netmask: $mask ($imask)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | ▶ | } elsif ( $net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ && !$mask ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ and not $mask
MC/DC100%2/2
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ and not $mask
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
not $mask
Truth table100%3/3
A and not(B)
A= $net =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/B= not $mask
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 770 | ( $base, $bits ) = ( $net, 32 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | ▶ | } elsif ( $net =~ /^[0-9]+\.[0-9]+\.[0-9]+$/ && !$mask && $shortnet ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+$/ and not $mask and $shortnet
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+$/ and not $mask
MC/DC100%3/3
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+$/ and not $mask and $shortnet
$net =~ /^[0-9]+\.[0-9]+\.[0-9]+$/
not $mask
$shortnet
Truth table100%4/4
A and not(B) and C
A= $net =~ /^[0-9]+\.[0-9]+\.[0-9]+$/B= not $maskC= $shortnet
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | ( $base, $bits ) = ( "$net.0", 24 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ▶ | } elsif ( $net =~ /^[0-9]+\.[0-9]+$/ && !$mask && $shortnet ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$net =~ /^[0-9]+\.[0-9]+$/ and not $mask and $shortnet
$net =~ /^[0-9]+\.[0-9]+$/ and not $mask
MC/DC100%3/3
$net =~ /^[0-9]+\.[0-9]+$/ and not $mask and $shortnet
$net =~ /^[0-9]+\.[0-9]+$/
not $mask
$shortnet
Truth table100%4/4
A and not(B) and C
A= $net =~ /^[0-9]+\.[0-9]+$/B= not $maskC= $shortnet
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | ( $base, $bits ) = ( "$net.0.0", 16 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ▶ | } elsif ( $net =~ /^[0-9]+$/ && !$mask && $shortnet ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$net =~ /^[0-9]+$/ and not $mask and $shortnet
$net =~ /^[0-9]+$/ and not $mask
MC/DC100%3/3
$net =~ /^[0-9]+$/ and not $mask and $shortnet
$net =~ /^[0-9]+$/
not $mask
$shortnet
Truth table100%4/4
A and not(B) and C
A= $net =~ /^[0-9]+$/B= not $maskC= $shortnet
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | ( $base, $bits ) = ( "$net.0.0.0", 8 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ▶ | } elsif ( $net =~ m,^([0-9]+\.[0-9]+\.[0-9]+)/([0-9]+)$, && $shortnet ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$net =~ m[^([0-9]+\.[0-9]+\.[0-9]+)/([0-9]+)$] and $shortnet
MC/DC100%2/2
$net =~ m[^([0-9]+\.[0-9]+\.[0-9]+)/([0-9]+)$] and $shortnet
$net =~ m[^([0-9]+\.[0-9]+\.[0-9]+)/([0-9]+)$]
$shortnet
Truth table100%3/3
A and B
A= $net =~ m[^([0-9]+\.[0-9]+\.[0-9]+)/([0-9]+)$]B= $shortnet
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | ( $base, $bits ) = ( "$1.0", $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ▶ | } elsif ( $net =~ m,^([0-9]+\.[0-9]+)/([0-9]+)$, && $shortnet ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$net =~ m[^([0-9]+\.[0-9]+)/([0-9]+)$] and $shortnet
MC/DC100%2/2
$net =~ m[^([0-9]+\.[0-9]+)/([0-9]+)$] and $shortnet
$net =~ m[^([0-9]+\.[0-9]+)/([0-9]+)$]
$shortnet
Truth table100%3/3
A and B
A= $net =~ m[^([0-9]+\.[0-9]+)/([0-9]+)$]B= $shortnet
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | ( $base, $bits ) = ( "$1.0.0", $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ▶ | } elsif ( $net =~ m,^([0-9]+)/([0-9]+)$, && $shortnet ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$net =~ m[^([0-9]+)/([0-9]+)$] and $shortnet
MC/DC100%2/2
$net =~ m[^([0-9]+)/([0-9]+)$] and $shortnet
$net =~ m[^([0-9]+)/([0-9]+)$]
$shortnet
Truth table100%3/3
A and B
A= $net =~ m[^([0-9]+)/([0-9]+)$]B= $shortnet
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ( $base, $bits ) = ( "$1.0.0.0", $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | ▶ | } elsif ( $net eq 'default' || $net eq 'any' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$net eq "default" or $net eq "any"
MC/DC100%2/2
$net eq "default" or $net eq "any"
$net eq "default"
$net eq "any"
Truth table100%3/3
A or B
A= $net eq "default"B= $net eq "any"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 5 | ( $base, $bits ) = ( "0.0.0.0", 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } elsif ( $net =~ m,^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s*-\s*([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$, ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # whois format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 12 | $ibase = quad2int($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 12 | my $end = quad2int($2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 12 | ▶ | $error = "illegal dotted quad: $net" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $ibase and defined $end
MC/DC100%2/2
defined $ibase and defined $end
defined $ibase
defined $end
Truth table100%3/3
A and B
A= defined $ibaseB= defined $end
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | unless defined($ibase) && defined($end); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 12 | ▶ | my $diff = ( $end || 0 ) - ( $ibase || 0 ) + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$end || 0
$ibase || 0
MC/DC100%1/1
$end || 0
$end
MC/DC100%1/1
$ibase || 0
$ibase
Truth table100%2/2
A
A= $end
Truth table100%2/2
A
A= $ibase
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 12 | $bits = $size2bits{$diff}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 12 | ▶ | $error = "could not find exact fit for $net" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not defined $Net::Netmask::error and !defined($bits) || $ibase & ~$imask[$bits]
not defined $bits or $ibase & ~$imask[$bits]
MC/DC66%2/3
not defined $Net::Netmask::error and !defined($bits) || $ibase & ~$imask[$bits]
not defined $Net::Netmask::error
not defined $bits
$ibase & ~$imask[$bits]
Truth table75%3/4
not(A) and not(B) or C
A= not defined $Net::Netmask::errorB= not defined $bitsC= $ibase & ~$imask[$bits]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | if !defined $error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | && ( !defined $bits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | || ( $ibase & ~$imask[$bits] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } elsif ( $net =~ m,^([0-9a-f]*:[0-9a-f]*:[0-9a-f:]*)/([0-9]+)$, ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # IPv6 with netmask - ex: 2001:db8::/32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 326 | ▶ | if ( $mask ne '' ) { $error = "mask ignored for IPv6 address" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 326 | ( $base, $bits, $proto ) = ( $1, $2, 'IPv6' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } elsif ( $net =~ m,^([0-9a-f]*:[0-9a-f]*:[0-9a-f:]*)$, ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # IPv6 without netmask - ex: 2001:db8::1234 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 272 | ▶ | if ( $mask ne '' ) { $error = "mask ignored for IPv6 address" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 272 | ( $base, $bits, $proto ) = ( $1, 128, 'IPv6' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ▶ | } elsif ( $net eq 'default6' || $net eq 'any6' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$net eq "default6" or $net eq "any6"
MC/DC50%1/2
$net eq "default6" or $net eq "any6"
$net eq "default6"
$net eq "any6"
Truth table66%2/3
A or B
A= $net eq "default6"B= $net eq "any6"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | ▶ | if ( $mask ne '' ) { $error = "mask ignored for IPv6 address" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 4 | ( $base, $bits, $proto ) = ( "::", 0, 'IPv6' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 59 | $error = "could not parse $net"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 59 | ▶ | $error .= " $mask" if $mask; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1900 | ▶ | carp $error if $error && $debug; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Net::Netmask::error and $Net::Netmask::debug
MC/DC0%0/2
$Net::Netmask::error and $Net::Netmask::debug
$Net::Netmask::error
$Net::Netmask::debug
Truth table66%2/3
A and B
A= $Net::Netmask::errorB= $Net::Netmask::debug
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1900 | ▶ | $bits = 0 unless $bits; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1900 | ▶ | if ( ( $proto eq 'IPv4' ) && ( $bits > 32 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$proto eq "IPv4" and $bits > 32
MC/DC100%2/2
$proto eq "IPv4" and $bits > 32
$proto eq "IPv4"
$bits > 32
Truth table100%3/3
A and B
A= $proto eq "IPv4"B= $bits > 32
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | ▶ | $error = "illegal number of bits: $bits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | unless $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | $bits = 32; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | ▶ | } elsif ( ( $proto eq 'IPv6' ) && ( $bits > 128 ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$proto eq "IPv6" and $bits > 128
MC/DC100%2/2
$proto eq "IPv6" and $bits > 128
$proto eq "IPv6"
$bits > 128
Truth table100%3/3
A and B
A= $proto eq "IPv6"B= $bits > 128
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | ▶ | $error = "illegal number of bits: $bits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | unless $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | $bits = 128; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1900 | ▶ | $ibase = ascii2int( ( $base || '::' ), $proto ) unless (defined $ibase or $error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
defined $ibase or $Net::Netmask::error
$base || '::'
MC/DC100%2/2
defined $ibase or $Net::Netmask::error
defined $ibase
$Net::Netmask::error
MC/DC0%0/1
$base || '::'
$base
Truth table100%3/3
A or B
A= defined $ibaseB= $Net::Netmask::error
Truth table50%1/2
A
A= $base
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1900 | ▶ | unless ( defined($ibase) || defined($error) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $ibase or defined $Net::Netmask::error
MC/DC100%2/2
defined $ibase or defined $Net::Netmask::error
defined $ibase
defined $Net::Netmask::error
Truth table100%3/3
A or B
A= defined $ibaseB= defined $Net::Netmask::error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 24 | $error = "could not parse $net"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 24 | ▶ | $error .= " $mask" if $mask; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1900 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 103 | $ibase = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 103 | $bits = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1900 | $ibase = i_getnet_addr( $ibase, $bits, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1900 | ▶ | return bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 'IBASE' => $ibase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 'BITS' => $bits, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 'PROTOCOL' => $proto, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | ( $error ? ( 'ERROR' => $error ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | sub i_getnet_addr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 17743 | ▶ | my ( $ibase, $bits, $proto ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
i_getnet_addr: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 17743 | ▶ | if ( !defined($ibase) ) { return; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 17743 | ▶ | if ( $proto eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 3784 | return $ibase & $imask[$bits]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 13959 | return $ibase & $i6mask[$bits]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | sub new2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 50 | ▶ | goto &safe_new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new2: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | sub safe_new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 105 | ▶ | local ($debug) = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
safe_new: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 105 | my $net = new(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 105 | ▶ | return if $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 53 | return $net; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 52 | ▶ | sub errstr { return $error; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errstr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 2 | ▶ | sub debug { my $this = shift; return ( @_ ? $debug = shift : $debug ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=2 SCAR=7.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1021 | ▶ | sub base { my ($this) = @_; return int2ascii( $this->{IBASE}, $this->{PROTOCOL} ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
base: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 25 | ▶ | sub bits { my ($this) = @_; return $this->{'BITS'}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bits: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 21 | ▶ | sub protocol { my ($this) = @_; return $this->{'PROTOCOL'}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
protocol: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | sub size { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 700 | ▶ | my ($this) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
size: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 700 | ▶ | if ( $this->{PROTOCOL} eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 392 | return 2**( 32 - $this->{'BITS'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 308 | return Math::BigInt->new(2)->bpow( 128 - $this->{'BITS'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | sub next { ## no critic: (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | ▶ | my ($this) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # TODO: CONSOLIDATE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 3 | ▶ | if ( $this->{PROTOCOL} eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | return int2quad( $this->{'IBASE'} + $this->size() ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 2 | return $this->_ipv6next( $this->size ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | sub broadcast { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | ▶ | my ($this) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
broadcast: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | return int2ascii( $this->{'IBASE'} + $this->size() - 1, $this->{PROTOCOL} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 8 | *first = \&base; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 8 | *last = \&broadcast; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | sub desc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 480 | ▶ | return int2ascii( $_[0]->{IBASE}, $_[0]->{PROTOCOL} ) . '/' . $_[0]->{BITS}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | sub imask { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 264 | ▶ | return ( 2**32 - ( 2**( 32 - $_[0] ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
imask: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | sub i6mask { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1032 | ▶ | my $bits = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
i6mask: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 1032 | return Math::BigInt->new(2)->bpow(128) - Math::BigInt->new(2)->bpow( 128 - $bits ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | sub mask { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 21 | ▶ | my ($this) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mask: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 21 | ▶ | if ( $this->{PROTOCOL} eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 15 | return int2quad( $imask[ $this->{'BITS'} ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | return int2ascii( $i6mask[ $this->{'BITS'} ], $this->{PROTOCOL} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | sub hostmask { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | ▶ | my ($this) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hostmask: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 4 | ▶ | if ( $this->{PROTOCOL} eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | return int2quad( ~$imask[ $this->{BITS} ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | return int2ascii( $i6mask[ $this->{BITS} ] ^ $i6mask[128], $this->{PROTOCOL} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | sub nth { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 528 | ▶ | my ( $this, $index, $bitstep ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nth: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 528 | ▶ | my $maxbits = $this->{PROTOCOL} eq 'IPv4' ? 32 : 128; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 528 | my $size = $this->size(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 528 | my $ibase = $this->{'IBASE'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 528 | ▶ | $bitstep = $maxbits unless $bitstep; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 528 | my $increment = 2**( $maxbits - $bitstep ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 528 | $index *= $increment; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 528 | ▶ | $index += $size if $index < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 528 | ▶ | return if $index < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 526 | ▶ | return if $index >= $size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 524 | my $i = $ibase + $index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 524 | return int2ascii( $i, $this->{PROTOCOL} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | sub enumerate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 5 | ▶ | my ( $this, $bitstep ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enumerate: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 5 | my $proto = $this->{PROTOCOL}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # Set default step size by protocol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 5 | ▶ | $bitstep = ( $proto eq 'IPv4' ? 32 : 128 ) unless $bitstep; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 5 | my $size = $this->size(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 5 | my @ary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | ### We should be able to consolidate this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 5 | ▶ | if ( $proto eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | my $increment = 2**( 32 - $bitstep ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 3 | my $ibase = $this->{'IBASE'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 3 | ▶ | for ( my $i = 0; $i < $size; $i += $increment ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 8240 | push( @ary, int2quad( $ibase + $i ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 2 | my $increment = Math::BigInt->new(2)->bpow( 128 - $bitstep ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | ▶ | if ( ( $size / $increment ) > 1_000_000_000 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # Let's help the user out and catch really obvious issues. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # Asking for a billion IP addresses is probably one of them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # That said, please contact the author if this number causes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # you issues! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | confess("More than 1,000,000,000 results would be returned, dieing"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | ▶ | for ( my $i = Math::BigInt->new(0); $i < $size; $i += $increment ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 256 | push( @ary, $this->_ipv6next($i) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 4 | return @ary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | sub _ipv6next { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 258 | ▶ | my ( $this, $bitstep ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ipv6next: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 258 | my $istart = $this->{IBASE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 258 | my $val = $istart + $bitstep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 258 | return ipv6Cannonical( int2ascii( $val, $this->{PROTOCOL} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | sub inaddr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 8 | ▶ | my ($this) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inaddr: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 8 | ▶ | if ( $this->{PROTOCOL} eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 4 | return $this->inaddr4(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 4 | return $this->inaddr6(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | sub inaddr4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | ▶ | my ($this) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inaddr4: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 4 | my $ibase = $this->{'IBASE'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 4 | my $blocks = floor( $this->size() / 256 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 4 | ▶ | join( '.', unpack( 'xC3', pack( 'V', $ibase ) ) ) . ".in-addr.arpa", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | $ibase % 256, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | $ibase % 256 + $this->size() - 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | ) if $blocks == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | my @ary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | ▶ | for ( my $i = 0; $i < $blocks; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 32 | push( @ary, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | join( '.', unpack( 'xC3', pack( 'V', $ibase + $i * 256 ) ) ) . ".in-addr.arpa", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0, 255 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | return @ary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | sub inaddr6 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 4 | ▶ | my ($this) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inaddr6: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 4 | my (@digits) = split //, $this->{IBASE}->to_hex; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 4 | my $static = floor( $this->{BITS} / 4 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 4 | my $len = floor( ( $static + 3 ) / 4 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 4 | my $remainder = $this->{BITS} % 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 4 | ▶ | my $blocks = $remainder ? ( 2**( 4 - $remainder ) ) : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 4 | my @tail; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 4 | ▶ | if ( !$len ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # Specal case: 0 len | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | return ('ip6.arpa'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 3 | push @tail, reverse( @digits[ 0 .. ( $static - 1 ) ] ), 'ip6.arpa'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 3 | ▶ | if ( !$remainder ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # Special case - at nibble boundary already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 2 | return ( join '.', @tail ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | my $last = hex $digits[$static]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | my @ary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | ▶ | for ( my $i = 0; $i < $blocks; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 8 | push @ary, join( '.', sprintf( "%x", $last ), @tail ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 8 | $last++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 1 | return @ary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | sub tag { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 11 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 11 | my $tag = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 11 | my $val = $this->{ 'T' . $tag }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 11 | ▶ | $this->{ 'T' . $tag } = $_[0] if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 11 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | sub quad2int { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 1336 | ▶ | my @bytes = split( /\./, $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quad2int: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 1336 | ▶ | return unless @bytes == 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1335 | ▶ | return unless !grep { !( /^(([0-9])|([1-9][0-9]*))$/ && $_ < 256 ) } @bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^(([0-9])|([1-9][0-9]*))$/ && $_ < 256
MC/DC100%2/2
/^(([0-9])|([1-9][0-9]*))$/ && $_ < 256
/^(([0-9])|([1-9][0-9]*))$/
$_ < 256
Truth table100%3/3
A && B
A= /^(([0-9])|([1-9][0-9]*))$/B= $_ < 256
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 1307 | return unpack( "N", pack( "C4", @bytes ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | sub int2quad { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 8785 | ▶ | return join( '.', unpack( 'C4', pack( "N", $_[0] ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
int2quad: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # Uses the internal "raw" representation (such as IBASE). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # For IPv4, this is an integer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | # For IPv6, this is a raw bit string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | sub int2ascii { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 2312 | ▶ | if ( $_[1] eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
int2ascii: called CC=4 SCAR=14.1
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 1611 | return join( '.', unpack( 'C4', pack( "N", $_[0] ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } elsif ( $_[1] eq 'IPv6' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 701 | ▶ | my $addr = ( ref $_[0] ) ne '' ? $_[0]->to_hex : Math::BigInt->new( $_[0] )->to_hex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 701 | return ipv6Cannonical($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | confess("Incorrect call"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # Produces the internal "raw" representation (such as IBASE). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # For IPv4, this is an integer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # For IPv6, this is a raw bit string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | sub ascii2int { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 1946 | ▶ | if ( $_[1] eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ascii2int: called CC=3 SCAR=11.4
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 1312 | return quad2int( $_[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } elsif ( $_[1] eq 'IPv6' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 634 | return ipv6ascii2int( $_[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | confess("Incorrect call"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # Take an IPv6 ASCII address and produce a raw value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | sub ipv6ascii2int { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 634 | ▶ | my $addr = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ipv6ascii2int: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 634 | $addr = ipv6NonCompacted($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 634 | $addr = join '', map { sprintf( "%04x", hex($_) ) } split( /:/, $addr ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 634 | return Math::BigInt->from_hex($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # Takes an IPv6 address and produces a standard version seperated by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # colons (without compacting) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | sub ipv6NonCompacted { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 1610 | ▶ | my $addr = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ipv6NonCompacted: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1610 | ▶ | if ( $addr !~ /:/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 701 | ▶ | if ( length($addr) < 32 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 37 | $addr = ( "0" x ( 32 - length($addr) ) ) . $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 701 | $addr =~ s/(....)(?=....)/$1:/gsx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # Handle address format with trailing IPv6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # Ex: 0:0:0:0:1.2.3.4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1610 | ▶ | if ( $addr =~ m/^[0-9a-f:]+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/i ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 2 | my ( $l, $r1, $r2, $r3, $r4 ) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | $addr =~ m/^([0-9a-f:]+)([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 2 | $addr = sprintf( "%s%02x%02x:%02x%02x", $l, $r1, $r2, $r3, $r4 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 1610 | my ( $left, $right ) = split /::/, $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 1610 | ▶ | if ( !defined($right) ) { $right = '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 1610 | my (@lparts) = split /:/, $left; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 1610 | my (@rparts) = split /:/, $right; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # Strip leading 0's & lowercase | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 1610 | @lparts = map { $_ =~ s/^0+([0-9a-f]+)/$1/; lc($_) } @lparts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 1610 | @rparts = map { $_ =~ s/^0+([0-9a-f]+)/$1/; lc($_) } @rparts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | # Expand :: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 1610 | my $missing = 8 - ( @lparts + @rparts ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 1610 | ▶ | if ($missing) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 887 | $addr = join ':', @lparts, ( 0, 0, 0, 0, 0, 0, 0, 0 )[ 0 .. $missing - 1 ], @rparts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 723 | $addr = join ':', @lparts, @rparts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 1610 | return $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # Compacts an IPv6 address (reduces successive :0: runs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | sub ipv6AsciiCompact { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 976 | ▶ | my $addr = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ipv6AsciiCompact: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | # Compress, per RFC5952 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 976 | ▶ | if ( $addr =~ s/^0:0:0:0:0:0:0:0$/::/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 18 | return $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } elsif ( $addr =~ s/(:?^|:)0:0:0:0:0:0:0(:?:|$)/::/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 2 | return $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } elsif ( $addr =~ s/(:?^|:)0:0:0:0:0:0(:?:|$)/::/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 11 | return $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } elsif ( $addr =~ s/(:?^|:)0:0:0:0:0(:?:|$)/::/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 285 | return $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } elsif ( $addr =~ s/(:?^|:)0:0:0:0(:?:|$)/::/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 567 | return $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } elsif ( $addr =~ s/(:?^|:)0:0:0(:?:|$)/::/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 39 | return $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } elsif ( $addr =~ s/(:?^|:)0:0(:?:|$)/::/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 29 | return $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | } elsif ( $addr =~ s/(:?^|:)0(:?:|$)/::/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 16 | return $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 9 | return $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # Cannonicalize IPv6 addresses in ascii format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | sub ipv6Cannonical { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 976 | ▶ | my $addr = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ipv6Cannonical: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 976 | $addr = ipv6NonCompacted($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 976 | $addr = ipv6AsciiCompact($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 976 | return $addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | # IPv6 addresses are stored with a leading zero. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | sub storeNetblock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 46 | ▶ | my ( $this, $t ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
storeNetblock: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 46 | ▶ | $t = $remembered unless $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 46 | my $base = $this->{'IBASE'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 46 | ▶ | if ( $this->{PROTOCOL} eq 'IPv6' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 14 | $base = "0$base"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 46 | ▶ | $t->{$base} = [] unless exists $t->{$base}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 46 | my $mb = maxblock($this); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 46 | my $bits = $this->{'BITS'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 46 | my $i = $bits - $mb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 46 | return ( $t->{$base}[$i] = $this ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | sub deleteNetblock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 13 | ▶ | my ( $this, $t ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deleteNetblock: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 13 | ▶ | $t = $remembered unless $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 13 | my $base = $this->{'IBASE'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 13 | ▶ | if ( $this->{PROTOCOL} eq 'IPv6' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 1 | $base = "0$base"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 13 | my $mb = maxblock($this); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 13 | my $bits = $this->{'BITS'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 13 | my $i = $bits - $mb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 13 | ▶ | return unless defined $t->{$base}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 13 | undef $t->{$base}->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 13 | for my $x ( @{ $t->{$base} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 46 | ▶ | return if $x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 10 | return delete $t->{$base}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | sub findNetblock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 56 | ▶ | my ( $ascii, $t ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findNetblock: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 56 | ▶ | $t = $remembered unless $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 56 | ▶ | my $proto = ( $ascii =~ m/:/ ) ? 'IPv6' : 'IPv4'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 56 | my $ip = ascii2int( $ascii, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 56 | ▶ | return unless defined $ip; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 55 | my %done; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 55 | ▶ | my $maxbits = $proto eq 'IPv6' ? 128 : 32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 55 | ▶ | for ( my $bits = $maxbits; $bits >= 0; $bits-- ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 1251 | my $nb = i_getnet_addr( $ip, $bits, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 1251 | ▶ | if ( $proto eq 'IPv6' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 568 | $nb = "0$nb"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 1251 | ▶ | next unless exists $t->{$nb}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 44 | my $mb = imaxblock( $nb, $maxbits, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 44 | ▶ | next if $done{$mb}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 41 | my $i = $bits - $mb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 41 | ▶ | while ( $i >= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | return $t->{$nb}->[$i] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 308 | ▶ | if defined $t->{$nb}->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 268 | $i--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | sub findOuterNetblock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 56 | ▶ | my ( $ipstr, $t ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findOuterNetblock: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 56 | ▶ | $t = $remembered unless $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 56 | my $proto; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | my $maxbits; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 56 | my $ip; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 56 | my $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 56 | ▶ | if ( ref($ipstr) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 28 | $proto = $ipstr->{PROTOCOL}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 28 | ▶ | $maxbits = $proto eq 'IPv4' ? 32 : 128; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 28 | $ip = $ipstr->{IBASE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 28 | $len = $ipstr->{BITS}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 28 | ▶ | $proto = ( $ipstr =~ m/:/ ) ? 'IPv6' : 'IPv4'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 28 | ▶ | $maxbits = $proto eq 'IPv4' ? 32 : 128; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 28 | $ip = ascii2int( $ipstr, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 28 | $len = $maxbits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 56 | ▶ | for ( my $bits = 0; $bits <= $len; $bits++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 2028 | ▶ | my $nb = $ip & ( $proto eq 'IPv4' ? $imask[$bits] : $i6mask[$bits] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 2028 | ▶ | if ( $proto eq 'IPv6' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 646 | $nb = "0$nb"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 2028 | ▶ | next unless exists $t->{$nb}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 74 | my $mb = imaxblock( $nb, $len, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 74 | my $i = $bits - $mb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 74 | ▶ | confess "$mb, $bits, $ipstr, $nb" if $i < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 74 | ▶ | confess "$mb, $bits, $ipstr, $nb" if $i > $maxbits; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 74 | ▶ | while ( $i >= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | return $t->{$nb}->[$i] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 173 | ▶ | if defined $t->{$nb}->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 151 | $i--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 34 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | sub findAllNetblock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 2 | ▶ | my ( $ipstr, $t ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findAllNetblock: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 2 | ▶ | $t = $remembered unless $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 2 | ▶ | my $proto = ( $ipstr =~ m/:/ ) ? 'IPv6' : 'IPv4'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 2 | ▶ | my $maxbits = $proto eq 'IPv4' ? 32 : 128; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 2 | my $ip = ascii2int( $ipstr, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 2 | my %done; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | my @ary; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 2 | ▶ | for ( my $bits = $maxbits; $bits >= 0; $bits-- ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 162 | ▶ | my $nb = $ip & ( $proto eq 'IPv4' ? $imask[$bits] : $i6mask[$bits] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 162 | ▶ | if ( $proto eq 'IPv6' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 129 | $nb = "0$nb"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 162 | ▶ | next unless exists $t->{$nb}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 109 | my $mb = imaxblock( $nb, $maxbits, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 109 | ▶ | next if $done{$mb}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 3 | my $i = $bits - $mb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 3 | ▶ | confess "$mb, $bits, $ipstr, $nb" if $i < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 3 | ▶ | confess "$mb, $bits, $ipstr, $nb" if $i > $maxbits; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 3 | ▶ | while ( $i >= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | push( @ary, $t->{$nb}->[$i] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 109 | ▶ | if defined $t->{$nb}->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 109 | $i--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 2 | return @ary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | sub dumpNetworkTable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 1 | ▶ | my ($t) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dumpNetworkTable: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 1 | ▶ | $t = $remembered unless $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 1 | my @ary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 1 | foreach my $base ( keys %$t ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 6 | push @ary, grep { defined($_) } @{ $t->{base} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 6 | for my $x ( @{ $t->{$base} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 19 | ▶ | push( @ary, $x ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | if defined $x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 1 | return ( sort @ary ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | sub checkNetblock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | my ( $this, $t ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkNetblock: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | ▶ | $t = $remembered unless $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | my $base = $this->{'IBASE'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | my $mb = maxblock($this); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | my $bits = $this->{'BITS'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | my $i = $bits - $mb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | return defined $t->{$base}->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | sub match { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 24 | ▶ | my ( $this, $ip ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 24 | my $proto = $this->{PROTOCOL}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | # Two different protocols: return undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 24 | ▶ | if ( $ip =~ /:/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 10 | ▶ | if ( $proto ne 'IPv6' ) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 14 | ▶ | if ( $proto ne 'IPv4' ) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 24 | my $i = ascii2int( $ip, $this->{PROTOCOL} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 24 | my $ia = i_getnet_addr( $i, $this->{BITS}, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 24 | ▶ | if ( $proto eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 14 | ▶ | if ( $ia == $this->{IBASE} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 8 | ▶ | return ( ( $i & ~( $this->{IBASE} ) ) || "0 " ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$i & ~$this->{'IBASE'} || '0 '
MC/DC100%1/1
$i & ~$this->{'IBASE'} || '0 '
$i & ~$this->{'IBASE'}
Truth table100%2/2
A
A= $i & ~$this->{'IBASE'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 6 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 10 | ▶ | if ( $ia == $this->{IBASE} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 6 | ▶ | return ( ( $i - $this->{IBASE} ) || "0 " ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$i - $this->{'IBASE'} || '0 '
MC/DC100%1/1
$i - $this->{'IBASE'} || '0 '
$i - $this->{'IBASE'}
Truth table100%2/2
A
A= $i - $this->{'IBASE'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | sub maxblock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 80 | ▶ | my ($this) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
maxblock: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | return ( !defined $this->{ERROR} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | ? imaxblock( $this->{IBASE}, $this->{BITS}, $this->{PROTOCOL} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 80 | ▶ | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | sub nextblock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 8 | ▶ | my ( $this, $index ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nextblock: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 8 | ▶ | $index = 1 unless defined $index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 8 | my $ibase = $this->{IBASE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 8 | ▶ | if ( $this->{PROTOCOL} eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 4 | $ibase += $index * 2**( 32 - $this->{BITS} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 4 | $ibase += $index * Math::BigInt->new(2)->bpow( 128 - $this->{BITS} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | my $newblock = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | IBASE => $ibase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | BITS => $this->{BITS}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | PROTOCOL => $this->{PROTOCOL}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 8 | ▶ | if ( $this->{PROTOCOL} eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 4 | ▶ | return if $newblock->{IBASE} >= 2**32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 4 | ▶ | return if $newblock->{IBASE} >= Math::BigInt->new(2)->bpow(128); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 8 | ▶ | return if $newblock->{IBASE} < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 8 | return $newblock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | sub imaxblock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 427 | ▶ | my ( $ibase, $tbit, $proto ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
imaxblock: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 427 | ▶ | confess unless defined $ibase; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 427 | ▶ | if ( !defined($proto) ) { $proto = 'IPv4'; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 427 | ▶ | while ( $tbit > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 14568 | my $ia = i_getnet_addr( $ibase, $tbit - 1, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 14568 | ▶ | last if ( $ia != $ibase ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 14153 | $tbit--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 427 | return $tbit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | sub range2cidrlist { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 5 | ▶ | my ( $startip, $endip ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
range2cidrlist: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 5 | my $proto; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 5 | ▶ | if ( $startip =~ m/:/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 2 | ▶ | if ( $endip =~ m/:/ ) { $proto = 'IPv6'; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 3 | ▶ | if ( $endip !~ m/:/ ) { $proto = 'IPv4'; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 5 | ▶ | if ( !defined($proto) ) { confess("Cannot mix IPv4 and IPv6 in range2cidrlist()"); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 5 | my $start = ascii2int( $startip, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 5 | my $end = ascii2int( $endip, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 5 | ▶ | ( $start, $end ) = ( $end, $start ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | if $start > $end; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 5 | return irange2cidrlist( $start, $end, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | sub irange2cidrlist { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 39 | ▶ | my ( $start, $end, $proto ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
irange2cidrlist: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 39 | ▶ | if ( !defined($proto) ) { $proto = 'IPv4' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 39 | ▶ | my $bits = $proto eq 'IPv4' ? 32 : 128; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 39 | my @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 39 | ▶ | while ( $end >= $start ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 120 | my $maxsize = imaxblock( $start, $bits, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 120 | my $maxdiff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 120 | ▶ | if ( $proto eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 40 | $maxdiff = $bits - _log2( $end - $start + 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 80 | $maxdiff = $bits - ( $end - $start + 1 )->blog(2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 120 | ▶ | $maxsize = $maxdiff if $maxsize < $maxdiff; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 120 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | @result, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 'IBASE' => $start, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 'BITS' => $maxsize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 'PROTOCOL' => $proto, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 120 | ▶ | if ( $proto eq 'IPv4' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 40 | $start += 2**( 32 - $maxsize ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 80 | $start += Math::BigInt->new(2)->bpow( $bits - $maxsize ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 39 | return @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | sub cidrs2contiglists { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 1 | ▶ | my (@cidrs) = sort_network_blocks(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cidrs2contiglists: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 1 | my @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 1 | ▶ | while (@cidrs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 2 | my (@r) = shift(@cidrs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 2 | my $max = $r[0]->{IBASE} + $r[0]->size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 2 | ▶ | while ( $cidrs[0] && $cidrs[0]->{IBASE} <= $max ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$cidrs[0] and $cidrs[0]{"IBASE"} <= $max
MC/DC100%2/2
$cidrs[0] and $cidrs[0]{"IBASE"} <= $max
$cidrs[0]
$cidrs[0]{"IBASE"} <= $max
Truth table100%3/3
A and B
A= $cidrs[0]B= $cidrs[0]{"IBASE"} <= $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 1 | my $nm = $cidrs[0]->{IBASE} + $cidrs[0]->size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 1 | ▶ | $max = $nm if $nm > $max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 1 | push( @r, shift(@cidrs) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 2 | push( @result, [@r] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 1 | return @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | sub cidrs2cidrs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 15 | ▶ | my (@cidrs) = sort_network_blocks(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cidrs2cidrs: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 15 | my @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | my $proto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 15 | ▶ | if ( scalar(@cidrs) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 15 | $proto = $cidrs[0]->{PROTOCOL}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 15 | ▶ | if ( grep { $proto ne $_->{PROTOCOL} } @cidrs ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | confess("Cannot call cidrs2cidrs with mixed protocol arguments"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 15 | ▶ | while (@cidrs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 24 | my (@r) = shift(@cidrs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 24 | my $max = $r[0]->{IBASE} + $r[0]->size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 24 | ▶ | while ( $cidrs[0] && $cidrs[0]->{IBASE} <= $max ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$cidrs[0] and $cidrs[0]{"IBASE"} <= $max
MC/DC100%2/2
$cidrs[0] and $cidrs[0]{"IBASE"} <= $max
$cidrs[0]
$cidrs[0]{"IBASE"} <= $max
Truth table100%3/3
A and B
A= $cidrs[0]B= $cidrs[0]{"IBASE"} <= $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 25 | my $nm = $cidrs[0]->{IBASE} + $cidrs[0]->size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 25 | ▶ | $max = $nm if $nm > $max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 25 | push( @r, shift(@cidrs) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 24 | my $start = $r[0]->{IBASE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 24 | my $end = $max - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 24 | push( @result, irange2cidrlist( $start, $end, $proto ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 15 | return @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | sub cidrs2inverse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 10 | ▶ | my $outer = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cidrs2inverse: called CC=12 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 10 | ▶ | $outer = __PACKAGE__->new2($outer) || croak($error) unless ref($outer); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
__PACKAGE__->new2($outer) || croak($Net::Netmask::error)
MC/DC0%0/2
__PACKAGE__->new2($outer) || croak($Net::Netmask::error)
__PACKAGE__->new2($outer)
croak($Net::Netmask::error)
Truth table33%1/3
A || B
A= __PACKAGE__->new2($outer)B= croak($Net::Netmask::error)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | # cidrs2cidrs validates that everything is in the same address | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | # family | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 10 | my (@cidrs) = cidrs2cidrs(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 10 | my $proto; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 10 | ▶ | if ( scalar(@cidrs) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 10 | $proto = $cidrs[0]->{PROTOCOL}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 10 | my $first = $outer->{IBASE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 10 | my $last = $first + $outer->size() - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 10 | ▶ | shift(@cidrs) while $cidrs[0] && $cidrs[0]->{IBASE} + $cidrs[0]->size < $first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cidrs[0] and $cidrs[0]{"IBASE"} + $cidrs[0]->size < $first
MC/DC50%1/2
$cidrs[0] and $cidrs[0]{"IBASE"} + $cidrs[0]->size < $first
$cidrs[0]
$cidrs[0]{"IBASE"} + $cidrs[0]->size < $first
Truth table66%2/3
A and B
A= $cidrs[0]B= $cidrs[0]{"IBASE"} + $cidrs[0]->size < $first
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 10 | my @r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 10 | ▶ | while ( @cidrs && $first <= $last ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@cidrs and $first <= $last
MC/DC50%1/2
@cidrs and $first <= $last
@cidrs
$first <= $last
Truth table66%2/3
A and B
A= @cidrsB= $first <= $last
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 16 | ▶ | if ( $first < $cidrs[0]->{IBASE} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 6 | ▶ | if ( $last <= $cidrs[0]->{IBASE} - 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 2 | return ( @r, irange2cidrlist( $first, $last, $proto ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 4 | push( @r, irange2cidrlist( $first, $cidrs[0]->{IBASE} - 1, $proto ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 14 | ▶ | last if $cidrs[0]->{IBASE} > $last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 14 | $first = $cidrs[0]->{IBASE} + $cidrs[0]->size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 14 | shift(@cidrs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 8 | ▶ | if ( $first <= $last ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 4 | push( @r, irange2cidrlist( $first, $last, $proto ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 8 | return @r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | sub by_net_netmask_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | return $a->{'IBASE'} <=> $b->{'IBASE'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 0 | ▶ | || $a->{'BITS'} <=> $b->{'BITS'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
by_net_netmask_block: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/3
$Net::Netmask::a->{'IBASE'} <=> $Net::Netmask::b->{'IBASE'} || $Net::Netmask::a->{'BITS'} <=> $Net::Netmask::b->{'BITS'}
MC/DC0%0/2
$Net::Netmask::a->{'IBASE'} <=> $Net::Netmask::b->{'IBASE'} || $Net::Netmask::a->{'BITS'} <=> $Net::Netmask::b->{'BITS'}
$Net::Netmask::a->{'IBASE'} <=> $Net::Netmask::b->{'IBASE'}
$Net::Netmask::a->{'BITS'} <=> $Net::Netmask::b->{'BITS'}
Truth table0%0/3
A || B
A= $Net::Netmask::a->{'IBASE'} <=> $Net::Netmask::b->{'IBASE'}B= $Net::Netmask::a->{'BITS'} <=> $Net::Netmask::b->{'BITS'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | sub sameblock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 29 | ▶ | return !cmpblocks(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sameblock: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | sub cmpblocks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 45 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmpblocks: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 45 | my $class = ref $this; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 45 | ▶ | my $other = ( ref $_[0] ) ? shift : $class->new(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 45 | return cmp_net_netmask_block( $this, $other ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | sub contains { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 66 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contains: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 66 | my $class = ref $this; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 66 | ▶ | my $other = ( ref $_[0] ) ? shift : $class->new(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 66 | ▶ | return 0 if $this->{IBASE} > $other->{IBASE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 51 | ▶ | return 0 if $this->{BITS} > $other->{BITS}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 46 | ▶ | return 0 if $other->{IBASE} > $this->{IBASE} + $this->size - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 40 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | sub cmp_net_netmask_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 7866 | ▶ | if ( ( $_[0]->{PROTOCOL} eq 'IPv4' ) && ( $_[1]->{PROTOCOL} eq 'IPv4' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmp_net_netmask_block: called CC=7 SCAR=19.5
Pod
undocumented
Branch: 2 branches
Condition100%3/3
$_[0]{"PROTOCOL"} eq "IPv4" and $_[1]{"PROTOCOL"} eq "IPv4"
MC/DC100%2/2
$_[0]{"PROTOCOL"} eq "IPv4" and $_[1]{"PROTOCOL"} eq "IPv4"
$_[0]{"PROTOCOL"} eq "IPv4"
$_[1]{"PROTOCOL"} eq "IPv4"
Truth table100%3/3
A and B
A= $_[0]{"PROTOCOL"} eq "IPv4"B= $_[1]{"PROTOCOL"} eq "IPv4"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | # IPv4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 7827 | ▶ | return ( $_[0]->{IBASE} <=> $_[1]->{IBASE} || $_[0]->{BITS} <=> $_[1]->{BITS} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_[0]{'IBASE'} <=> $_[1]{'IBASE'} || $_[0]{'BITS'} <=> $_[1]{'BITS'}
MC/DC100%2/2
$_[0]{'IBASE'} <=> $_[1]{'IBASE'} || $_[0]{'BITS'} <=> $_[1]{'BITS'}
$_[0]{'IBASE'} <=> $_[1]{'IBASE'}
$_[0]{'BITS'} <=> $_[1]{'BITS'}
Truth table100%3/3
A || B
A= $_[0]{'IBASE'} <=> $_[1]{'IBASE'}B= $_[0]{'BITS'} <=> $_[1]{'BITS'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | ▶ | } elsif ( ( $_[0]->{PROTOCOL} eq 'IPv6' ) && ( $_[1]->{PROTOCOL} eq 'IPv6' ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_[0]{"PROTOCOL"} eq "IPv6" and $_[1]{"PROTOCOL"} eq "IPv6"
MC/DC100%2/2
$_[0]{"PROTOCOL"} eq "IPv6" and $_[1]{"PROTOCOL"} eq "IPv6"
$_[0]{"PROTOCOL"} eq "IPv6"
$_[1]{"PROTOCOL"} eq "IPv6"
Truth table100%3/3
A and B
A= $_[0]{"PROTOCOL"} eq "IPv6"B= $_[1]{"PROTOCOL"} eq "IPv6"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | # IPv6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 36 | ▶ | return ( $_[0]->{IBASE} <=> $_[1]->{IBASE} || $_[0]->{BITS} <=> $_[1]->{BITS} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_[0]{'IBASE'} <=> $_[1]{'IBASE'} || $_[0]{'BITS'} <=> $_[1]{'BITS'}
MC/DC100%2/2
$_[0]{'IBASE'} <=> $_[1]{'IBASE'} || $_[0]{'BITS'} <=> $_[1]{'BITS'}
$_[0]{'IBASE'} <=> $_[1]{'IBASE'}
$_[0]{'BITS'} <=> $_[1]{'BITS'}
Truth table100%3/3
A || B
A= $_[0]{'IBASE'} <=> $_[1]{'IBASE'}B= $_[0]{'BITS'} <=> $_[1]{'BITS'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | # IPv4 to IPv6, order by protocol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 3 | return ( $_[0]->{PROTOCOL} cmp $_[1]->{PROTOCOL} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | sub sort_network_blocks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 52 | return map { $_->[0] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 64 | ▶ | sort { $a->[3] cmp $b->[3] || $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Net::Netmask::a->[3] cmp $Net::Netmask::b->[3] or $Net::Netmask::a->[1] <=> $Net::Netmask::b->[1]
MC/DC50%1/2
$Net::Netmask::a->[3] cmp $Net::Netmask::b->[3] or $Net::Netmask::a->[1] <=> $Net::Netmask::b->[1]
$Net::Netmask::a->[3] cmp $Net::Netmask::b->[3]
$Net::Netmask::a->[1] <=> $Net::Netmask::b->[1]
Truth table66%2/3
A or B
A= $Net::Netmask::a->[3] cmp $Net::Netmask::b->[3]B= $Net::Netmask::a->[1] <=> $Net::Netmask::b->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 16 | ▶ | map { [ $_, $_->{IBASE}, $_->{BITS}, $_->{PROTOCOL} ] } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort_network_blocks: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | sub sort_by_ip_address { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 500 | return map { $_->[0] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 3887 | sort { $a->[1] cmp $b->[1] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 1 | ▶ | map { [ $_, pack( "C4", split( /\./, $_ ) ) ] } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort_by_ip_address: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | sub split ## no critic: (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 14 | ▶ | my ( $self, $parts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 14 | my $num_ips = $self->size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 14 | ▶ | confess "Parts must be defined and greater than 0." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $parts and $parts > 0
MC/DC100%2/2
defined $parts and $parts > 0
defined $parts
$parts > 0
Truth table100%3/3
A and B
A= defined $partsB= $parts > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | unless defined($parts) && $parts > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 8 | ▶ | confess "Netmask only contains $num_ips IPs. Cannot split into $parts." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | unless $num_ips >= $parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 6 | my $log2 = _log2($parts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 6 | ▶ | confess "Parts count must be a number of base 2. Got: $parts" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | unless ( 2**$log2 ) == $parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 4 | my $new_mask = $self->bits + $log2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 516 | return map { Net::Netmask->new( $_ . "/" . $new_mask ) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 4 | map { $self->nth( ( $num_ips / $parts ) * $_ ) } ( 0 .. ( $parts - 1 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | # Implement log2 sub routine directly, to avoid precision problems with floor() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | # problems with perls built with uselongdouble defined. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | # Credit: xenu, on IRC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | sub _log2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 46 | ▶ | my $n = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log2: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 46 | my $ret = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 46 | ▶ | $ret++ while ( $n >>= 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 46 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 8 | ▶ | for ( my $i = 0; $i <= 32; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 264 | $imask[$i] = imask($i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 264 | $imask2bits{ $imask[$i] } = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 264 | $quadmask2bits{ int2quad( $imask[$i] ) } = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 264 | $quadhostmask2bits{ int2quad( ~$imask[$i] ) } = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 264 | $size2bits{ 2**( 32 - $i ) } = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 8 | ▶ | for ( my $i = 0; $i <= 128; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 1032 | $i6mask[$i] = i6mask($i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||