blib/lib/Net/IP/XS.pm

filter: Statementstmt 68.4% 50 / 73 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.6% 22 / 26 Podpod 23.5% 4 / 17 totaltotal 61.2% 76 / 124 CC 5 SCAR 11.8
CC
5
Cov
62%
auth
12.0
ip_auth
12.0
error
2.0
CRAP 3.3
↑ Summary object.c »
1 package Net::IP::XS;
2  
3 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 44 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 44 ▶use Math::BigInt;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 44 ▶use Tie::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 44 our $VERSION = '0.23';
12  
13 44 our $IP_NO_OVERLAP = 0;
14 44 our $IP_PARTIAL_OVERLAP = 1;
15 44 our $IP_A_IN_B_OVERLAP = -1;
16 44 our $IP_B_IN_A_OVERLAP = -2;
17 44 our $IP_IDENTICAL = -3;
18  
19 44 our @EXPORT_OK = qw(Error
20 Errno
21 ip_iptobin
22 ip_bintoip
23 ip_iplengths
24 ip_bintoint
25 ip_inttobin
26 ip_expand_address
27 ip_is_ipv4
28 ip_is_ipv6
29 ip_get_version
30 ip_get_mask
31 ip_last_address_bin
32 ip_splitprefix
33 ip_is_valid_mask
34 ip_bincomp
35 ip_binadd
36 ip_get_prefix_length
37 ip_compress_v4_prefix
38 ip_is_overlap
39 ip_check_prefix
40 ip_range_to_prefix
41 ip_get_embedded_ipv4
42 ip_aggregate
43 ip_prefix_to_range
44 ip_reverse
45 ip_normalize
46 ip_compress_address
47 ip_iptype
48 ip_auth
49 ip_normal_range
50 $IP_NO_OVERLAP
51 $IP_PARTIAL_OVERLAP
52 $IP_A_IN_B_OVERLAP
53 $IP_B_IN_A_OVERLAP
54 $IP_IDENTICAL);
55  
56 44 our %EXPORT_TAGS = (PROC => [@EXPORT_OK]);
57  
58 44 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
59 '+' => 'ip_add_num',
60 777 ▶ 'bool' => sub { @_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
61 44 );
62  
63 44 ▶use base qw(DynaLoader Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
64 44 __PACKAGE__->bootstrap($VERSION);
65  
66 44 our $ERROR;
67 44 our $ERRNO;
68  
69 44 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
70 44 tie $ERROR, 'Tie::Simple', 1, FETCH => \&ip_get_Error,
71 STORE => \&ip_set_Error;
72 44 tie $ERRNO, 'Tie::Simple', 1, FETCH => \&ip_get_Errno,
73 STORE => \&ip_set_Errno;
74 };
75  
76 44 our %IPv4ranges = (
77 '00000000' => 'PRIVATE', # 0/8
78 '00001010' => 'PRIVATE', # 10/8
79 '01111111' => 'PRIVATE', # 127.0/8
80 '101011000001' => 'PRIVATE', # 172.16/12
81 '1100000010101000' => 'PRIVATE', # 192.168/16
82 '1010100111111110' => 'RESERVED', # 169.254/16
83 '110000000000000000000010' => 'RESERVED', # 192.0.2/24
84 '1110' => 'RESERVED', # 224/4
85 '11110' => 'RESERVED', # 240/5
86 '11111' => 'RESERVED', # 248/5
87 );
88  
89 44 our %IPv6ranges = (
90 '00000000' => 'RESERVED', # ::/8
91 '00000001' => 'RESERVED', # 0100::/8
92 '0000001' => 'RESERVED', # 0200::/7
93 '000001' => 'RESERVED', # 0400::/6
94 '00001' => 'RESERVED', # 0800::/5
95 '0001' => 'RESERVED', # 1000::/4
96 '001' => 'GLOBAL-UNICAST', # 2000::/3
97 '010' => 'RESERVED', # 4000::/3
98 '011' => 'RESERVED', # 6000::/3
99 '100' => 'RESERVED', # 8000::/3
100 '101' => 'RESERVED', # A000::/3
101 '110' => 'RESERVED', # C000::/3
102 '1110' => 'RESERVED', # E000::/4
103 '11110' => 'RESERVED', # F000::/5
104 '111110' => 'RESERVED', # F800::/6
105 '1111101' => 'RESERVED', # FA00::/7
106 '1111110' => 'UNIQUE-LOCAL-UNICAST', # FC00::/7
107 '111111100' => 'RESERVED', # FE00::/9
108 '1111111010' => 'LINK-LOCAL-UNICAST', # FE80::/10
109 '1111111011' => 'RESERVED', # FEC0::/10
110 '11111111' => 'MULTICAST', # FF00::/8
111 '00100000000000010000110110111000' => 'RESERVED', # 2001:DB8::/32
112  
113 '0' x 96 => 'IPV4COMP', # ::/96
114 ('0' x 80) . ('1' x 16) => 'IPV4MAP', # ::FFFF:0:0/96
115  
116 '0' x 128 => 'UNSPECIFIED', # ::/128
117 ('0' x 127) . '1' => 'LOOPBACK' # ::1/128
118 );
119  
120 48 ▶sub Error { $ERROR }
Subroutine Error: called CC=1 SCAR=0.0
Pod documented
121 51 ▶sub Errno { $ERRNO }
Subroutine Errno: called CC=1 SCAR=0.0
Pod undocumented
122  
123 10 ▶sub ip_bintoint { Math::BigInt->new(ip_bintoint_str($_[0])) }
Subroutine ip_bintoint: called CC=1 SCAR=0.0
Pod documented
124 13 ▶sub ip_inttobin { ip_inttobin_str(Math::BigInt->new($_[0]), $_[1]) }
Subroutine ip_inttobin: called CC=1 SCAR=0.0
Pod documented
125  
126 5 ▶sub binip { $_[0]->{'binip'} }
Subroutine binip: called CC=1 SCAR=0.0
Pod undocumented
127 4 ▶sub version { $_[0]->{'ipversion'} }
Subroutine version: called CC=1 SCAR=0.0
Pod undocumented
128 0 ▶sub error { $_[0]->{'error'} }
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
129 0 ▶sub errno { $_[0]->{'errno'} }
Subroutine errno: not called CC=1 SCAR=6.9
Pod undocumented
130 6 ▶sub prefixlen { $_[0]->{'prefixlen'} }
Subroutine prefixlen: called CC=1 SCAR=0.0
Pod undocumented
131 9 ▶sub ip { $_[0]->{'ip'} }
Subroutine ip: called CC=1 SCAR=0.0
Pod undocumented
132 4 ▶sub is_prefix { $_[0]->{'is_prefix'} }
Subroutine is_prefix: called CC=1 SCAR=0.0
Pod undocumented
133 4 ▶sub binmask { $_[0]->{'binmask'} }
Subroutine binmask: called CC=1 SCAR=0.0
Pod undocumented
134  
135 19 ▶sub size { Math::BigInt->new(size_str($_[0])) }
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
136 19 ▶sub intip { Math::BigInt->new(intip_str($_[0])) }
Subroutine intip: called CC=1 SCAR=0.0
Pod undocumented
137 18 ▶sub last_int { Math::BigInt->new(last_int_str($_[0])) }
Subroutine last_int: called CC=1 SCAR=0.0
Pod undocumented
138  
139 sub auth
140 0 ▶{
Subroutine auth: not called CC=3 SCAR=24.8
Pod undocumented
141 0 my ($self) = shift;
142  
143 0 ▶ return ($self->{auth}) if defined($self->{auth});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"auth"} 0 0 0
144  
145 0 my $auth = ip_auth($self->ip, $self->version);
146  
147 0 ▶ if (!$auth) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($auth) 0 0 0
148 0 $self->{error} = $ERROR;
149 0 $self->{errno} = $ERRNO;
150 0 return;
151 }
152  
153 0 $self->{auth} = $auth;
154  
155 0 return ($self->{auth});
156 }
157  
158 sub ip_auth
159 0 ▶{
Subroutine ip_auth: not called CC=3 SCAR=24.8
Pod documented
160 0 my ($ip, $ip_version) = (@_);
161  
162 0 ▶ if (not $ip_version) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ip_version) 0 0 0
163 0 $ERROR = "Cannot determine IP version for $ip";
164 0 $ERRNO = 101;
165 0 return;
166 }
167  
168 0 ▶ if ($ip_version != 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ip_version != 4) 0 0 0
169 0 $ERROR = "Cannot get auth information: Not an IPv4 address";
170 0 $ERRNO = 308;
171 0 return;
172 }
173  
174 0 require IP::Authority;
175  
176 0 my $reg = new IP::Authority;
177  
178 0 return ($reg->inet_atoauth($ip));
179 }
180  
181 44 1;
182  
183 __END__
↑ Summary object.c »