line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Works::Role::IP; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
25048
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
116
|
|
4
|
4
|
|
|
4
|
|
14
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
89
|
|
5
|
4
|
|
|
4
|
|
1591
|
use namespace::autoclean 0.16; |
|
4
|
|
|
|
|
34517
|
|
|
4
|
|
|
|
|
17
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.21'; |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
223
|
use Carp qw( confess ); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
161
|
|
10
|
4
|
|
|
4
|
|
14
|
use Math::Int128 qw( string_to_uint128 uint128 uint128_to_number ); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
156
|
|
11
|
4
|
|
|
4
|
|
15
|
use Net::Works::Types qw( Int IPInt IPVersion ); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
141
|
|
12
|
4
|
|
|
4
|
|
17
|
use Socket qw( AF_INET AF_INET6 ); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
127
|
|
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
|
16
|
use Moo::Role; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
28
|
|
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
1075
|
use integer; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
20
|
|
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
|
|
37631
|
my $self = shift; |
46
|
28301
|
|
33
|
|
|
57805
|
my $version = shift // $self->version(); |
47
|
|
|
|
|
|
|
|
48
|
28301
|
|
|
|
|
49448
|
return $max{$version}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
14987
|
100
|
|
14987
|
0
|
56762
|
sub bits { $_[0]->version() == 6 ? 128 : 32 } |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _validate_ip_integer { |
55
|
3673
|
|
|
3673
|
|
3074
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
3673
|
|
|
|
|
6876
|
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
|
3673
|
100
|
|
|
|
81082
|
if ( $self->version() == 6 ) { |
62
|
2929
|
100
|
|
|
|
5552
|
$self->_set_integer( uint128($int) ) |
63
|
|
|
|
|
|
|
unless ref $int; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
744
|
100
|
|
|
|
1768
|
confess("$int is not a valid integer for an IP address") |
67
|
|
|
|
|
|
|
if $int >= 2**32; |
68
|
741
|
100
|
|
|
|
1339
|
if ( ref $int ) { |
69
|
254
|
|
|
|
|
735
|
$self->_set_integer( uint128_to_number($int) ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
3670
|
|
|
|
|
13667
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# overload passes extra arguments to this sub for some reason |
77
|
|
|
|
|
|
|
sub _overloaded_as_string { |
78
|
1013
|
|
|
1013
|
|
295027
|
return $_[0]->as_string(); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |