| 1 | package Net::IP::Lite; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 23 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 23 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 23 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 23 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 23 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 23 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ip2bin ip_validate ip_is_ipv4 ip_is_ipv6 ip_is_ipv6ipv4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ip_transform ip_equal ip_equal_v4 ip_equal_v6 ip_in_range | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 23 | ▶ | use constant IPV6IPV4HEAD => '0' x 80 . '1' x 16; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 23 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 693 | ▶ | sub _wrong_ip { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrong_ip: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 693 | my $addr = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 693 | ▶ | $addr = 'UNDEFINED' unless defined $addr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 693 | return "Wrong IP address: '$addr'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 42 | ▶ | sub _wrong_ipv6ipv4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrong_ipv6ipv4: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 42 | my $addr = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 42 | ▶ | $addr = 'UNDEFINED' unless defined $addr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 42 | return "Failed to convert IPv6 address '$addr' to IPv4 address"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 212 | ▶ | sub _wrong_net { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrong_net: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 212 | my $net = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 212 | ▶ | $net = 'UNDEFINED' unless defined $net; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 212 | return "Wrong network definition: '$net'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 10668 | ▶ | sub ip2bin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip2bin: called CC=42 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 10668 | my $addr = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 10668 | ▶ | return '' unless defined $addr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 10651 | my $bin = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 10651 | ▶ | if ($addr =~ /:/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # IPv6 address | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3087 | ▶ | return '0' x 128 if $addr eq '::'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2600 | ▶ | return '' if $addr =~ s/^:// && $addr !~ /^:/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$addr =~ s/^:// and not $addr =~ /^:/
MC/DC100%2/2
$addr =~ s/^:// and not $addr =~ /^:/
$addr =~ s/^://
not $addr =~ /^:/
Truth table100%3/3
A and not(B)
A= $addr =~ s/^://B= not $addr =~ /^:/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2370 | ▶ | return '' if $addr =~ s/:$// && $addr !~ /:$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$addr =~ s/:$// and not $addr =~ /:$/
MC/DC100%2/2
$addr =~ s/:$// and not $addr =~ /:$/
$addr =~ s/:$//
not $addr =~ /:$/
Truth table100%3/3
A and not(B)
A= $addr =~ s/:$//B= not $addr =~ /:$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2229 | my @words = split(/:/, $addr, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 2229 | my $words_amount = scalar @words; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # IPv4 representation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2229 | ▶ | $words_amount++ if $addr =~ /\./; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2229 | my $reduct = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2229 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2229 | for my $word (@words) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 11841 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 11841 | ▶ | if ($word =~ /\./) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # IPv4 representation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 318 | ▶ | return '' if $i != scalar @words || $bin ne IPV6IPV4HEAD; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i != scalar @words or $bin ne "000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111"
MC/DC100%2/2
$i != scalar @words or $bin ne "000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111"
$i != scalar @words
$bin ne "000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111"
Truth table100%3/3
A or B
A= $i != scalar @wordsB= $bin ne "000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 218 | my @octets = split(/\./, $word); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 218 | ▶ | return '' if scalar @octets != 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 198 | for my $octet (@octets) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 792 | ▶ | return '' if $octet !~ /^\d+$/ || $octet > 255; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $octet =~ /^\d+$/ or $octet > 255
MC/DC100%2/2
not $octet =~ /^\d+$/ or $octet > 255
not $octet =~ /^\d+$/
$octet > 255
Truth table100%3/3
not(A) or B
A= not $octet =~ /^\d+$/B= $octet > 255
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 752 | $bin .= unpack('B8', pack('C', $octet)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 158 | return $bin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } elsif (!length $word) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1336 | ▶ | return '' if $reduct; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1198 | $reduct = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1198 | my $len = (9 - $words_amount) << 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1198 | ▶ | return '' unless $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1173 | $bin .= '0' x ((9 - $words_amount) << 4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } elsif ($word =~ /^[0-9a-f]+$/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 10110 | $word =~ s/^0+//i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 10110 | ▶ | return '' if length($word) > 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 9927 | my $int = hex($word); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 9927 | $bin .= unpack('B16', pack('n', $int)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 77 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 11100 | ▶ | return '' if length($bin) > 128; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1488 | ▶ | return '' if length($bin) < 128; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } elsif ($addr =~ /\./) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # IPv4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 5205 | my @octets = split(/\./, $addr, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 5205 | ▶ | return '' if scalar @octets > 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 5182 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 5182 | for my $octet (@octets) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 19805 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 19805 | my $dec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 19805 | ▶ | if ($octet =~ /^0[0-7]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # Octal octet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2297 | $octet =~ s/^0+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2297 | ▶ | return '' if length($octet) > 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2297 | $dec = oct($octet); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } elsif ($octet =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # Decimal octet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 15736 | ▶ | return '' if length($octet) > 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 15713 | $dec = $octet; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } elsif ($octet =~ /^0x[0-9a-f]+$/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # Hexadecimal octet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1617 | $octet =~ s/^0x0*//i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1617 | ▶ | return '' if length($octet) > 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1594 | $dec = hex($octet); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 155 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 19604 | ▶ | return '' if $dec > 255; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 19581 | ▶ | if ($i == scalar @octets && $i < 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i == scalar @octets and $i < 4
MC/DC100%2/2
$i == scalar @octets and $i < 4
$i == scalar @octets
$i < 4
Truth table100%3/3
A and B
A= $i == scalar @octetsB= $i < 4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # add missed octets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 336 | $bin .= '0' x ((4 - $i) << 3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 19581 | $bin .= unpack('B8', pack('C', $dec)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } elsif ($addr =~ /^0[0-7]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # Octal IPv4 address | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 604 | $addr =~ s/^0+//i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 604 | ▶ | return '' if $addr > 37777777777; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 581 | my $int = oct($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 581 | $bin = unpack('B32', pack('N', $int)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } elsif ($addr =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # Decimal IPv4 address | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1151 | ▶ | return '' if $addr > 4294967295; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1128 | $bin = unpack('B32', pack('N', $addr)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } elsif ($addr =~ /^0x[0-9a-f]+$/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Hexadecimal IPv4 addres | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 544 | $addr =~ s/^0x0*//i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 544 | ▶ | return '' if length($addr) > 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 521 | my $int = hex($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 521 | $bin = unpack('B32', pack('N', $int)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 8711 | return $bin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 12612 | ▶ | sub _ip_validate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ip_validate: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 12612 | return length(shift) > 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 87 | ▶ | sub ip_validate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip_validate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 87 | return _ip_validate(ip2bin(shift)) > 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 5087 | ▶ | sub _ip_is_ipv4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ip_is_ipv4: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 5087 | return length(shift) eq 32; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 87 | ▶ | sub ip_is_ipv4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip_is_ipv4: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 87 | return _ip_is_ipv4(ip2bin(shift)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 4610 | ▶ | sub _ip_type_equal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ip_type_equal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 4610 | return length(shift) == length(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 647 | ▶ | sub _ip_is_ipv6 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ip_is_ipv6: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 647 | return length(shift) eq 128; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 87 | ▶ | sub ip_is_ipv6 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip_is_ipv6: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 87 | return _ip_is_ipv6(ip2bin(shift)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 536 | ▶ | sub _ip_is_ipv6ipv4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ip_is_ipv6ipv4: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 536 | return substr(shift, 0, 96) eq IPV6IPV4HEAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 87 | ▶ | sub ip_is_ipv6ipv4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip_is_ipv6ipv4: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 87 | return _ip_is_ipv6ipv4(ip2bin(shift)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 640 | ▶ | sub _bin2ipv6 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bin2ipv6: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 640 | my ($bin, $lead_zeros, $short) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 640 | my $result = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 640 | my @chunks = $bin =~ m/[0..1]{16}/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 640 | my $short_len = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 640 | ▶ | if ($short) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 200 | my @zero_chunks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 200 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 200 | for my $chunk (@chunks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1528 | ▶ | if ($chunk !~ /1/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1120 | $zero_chunks[$i]++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 408 | ▶ | $i++ if defined $zero_chunks[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 200 | @zero_chunks = sort @zero_chunks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 200 | ▶ | $short_len = pop @zero_chunks if scalar @zero_chunks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 640 | for my $chunk (@chunks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 4960 | my $word = unpack('H4', pack('B16', $chunk)) . ':'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 4960 | ▶ | $word =~ s/^0{1,3}// unless $lead_zeros; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 4960 | $result .= $word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 640 | ▶ | $result =~ s/(^|:)(0{1,4}:){$short_len}/::/ if $short_len > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 640 | ▶ | $result =~ s/:$// if $result !~ /::$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 640 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 730 | ▶ | sub _bin2ipv4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bin2ipv4: called CC=19 SCAR=29.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 730 | my ($bin, $format, $lead_zeros, $short) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 730 | ▶ | $format ||= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$format ||= ""
MC/DC100%1/1
$format ||= ""
$format
Truth table100%2/2
A
A= $format
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 730 | my @chunks = $bin =~ m/[0..1]{8}/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 730 | ▶ | if ($format =~ /^(D|O|X)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 72 | my $result = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 72 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 72 | for my $chunk (reverse @chunks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 288 | $result += unpack('C', pack('B8', $chunk)) << $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 288 | $i +=8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 72 | ▶ | return sprintf("%#1o", $result) if $format eq 'O'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 48 | ▶ | return sprintf("0x%.8x", $result) if $format eq 'X' && $lead_zeros; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$format eq "X" and $lead_zeros
MC/DC100%2/2
$format eq "X" and $lead_zeros
$format eq "X"
$lead_zeros
Truth table100%3/3
A and B
A= $format eq "X"B= $lead_zeros
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 40 | ▶ | return sprintf("0x%x", $result) if $format eq 'X'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 20 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 658 | my $result = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 658 | my $f = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 658 | ▶ | if ($format eq 'o') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 40 | $f = '%#.1o'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } elsif ($format eq 'x') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 48 | ▶ | $f = $lead_zeros ? '0x%.2x' : '0x%x' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 658 | my $i = 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 658 | for my $chunk (reverse @chunks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 2632 | $i--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 2632 | my $octet = unpack('C', pack('B8', $chunk)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2632 | ▶ | if ($short) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 452 | ▶ | next if (!$octet && $i && $i < 3 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $octet and $i and $i < 3
not $octet and $i
MC/DC100%3/3
not $octet and $i and $i < 3
not $octet
$i
$i < 3
Truth table100%4/4
not(A) and B and C
A= not $octetB= $iC= $i < 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 242 | ▶ | $short = 0 if $i == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 2422 | ▶ | if ($format eq 'o') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 128 | $octet = sprintf($f, $octet); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } elsif ($format eq 'x') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 158 | $octet = sprintf($f, $octet); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2422 | $result = "$octet.$result"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 658 | $result =~ s/\.$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 658 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 352 | ▶ | sub _reverse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reverse: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 352 | my $bin = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 352 | ▶ | my $len = _ip_is_ipv4($bin) ? 8 : 16; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 352 | my @chunks = $bin =~ m/[0..1]{$len}/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 352 | return join('', reverse @chunks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 704 | ▶ | sub _ip_transform { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ip_transform: called CC=16 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 704 | my ($bin, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 704 | ▶ | my $format = $opts->{format_ipv4} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{'format_ipv4'} || ''
MC/DC100%1/1
$opts->{'format_ipv4'} || ''
$opts->{'format_ipv4'}
Truth table100%2/2
A
A= $opts->{'format_ipv4'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 704 | ▶ | my $convert_to = $opts->{convert_to} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{'convert_to'} || ''
MC/DC100%1/1
$opts->{'convert_to'} || ''
$opts->{'convert_to'}
Truth table100%2/2
A
A= $opts->{'convert_to'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 704 | my $ipv6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | my $ipv4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 704 | ▶ | if ($convert_to eq 'ipv4' && _ip_is_ipv6ipv4($bin)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$convert_to eq "ipv4" and _ip_is_ipv6ipv4($bin)
MC/DC100%2/2
$convert_to eq "ipv4" and _ip_is_ipv6ipv4($bin)
$convert_to eq "ipv4"
_ip_is_ipv6ipv4($bin)
Truth table100%3/3
A and B
A= $convert_to eq "ipv4"B= _ip_is_ipv6ipv4($bin)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # convert ipv6ipv4 to ipv4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 36 | $bin = substr($bin, 96, 32); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 704 | ▶ | if (($convert_to eq 'ipv6' || $convert_to eq 'ipv6ipv4') && _ip_is_ipv4($bin)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$convert_to eq "ipv6" || $convert_to eq "ipv6ipv4" and _ip_is_ipv4($bin)
$convert_to eq "ipv6" or $convert_to eq "ipv6ipv4"
MC/DC100%3/3
$convert_to eq "ipv6" || $convert_to eq "ipv6ipv4" and _ip_is_ipv4($bin)
$convert_to eq "ipv6"
$convert_to eq "ipv6ipv4"
_ip_is_ipv4($bin)
Truth table100%5/5
A or B and C
A= $convert_to eq "ipv6"B= $convert_to eq "ipv6ipv4"C= _ip_is_ipv4($bin)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # convert ipv4 to ipv6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 136 | $bin = IPV6IPV4HEAD . $bin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 704 | ▶ | if ($convert_to eq 'ipv6ipv4' && _ip_is_ipv6ipv4($bin)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$convert_to eq "ipv6ipv4" and _ip_is_ipv6ipv4($bin)
MC/DC100%2/2
$convert_to eq "ipv6ipv4" and _ip_is_ipv6ipv4($bin)
$convert_to eq "ipv6ipv4"
_ip_is_ipv6ipv4($bin)
Truth table100%3/3
A and B
A= $convert_to eq "ipv6ipv4"B= _ip_is_ipv6ipv4($bin)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # convert ipv4 to ipv6ipv4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 80 | $ipv4 = substr($bin, 96, 32); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 80 | ▶ | $ipv4 = _reverse($ipv4) if $opts->{reverse}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 80 | $bin = IPV6IPV4HEAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 624 | ▶ | $bin = _reverse($bin) if $opts->{reverse}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 704 | my $result = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 704 | ▶ | if (length($bin) > 32) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # IPv6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 366 | $result = _bin2ipv6($bin, $opts->{lead_zeros}, $opts->{short_ipv6}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 366 | ▶ | if ($ipv4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 80 | $bin = $ipv4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 80 | $ipv6 = $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 704 | ▶ | if (length($bin) == 32) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # IPv4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 418 | ▶ | if ($ipv6) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 80 | $result = "$ipv6:" . _bin2ipv4($bin); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 338 | $result = _bin2ipv4($bin, $format, $opts->{lead_zeros}, $opts->{short_ipv4}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 704 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 416 | ▶ | sub ip_transform { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip_transform: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 416 | my ($addr, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 416 | ▶ | $opts ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts ||= {}
MC/DC100%1/1
$opts ||= {}
$opts
Truth table100%2/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 416 | ▶ | croak 'Options must be a hash' unless ref($opts) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 415 | my $bin = ip2bin($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 415 | ▶ | croak _wrong_ip($addr) unless _ip_validate($bin); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 352 | return _ip_transform($bin, $opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 2951 | ▶ | sub _ip_equal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ip_equal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2951 | my ($bin1, $bin2) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 2951 | return $bin1 eq $bin2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 157 | ▶ | sub ip_equal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip_equal: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 157 | my ($addr1, $addr2) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 157 | my $bin1 = ip2bin($addr1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 157 | my $bin2 = ip2bin($addr2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 157 | ▶ | croak _wrong_ip($addr1) unless _ip_validate($bin1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 94 | ▶ | croak _wrong_ip($addr2) unless _ip_validate($bin2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 31 | return $bin1 eq $bin2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 93 | ▶ | sub _ip_equal_v4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ip_equal_v4: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 93 | my ($bin1, $bin2) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 93 | ▶ | $bin1 = substr($bin1, 96, 32) if _ip_is_ipv6ipv4($bin1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 93 | ▶ | $bin2 = substr($bin2, 96, 32) if _ip_is_ipv6ipv4($bin2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 93 | return _ip_equal($bin1, $bin2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 177 | ▶ | sub ip_equal_v4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip_equal_v4: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 177 | my ($addr1, $addr2) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 177 | my $bin1 = ip2bin($addr1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 177 | my $bin2 = ip2bin($addr2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 177 | ▶ | croak _wrong_ip($addr1) unless _ip_validate($bin1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 177 | ▶ | croak _wrong_ip($addr2) unless _ip_validate($bin2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 51 | ▶ | if ((_ip_is_ipv6($bin1) && ! _ip_is_ipv6ipv4($bin1))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
_ip_is_ipv6($bin1) and not _ip_is_ipv6ipv4($bin1)
MC/DC100%2/2
_ip_is_ipv6($bin1) and not _ip_is_ipv6ipv4($bin1)
_ip_is_ipv6($bin1)
not _ip_is_ipv6ipv4($bin1)
Truth table100%3/3
A and not(B)
A= _ip_is_ipv6($bin1)B= not _ip_is_ipv6ipv4($bin1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 11 | croak _wrong_ipv6ipv4($addr1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 40 | ▶ | if ((_ip_is_ipv6($bin2) && ! _ip_is_ipv6ipv4($bin2))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
_ip_is_ipv6($bin2) and not _ip_is_ipv6ipv4($bin2)
MC/DC100%2/2
_ip_is_ipv6($bin2) and not _ip_is_ipv6ipv4($bin2)
_ip_is_ipv6($bin2)
not _ip_is_ipv6ipv4($bin2)
Truth table100%3/3
A and not(B)
A= _ip_is_ipv6($bin2)B= not _ip_is_ipv6ipv4($bin2)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 9 | croak _wrong_ipv6ipv4($addr2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 31 | return _ip_equal_v4($bin1, $bin2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 114 | ▶ | sub _ip_equal_v6 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ip_equal_v6: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 114 | my ($bin1, $bin2) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 114 | ▶ | $bin1 = IPV6IPV4HEAD . $bin1 if _ip_is_ipv4($bin1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 114 | ▶ | $bin2 = IPV6IPV4HEAD . $bin2 if _ip_is_ipv4($bin2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 114 | return _ip_equal($bin1, $bin2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 164 | ▶ | sub ip_equal_v6 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip_equal_v6: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 164 | my ($addr1, $addr2) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 164 | my $bin1 = ip2bin($addr1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 164 | my $bin2 = ip2bin($addr2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 164 | ▶ | croak _wrong_ip($addr1) unless _ip_validate($bin1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 164 | ▶ | croak _wrong_ip($addr2) unless _ip_validate($bin2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 38 | return _ip_equal_v6($bin1, $bin2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 2682 | ▶ | sub __ip_in_range { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ip_in_range: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 2682 | my ($bin_addr, $bin_net, $bin_mask) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 2682 | my @addr_bits = split(//, $bin_addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 2682 | my @mask_bits = split(//, $bin_mask); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 2682 | my $result = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 2682 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 2682 | for my $bit (@addr_bits) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 130560 | $result .= $bit & $mask_bits[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 130560 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 2682 | return _ip_equal($bin_net, $result); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 2098 | ▶ | sub _ip_in_range { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ip_in_range: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 2098 | my ($bin_addr, $net, $addr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 2098 | my $bin_net; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | my $bin_mask; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 2098 | ▶ | if ($net =~ /^(.+)\/(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 796 | my $mask = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 796 | $bin_net = ip2bin($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 796 | ▶ | croak _wrong_net($net) unless _ip_validate($bin_net); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 796 | ▶ | my $mask_len = _ip_is_ipv4($bin_net) ? 32 : 128; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 796 | ▶ | croak _wrong_net($net) if $mask > $mask_len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 792 | $bin_mask = '1' x $mask . '0' x ($mask_len - $mask); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } elsif ($net =~ /^(\S+)\s+(\S+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 474 | $bin_net = ip2bin($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 474 | $bin_mask = ip2bin($2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 828 | $bin_net = ip2bin($net); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 828 | ▶ | $bin_mask = '1' x (_ip_is_ipv4($bin_net) ? 32 : 128); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 2094 | ▶ | unless (_ip_validate($bin_net) && _ip_validate($bin_mask) && _ip_type_equal($bin_net, $bin_mask)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
_ip_validate($bin_net) and _ip_validate($bin_mask) and _ip_type_equal($bin_net, $bin_mask)
_ip_validate($bin_net) and _ip_validate($bin_mask)
MC/DC100%3/3
_ip_validate($bin_net) and _ip_validate($bin_mask) and _ip_type_equal($bin_net, $bin_mask)
_ip_validate($bin_net)
_ip_validate($bin_mask)
_ip_type_equal($bin_net, $bin_mask)
Truth table100%4/4
A and B and C
A= _ip_validate($bin_net)B= _ip_validate($bin_mask)C= _ip_type_equal($bin_net, $bin_mask)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 206 | croak _wrong_net($net); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 1888 | ▶ | return 0 unless _ip_type_equal($bin_addr, $bin_net); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 1870 | return __ip_in_range($bin_addr, $bin_net, $bin_mask); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 1403 | ▶ | sub ip_in_range { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip_in_range: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 1403 | my ($addr, $range) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 1403 | ▶ | croak _wrong_net($range) unless defined $range; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 1402 | ▶ | if (ref($range) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 410 | for my $net (@$range) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 617 | ▶ | return 1 if ip_in_range($addr, $net); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 107 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 992 | my $bin_addr = ip2bin($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 992 | ▶ | croak _wrong_ip($addr) unless _ip_validate($bin_addr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 929 | return _ip_in_range($bin_addr, $range, $addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 4533 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 4533 | my ($class, $addr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 4533 | my $bin = ip2bin($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 4533 | ▶ | return 0 unless _ip_validate($bin); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 4371 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | bin => $bin, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | addr => $addr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 4371 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 4371 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | sub _set_binary { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_binary: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my ($self, $bin) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $self->{bin} = $bin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $self->{addr} = $self->transform(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 1182 | ▶ | sub address { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
address: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 1182 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 1182 | return $self->{addr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 8377 | ▶ | sub binary { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
binary: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 8377 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 8377 | return $self->{bin}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 2616 | ▶ | sub is_ipv4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ipv4: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 2616 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 2616 | return _ip_is_ipv4($self->binary); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 398 | ▶ | sub is_ipv6 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ipv6: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 398 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 398 | return _ip_is_ipv6($self->binary); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 51 | ▶ | sub is_ipv6ipv4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ipv6ipv4: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 51 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 51 | return _ip_is_ipv6ipv4($self->binary); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 353 | ▶ | sub transform { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transform: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 353 | my ($self, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 353 | ▶ | $opts ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts ||= {}
MC/DC100%1/1
$opts ||= {}
$opts
Truth table100%2/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 353 | ▶ | croak 'Options must be a hash' unless ref($opts) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 352 | return _ip_transform($self->binary, $opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 125 | ▶ | sub equal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equal: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 125 | my ($self, $addr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 125 | ▶ | if (blessed($addr) && $addr->isa('Net::IP::Lite')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($addr) and $addr->isa("Net::IP::Lite")
MC/DC50%1/2
builtin::blessed($addr) and $addr->isa("Net::IP::Lite")
builtin::blessed($addr)
$addr->isa("Net::IP::Lite")
Truth table66%2/3
A and B
A= builtin::blessed($addr)B= $addr->isa("Net::IP::Lite")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 31 | return _ip_equal($self->binary, $addr->binary); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 94 | my $bin2 = ip2bin($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 94 | ▶ | croak _wrong_ip($addr) unless _ip_validate($bin2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 31 | return _ip_equal($self->binary, $bin2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 147 | ▶ | sub equal_v4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equal_v4: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 147 | my ($self, $addr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 147 | ▶ | my $bin2 = (blessed($addr) && $addr->isa('Net::IP::Lite')) ? $addr->binary : ip2bin($addr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($addr) and $addr->isa("Net::IP::Lite")
MC/DC50%1/2
builtin::blessed($addr) and $addr->isa("Net::IP::Lite")
builtin::blessed($addr)
$addr->isa("Net::IP::Lite")
Truth table66%2/3
A and B
A= builtin::blessed($addr)B= $addr->isa("Net::IP::Lite")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 147 | ▶ | croak _wrong_ip($addr) unless _ip_validate($bin2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 84 | ▶ | if (($self->is_ipv6() && ! $self->is_ipv6ipv4())) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->is_ipv6 and not $self->is_ipv6ipv4
MC/DC100%2/2
$self->is_ipv6 and not $self->is_ipv6ipv4
$self->is_ipv6
not $self->is_ipv6ipv4
Truth table100%3/3
A and not(B)
A= $self->is_ipv6B= not $self->is_ipv6ipv4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 13 | croak _wrong_ipv6ipv4($self->address); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 71 | ▶ | if ((_ip_is_ipv6($bin2) && ! _ip_is_ipv6ipv4($bin2))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
_ip_is_ipv6($bin2) and not _ip_is_ipv6ipv4($bin2)
MC/DC100%2/2
_ip_is_ipv6($bin2) and not _ip_is_ipv6ipv4($bin2)
_ip_is_ipv6($bin2)
not _ip_is_ipv6ipv4($bin2)
Truth table100%3/3
A and not(B)
A= _ip_is_ipv6($bin2)B= not _ip_is_ipv6ipv4($bin2)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 9 | croak _wrong_ipv6ipv4($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 62 | return _ip_equal_v4($self->binary, $bin2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 139 | ▶ | sub equal_v6 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equal_v6: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 139 | my ($self, $addr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 139 | ▶ | my $bin2 = (blessed($addr) && $addr->isa('Net::IP::Lite')) ? $addr->binary : ip2bin($addr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($addr) and $addr->isa("Net::IP::Lite")
MC/DC50%1/2
builtin::blessed($addr) and $addr->isa("Net::IP::Lite")
builtin::blessed($addr)
$addr->isa("Net::IP::Lite")
Truth table66%2/3
A and B
A= builtin::blessed($addr)B= $addr->isa("Net::IP::Lite")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 139 | ▶ | croak _wrong_ip($addr) unless _ip_validate($bin2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 76 | return _ip_equal_v6($self->binary, $bin2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 2234 | ▶ | sub in_range { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in_range: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 2234 | my ($self, $range) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 2234 | ▶ | croak _wrong_net($range) unless defined $range; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 2233 | ▶ | if (ref($range) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 650 | for my $net (@$range) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 1097 | ▶ | return 1 if $self->in_range($net); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 227 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 1583 | ▶ | if (blessed($range) && $range->isa('Net::IP::Lite::Net')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($range) and $range->isa("Net::IP::Lite::Net")
MC/DC50%1/2
builtin::blessed($range) and $range->isa("Net::IP::Lite::Net")
builtin::blessed($range)
$range->isa("Net::IP::Lite::Net")
Truth table66%2/3
A and B
A= builtin::blessed($range)B= $range->isa("Net::IP::Lite::Net")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 414 | return $range->contains($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 1169 | return _ip_in_range($self->binary, $range, $self->address); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | package Net::IP::Lite::Net; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 23 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 23 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 23 | ▶ | use base qw(Net::IP::Lite); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 1104 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=16 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 1104 | my ($class, $net) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 1104 | ▶ | return 0 unless defined $net; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 1103 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 1103 | my $bin_mask; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 1103 | ▶ | if ($net =~ /^(.+)\/(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 511 | my $mask = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 511 | $self = $class->SUPER::new($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 511 | ▶ | my $mask_len = $self->is_ipv4() ? 32 : 128; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 511 | ▶ | return 0 if $mask > $mask_len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 509 | $bin_mask = '1' x $mask . '0' x ($mask_len - $mask); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } elsif ($net =~ /^(\S+)\s+(\S+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 454 | $self = $class->SUPER::new($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 454 | ▶ | return 0 unless $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 453 | $self->{mask} = Net::IP::Lite->new($2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 138 | $self = $class->SUPER::new($net); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 138 | ▶ | return 0 unless $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 77 | ▶ | $bin_mask = '1' x ($self->is_ipv4 ? 32 : 128); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 1039 | ▶ | if ($bin_mask) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 586 | ▶ | if (length($bin_mask) == 32) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 312 | $self->{mask} = Net::IP::Lite->new(Net::IP::Lite::_bin2ipv4($bin_mask)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 274 | $self->{mask} = Net::IP::Lite->new(Net::IP::Lite::_bin2ipv6($bin_mask)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 1039 | ▶ | return 0 unless $self->{mask}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 1002 | my $ipv4_mask = $self->{mask}->is_ipv4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 1002 | ▶ | return 0 unless (($self->is_ipv4 && $ipv4_mask) || ($self->is_ipv6 && ! $ipv4_mask)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$self->is_ipv4 and $ipv4_mask or $self->is_ipv6 and not $ipv4_mask
$self->is_ipv4 and $ipv4_mask
$self->is_ipv6 and not $ipv4_mask
MC/DC75%3/4
$self->is_ipv4 and $ipv4_mask or $self->is_ipv6 and not $ipv4_mask
$self->is_ipv4
$ipv4_mask
$self->is_ipv6
not $ipv4_mask
Truth table57%4/7
A and B or C and not(D)
A= $self->is_ipv4B= $ipv4_maskC= $self->is_ipv6D= not $ipv4_mask
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 999 | $self->{net} = $net; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 999 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 962 | ▶ | sub mask { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mask: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 962 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 962 | return $self->{mask}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | ▶ | sub network { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
network: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | return $self->{net}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 828 | ▶ | sub contains { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contains: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 828 | my ($self, $addr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 828 | ▶ | if (blessed($addr) && $addr->isa('Net::IP::Lite')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($addr) and $addr->isa("Net::IP::Lite")
MC/DC50%1/2
builtin::blessed($addr) and $addr->isa("Net::IP::Lite")
builtin::blessed($addr)
$addr->isa("Net::IP::Lite")
Truth table66%2/3
A and B
A= builtin::blessed($addr)B= $addr->isa("Net::IP::Lite")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 414 | ▶ | return 0 unless Net::IP::Lite::_ip_type_equal($self->binary, $addr->binary); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 406 | return Net::IP::Lite::__ip_in_range($addr->binary, $self->binary, $self->mask->binary); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 414 | my $bin_addr = Net::IP::Lite::ip2bin($addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 414 | ▶ | croak Net::IP::Lite::_wrong_ip($addr) unless Net::IP::Lite::_ip_validate($bin_addr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 414 | ▶ | return 0 unless Net::IP::Lite::_ip_type_equal($self->binary, $bin_addr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 406 | return Net::IP::Lite::__ip_in_range($bin_addr, $self->binary, $self->mask->binary); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 23 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||