| 1 | # | ||||||||||
| 2 | # $Id: Layer.pm 2002 2015-02-15 16:50:35Z gomor $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Net::Packet::Layer; | ||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | require Class::Gomor::Array; | |||||||||
| 10 | 1 | our @ISA = qw(Class::Gomor::Array); | |||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use Net::Packet::Consts qw(:layer); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | our @AS = qw( | |||||||||
| 15 | raw | ||||||||||
| 16 | payload | ||||||||||
| 17 | ); | ||||||||||
| 18 | 1 | __PACKAGE__->cgBuildIndices; | |||||||||
| 19 | 1 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | no strict 'vars'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 24 | 0 | my $self = shift->SUPER::new(@_); | |||||||||
| 25 | 0 | ▶ | $self->unpack if $self->raw; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | $self; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | sub is { | ||||||||
|
Subroutine
is: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 30 | 0 | my $layer = ref(shift); | |||||||||
| 31 | 0 | $layer =~ s/^Net::Packet:://; | |||||||||
| 32 | 0 | $layer; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub pack { | ||||||||
|
Subroutine
pack: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 36 | 0 | my $self = shift; | |||||||||
| 37 | 0 | my ($fmt, @args) = @_; | |||||||||
| 38 | 0 | my $res; | |||||||||
| 39 | 0 | eval { $res = CORE::pack($fmt, @args) }; | |||||||||
| 40 | 0 | ▶ | $@ ? do { carp("@{[ref($self)]}: unable to pack structure\n"); undef } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | : $res; | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub unpack { | ||||||||
|
Subroutine
unpack: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | 0 | my ($fmt, $arg) = @_; | |||||||||
| 47 | 0 | my @res; | |||||||||
| 48 | 0 | eval { @res = CORE::unpack($fmt, $arg) }; | |||||||||
| 49 | 0 | ▶ | $@ ? do { carp("@{[ref($self)]}: unable to unpack structure\n"); () } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | : @res; | ||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | sub getPayloadLength { | ||||||||
|
Subroutine
getPayloadLength: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 54 | 0 | my $self = shift; | |||||||||
| 55 | 0 | ▶ | $self->[$__payload] ? length($self->[$__payload]) : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | sub layer { NP_LAYER_N_UNKNOWN } | ||||||||
|
Subroutine
layer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 59 | 0 | ▶ | sub encapsulate { NP_LAYER_NONE } | ||||||||
|
Subroutine
encapsulate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 60 | 0 | ▶ | sub getKey { shift->is } | ||||||||
|
Subroutine
getKey: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 61 | 0 | ▶ | sub getKeyReverse { shift->is } | ||||||||
|
Subroutine
getKeyReverse: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 62 | 0 | ▶ | sub computeLengths { 1 } | ||||||||
|
Subroutine
computeLengths: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 63 | 0 | ▶ | sub computeChecksums { 1 } | ||||||||
|
Subroutine
computeChecksums: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 64 | 0 | ▶ | sub print { "" } | ||||||||
|
Subroutine
print: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 65 | 0 | ▶ | sub getLength { 0 } | ||||||||
|
Subroutine
getLength: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | sub dump { | ||||||||
|
Subroutine
dump: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 68 | 0 | my $self = shift; | |||||||||
| 69 | |||||||||||
| 70 | 0 | my $hex = CORE::unpack('H*', $self->raw); | |||||||||
| 71 | 0 | $hex =~ s/(..)/\\x$1/g; | |||||||||
| 72 | 0 | $hex =~ s/\\x$//; | |||||||||
| 73 | 0 | sprintf "@{[$self->layer]}:+@{[$self->is]}: \"$hex\""; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 0 | ▶ | sub _isLayer { shift->layer eq shift() } | ||||||||
|
Subroutine
_isLayer: not called CC=1 SCAR=6.9
| |||||||||||
| 77 | 0 | ▶ | sub isLayer2 { shift->_isLayer(NP_LAYER_N_2) } | ||||||||
|
Subroutine
isLayer2: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 78 | 0 | ▶ | sub isLayer3 { shift->_isLayer(NP_LAYER_N_3) } | ||||||||
|
Subroutine
isLayer3: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 79 | 0 | ▶ | sub isLayer4 { shift->_isLayer(NP_LAYER_N_4) } | ||||||||
|
Subroutine
isLayer4: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 80 | 0 | ▶ | sub isLayer7 { shift->_isLayer(NP_LAYER_N_7) } | ||||||||
|
Subroutine
isLayer7: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 81 | |||||||||||
| 82 | 1 | 1; | |||||||||
| 83 | |||||||||||
| 84 | __END__ | ||||||||||