line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Works::Role::IP; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
25916
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
97
|
|
4
|
4
|
|
|
4
|
|
15
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
94
|
|
5
|
4
|
|
|
4
|
|
1826
|
use namespace::autoclean 0.16; |
|
4
|
|
|
|
|
33282
|
|
|
4
|
|
|
|
|
13
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.22'; |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
226
|
use Carp qw( confess ); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
163
|
|
10
|
4
|
|
|
4
|
|
16
|
use Math::Int128 qw( string_to_uint128 uint128 uint128_to_number ); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
170
|
|
11
|
4
|
|
|
4
|
|
14
|
use Net::Works::Types qw( Int IPInt IPVersion ); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
155
|
|
12
|
4
|
|
|
4
|
|
12
|
use Socket qw( AF_INET AF_INET6 ); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
147
|
|
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
|
15
|
use Moo::Role; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
25
|
|
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
959
|
use integer; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
21
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has version => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => IPVersion, |
21
|
|
|
|
|
|
|
required => 1, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has _integer => ( |
25
|
|
|
|
|
|
|
is => 'rw', |
26
|
|
|
|
|
|
|
writer => '_set_integer', |
27
|
|
|
|
|
|
|
isa => IPInt, |
28
|
|
|
|
|
|
|
required => 1, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has address_family => ( |
32
|
|
|
|
|
|
|
is => 'ro', |
33
|
|
|
|
|
|
|
isa => Int, |
34
|
|
|
|
|
|
|
lazy => 1, |
35
|
|
|
|
|
|
|
default => sub { $_[0]->version() == 6 ? AF_INET6 : AF_INET }, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
my %max = ( |
40
|
|
|
|
|
|
|
4 => 0xFFFFFFFF, |
41
|
|
|
|
|
|
|
6 => string_to_uint128( '0x' . ( 'F' x 32 ) ), |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _max { |
45
|
28301
|
|
|
28301
|
|
38357
|
my $self = shift; |
46
|
28301
|
|
33
|
|
|
60856
|
my $version = shift // $self->version(); |
47
|
|
|
|
|
|
|
|
48
|
28301
|
|
|
|
|
49781
|
return $max{$version}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
14999
|
100
|
|
14999
|
0
|
58716
|
sub bits { $_[0]->version() == 6 ? 128 : 32 } |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _validate_ip_integer { |
55
|
3685
|
|
|
3685
|
|
2861
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
3685
|
|
|
|
|
6428
|
my $int = $self->_integer(); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# We don't need to check if it's too big with v6 because uint128 does not |
60
|
|
|
|
|
|
|
# allow a number larger than 2**128-1. |
61
|
3685
|
100
|
|
|
|
72494
|
if ( $self->version() == 6 ) { |
62
|
2935
|
100
|
|
|
|
5206
|
$self->_set_integer( uint128($int) ) |
63
|
|
|
|
|
|
|
unless ref $int; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
750
|
100
|
|
|
|
1849
|
confess("$int is not a valid integer for an IP address") |
67
|
|
|
|
|
|
|
if $int >= 2**32; |
68
|
747
|
100
|
|
|
|
1248
|
if ( ref $int ) { |
69
|
254
|
|
|
|
|
669
|
$self->_set_integer( uint128_to_number($int) ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
3682
|
|
|
|
|
13251
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# overload passes extra arguments to this sub for some reason |
77
|
|
|
|
|
|
|
sub _overloaded_as_string { |
78
|
1013
|
|
|
1013
|
|
278302
|
return $_[0]->as_string(); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |