line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Works::Role::IP; |
2
|
|
|
|
|
|
|
$Net::Works::Role::IP::VERSION = '0.20'; |
3
|
4
|
|
|
4
|
|
28481
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
124
|
|
4
|
4
|
|
|
4
|
|
15
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
96
|
|
5
|
4
|
|
|
4
|
|
1787
|
use namespace::autoclean 0.16; |
|
4
|
|
|
|
|
39625
|
|
|
4
|
|
|
|
|
20
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
210
|
use Carp qw( confess ); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
267
|
|
8
|
4
|
|
|
4
|
|
20
|
use Math::Int128 qw( string_to_uint128 uint128 uint128_to_number ); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
192
|
|
9
|
4
|
|
|
4
|
|
17
|
use Net::Works::Types qw( Int IPInt IPVersion ); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
172
|
|
10
|
4
|
|
|
4
|
|
16
|
use Socket qw( AF_INET AF_INET6 ); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
171
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
24
|
use Moo::Role; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
29
|
|
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
|
1172
|
use integer; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
21
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has version => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
isa => IPVersion, |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has _integer => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
writer => '_set_integer', |
25
|
|
|
|
|
|
|
isa => IPInt, |
26
|
|
|
|
|
|
|
required => 1, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has address_family => ( |
30
|
|
|
|
|
|
|
is => 'ro', |
31
|
|
|
|
|
|
|
isa => Int, |
32
|
|
|
|
|
|
|
lazy => 1, |
33
|
|
|
|
|
|
|
default => sub { $_[0]->version() == 6 ? AF_INET6 : AF_INET }, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
{ |
37
|
|
|
|
|
|
|
my %max = ( |
38
|
|
|
|
|
|
|
4 => 0xFFFFFFFF, |
39
|
|
|
|
|
|
|
6 => string_to_uint128( '0x' . ( 'F' x 32 ) ), |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _max { |
43
|
28293
|
|
|
28293
|
|
49147
|
my $self = shift; |
44
|
28293
|
|
33
|
|
|
85417
|
my $version = shift // $self->version(); |
45
|
|
|
|
|
|
|
|
46
|
28293
|
|
|
|
|
71753
|
return $max{$version}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
14979
|
100
|
|
14979
|
0
|
88460
|
sub bits { $_[0]->version() == 6 ? 128 : 32 } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _validate_ip_integer { |
53
|
3667
|
|
|
3667
|
|
3511
|
my $self = shift; |
54
|
|
|
|
|
|
|
|
55
|
3667
|
|
|
|
|
8231
|
my $int = $self->_integer(); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# We don't need to check if it's too big with v6 because uint128 does not |
58
|
|
|
|
|
|
|
# allow a number larger than 2**128-1. |
59
|
3667
|
100
|
|
|
|
96353
|
if ( $self->version() == 6 ) { |
60
|
2925
|
100
|
|
|
|
6656
|
$self->_set_integer( uint128($int) ) |
61
|
|
|
|
|
|
|
unless ref $int; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
742
|
100
|
|
|
|
2378
|
confess("$int is not a valid integer for an IP address") |
65
|
|
|
|
|
|
|
if $int >= 2**32; |
66
|
739
|
100
|
|
|
|
1299
|
if ( ref $int ) { |
67
|
252
|
|
|
|
|
821
|
$self->_set_integer( uint128_to_number($int) ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
3664
|
|
|
|
|
16291
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# overload passes extra arguments to this sub for some reason |
75
|
|
|
|
|
|
|
sub _overloaded_as_string { |
76
|
1013
|
|
|
1013
|
|
325312
|
return $_[0]->as_string(); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |