line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# NetPacket::LLC - Decode and encode IEEE Logical Link Layer |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Comments/suggestions to cganesan@cpan.org |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package NetPacket::LLC; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Copyright (c) 2002 Chander Ganesan. |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# This package is free software and is provided "as is" without express |
13
|
|
|
|
|
|
|
# or implied warranty. It may be used, redistributed and/or modified |
14
|
|
|
|
|
|
|
# under the terms of the Perl Artistic License (see |
15
|
|
|
|
|
|
|
# http://www.perl.com/perl/misc/Artistic.html) |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# This software and all associated data and documentation |
18
|
|
|
|
|
|
|
# ('Software') is available free of charge. You may make copies of the |
19
|
|
|
|
|
|
|
# Software but you must include all of this notice on any copy. |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# The Software was developed for research purposes does not |
22
|
|
|
|
|
|
|
# warrant that it is error free or fit for any purpose. The author |
23
|
|
|
|
|
|
|
# disclaims any liability for all claims, expenses, losses, damages |
24
|
|
|
|
|
|
|
# and costs any user may incur as a result of using, copying or |
25
|
|
|
|
|
|
|
# modifying the Software. |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
11753
|
use 5.006; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
283
|
|
29
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
30
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
50
|
|
31
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
134
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $myclass; |
34
|
|
|
|
|
|
|
BEGIN { |
35
|
1
|
|
|
1
|
|
2
|
$myclass = __PACKAGE__; |
36
|
1
|
|
|
|
|
538
|
$VERSION = "0.01"; |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
0
|
1
|
|
sub Version () { "$myclass v$VERSION" } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
BEGIN { |
41
|
1
|
|
|
1
|
|
21
|
@ISA = qw(Exporter NetPacket); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Items to export into callers namespace by default |
44
|
|
|
|
|
|
|
# (move infrequently used names to @EXPORT_OK below) |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
2
|
@EXPORT = qw( |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Other items we are prepared to export if requested |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
2
|
@EXPORT_OK = qw(llc_strip |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Tags: |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
1528
|
%EXPORT_TAGS = ( |
57
|
|
|
|
|
|
|
ALL => [@EXPORT, @EXPORT_OK], |
58
|
|
|
|
|
|
|
strip => [qw(llc_strip)], |
59
|
|
|
|
|
|
|
types => [qw( |
60
|
|
|
|
|
|
|
)], |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# |
66
|
|
|
|
|
|
|
# Decode the packet |
67
|
|
|
|
|
|
|
# |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub decode { |
70
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
71
|
0
|
|
|
|
|
|
my($pkt, $parent, @rest) = @_; |
72
|
0
|
|
|
|
|
|
my $self = {}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Class fields |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$self->{_parent} = $parent; |
77
|
0
|
|
|
|
|
|
$self->{_frame} = $pkt; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Decode LLC data |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if (defined($pkt)) { |
82
|
0
|
|
|
|
|
|
($self->{dsap},$self->{ssap}, $self->{control}, |
83
|
|
|
|
|
|
|
$self->{data}) = |
84
|
|
|
|
|
|
|
unpack('H2H2B8a*' , $pkt); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Return a blessed object |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
bless($self, $class); |
90
|
0
|
|
|
|
|
|
return $self; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# |
94
|
|
|
|
|
|
|
# Strip header from data and return the data contained in it |
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
undef &llc_strip; # Create llc_strip alias |
98
|
|
|
|
|
|
|
*llc_strip = \&strip; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub strip { |
101
|
0
|
|
|
0
|
1
|
|
my ($pkt, @rest) = @_; |
102
|
0
|
|
|
|
|
|
my $llc_obj = NetPacket::LLC->decode($pkt); |
103
|
0
|
|
|
|
|
|
return $llc_obj->{data};; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# |
107
|
|
|
|
|
|
|
# Encode a packet - now implemented! |
108
|
|
|
|
|
|
|
# |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub encode { |
111
|
0
|
|
|
0
|
1
|
|
my ($self, $data) = @_; |
112
|
0
|
|
|
|
|
|
my $defaults = { |
113
|
|
|
|
|
|
|
dsap => undef, |
114
|
|
|
|
|
|
|
ssap => undef, |
115
|
|
|
|
|
|
|
control => undef, |
116
|
|
|
|
|
|
|
data => undef, |
117
|
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
my $packStruct = { |
120
|
|
|
|
|
|
|
1 => { 'dsap' => 'H2' }, |
121
|
|
|
|
|
|
|
2 => { 'ssap' => 'H2' }, |
122
|
|
|
|
|
|
|
3 => { 'control' => 'B8' }, |
123
|
|
|
|
|
|
|
4 => { 'data' => 'a*' }, |
124
|
|
|
|
|
|
|
}; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# |
127
|
|
|
|
|
|
|
# Ensure all required parameters are passed, and those that aren't |
128
|
|
|
|
|
|
|
# are defaulted. |
129
|
|
|
|
|
|
|
# |
130
|
0
|
|
|
|
|
|
foreach my $name (keys %$defaults) { |
131
|
0
|
0
|
|
|
|
|
if (defined $data->{$name}) { |
132
|
0
|
|
|
|
|
|
next; |
133
|
|
|
|
|
|
|
} else { |
134
|
0
|
0
|
|
|
|
|
if (defined $defaults->{$name}) { # we have a defaults |
135
|
0
|
|
|
|
|
|
$data->{$name} = $defaults->{$name}; |
136
|
|
|
|
|
|
|
} else { |
137
|
0
|
|
|
|
|
|
die "$name parameter is required to encode LLC\n"; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# |
143
|
|
|
|
|
|
|
# Encode the data |
144
|
|
|
|
|
|
|
# |
145
|
0
|
|
|
|
|
|
my $packed_data = ""; |
146
|
0
|
|
|
|
|
|
foreach my $key (sort { $a <=> $b } keys %$packStruct) { |
|
0
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
foreach my $subkey (keys %{$packStruct->{$key}}) { |
|
0
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$packed_data .= pack ($packStruct->{$key}{$subkey}, |
149
|
|
|
|
|
|
|
$data->{$subkey}); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
0
|
|
|
|
|
|
return $packed_data; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# |
156
|
|
|
|
|
|
|
# Module return value |
157
|
|
|
|
|
|
|
# |
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# autoloaded methods go after the END token (&& pod) below |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |