| 1 | #!/bin/false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Pure perl implementations of IPv4 and IPv6 address utilities | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # PODNAME: NetAddr::IP::UtilPP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | package NetAddr::IP::UtilPP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '4.080_09'; # TRIAL VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use parent 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Scalar::Util qw( looks_like_number ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use NetAddr::IP::Constants qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | $IPV4_BITS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | $IPV6_BITS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | $MAX_BCD_DIGITS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | $MAX_SHIFTLEFT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | $OCTET_BITS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | $PACKED_BCD_BYTES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | $V4_PACKED_BYTES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | $V6_PACKED_BYTES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | hasbits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | shiftleft | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | addconst | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | add128 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | sub128 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | notcontiguous | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ipv4to6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | mask4to6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ipanyto6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | maskanyto6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ipv6to4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | bin2bcd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | bcd2bin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | comp128 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | bin2bcdn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | bcdn2txt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | bcdn2bin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | simple_pack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | all => [@EXPORT_OK], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # the error for a packed argument with a character above 0xFF, worded as perl's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # from the XS, with the function named in place of "subroutine entry" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | my $WIDE_DIES = 'Wide character in %s'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub DESTROY { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 20 | ▶ | sub _callersub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_callersub: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 20 | (my $sub = (caller(2))[3]) =~ s/UtilPP::/Util::/; # callers use NetAddr::IP::Util | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 20 | return $sub; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # a downgraded copy of a packed argument, so it is measured in bytes as the XS measures it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 75 | ▶ | sub _bytes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bytes: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 75 | my ($packed) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 75 | ▶ | croak sprintf($WIDE_DIES, _callersub()) unless utf8::downgrade($packed, 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 55 | return $packed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub _deadlen { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deadlen: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my ($len, $should) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $should = $IPV6_BITS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | unless $should; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $sub = _callersub(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | my $bits = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | defined $len | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ? $len * $OCTET_BITS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | : 'undefined'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | croak "Bad arg length for $sub, length is $bits, should be $should"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | ▶ | sub hasbits($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hasbits: called CC=7 SCAR=31.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | my $bits128 = _bytes(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | _deadlen(length($bits128)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $bits128 or length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $bits128 or length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $bits128
length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $bits128B= length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | if !defined($bits128) || length($bits128) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | ▶ | return 1 if vec($bits128, 0, $IPV4_BITS); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | return 1 if vec($bits128, 1, $IPV4_BITS); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return 1 if vec($bits128, 2, $IPV4_BITS); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return 1 if vec($bits128, 3, $IPV4_BITS); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | #=item $rv = isIPv4($bits128); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | #This function returns true if there are no on bits present in the IPv6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | #portion of the 128 bit string and false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | #=cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | #sub xisIPv4 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # _deadlen(length($_[0])) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # if length($_[0]) != 16; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # return 0 if vec($_[0],0,32); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # return 0 if vec($_[0],1,32); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # return 0 if vec($_[0],2,32); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | #} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # multiply x 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # returns true if the result overflowed 128 bits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 26 | ▶ | sub _128x2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_128x2: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 26 | my $inp = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 26 | ▶ | my $carry = ($$inp[0] & 0x80000000) ? 1 : 0; # bit shifted out the top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 26 | ▶ | $$inp[0] = ($$inp[0] << 1 & 0xffffffff) + (($$inp[1] & 0x80000000) ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 26 | ▶ | $$inp[1] = ($$inp[1] << 1 & 0xffffffff) + (($$inp[2] & 0x80000000) ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 26 | ▶ | $$inp[2] = ($$inp[2] << 1 & 0xffffffff) + (($$inp[3] & 0x80000000) ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 26 | $$inp[3] = $$inp[3] << 1 & 0xffffffff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 26 | return $carry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # multiply x 10, returns true if the result overflowed 128 bits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | ▶ | sub _128x10 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_128x10: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 8 | my $a128p = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | my $overflow = _128x2($a128p); # x2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 8 | my @x2 = @$a128p; # save the x2 value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | $overflow |= _128x2($a128p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 8 | $overflow |= _128x2($a128p); # x8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | $overflow |= _sa128($a128p, \@x2, 0); # add for x10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 8 | return $overflow; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # a count or constant as a plain scalar: an object goes through its numeric | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # conversion, as the XS reads it, or else its text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 10 | ▶ | sub _plain_number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_plain_number: called CC=3 SCAR=15.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 10 | my ($n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 10 | ▶ | return $n unless ref $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | return looks_like_number($n) ? sprintf('%.17g', $n) : "$n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | ▶ | sub shiftleft($;@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shiftleft: called CC=11 SCAR=30.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 3 | my $bits = _bytes($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | _deadlen(length($bits)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $bits or length $bits != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $bits or length $bits != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $bits
length $bits != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $bitsB= length $bits != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | if !defined($bits) || length($bits) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | my $given = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | my $shifts = _plain_number($given); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | ▶ | return $bits unless defined $shifts && $shifts ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $shifts and $shifts ne ""
MC/DC0%0/2
defined $shifts and $shifts ne ""
defined $shifts
$shifts ne ""
Truth table33%1/3
A and B
A= defined $shiftsB= $shifts ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # an integer count from 0 to 128; undef or the empty string returns the input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | croak "Bad arg value for NetAddr::IP::Util::shiftleft, is $given, should be 0 thru $MAX_SHIFTLEFT" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
&looks_like_number($shifts) and $shifts >= 0 and $shifts <= $NetAddr::IP::UtilPP::MAX_SHIFTLEFT and $shifts == int $shifts
&looks_like_number($shifts) and $shifts >= 0 and $shifts <= $NetAddr::IP::UtilPP::MAX_SHIFTLEFT
&looks_like_number($shifts) and $shifts >= 0
MC/DC0%0/4
&looks_like_number($shifts) and $shifts >= 0 and $shifts <= $NetAddr::IP::UtilPP::MAX_SHIFTLEFT and $shifts == int $shifts
&looks_like_number($shifts)
$shifts >= 0
$shifts <= $NetAddr::IP::UtilPP::MAX_SHIFTLEFT
$shifts == int $shifts
Truth table20%1/5
A and B and C and D
A= &looks_like_number($shifts)B= $shifts >= 0C= $shifts <= $NetAddr::IP::UtilPP::MAX_SHIFTLEFTD= $shifts == int $shifts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | unless looks_like_number($shifts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | && $shifts >= 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | && $shifts <= $MAX_SHIFTLEFT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | && $shifts == int($shifts); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | ▶ | return $bits if $shifts == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | my @uint32t = unpack('N4', $bits); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | _128x2(\@uint32t) for 1 .. $shifts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | return pack('N4', @uint32t); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 10 | ▶ | sub slowadd128 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
slowadd128: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 10 | my @ua = unpack('N4', $_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 10 | my @ub = unpack('N4', $_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 10 | my $carry = _sa128(\@ua, \@ub, $_[2]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 10 | ▶ | return ($carry, pack('N4', @ua)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 10 | return $carry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 26 | ▶ | sub _sa128 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sa128: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 26 | my ($uap, $ubp, $carry) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 26 | ▶ | if (($$uap[3] += $$ubp[3] + $carry) > 0xffffffff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 8 | $$uap[3] -= 4294967296; # 0x1_00000000 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 8 | $carry = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 18 | $carry = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 26 | ▶ | if (($$uap[2] += $$ubp[2] + $carry) > 0xffffffff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 4 | $$uap[2] -= 4294967296; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 4 | $carry = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 22 | $carry = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 26 | ▶ | if (($$uap[1] += $$ubp[1] + $carry) > 0xffffffff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 4 | $$uap[1] -= 4294967296; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 4 | $carry = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 22 | $carry = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 26 | ▶ | if (($$uap[0] += $$ubp[0] + $carry) > 0xffffffff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 4 | $$uap[0] -= 4294967296; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 4 | $carry = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 22 | $carry = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 26 | return $carry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 5 | ▶ | sub addconst { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addconst: called CC=13 SCAR=30.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 5 | my ($a128, $given) = (_bytes($_[0]), $_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 4 | my $const = _plain_number($given); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 4 | ▶ | _deadlen(length($a128)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $a128 or length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $a128 or length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $a128
length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $a128B= length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | if !defined($a128) || length($a128) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | ▶ | unless (defined $const && $const ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $const and $const ne ""
MC/DC50%1/2
defined $const and $const ne ""
defined $const
$const ne ""
Truth table66%2/3
A and B
A= defined $constB= $const ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | ▶ | return (wantarray) ? (0, $a128) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # an integer in the signed 32 bit range, the rule the XS applies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | croak | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | ▶ | "Bad arg value for NetAddr::IP::Util::addconst, is $given, should be an integer from -2147483648 thru 2147483647" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
&looks_like_number($const) and $const >= '-2147483648' and $const <= 2147483647 and $const == int $const
&looks_like_number($const) and $const >= '-2147483648' and $const <= 2147483647
&looks_like_number($const) and $const >= '-2147483648'
MC/DC0%0/4
&looks_like_number($const) and $const >= '-2147483648' and $const <= 2147483647 and $const == int $const
&looks_like_number($const)
$const >= '-2147483648'
$const <= 2147483647
$const == int $const
Truth table20%1/5
A and B and C and D
A= &looks_like_number($const)B= $const >= '-2147483648'C= $const <= 2147483647D= $const == int $const
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | unless looks_like_number($const) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | && $const >= -2_147_483_648 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | && $const <= 2_147_483_647 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | && $const == int($const); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | ▶ | return (wantarray) ? (0, $a128) : 0 if $const == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | ▶ | my $sign = ($const < 0) ? 0xffffffff : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 2 | my $b128 = pack('N4', $sign, $sign, $sign, $const); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | @_ = ($a128, $b128, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 2 | goto &slowadd128; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 6 | ▶ | sub add128 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add128: called CC=5 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # copied before the second argument is read: its get magic can replace it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 6 | my $a128 = _bytes($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 5 | ▶ | _deadlen(length($a128)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $a128 or length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $a128 or length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $a128
length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $a128B= length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | if !defined($a128) || length($a128) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 5 | my $b128 = _bytes($_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | ▶ | _deadlen(length($b128)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $b128 or length $b128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $b128 or length $b128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $b128
length $b128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $b128B= length $b128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | if !defined($b128) || length($b128) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | @_ = ($a128, $b128, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | goto &slowadd128; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 6 | ▶ | sub sub128 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sub128: called CC=5 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # copied before the second argument is read: its get magic can replace it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 6 | my $a128 = _bytes($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 5 | ▶ | _deadlen(length($a128)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $a128 or length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $a128 or length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $a128
length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $a128B= length $a128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | if !defined($a128) || length($a128) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 5 | my $b128 = _bytes($_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | ▶ | _deadlen(length($b128)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $b128 or length $b128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $b128 or length $b128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $b128
length $b128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $b128B= length $b128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | if !defined($b128) || length($b128) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 4 | @_ = ($a128, ~$b128, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | goto &slowadd128; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 3 | ▶ | sub notcontiguous($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
notcontiguous: called CC=10 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 3 | my $mask128 = _bytes(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | ▶ | _deadlen(length($mask128)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $mask128 or length $mask128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $mask128 or length $mask128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $mask128
length $mask128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $mask128B= length $mask128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | if !defined($mask128) || length($mask128) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | my @ua = unpack('N4', ~$mask128); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | my $count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | ▶ | for ($count = $IPV6_BITS ; $count > 0 ; $count--) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 18 | ▶ | last unless $ua[3] & 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 16 | $ua[3] >>= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 16 | ▶ | $ua[3] |= 0x80000000 if $ua[2] & 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 16 | $ua[2] >>= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 16 | ▶ | $ua[2] |= 0x80000000 if $ua[1] & 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 16 | $ua[1] >>= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 16 | ▶ | $ua[1] |= 0x80000000 if $ua[0] & 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 16 | $ua[0] >>= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # 1 or 0, as the XS returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | ▶ | my $spurious = ($ua[0] | $ua[1] | $ua[2] | $ua[3]) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | ▶ | return $spurious | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | unless wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | return ($spurious, $count); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 3 | ▶ | sub ipv4to6($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ipv4to6: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 3 | my $netaddr = _bytes(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | ▶ | _deadlen(length($netaddr), $IPV4_BITS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $netaddr or length $netaddr != $NetAddr::IP::UtilPP::V4_PACKED_BYTES
MC/DC0%0/2
not defined $netaddr or length $netaddr != $NetAddr::IP::UtilPP::V4_PACKED_BYTES
not defined $netaddr
length $netaddr != $NetAddr::IP::UtilPP::V4_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $netaddrB= length $netaddr != $NetAddr::IP::UtilPP::V4_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | if !defined($netaddr) || length($netaddr) != $V4_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 2 | return pack('L3a4', 0, 0, 0, $netaddr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 3 | ▶ | sub mask4to6($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mask4to6: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 3 | my $netaddr = _bytes(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 2 | ▶ | _deadlen(length($netaddr), $IPV4_BITS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $netaddr or length $netaddr != $NetAddr::IP::UtilPP::V4_PACKED_BYTES
MC/DC0%0/2
not defined $netaddr or length $netaddr != $NetAddr::IP::UtilPP::V4_PACKED_BYTES
not defined $netaddr
length $netaddr != $NetAddr::IP::UtilPP::V4_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $netaddrB= length $netaddr != $NetAddr::IP::UtilPP::V4_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | if !defined($netaddr) || length($netaddr) != $V4_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 2 | return pack('L3a4', 0xffffffff, 0xffffffff, 0xffffffff, $netaddr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 6 | ▶ | sub ipanyto6($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ipanyto6: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 6 | my $naddr = _bytes(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 4 | ▶ | return _deadlen(undef, "$IPV4_BITS or $IPV6_BITS") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | unless defined $naddr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 4 | my $len = length($naddr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 4 | ▶ | return $naddr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | if $len == $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | ▶ | return pack('L3a4', 0, 0, 0, $naddr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | if $len == $V4_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | return _deadlen($len, "$IPV4_BITS or $IPV6_BITS"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 6 | ▶ | sub maskanyto6($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
maskanyto6: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 6 | my $naddr = _bytes(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 4 | ▶ | return _deadlen(undef, "$IPV4_BITS or $IPV6_BITS") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | unless defined $naddr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 4 | my $len = length($naddr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 4 | ▶ | return $naddr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | if $len == $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | ▶ | return pack('L3a4', 0xffffffff, 0xffffffff, 0xffffffff, $naddr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | if $len == $V4_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | return _deadlen($len, "$IPV4_BITS or $IPV6_BITS"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 3 | ▶ | sub ipv6to4($;@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ipv6to4: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 3 | my $naddr = _bytes(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | ▶ | _deadlen(length($naddr)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $naddr or length $naddr != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $naddr or length $naddr != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $naddr
length $naddr != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $naddrB= length $naddr != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | if !defined($naddr) || length($naddr) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | @_ = unpack('L3H8', $naddr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | return pack('H8', @{_}[ 3 .. 10 ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 3 | ▶ | sub bin2bcd($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bin2bcd: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 3 | my $bits128 = _bytes(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 2 | ▶ | _deadlen(length($bits128)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $bits128 or length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $bits128 or length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $bits128
length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $bits128B= length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | if !defined($bits128) || length($bits128) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | unpack("H$MAX_BCD_DIGITS", _bin2bcdn($bits128)) =~ /^0*(.+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 2 | return $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | sub bcd2bin($;@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bcd2bin: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my ($bcd) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | _bcdcheck($bcd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | @_ = ($bcd, 'NetAddr::IP::Util::bcd2bin'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | goto &_bcd2bin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | #=item $onescomp = comp128($bits128); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | #This function is for testing, it is more efficient to use perl " ~ " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | #on the bit string directly. This interface to the B<C> routine is published for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | #module testing purposes because it is used internally in the B<sub128> routine. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | #function is very fast, but calling if from perl directly is very slow. It is almost | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | #33% faster to use B<sub128> than to do a 1's comp with perl and then call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | #B<add128>. In the PurePerl version, it is a call to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # sub {return ~ $_[0]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | #=cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 3 | ▶ | sub comp128($;@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
comp128: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 3 | my $bits128 = _bytes(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | ▶ | _deadlen(length($bits128)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $bits128 or length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $bits128 or length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $bits128
length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $bits128B= length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | if !defined($bits128) || length($bits128) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | return ~$bits128; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | #=item $bcdpacked = bin2bcdn($bits128); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | #Convert a 128 bit binary string into binary coded decimal digits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | #This function is for testing only. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # input: 128 bit string variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # returns: string of packed decimal digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # i.e. text = unpack("H*", $bcd); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | #=cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 4 | ▶ | sub bin2bcdn($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bin2bcdn: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 4 | my $bits128 = _bytes(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 3 | ▶ | _deadlen(length($bits128)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $bits128 or length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
MC/DC0%0/2
not defined $bits128 or length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
not defined $bits128
length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
Truth table33%1/3
not(A) or B
A= not defined $bits128B= length $bits128 != $NetAddr::IP::UtilPP::V6_PACKED_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | if !defined($bits128) || length($bits128) != $V6_PACKED_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 3 | return _bin2bcdn($bits128); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 5 | ▶ | sub _bin2bcdn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bin2bcdn: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 5 | my ($b128) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 5 | my @binary = unpack('N4', $b128); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 5 | my @nbcd = (0, 0, 0, 0, 0); # 5 - 32 bit registers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 5 | my ($add3, $msk8, $bcd8, $carry, $tmp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 5 | my $j = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 5 | my $k = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 5 | my $binmsk = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 5 | for (0 .. 127) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 640 | ▶ | unless ($binmsk) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 20 | $binmsk = 0x80000000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 20 | $k++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 640 | $carry = $binary[$k] & $binmsk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 640 | $binmsk >>= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 640 | ▶ | next unless $carry || $j; # skip leading zeros | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$carry or $j
MC/DC100%2/2
$carry or $j
$carry
$j
Truth table100%3/3
A or B
A= $carryB= $j
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 510 | for (4, 3, 2, 1, 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 2550 | $bcd8 = $nbcd[$_]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 2550 | $add3 = 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 2550 | $msk8 = 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 2550 | $j = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 2550 | ▶ | while ($j < 8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 20400 | $tmp = $bcd8 + $add3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 20400 | ▶ | if ($tmp & $msk8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 4501 | $bcd8 = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 20400 | $add3 <<= 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 20400 | $msk8 <<= 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 20400 | $j++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2550 | $tmp = $bcd8 & 0x80000000; # propagate carry | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 2550 | $bcd8 <<= 1; # x2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 2550 | ▶ | if ($carry) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 599 | $bcd8 += 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 2550 | $nbcd[$_] = $bcd8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 2550 | $carry = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 5 | return pack('N5', @nbcd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | #=item $bcdtext = bcdn2txt($bcdpacked); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | #Convert a packed bcd string into text digits, suppress the leading zeros. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | #This function is for testing only. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # input: string of packed decimal digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # consisting of exactly 40 digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # returns: hexdecimal digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | #Similar to unpack("H*", $bcd); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | #=cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 3 | ▶ | sub bcdn2txt($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bcdn2txt: called CC=4 SCAR=17.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 3 | my $bcdn = _bytes(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 2 | ▶ | if (!defined($bcdn) || length($bcdn) != $PACKED_BCD_BYTES) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $bcdn or length $bcdn != $NetAddr::IP::UtilPP::PACKED_BCD_BYTES
MC/DC0%0/2
not defined $bcdn or length $bcdn != $NetAddr::IP::UtilPP::PACKED_BCD_BYTES
not defined $bcdn
length $bcdn != $NetAddr::IP::UtilPP::PACKED_BCD_BYTES
Truth table33%1/3
not(A) or B
A= not defined $bcdnB= length $bcdn != $NetAddr::IP::UtilPP::PACKED_BCD_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | my $digits = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | defined $bcdn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | ? 2 * length($bcdn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | : 'undefined'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | croak 'Bad arg length for NetAddr::IP::Util::bcdn2txt, length is ' . $digits | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | . ", should be $MAX_BCD_DIGITS digits"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 2 | my $txt = unpack("H$MAX_BCD_DIGITS", $bcdn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 2 | _bcdcheck($txt); # a nibble above 9 unpacks as a-f | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 2 | $txt =~ /^0*(.+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 2 | return $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | #=item $bits128 = bcdn2bin($bcdpacked,$ndigits); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # Convert a packed bcd string into a 128 bit string variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # input: packed bcd string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # number of digits in string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # returns: 128 bit string variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 5 | ▶ | sub bcdn2bin($;@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bcdn2bin: called CC=11 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 5 | ▶ | croak q|Bad usage, should have NetAddr::IP::Util::bcdn2bin('packedbcd','length')| | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | if @_ < 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 5 | my ($bcd, $given) = (_bytes($_[0]), $_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 4 | my $dc = _plain_number($given); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 4 | ▶ | $dc = 0 unless defined $dc && $dc ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $dc and $dc ne ""
MC/DC100%2/2
defined $dc and $dc ne ""
defined $dc
$dc ne ""
Truth table100%3/3
A and B
A= defined $dcB= $dc ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 4 | ▶ | my $digits = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | defined $bcd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | ? 2 * length($bcd) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | : 'undefined'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 4 | ▶ | croak "Bad arg length for NetAddr::IP::Util::bcdn2bin, length is $digits, should be 1 to $MAX_BCD_DIGITS digits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $bcd or length $bcd > $NetAddr::IP::UtilPP::PACKED_BCD_BYTES
MC/DC0%0/2
not defined $bcd or length $bcd > $NetAddr::IP::UtilPP::PACKED_BCD_BYTES
not defined $bcd
length $bcd > $NetAddr::IP::UtilPP::PACKED_BCD_BYTES
Truth table33%1/3
not(A) or B
A= not defined $bcdB= length $bcd > $NetAddr::IP::UtilPP::PACKED_BCD_BYTES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | if !defined($bcd) || length($bcd) > $PACKED_BCD_BYTES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # an integer count, made plain because it goes into an unpack template | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 4 | ▶ | croak "Bad digit count for NetAddr::IP::Util::bcdn2bin, is $dc, should be 1 to $digits digits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
&looks_like_number($dc) and $dc >= 1 and $dc < $digits + 1 and $dc == int $dc
&looks_like_number($dc) and $dc >= 1 and $dc < $digits + 1
&looks_like_number($dc) and $dc >= 1
MC/DC25%1/4
&looks_like_number($dc) and $dc >= 1 and $dc < $digits + 1 and $dc == int $dc
&looks_like_number($dc)
$dc >= 1
$dc < $digits + 1
$dc == int $dc
Truth table40%2/5
A and B and C and D
A= &looks_like_number($dc)B= $dc >= 1C= $dc < $digits + 1D= $dc == int $dc
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | unless looks_like_number($dc) && $dc >= 1 && $dc < $digits + 1 && $dc == int($dc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 2 | $dc = int($dc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 2 | my $txt = unpack("H$dc", $bcd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 2 | _bcdcheck($txt); # a nibble above 9 unpacks as a-f | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 2 | return _bcd2bin($txt, 'NetAddr::IP::Util::bcdn2bin'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 2 | ▶ | sub _bcd2bin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bcd2bin: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 2 | ▶ | my $caller = $_[1] // 'NetAddr::IP::Util::_bcd2bin'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] // "NetAddr::IP::Util::_bcd2bin"
MC/DC0%0/1
$_[1] // "NetAddr::IP::Util::_bcd2bin"
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 2 | my @bcd = split('', $_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 2 | my @hbits = (0, 0, 0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 2 | my @digit = (0, 0, 0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 2 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 2 | my $overflow = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 2 | for (@bcd) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 10 | my $bcd = $_ & 0xf; # just the nibble | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 10 | ▶ | unless ($found) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 2 | ▶ | next unless $bcd; # skip leading zeros | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 2 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 2 | $hbits[3] = $bcd; # set the first digit, no x10 necessary | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 8 | $overflow |= _128x10(\@hbits); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 8 | $digit[3] = $bcd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 8 | $overflow |= _sa128(\@hbits, \@digit, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 2 | ▶ | if ($overflow) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | croak "Bad arg value for $caller, number is larger than 128 bits"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 2 | return pack('N4', @hbits); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | #=item $bcdpacked = simple_pack($bcdtext); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | #Convert a numeric string into a packed bcd string, left fill with zeros | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | #This function is for testing only. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | # input: string of decimal digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | # returns: string of packed decimal digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | #Similar to pack("H*", $bcdtext); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 4 | ▶ | sub _bcdcheck { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bcdcheck: called CC=6 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 4 | my ($bcd) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 4 | ▶ | my $len = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | defined $bcd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | ? length($bcd) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | : 'undefined'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 4 | ▶ | croak sprintf("Bad arg length for %s, length is %s, should be 1 to $MAX_BCD_DIGITS digits", _callersub(), $len) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $bcd or length $bcd > $NetAddr::IP::UtilPP::MAX_BCD_DIGITS or length $bcd < 1
not defined $bcd or length $bcd > $NetAddr::IP::UtilPP::MAX_BCD_DIGITS
MC/DC0%0/3
not defined $bcd or length $bcd > $NetAddr::IP::UtilPP::MAX_BCD_DIGITS or length $bcd < 1
not defined $bcd
length $bcd > $NetAddr::IP::UtilPP::MAX_BCD_DIGITS
length $bcd < 1
Truth table25%1/4
not(A) or B or C
A= not defined $bcdB= length $bcd > $NetAddr::IP::UtilPP::MAX_BCD_DIGITSC= length $bcd < 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | if !defined($bcd) || length($bcd) > $MAX_BCD_DIGITS || length($bcd) < 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 4 | ▶ | croak sprintf("Bad char in string for %s, character is '%s', allowed are 0-9", _callersub(), $1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | if $bcd =~ /([^0-9])/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | sub simple_pack($;@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simple_pack: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | my ($bcd) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | _bcdcheck($bcd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | while (length($bcd) < $MAX_BCD_DIGITS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | $bcd = '0' . $bcd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | return pack("H$MAX_BCD_DIGITS", $bcd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||