| 1 | # | ||||||||||
| 2 | # $Id: SLL.pm 2002 2015-02-15 16:50:35Z gomor $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Net::Packet::SLL; | ||||||||||
| 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 | |||||||||||
| 8 | 1 | require Net::Packet::Layer2; | |||||||||
| 9 | 1 | our @ISA = qw(Net::Packet::Layer2); | |||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Net::Packet::Consts qw(:sll :layer); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | our @AS = qw( | |||||||||
| 14 | packetType | ||||||||||
| 15 | addressType | ||||||||||
| 16 | addressLength | ||||||||||
| 17 | source | ||||||||||
| 18 | protocol | ||||||||||
| 19 | ); | ||||||||||
| 20 | 1 | __PACKAGE__->cgBuildIndices; | |||||||||
| 21 | 1 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | no strict 'vars'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 26 | shift->SUPER::new( | ||||||||||
| 27 | 0 | packetType => NP_SLL_PACKET_TYPE_SENT_BY_US, | |||||||||
| 28 | addressType => NP_SLL_ADDRESS_TYPE_512, | ||||||||||
| 29 | addressLength => 0, | ||||||||||
| 30 | source => 0, | ||||||||||
| 31 | protocol => NP_SLL_PROTOCOL_IPv4, | ||||||||||
| 32 | @_, | ||||||||||
| 33 | ); | ||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub getLength { NP_SLL_HDR_LEN } | ||||||||
|
Subroutine
getLength: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 37 | |||||||||||
| 38 | 0 | ▶ | sub pack { | ||||||||
|
Subroutine
pack: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 39 | 0 | my $self = shift; | |||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | $self->[$__raw] = $self->SUPER::pack('nnnH16n', | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | $self->[$__packetType], | ||||||||||
| 43 | $self->[$__addressType], | ||||||||||
| 44 | $self->[$__addressLength], | ||||||||||
| 45 | $self->[$__source], | ||||||||||
| 46 | $self->[$__protocol], | ||||||||||
| 47 | ) or return undef; | ||||||||||
| 48 | |||||||||||
| 49 | 0 | 1; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub unpack { | ||||||||
|
Subroutine
unpack: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 53 | 0 | my $self = shift; | |||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | my ($pt, $at, $al, $s, $p, $payload) = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | $self->SUPER::unpack('nnnH16n a*', $self->[$__raw]) | ||||||||||
| 57 | or return undef; | ||||||||||
| 58 | |||||||||||
| 59 | 0 | $self->[$__packetType] = $pt; | |||||||||
| 60 | 0 | $self->[$__addressType] = $at; | |||||||||
| 61 | 0 | $self->[$__addressLength] = $al; | |||||||||
| 62 | 0 | $self->[$__source] = $s; | |||||||||
| 63 | 0 | $self->[$__protocol] = $p; | |||||||||
| 64 | 0 | $self->[$__payload] = $payload; | |||||||||
| 65 | |||||||||||
| 66 | 0 | 1; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub encapsulate { | ||||||||
|
Subroutine
encapsulate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 70 | 0 | my $types = { | |||||||||
| 71 | NP_SLL_PROTOCOL_IPv4() => NP_LAYER_IPv4(), | ||||||||||
| 72 | NP_SLL_PROTOCOL_IPv6() => NP_LAYER_IPv6(), | ||||||||||
| 73 | NP_SLL_PROTOCOL_ARP() => NP_LAYER_ARP(), | ||||||||||
| 74 | NP_SLL_PROTOCOL_VLAN() => NP_LAYER_VLAN(), | ||||||||||
| 75 | }; | ||||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | $types->{shift->[$__protocol]} || NP_LAYER_UNKNOWN(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | sub print { | ||||||||
|
Subroutine
print: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 81 | 0 | my $self = shift; | |||||||||
| 82 | |||||||||||
| 83 | 0 | my $l = $self->layer; | |||||||||
| 84 | 0 | my $i = $self->is; | |||||||||
| 85 | 0 | sprintf "$l:+$i: packetType:0x%04x addressType:0x%04x ". | |||||||||
| 86 | "addressLength:0x%04x\n". | ||||||||||
| 87 | "$l: $i: source:%d protocol:0x%04x", | ||||||||||
| 88 | $self->[$__packetType], $self->[$__addressType], | ||||||||||
| 89 | $self->[$__addressLength], $self->[$__source], $self->[$__protocol]; | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | # | ||||||||||
| 93 | # Helpers | ||||||||||
| 94 | # | ||||||||||
| 95 | |||||||||||
| 96 | 0 | ▶ | sub _isProtocol { shift->[$__protocol] == shift() } | ||||||||
|
Subroutine
_isProtocol: not called CC=1 SCAR=6.9
| |||||||||||
| 97 | 0 | ▶ | sub isProtocolIpv4 { shift->_isProtocol(NP_SLL_PROTOCOL_IPv4) } | ||||||||
|
Subroutine
isProtocolIpv4: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 98 | 0 | ▶ | sub isProtocolIpv6 { shift->_isProtocol(NP_SLL_PROTOCOL_IPv6) } | ||||||||
|
Subroutine
isProtocolIpv6: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 99 | 0 | ▶ | sub isProtocolIp { | ||||||||
|
Subroutine
isProtocolIp: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 100 | 0 | ▶ | my $self = shift; $self->isProtocolIpv4 || $self->isProtocolIpv6; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | 1 | 1; | |||||||||
| 104 | |||||||||||
| 105 | __END__ | ||||||||||