line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Protocol::Simple; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
28659
|
use 5.008006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
511
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $PROTOCOLS = { |
10
|
|
|
|
|
|
|
ICMP => 1, |
11
|
|
|
|
|
|
|
TCP => 6, |
12
|
|
|
|
|
|
|
UDP => 17, |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# CONSTRUCTOR |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
|
|
0
|
0
|
|
my ($class, %data) = @_; |
19
|
0
|
|
|
|
|
|
my $self = {}; |
20
|
0
|
|
|
|
|
|
bless($self,$class); |
21
|
0
|
|
|
|
|
|
$self->init(%data); |
22
|
0
|
|
|
|
|
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub init { |
26
|
0
|
|
|
0
|
0
|
|
my ($self,%data) = @_; |
27
|
0
|
|
|
|
|
|
$self->protocol($data{protocol}); |
28
|
0
|
|
|
|
|
|
$self->layer( $data{layer}); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# METHODS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub int { |
34
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
35
|
0
|
0
|
|
|
|
|
return $PROTOCOLS->{$self->protocol()} if(exists($PROTOCOLS->{$self->protocol()})); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
# ACCESSORS/MODIFIERS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub protocol { |
40
|
0
|
|
|
0
|
0
|
|
my ($self,$v) = @_; |
41
|
0
|
0
|
|
|
|
|
$self->{_protocol} = normalize($v) if(defined($v)); |
42
|
0
|
|
|
|
|
|
return $self->{_protocol}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub layer { |
46
|
0
|
|
|
0
|
0
|
|
my ($self,$v) = @_; |
47
|
0
|
0
|
|
|
|
|
$self->{_layer} = $v if(defined($v)); |
48
|
0
|
|
|
|
|
|
return $self->{_layer}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# FUNCTIONS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub normalize { |
54
|
0
|
|
|
0
|
0
|
|
my $proto = uc(shift); |
55
|
0
|
0
|
|
|
|
|
if($proto =~ /^\d+$/){ |
56
|
0
|
|
|
|
|
|
foreach my $x (keys %$PROTOCOLS){ |
57
|
0
|
0
|
|
|
|
|
return $x if($proto eq $PROTOCOLS->{$x}); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
return $proto; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
__END__ |