RIP/v2.pm

filter: Statementstmt 89.1% 66 / 74 Branchbran 59.0% 13 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod 100% 8 / 8 totaltotal 84.8% 101 / 119 CC 13 SCAR 11.5
CC
13
Cov
82%
unpack
6.9
pack
4.1
encapsulate
3.3
CRAP 3.1
« RIP.pm ↑ Summary RIP/v1.pm »
1 #
2 # $Id: v2.pm 49 2009-05-31 13:15:34Z VinsWorldcom $
3 #
4 package Net::Frame::Layer::RIP::v2;
5 9 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Net::Frame::Layer qw(:consts :subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 our @ISA = qw(Net::Frame::Layer Exporter);
9  
10 9 our %EXPORT_TAGS = (
11 consts => [qw(
12 NF_RIP_V2_ADDRESSFAMILY_IPV4
13 NF_RIP_V2_ADDRESSFAMILY_AUTH
14 NF_RIP_V2_AUTHTYPE_SIMPLE
15 NF_RIP_V2_METRIC_INFINITY
16 )],
17 );
18 our @EXPORT_OK = (
19 9 @{$EXPORT_TAGS{consts}},
20 );
21  
22 9 ▶use constant NF_RIP_V2_ADDRESSFAMILY_IPV4 => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 9 ▶use constant NF_RIP_V2_ADDRESSFAMILY_AUTH => 0xffff;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 9 ▶use constant NF_RIP_V2_AUTHTYPE_SIMPLE => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 9 ▶use constant NF_RIP_V2_METRIC_INFINITY => 16;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 9 our @AS = qw(
28 addressFamily
29 routeTag
30 address
31 subnetMask
32 nextHop
33 metric
34 authType
35 authentication
36 );
37 9 __PACKAGE__->cgBuildIndices;
38 9 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
39  
40 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
41 shift->SUPER::new(
42 3 addressFamily => NF_RIP_V2_ADDRESSFAMILY_IPV4,
43 routeTag => 0,
44 address => '0.0.0.0',
45 subnetMask => '0.0.0.0',
46 nextHop => '0.0.0.0',
47 metric => 1,
48 @_,
49 );
50 }
51  
52 2 ▶sub full {
Subroutine full: called CC=1 SCAR=0.0
Pod documented
53 shift->SUPER::new(
54 2 addressFamily => 0,
55 routeTag => 0,
56 address => '0.0.0.0',
57 subnetMask => '0.0.0.0',
58 nextHop => '0.0.0.0',
59 metric => NF_RIP_V2_METRIC_INFINITY,
60 @_,
61 );
62 }
63  
64 4 ▶sub auth {
Subroutine auth: called CC=3 SCAR=11.0
Pod documented
65 4 my $self = shift;
66  
67 4 my %params = (
68 authentication => ''
69 );
70  
71 4 my %args = @_;
72 4 for (keys(%args)) {
73 4 ▶ if (/^authentication$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^authentication$/i) 3 1 4
74 3 $params{'authentication'} = substr $args{$_}, 0, 16
75 }
76 }
77  
78 $self->SUPER::new(
79 4 addressFamily => NF_RIP_V2_ADDRESSFAMILY_AUTH,
80 authType => NF_RIP_V2_AUTHTYPE_SIMPLE,
81 authentication => '',
82 @_,
83 %params,
84 );
85 }
86  
87 0 ▶sub getLength { 20 }
Subroutine getLength: not called CC=1 SCAR=6.9
Pod documented
88  
89 11 ▶sub pack {
Subroutine pack: called CC=4 SCAR=14.1
Pod documented
90 11 my $self = shift;
91  
92 11 ▶ if ($self->addressFamily == NF_RIP_V2_ADDRESSFAMILY_AUTH) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->addressFamily == 65535) { } 6 5 11
93 6 ▶ $self->raw($self->SUPER::pack('nna16',
Branch: 1 branch
BranchTrueFalseTotal
$self->raw($self->SUPER::pack("nna16", $self->addressFamily, $self->authType, $self->authentication)) or return 6 0 6
94 $self->addressFamily,
95 $self->authType,
96 $self->authentication
97 )) or return;
98  
99 } else {
100 5 ▶ $self->raw($self->SUPER::pack('nna4a4a4N',
Branch: 1 branch
BranchTrueFalseTotal
$self->raw($self->SUPER::pack("nna4a4a4N", $self->addressFamily, $self->routeTag, inetAton($self->address), inetAton($self->subnetMask), inetAton($self->nextHop), $self->metric)) or return 5 0 5
101 $self->addressFamily,
102 $self->routeTag,
103 inetAton($self->address),
104 inetAton($self->subnetMask),
105 inetAton($self->nextHop),
106 $self->metric
107 )) or return;
108 }
109  
110 11 return $self->raw;
111 }
112  
113 1 ▶sub unpack {
Subroutine unpack: called CC=5 SCAR=19.3
Pod documented
114 1 my $self = shift;
115  
116 1 ▶ my ($addressFamily, $remain) =
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("n a*", $self->raw) or return 1 0 1
117 $self->SUPER::unpack('n a*', $self->raw)
118 or return;
119  
120 1 ▶ if ($addressFamily == NF_RIP_V2_ADDRESSFAMILY_AUTH) {
Branch: 1 branch
BranchTrueFalseTotal
if ($addressFamily == 65535) { } 0 1 1
121 0 ▶ my ($authType, $authentication, $payload) =
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("na16 a*", $remain) or return 0 0 0
122 $self->SUPER::unpack('na16 a*', $remain)
123 or return;
124  
125 0 $self->addressFamily($addressFamily);
126 0 $self->authType($authType);
127 0 $authentication =~ s/\0{0,}$//g;
128 0 $self->authentication($authentication);
129  
130 0 $self->payload($payload);
131  
132 } else {
133 1 ▶ my ($routeTag, $address, $subnetMask, $nextHop, $metric, $payload) =
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("na4a4a4N a*", $remain) or return 1 0 1
134 $self->SUPER::unpack('na4a4a4N a*', $remain)
135 or return;
136  
137 1 $self->addressFamily($addressFamily);
138 1 $self->routeTag($routeTag);
139 1 $self->address(inetNtoa($address));
140 1 $self->subnetMask(inetNtoa($subnetMask));
141 1 $self->nextHop(inetNtoa($nextHop));
142 1 $self->metric($metric);
143  
144 1 $self->payload($payload);
145 }
146  
147 1 return $self;
148 }
149  
150 1 ▶sub encapsulate {
Subroutine encapsulate: called CC=3 SCAR=12.0
Pod documented
151 1 my $self = shift;
152  
153 1 ▶ return $self->nextLayer if $self->nextLayer;
Branch: 1 branch
BranchTrueFalseTotal
if $self->nextLayer 0 1 1
154  
155 1 ▶ if ($self->payload) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->payload) 0 1 1
156 0 return "RIP::v2";
157 }
158  
159 1 NF_LAYER_NONE;
160 }
161  
162 11 ▶sub print {
Subroutine print: called CC=2 SCAR=6.9
Pod documented
163 11 my $self = shift;
164  
165 11 my $l = $self->layer;
166 11 my $buf;
167
168 11 ▶ if ($self->addressFamily == NF_RIP_V2_ADDRESSFAMILY_AUTH) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->addressFamily == 65535) { } 6 5 11
169 6 $buf = sprintf
170 "$l: addressFamily:0x%02x authType:%d\n".
171 "$l: authentication:%s",
172 $self->addressFamily, $self->authType,
173 $self->authentication;
174  
175 } else {
176 5 $buf = sprintf
177 "$l: addressFamily:%d routeTag:%d\n".
178 "$l: address:%s subnetMask:%s nextHop:%s\n".
179 "$l: metric:%d",
180 $self->addressFamily, $self->routeTag,
181 $self->address, $self->subnetMask, $self->nextHop,
182 $self->metric;
183 }
184  
185 11 return $buf;
186 }
187  
188 9 1;
189  
190 __END__
« RIP.pm ↑ Summary RIP/v1.pm »