1LLC(3) User Contributed Perl Documentation LLC(3)
2
3
4
6 "NetPacket::LLC" - Assemble and disassemble IEEE 802.3 LLC protocol
7 packets.
8
10 use NetPacket::LLC;
11 use NetPacket::SpanningTree;
12
13 $llc_data = NetPacket::Ethernet->strip($raw_packet);
14 $st_data = NetPacket::LLC->strip($llc_data);
15 $st_obj = NetPacket::SpanningTree->decode($st_data);
16
18 "NetPacket::LLC" provides a set of routines for assembling and
19 disassembling packets using the IEEE standard LLC protocol layer.
20
21 Methods
22 "NetPacket::LLC->decode([ST DATA])"
23 Decode the LLC packet data and return an object containing instance
24 data. This method will probably decode garbage input, but it won't
25 mean much.
26
27 "NetPacket::SpanningTree->encode($st_hash)"
28 Encode the hash into a raw data stream that may be appended to
29 ethernet packet data. This allows the user to create his/her own
30 LLC protocol packet and subsequently send it out on the wire
31 (though sending on the wire isn't a function of this module).
32
33 Functions
34 "NetPacket::LLC->strip([LLC DATA])"
35 Strip the LLC data from the packet, and return any underlying data.
36
37 Instance data
38 The instance data contains in the hash returned by the encode and
39 decode methodsof the "NetPacket::LLC" module contain the following
40 fields. Note, please refer to the IEEE spec for a description of these
41 fields. They are not described in detail here unless relevant to
42 encoding.
43
44 max_age
45 message_age
46 bpdu_flags
47 bridge_id
48
49 Exports
50 exportable
51 llc_strip
52
53 tags
54 The following tags group together related exportable items.
55
56 ":strip"
57 Import the strip function "st_strip"
58
59 ":ALL"
60 All the above exportable items
61
63 The following is a script that listens on device "eth1" for spanning
64 tree packets. It then decodes the packets, re-encodes them, and
65 verifies that the both the original and re-encoded data are identical.
66 It uses tLLC module to decode the LLC layer.
67
68 #!/usr/bin/perl -w # # Perl script to verify that Spanning Tree packet
69 intervals are correct # # #
70
71 use strict; use Net::PcapUtils; use NetPacket::Ethernet; use
72 NetPacket::LLC; use NetPacket::SpanningTree;
73
74 {
75 my $iface = "eth1";
76 my $errmsg = Net::PcapUtils::loop(\&process_pkt,
77 DEV => $iface );
78 if (defined $errmsg) { die "$errmsg\n"; } }
79
80 sub process_pkt {
81 my ($arg, $hdr, $pkt) = @_;
82 my $eth_obj = NetPacket::Ethernet->decode($pkt);
83
84 if ((defined $eth_obj->{length}) &&
85 ($eth_obj->{dest_mac} =~ m/^0180c200000/)) { # Spanning Tree protocol
86 my $llc_obj = NetPacket::LLC->decode($eth_obj->{data});
87 my $st_obj = NetPacket::SpanningTree->decode($llc_obj->{data});
88 verifyEncoding($st_obj);
89
90 my $newdata = NetPacket::SpanningTree->encode($st_obj);
91 return;
92 }
93 }
94
95 # # Decode a packet and compare it to a hash of data to be encoded. #
96 # Input is a hash of data to be encoded. The subroutine encodes and #
97 subsequently decodes the data and verifies the data matches. #
98
99 sub verifyEncoding {
100 my ($st_obj) = @_;
101 my $newdata =
102 NetPacket::SpanningTree->encode($st_obj);
103 my $st_obj1 =
104 NetPacket::SpanningTree->decode($newdata);
105 foreach my $key (keys %$st_obj) {
106 if ($key =~ m/data/i) { next; }
107 if ($key =~ m/frame/i) { next; }
108 if ($key =~ m/_parent/i) { next; }
109 if ($st_obj->{$key} eq $st_obj1->{$key}) {
110 print "$key is identical ($st_obj1->{$key})\n";
111 } else {
112 print
113 "$key is $st_obj->{$key} before $st_obj1->{$key}
114 after\n";
115 }
116 }
117 }
118
120 Better documentation
121 Clean up some code.
122
124 "NetPacket::LLC"
125 Module to decode LLC packets (Logical Link Control)
126
127 "NetPacket::Ethernet"
128 Module to decode Ethernet Packets
129
130 "Net::RawIP"
131 Module to send encoded data out.
132
133 "Net::PcapUtils"
134 Utility module to be used for packet capture.
135
137 Copyright (c) 2002 Chander Ganesan.
138
139 This package is free software and is provided "as is" without express
140 or implied warranty. It may be used, redistributed and/or modified
141 under the terms of the Perl Artistic License (see
142 http://www.perl.com/perl/misc/Artistic.html)
143
144 This software and all associated data and documentation ('Software') is
145 available free of charge. You may make copies of the Software but you
146 must include all of this notice on any copy.
147
148 The Software was developed for research purposes does not warrant that
149 it is error free or fit for any purpose. The author disclaims any
150 liability for all claims, expenses, losses, damages and costs any user
151 may incur as a result of using, copying or modifying the Software.
152
154 Chander Ganesan <cganesan@cpan.org<gt>
155
156
157
158perl v5.36.0 2022-07-22 LLC(3)