line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Works::Util; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
13
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
96
|
|
4
|
4
|
|
|
4
|
|
11
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
114
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.21'; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
12
|
use Carp qw( confess ); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
138
|
|
9
|
4
|
|
|
4
|
|
14
|
use Math::Int128 qw( net_to_uint128 uint128_to_net ); |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
148
|
|
10
|
4
|
|
|
4
|
|
1772
|
use Socket qw( AF_INET AF_INET6 inet_pton inet_ntop ); |
|
4
|
|
|
|
|
12344
|
|
|
4
|
|
|
|
|
584
|
|
11
|
4
|
|
|
4
|
|
19
|
use Scalar::Util qw( blessed ); |
|
4
|
|
|
|
|
2
|
|
|
4
|
|
|
|
|
130
|
|
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
12
|
use Exporter qw( import ); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
959
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
16
|
|
|
|
|
|
|
_string_address_to_integer |
17
|
|
|
|
|
|
|
_integer_address_to_binary |
18
|
|
|
|
|
|
|
_binary_address_to_string |
19
|
|
|
|
|
|
|
_integer_address_to_string |
20
|
|
|
|
|
|
|
_validate_ip_string |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
24
|
|
|
|
|
|
|
sub _string_address_to_integer { |
25
|
888
|
|
|
888
|
|
868
|
my $string = shift; |
26
|
888
|
|
|
|
|
792
|
my $version = shift; |
27
|
|
|
|
|
|
|
|
28
|
888
|
100
|
|
|
|
2915
|
my $binary = inet_pton( $version == 4 ? AF_INET : AF_INET6, $string ) |
|
|
100
|
|
|
|
|
|
29
|
|
|
|
|
|
|
or return; |
30
|
|
|
|
|
|
|
|
31
|
870
|
100
|
|
|
|
4749
|
return $version == 4 |
32
|
|
|
|
|
|
|
? unpack( N => $binary ) |
33
|
|
|
|
|
|
|
: net_to_uint128($binary); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _integer_address_to_binary { |
37
|
2736
|
|
|
2736
|
|
2464
|
my $integer = shift; |
38
|
|
|
|
|
|
|
|
39
|
2736
|
100
|
66
|
|
|
10968
|
if ( ref $integer && blessed $integer) { |
40
|
2259
|
|
|
|
|
5324
|
return uint128_to_net($integer); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
477
|
|
|
|
|
1320
|
return pack( N => $integer ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _binary_address_to_string { |
48
|
2736
|
|
|
2736
|
|
2761
|
my $binary = shift; |
49
|
|
|
|
|
|
|
|
50
|
2736
|
100
|
|
|
|
4093
|
my $family = length($binary) == 4 ? AF_INET : AF_INET6; |
51
|
|
|
|
|
|
|
|
52
|
2736
|
|
|
|
|
10066
|
my $string = inet_ntop( $family, $binary ); |
53
|
2736
|
100
|
|
|
|
43577
|
return $string eq '::' ? '::0' : $string; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _integer_address_to_string { |
57
|
2736
|
|
|
2736
|
|
58524
|
_binary_address_to_string( _integer_address_to_binary( $_[0] ) ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _validate_ip_string { |
61
|
84
|
|
|
84
|
|
77
|
my $str = shift; |
62
|
84
|
|
|
|
|
64
|
my $version = shift; |
63
|
|
|
|
|
|
|
|
64
|
84
|
100
|
|
|
|
106
|
my $str_val = defined $str ? $str : 'undef'; |
65
|
84
|
100
|
|
|
|
101
|
if ( $version == 4 ) { |
66
|
7
|
50
|
66
|
|
|
1226
|
confess("$str_val is not a valid IPv4 address") |
67
|
|
|
|
|
|
|
unless defined $str && defined inet_pton( AF_INET, $str ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
77
|
100
|
100
|
|
|
2020
|
confess("$str_val is not a valid IPv6 address") |
71
|
|
|
|
|
|
|
unless defined $str && defined inet_pton( AF_INET6, $str ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# ABSTRACT: Utility subroutines for Net-Works |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |