View on
MetaCPAN
Chander Ganesan > NetPacket-LLC-0.01 > NetPacket::LLC

Download:
NetPacket-LLC-0.01.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

NetPacket::LLC - Assemble and disassemble IEEE 802.3 LLC protocol packets.

SYNOPSIS ^

 use NetPacket::LLC;
 use NetPacket::SpanningTree;

 $llc_data = NetPacket::Ethernet->strip($raw_packet);
 $st_data = NetPacket::LLC->strip($llc_data);
 $st_obj = NetPacket::SpanningTree->decode($st_data);

DESCRIPTION ^

NetPacket::LLC provides a set of routines for assembling and disassembling packets using the IEEE standard LLC protocol layer.

Methods

NetPacket::LLC->decode([ST DATA])

Decode the LLC packet data and return an object containing instance data. This method will probably decode garbage input, but it won't mean much.

NetPacket::SpanningTree->encode($st_hash)

Encode the hash into a raw data stream that may be appended to ethernet packet data. This allows the user to create his/her own LLC protocol packet and subsequently send it out on the wire (though sending on the wire isn't a function of this module).

Functions

NetPacket::LLC->strip([LLC DATA])

Strip the LLC data from the packet, and return any underlying data.

Instance data

The instance data contains in the hash returned by the encode and decode methodsof the NetPacket::LLC module contain the following fields. Note, please refer to the IEEE spec for a description of these fields. They are not described in detail here unless relevant to encoding.

max_age
message_age
bpdu_flags
bridge_id

Exports

exportable

llc_strip

tags

The following tags group together related exportable items.

:strip

Import the strip function st_strip

:ALL

All the above exportable items

EXAMPLE ^

The following is a script that listens on device "eth1" for spanning tree packets. It then decodes the packets, re-encodes them, and verifies that the both the original and re-encoded data are identical. It uses tLLC module to decode the LLC layer.

#!/usr/bin/perl -w # # Perl script to verify that Spanning Tree packet intervals are correct # # #

use strict; use Net::PcapUtils; use NetPacket::Ethernet; use NetPacket::LLC; use NetPacket::SpanningTree;

{ my $iface = "eth1"; my $errmsg = Net::PcapUtils::loop(\&process_pkt, DEV => $iface ); if (defined $errmsg) { die "$errmsg\n"; } }

sub process_pkt { my ($arg, $hdr, $pkt) = @_; my $eth_obj = NetPacket::Ethernet->decode($pkt);

    if ((defined $eth_obj->{length}) && 
        ($eth_obj->{dest_mac} =~ m/^0180c200000/)) { # Spanning Tree protocol
        my $llc_obj = NetPacket::LLC->decode($eth_obj->{data});
        my $st_obj = NetPacket::SpanningTree->decode($llc_obj->{data});
        verifyEncoding($st_obj);

        my $newdata = NetPacket::SpanningTree->encode($st_obj);
        return;
    }
 }

# # Decode a packet and compare it to a hash of data to be encoded. # # Input is a hash of data to be encoded. The subroutine encodes and # subsequently decodes the data and verifies the data matches. #

sub verifyEncoding { my ($st_obj) = @_; my $newdata = NetPacket::SpanningTree->encode($st_obj); my $st_obj1 = NetPacket::SpanningTree->decode($newdata); foreach my $key (keys %$st_obj) { if ($key =~ m/data/i) { next; } if ($key =~ m/frame/i) { next; } if ($key =~ m/_parent/i) { next; } if ($st_obj->{$key} eq $st_obj1->{$key}) { print "$key is identical ($st_obj1->{$key})\n"; } else { print "$key is $st_obj->{$key} before $st_obj1->{$key} after\n"; } } }

TODO ^

Better documentation
Clean up some code.

SEE ALSO ^

NetPacket::LLC
    Module to decode LLC packets (Logical Link Control)
NetPacket::Ethernet
    Module to decode Ethernet Packets
Net::RawIP
    Module to send encoded data out.
Net::PcapUtils
    Utility module to be used for packet capture.

COPYRIGHT ^

Copyright (c) 2002 Chander Ganesan.

This package is free software and is provided "as is" without express or implied warranty. It may be used, redistributed and/or modified under the terms of the Perl Artistic License (see http://www.perl.com/perl/misc/Artistic.html)

This software and all associated data and documentation ('Software') is available free of charge. You may make copies of the Software but you must include all of this notice on any copy.

The Software was developed for research purposes does not warrant that it is error free or fit for any purpose. The author disclaims any liability for all claims, expenses, losses, damages and costs any user may incur as a result of using, copying or modifying the Software.

AUTHOR ^

Chander Ganesan <cganesan@cpan.org<gt>

syntax highlighting: