Lookup/Ethernet.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Lookup/Countrycode.pm ↑ Summary Lookup/Ip.pm »
1 #
2 # $Id$
3 #
4 # lookup::ethernet Brik
5 #
6 package Metabrik::Lookup::Ethernet;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 commands => {
19 from_dec => [ qw(dec_number) ],
20 from_hex => [ qw(hex_number) ],
21 from_string => [ qw(ethernet_type) ],
22 },
23 };
24 }
25  
26 sub _lookup {
27 my $self = shift;
28  
29 my $lookup = {
30 '0x0800' => 'ipv4',
31 '0x0805' => 'x25',
32 '0x0806' => 'arp',
33 '0x2001' => 'cgmp',
34 '0x2452' => '802.11',
35 '0x8021' => 'pppipcp',
36 '0x8035' => 'rarp',
37 '0x809b' => 'ddp',
38 '0x80f3' => 'aarp',
39 '0x80fd' => 'pppccp',
40 '0x80ff' => 'wcp',
41 '0x8100' => '802.1q',
42 '0x8137' => 'ipx',
43 '0x8181' => 'stp',
44 '0x86dd' => 'ipv6',
45 '0x872d' => 'wlccp',
46 '0x8847' => 'mpls',
47 '0x8863' => 'pppoed',
48 '0x8864' => 'pppoes',
49 '0x888e' => '802.1x',
50 '0x88a2' => 'aoe',
51 '0x88c7' => '802.11i',
52 '0x88cc' => 'lldp',
53 '0x88d9' => 'lltd',
54 '0x9000' => 'loop',
55 '0x9100' => 'vlan',
56 '0xc023' => 'ppppap',
57 '0xc223' => 'pppchap',
58 };
59  
60 return $lookup;
61 }
62  
63 sub from_hex {
64 my $self = shift;
65 my ($hex) = @_;
66  
67 $self->brik_help_run_undef_arg('from_hex', $hex) or return;
68  
69 $hex =~ s/^0x//;
70 if ($hex !~ /^[0-9a-f]+$/i) {
71 return $self->log->error("from_hex: invalid format for hex [$hex]");
72 }
73 $hex = sprintf("0x%04s", $hex);
74  
75 return $self->_lookup->{$hex} || 'undef';
76 }
77  
78 sub from_dec {
79 my $self = shift;
80 my ($dec) = @_;
81  
82 $self->brik_help_run_undef_arg('from_dec', $dec) or return;
83  
84 if ($dec !~ /^[0-9]+$/) {
85 return $self->log->error("from_dec: invalid format for dec [$dec]");
86 }
87 my $hex = sprintf("0x%04x", $dec);
88  
89 return $self->hex($hex);
90 }
91  
92 sub from_string {
93 my $self = shift;
94 my ($string) = @_;
95  
96 $self->brik_help_run_undef_arg('from_string', $string) or return;
97  
98 my $lookup = $self->_lookup;
99  
100 my $rev = {};
101 while (my ($key, $val) = each(%$lookup)) {
102 $rev->{$val} = $key;
103 }
104  
105 return $rev->{$string} || 'undef';
106 }
107  
108 1;
109  
110 __END__
« Lookup/Countrycode.pm ↑ Summary Lookup/Ip.pm »