| 1 | # | ||||||||||||||||||
| 2 | # $Id: RAW.pm,v ce68fbcc7f6d 2019/05/23 05:58:40 gomor $ | ||||||||||||||||||
| 3 | # | ||||||||||||||||||
| 4 | package Net::Frame::Layer::RAW; | ||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | |||||||||||||||||||
| 8 | 3 | ▶ | use Net::Frame::Layer qw(:consts); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | 3 | require Exporter; | |||||||||||||||||
| 10 | 3 | our @ISA = qw(Net::Frame::Layer Exporter); | |||||||||||||||||
| 11 | 3 | __PACKAGE__->cgBuildIndices; | |||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | 3 | our %EXPORT_TAGS = ( | |||||||||||||||||
| 14 | consts => [], | ||||||||||||||||||
| 15 | ); | ||||||||||||||||||
| 16 | our @EXPORT_OK = ( | ||||||||||||||||||
| 17 | 3 | @{$EXPORT_TAGS{consts}}, | |||||||||||||||||
| 18 | ); | ||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | 3 | ▶ | no strict 'vars'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | 1 | ▶ | sub pack { | ||||||||||||||||
|
Subroutine
pack: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 23 | 1 | my $self = shift; | |||||||||||||||||
| 24 | 1 | $self->[$__raw] = ''; | |||||||||||||||||
| 25 | 1 | $self->[$__raw]; | |||||||||||||||||
| 26 | } | ||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | 1 | ▶ | sub unpack { | ||||||||||||||||
|
Subroutine
unpack: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 29 | 1 | my $self = shift; | |||||||||||||||||
| 30 | 1 | $self->[$__payload] = $self->[$__raw]; | |||||||||||||||||
| 31 | 1 | $self; | |||||||||||||||||
| 32 | } | ||||||||||||||||||
| 33 | |||||||||||||||||||
| 34 | 1 | ▶ | sub encapsulate { | ||||||||||||||||
|
Subroutine
encapsulate: called CC=6 SCAR=30.2
Pod
documented
| |||||||||||||||||||
| 35 | 1 | my $self = shift; | |||||||||||||||||
| 36 | |||||||||||||||||||
| 37 | 1 | ▶ | return $self->[$__nextLayer] if $self->[$__nextLayer]; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 38 | |||||||||||||||||||
| 39 | 1 | ▶ | return NF_LAYER_NONE if ! $self->[$__payload]; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 40 | |||||||||||||||||||
| 41 | # With RAW layer, we must guess which type is the first layer | ||||||||||||||||||
| 42 | 0 | my $payload = CORE::unpack('H*', $self->[$__payload]); | |||||||||||||||||
| 43 | |||||||||||||||||||
| 44 | # XXX: may not work on big-endian arch | ||||||||||||||||||
| 45 | 0 | ▶ | if ($payload =~ /^4/) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 46 | 0 | return 'IPv4'; | |||||||||||||||||
| 47 | } | ||||||||||||||||||
| 48 | elsif ($payload =~ /^6/) { | ||||||||||||||||||
| 49 | 0 | return 'IPv6'; | |||||||||||||||||
| 50 | } | ||||||||||||||||||
| 51 | elsif ($payload =~ /^0001....06/) { | ||||||||||||||||||
| 52 | 0 | return 'ARP'; | |||||||||||||||||
| 53 | } | ||||||||||||||||||
| 54 | |||||||||||||||||||
| 55 | 0 | return NF_LAYER_UNKNOWN; | |||||||||||||||||
| 56 | } | ||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | 1 | ▶ | sub print { | ||||||||||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 59 | 1 | my $self = shift; | |||||||||||||||||
| 60 | 1 | my $l = $self->layer; | |||||||||||||||||
| 61 | 1 | "$l: empty"; | |||||||||||||||||
| 62 | } | ||||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | 3 | 1; | |||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||