line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Convert::TLI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14458
|
use 5.008008; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
533
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
) ] ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @EXPORT = qw( |
19
|
|
|
|
|
|
|
encode_tli decode_tli detect_tli |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
1
|
|
|
1
|
0
|
10
|
my $class = shift; |
26
|
1
|
|
|
|
|
2
|
my %opts = @_; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
2
|
my $self = { |
29
|
|
|
|
|
|
|
%opts |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
3
|
bless $self, $class; |
33
|
1
|
|
|
|
|
3
|
$self->initialize(@_); |
34
|
1
|
|
|
|
|
2
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub initialize { |
38
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
39
|
1
|
|
|
|
|
1
|
my $val = shift; |
40
|
1
|
|
50
|
|
|
10
|
$self->{prefix} = $self->{prefix} || "0x0002"; |
41
|
1
|
|
50
|
|
|
5
|
$self->{nulls} = $self->{nulls} || ""; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub encode_tli { |
46
|
1
|
|
|
1
|
0
|
343
|
my $self = shift; |
47
|
1
|
|
|
|
|
2
|
my $host_to_encode = shift; |
48
|
1
|
|
|
|
|
8
|
my $port_to_encode = shift; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
5
|
my @hosts = split '.', $host_to_encode; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
5
|
my $ip = $self->_get_ip_address( $host_to_encode, 'hex'); |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
3
|
my $hexport = sprintf("%4.4x", $port_to_encode); |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
5
|
return $self->{prefix}."$hexport$ip".$self->{nulls}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub decode_tli { |
62
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
63
|
1
|
|
|
|
|
1
|
my $to_decode = shift; |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
2
|
my $rsl = eval { |
66
|
1
|
|
|
|
|
5
|
hex(substr($to_decode, 10, 2)) |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
1
|
50
|
|
|
|
3
|
return if $@; |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
6
|
my ( @arr ) = ( |
72
|
|
|
|
|
|
|
hex(substr($to_decode, 10, 2)), |
73
|
|
|
|
|
|
|
hex(substr($to_decode, 12, 2)), |
74
|
|
|
|
|
|
|
hex(substr($to_decode, 14, 2)), |
75
|
|
|
|
|
|
|
hex(substr($to_decode, 16, 2)) |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
2
|
my $port = hex(substr($to_decode, 6, 4)); |
79
|
1
|
|
|
|
|
3
|
my $ip = join('.', @arr); |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
4
|
return ( $ip, $port ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub detect_tli { |
85
|
1
|
|
|
1
|
0
|
5
|
my $self = shift; |
86
|
1
|
|
|
|
|
2
|
my $str = shift; |
87
|
|
|
|
|
|
|
|
88
|
1
|
50
|
|
|
|
8
|
return ( $str =~ /0x/ ) ? '1' : '0'; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _get_ip_address { |
94
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
95
|
1
|
|
|
|
|
2
|
my ($host, $mode) = @_; |
96
|
1
|
|
|
|
|
93
|
my ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host); |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
9
|
my $mask = join('.', unpack('C4', $addrs[0])); |
99
|
|
|
|
|
|
|
|
100
|
1
|
50
|
|
|
|
6
|
if ($mode eq 'hex') |
101
|
|
|
|
|
|
|
{ |
102
|
1
|
|
|
|
|
8
|
$mask = sprintf("%2.2x%2.2x%2.2x%2.2x", split(/\./, $mask)); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
1
|
|
|
|
|
3
|
return $mask; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |