File Coverage

blib/lib/Net/Frame/Layer/ICMPv4/Timestamp.pm
Criterion Covered Total %
statement 25 26 96.1
branch 2 4 50.0
condition n/a
subroutine 7 8 87.5
pod 5 5 100.0
total 39 43 90.7


line stmt bran cond sub pod time code
1             #
2             # $Id: Timestamp.pm 56 2015-01-20 18:55:33Z gomor $
3             #
4             package Net::Frame::Layer::ICMPv4::Timestamp;
5 3     3   4685 use strict; use warnings;
  3     3   4  
  3         86  
  3         12  
  3         3  
  3         75  
6              
7 3     3   503 use Net::Frame::Layer qw(:consts :subs);
  3         60964  
  3         1298  
8             our @ISA = qw(Net::Frame::Layer);
9              
10             our @AS = qw(
11             identifier
12             sequenceNumber
13             originateTimestamp
14             receiveTimestamp
15             transmitTimestamp
16             );
17             __PACKAGE__->cgBuildIndices;
18             __PACKAGE__->cgBuildAccessorsScalar(\@AS);
19              
20             sub new {
21             shift->SUPER::new(
22 1     1 1 22 identifier => getRandom16bitsInt(),
23             sequenceNumber => getRandom16bitsInt(),
24             originateTimestamp => time(),
25             receiveTimestamp => 0,
26             transmitTimestamp => 0,
27             @_,
28             );
29             }
30              
31 0     0 1 0 sub getLength { 16 }
32              
33             sub pack {
34 1     1 1 300 my $self = shift;
35              
36 1 50       5 $self->raw($self->SUPER::pack('nnNNN',
37             $self->identifier, $self->sequenceNumber, $self->originateTimestamp,
38             $self->receiveTimestamp, $self->transmitTimestamp,
39             )) or return;
40              
41 1         69 return $self->raw;
42             }
43              
44             sub unpack {
45 1     1 1 10 my $self = shift;
46              
47 1 50       3 my ($identifier, $sequenceNumber, $originateTimestamp, $receiveTimestamp,
48             $transmitTimestamp, $payload)
49             = $self->SUPER::unpack('nnNNN a*', $self->raw)
50             or return;
51              
52 1         25 $self->identifier($identifier);
53 1         8 $self->sequenceNumber($sequenceNumber);
54 1         7 $self->originateTimestamp($originateTimestamp);
55 1         6 $self->receiveTimestamp($receiveTimestamp);
56 1         7 $self->transmitTimestamp($transmitTimestamp);
57 1         10 $self->payload($payload);
58              
59 1         6 return $self;
60             }
61              
62             sub print {
63 1     1 1 4 my $self = shift;
64              
65 1         5 my $l = $self->layer;
66 1         11 sprintf
67             "$l: identifier:%d sequenceNumber:%d\n".
68             "$l: originateTimestamp:%d receiveTimestamp:%d transmitTimestamp:%d",
69             $self->identifier, $self->sequenceNumber, $self->originateTimestamp,
70             $self->receiveTimestamp, $self->transmitTimestamp;
71             }
72              
73             1;
74              
75             __END__