IGMP.pm

filter: Statementstmt 66.6% 78 / 117 Branchbran 20.0% 8 / 40 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 76.9% 20 / 26 Podpod 100% 12 / 12 totaltotal 55.4% 118 / 213 CC 26 SCAR 35.4
CC
26
Cov
51%
computeChecksums
132.0
match
30.0
encapsulate
16.7
CRAP 34.5
↑ Summary IGMP/v3Report.pm »
1 #
2 # $Id: IGMP.pm 49 2009-05-31 13:15:34Z VinsWorldcom $
3 #
4 package Net::Frame::Layer::IGMP;
5 6 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = '1.02';
8  
9 6 ▶use Net::Frame::Layer qw(:consts :subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 our @ISA = qw(Net::Frame::Layer Exporter);
12  
13 6 our %EXPORT_TAGS = (
14 consts => [qw(
15 NF_IGMP_ALLIGMPRTRS
16 NF_IGMP_ALLIGMPRTRS_MAC
17 NF_IGMP_TYPE_QUERY
18 NF_IGMP_TYPE_DVMRP
19 NF_IGMP_TYPE_REPORTv1
20 NF_IGMP_TYPE_REPORTv2
21 NF_IGMP_TYPE_REPORTv3
22 NF_IGMP_TYPE_LEAVE
23 )],
24 );
25 our @EXPORT_OK = (
26 6 @{$EXPORT_TAGS{consts}},
27 );
28  
29 6 ▶use constant NF_IGMP_ALLIGMPRTRS => '224.0.0.22';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶use constant NF_IGMP_ALLIGMPRTRS_MAC => '01:00:5e:00:00:16';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 6 ▶use constant NF_IGMP_TYPE_QUERY => 0x11;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 6 ▶use constant NF_IGMP_TYPE_DVMRP => 0x13;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 6 ▶use constant NF_IGMP_TYPE_REPORTv1 => 0x12;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 6 ▶use constant NF_IGMP_TYPE_REPORTv2 => 0x16;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 6 ▶use constant NF_IGMP_TYPE_REPORTv3 => 0x22;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 6 ▶use constant NF_IGMP_TYPE_LEAVE => 0x17;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 6 our @AS = qw(
39 type
40 maxResp
41 checksum
42 groupAddress
43 reserved
44 numGroupRecs
45 );
46 6 __PACKAGE__->cgBuildIndices;
47 6 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
48  
49 #no strict 'vars';
50 6 ▶use Net::Frame::Layer::IGMP::v3Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 6 ▶use Net::Frame::Layer::IGMP::v3Report qw(:consts);
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 6 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
54 shift->SUPER::new(
55 6 type => NF_IGMP_TYPE_QUERY,
56 maxResp => 0,
57 checksum => 0,
58 groupAddress => '0.0.0.0',
59 reserved => 0,
60 numGroupRecs => 0,
61 @_,
62 );
63 }
64  
65 0 ▶sub v3query {
Subroutine v3query: not called CC=1 SCAR=6.9
Pod documented
66 0 return new(@_)
67 }
68  
69 1 ▶sub v3report {
Subroutine v3report: called CC=1 SCAR=0.0
Pod documented
70 shift->SUPER::new(
71 1 type => NF_IGMP_TYPE_REPORTv3,
72 maxResp => 0,
73 checksum => 0,
74 reserved => 0,
75 numGroupRecs => 0,
76 @_,
77 );
78 }
79  
80 0 ▶sub match {
Subroutine match: not called CC=5 SCAR=34.0
Pod documented
81 0 my $self = shift;
82 0 my ($with) = @_;
83 0 my $sType = $self->type;
84 0 my $wType = $with->type;
85 0 ▶ if ($sType eq NF_IGMP_TYPE_QUERY
Branch: 1 branch
BranchTrueFalseTotal
if ($sType eq 17 and $wType eq 18 || $wType eq 22 || $wType eq 34) 0 0 0
Condition0%0/9
$sType eq 17 and $wType eq 18 || $wType eq 22 || $wType eq 34
!ll&&!rl&&r
000
$wType eq 18 or $wType eq 22 or $wType eq 34
l!l&&r!l&&!r
000
$wType eq 18 or $wType eq 22
l!l&&r!l&&!r
000
MC/DC0%0/4
$sType eq 17 and $wType eq 18 || $wType eq 22 || $wType eq 34
$sType eq 17 $wType eq 18 $wType eq 22 $wType eq 34
Truth table0%0/5
A and B or C or D
A= $sType eq 17B= $wType eq 18C= $wType eq 22D= $wType eq 34
ABCDresult
0XXX0
10000
11XX1
101X1
10011
86 && ( ($wType eq NF_IGMP_TYPE_REPORTv1)
87 || ($wType eq NF_IGMP_TYPE_REPORTv2)
88 || ($wType eq NF_IGMP_TYPE_REPORTv3)) ) {
89 0 return 1;
90 }
91 0 0;
92 }
93  
94 # XXX: may be better, by keying on type also
95 0 ▶sub getKey { shift->layer }
Subroutine getKey: not called CC=1 SCAR=6.9
Pod documented
96 0 ▶sub getKeyReverse { shift->layer }
Subroutine getKeyReverse: not called CC=1 SCAR=6.9
Pod documented
97  
98 0 ▶sub getLength { 8 }
Subroutine getLength: not called CC=1 SCAR=6.9
Pod documented
99  
100 1 ▶sub pack {
Subroutine pack: called CC=4 SCAR=16.4
Pod documented
101 1 my $self = shift;
102  
103 1 my $raw;
104 1 ▶ if ($self->type == NF_IGMP_TYPE_REPORTv3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type == 34) { } 0 1 1
105 0 ▶ $raw = $self->SUPER::pack('CCnnn',
Branch: 1 branch
BranchTrueFalseTotal
$raw = $self->SUPER::pack("CCnnn", $self->type, $self->maxResp, $self->checksum, $self->reserved, $self->numGroupRecs) or return 0 0 0
106 $self->type,
107 $self->maxResp,
108 $self->checksum,
109 $self->reserved,
110 $self->numGroupRecs
111 ) or return;
112 } else {
113 1 ▶ $raw = $self->SUPER::pack('CCna4',
Branch: 1 branch
BranchTrueFalseTotal
$raw = $self->SUPER::pack("CCna4", $self->type, $self->maxResp, $self->checksum, inetAton($self->groupAddress)) or return 1 0 1
114 $self->type,
115 $self->maxResp,
116 $self->checksum,
117 inetAton($self->groupAddress)
118 ) or return;
119 }
120  
121 1 return $self->raw($raw);
122 }
123  
124 1 ▶sub unpack {
Subroutine unpack: called CC=3 SCAR=11.5
Pod documented
125 1 my $self = shift;
126  
127 1 ▶ my ($type, $maxResp, $checksum, $groupAddress, $payload) =
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("CCna4 a*", $self->raw) or return 1 0 1
128 $self->SUPER::unpack('CCna4 a*', $self->raw)
129 or return;
130  
131 1 $self->type($type);
132 1 $self->maxResp($maxResp);
133 1 $self->checksum($checksum);
134
135 1 ▶ if ($self->type == NF_IGMP_TYPE_REPORTv3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type == 34) { } 0 1 1
136 0 $self->reserved(unpack "n", (substr $groupAddress, 0, 2));
137 0 $self->numGroupRecs(unpack "n", (substr $groupAddress, 2, 2));
138 } else {
139 1 $self->groupAddress(inetNtoa($groupAddress))
140 }
141  
142 1 $self->payload($payload);
143  
144 1 return $self;
145 }
146  
147 0 ▶sub computeChecksums {
Subroutine computeChecksums: not called CC=11 SCAR=48.8
Pod documented
148 0 my $self = shift;
149 0 my ($layers) = @_;
150  
151 0 my $phpkt;
152 0 ▶ if ($self->type == NF_IGMP_TYPE_REPORTv3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type == 34) { } 0 0 0
153 0 ▶ $phpkt .= $self->SUPER::pack('CCnnn',
Branch: 1 branch
BranchTrueFalseTotal
$phpkt .= $self->SUPER::pack("CCnnn", $self->type, $self->maxResp, 0, $self->reserved, $self->numGroupRecs) or return 0 0 0
154 $self->type, $self->maxResp, 0, $self->reserved, $self->numGroupRecs)
155 or return;
156 } else {
157 0 ▶ $phpkt .= $self->SUPER::pack('CCna4',
Branch: 1 branch
BranchTrueFalseTotal
$phpkt .= $self->SUPER::pack("CCna4", $self->type, $self->maxResp, 0, inetAton($self->groupAddress)) or return 0 0 0
158 $self->type, $self->maxResp, 0, inetAton($self->groupAddress))
159 or return;
160 }
161  
162 0 my $start = 0;
163 0 my $last = $self;
164 0 my $payload = '';
165 0 for my $l (@$layers) {
166 0 $last = $l;
167 0 ▶ if (! $start) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($start) 0 0 0
168 0 ▶ $start++ if $l->layer eq 'IGMP';
Branch: 1 branch
BranchTrueFalseTotal
if $l->layer eq "IGMP" 0 0 0
169 0 next;
170 }
171 0 $payload .= $l->pack;
172 }
173  
174 0 ▶ if (defined($last->payload) && length($last->payload)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last->payload and length $last->payload) 0 0 0
Condition0%0/3
defined $last->payload and length $last->payload
!ll&&!rl&&r
000
MC/DC0%0/2
defined $last->payload and length $last->payload
defined $last->payload length $last->payload
Truth table0%0/3
A and B
A= defined $last->payloadB= length $last->payload
ABresult
0X0
100
111
175 0 $payload .= $last->payload;
176 }
177  
178 0 ▶ if (length($payload)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $payload) 0 0 0
179 0 ▶ $phpkt .= $self->SUPER::pack('a*', $payload)
Branch: 1 branch
BranchTrueFalseTotal
$phpkt .= $self->SUPER::pack("a*", $payload) or return 0 0 0
180 or return;
181 }
182  
183 0 $self->checksum(inetChecksum($phpkt));
184  
185 0 return 1;
186 }
187  
188 1 ▶sub encapsulate {
Subroutine encapsulate: called CC=6 SCAR=28.1
Pod documented
189 1 my $self = shift;
190  
191 1 ▶ return $self->nextLayer if $self->nextLayer;
Branch: 1 branch
BranchTrueFalseTotal
if $self->nextLayer 0 1 1
192  
193 1 ▶ if ($self->payload) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->payload) 0 1 1
194 0 ▶ if ($self->type == 0x11) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->type == 17) { } 0 0 0
elsif ($self->type == 34) { } 0 0 0
elsif ($self->type == 19) { } 0 0 0
195 0 return 'IGMP::v3Query';
196 } elsif ($self->type == 0x22) {
197 0 return 'IGMP::v3Report';
198 } elsif ($self->type == 0x13) {
199 0 return 'DVMRP';
200 }
201 }
202  
203 1 NF_LAYER_NONE;
204 }
205  
206 13 ▶sub print {
Subroutine print: called CC=2 SCAR=6.9
Pod documented
207 13 my $self = shift;
208  
209 13 my $l = $self->layer;
210 13 my $buf = sprintf
211 "$l: type:0x%02x maxResp:%d checksum:0x%04x\n",
212 $self->type, $self->maxResp, $self->checksum;
213  
214 13 ▶ if ($self->type == NF_IGMP_TYPE_REPORTv3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type == 34) { } 2 11 13
215 2 $buf .= sprintf
216 "$l: reserved:%d numGroupRecs:%d",
217 $self->reserved, $self->numGroupRecs;
218 } else {
219 11 $buf .= sprintf
220 "$l: groupAddress:%s",
221 $self->groupAddress;
222 }
223  
224 13 return $buf;
225 }
226  
227 6 1;
228  
229 __END__
↑ Summary IGMP/v3Report.pm »