| 1 | #!/bin/false | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # PODNAME: Net::DHCP::Packet | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # Author : D. Hamstead | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Original Author: F. van Dun, S. Hadinger | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Object methods to create a DHCP packet. | ||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use 5.8.0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | package Net::DHCP::Packet; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | $Net::DHCP::Packet::VERSION = '0.8'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use Carp qw( carp croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | use Net::DHCP::Constants qw( | |||||||||||||||||||||||||||||||||||||||||
| 14 | :DEFAULT | ||||||||||||||||||||||||||||||||||||||||||
| 15 | :dhcp_hashes | ||||||||||||||||||||||||||||||||||||||||||
| 16 | :dhcp_other | ||||||||||||||||||||||||||||||||||||||||||
| 17 | %DHO_FORMATS | ||||||||||||||||||||||||||||||||||||||||||
| 18 | %SUBOPTION_FORMATS | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 13 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 13 | ▶ | use Net::DHCP::Packet::Attributes qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | ▶ | use Net::DHCP::Packet::IPv4Utils qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 13 | ▶ | use Net::DHCP::Packet::OrderOptions qw( reorder_options ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 13 | ▶ | use List::Util qw(any first none); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 13 | my %newargs = ( | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | Comment => \&comment, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | Op => \&op, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | Htype => \&htype, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | Hlen => \&hlen, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | Hops => \&hops, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | Xid => \&xid, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | Secs => \&secs, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | Flags => \&flags, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | Ciaddr => \&ciaddr, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | Yiaddr => \&yiaddr, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | Siaddr => \&siaddr, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | Giaddr => \&giaddr, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | Chaddr => \&chaddr, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | Sname => \&sname, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | File => \&file, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | Padding => \&padding, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | isDhcp => \&isDhcp, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 43 | ▶ | my $p = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 43 | ▶ | my $class = ref($p) || $p; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $p || $p
MC/DC0%0/2
ref $p || $p
ref $p
$p
Truth table33%1/3
A || B
A= ref $pB= $p
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 43 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 58 | options => {}, # DHCP options | ||||||||||||||||||||||||||||||||||||||||||
| 59 | options_order => [], # order in which the options were added | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # defaults | ||||||||||||||||||||||||||||||||||||||||||
| 62 | comment => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | op => BOOTREQUEST(), | ||||||||||||||||||||||||||||||||||||||||||
| 64 | htype => 1, # 10mb ethernet | ||||||||||||||||||||||||||||||||||||||||||
| 65 | hlen => 6, # Use 6 bytes MAC | ||||||||||||||||||||||||||||||||||||||||||
| 66 | hops => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | xid => 0x12345678, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | secs => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | flags => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | ciaddr => "\0\0\0\0", | ||||||||||||||||||||||||||||||||||||||||||
| 71 | yiaddr => "\0\0\0\0", | ||||||||||||||||||||||||||||||||||||||||||
| 72 | siaddr => "\0\0\0\0", | ||||||||||||||||||||||||||||||||||||||||||
| 73 | giaddr => "\0\0\0\0", | ||||||||||||||||||||||||||||||||||||||||||
| 74 | chaddr => q||, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | sname => q||, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | file => q||, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | padding => q||, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | isDhcp => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 43 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | # single argument means deserialize from binary packet buffer | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 43 | ▶ | if (scalar @_ == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | $self->marshall(shift); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 36 | ▶ | croak("new: odd number of arguments") if @_ % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # split args into attribute pairs (named keys) and option pairs (numeric codes) | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # so we can sort attributes while preserving option insertion order | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 35 | my @attr_pairs; | |||||||||||||||||||||||||||||||||||||||||
| 95 | my @opt_pairs; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 35 | ▶ | while (my ($k, $v) = splice @_, 0, 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 22 | ▶ | if ($k =~ m/^[0-9]+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | push @opt_pairs, [$k, $v]; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 14 | push @attr_pairs, [$k, $v]; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | # process named attributes in sorted order for consistency | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 35 | for my $pair (sort { $a->[0] cmp $b->[0] } @attr_pairs) { | |||||||||||||||||||||||||||||||||||||||||
| 107 | 14 | my ($k, $v) = @$pair; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 14 | ▶ | if ($newargs{$k}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 14 | $newargs{$k}->($self, $v); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | carp sprintf('Ignoring unknown new() argument: %s', $k); | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | # process DHCP options in original order (matters for picky clients) | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 35 | for my $pair (@opt_pairs) { | |||||||||||||||||||||||||||||||||||||||||
| 118 | 8 | $self->addOptionValue($pair->[0], $pair->[1]); | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 35 | return $self | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 13 | sub addOptionRaw { | |||||||||||||||||||||||||||||||||||||||||
| 128 | 60 | ▶ | my ( $self, $key, $value_bin ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addOptionRaw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 60 | $self->{options}->{$key} = $value_bin; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 60 | ▶ | if ( none { $_ == $key } @{ $self->{options_order} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 53 | push @{ $self->{options_order} }, $key; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 60 | return 1 | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | sub addOptionValue { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 33 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addOptionValue: called CC=12 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 33 | my $code = shift; # option code | |||||||||||||||||||||||||||||||||||||||||
| 140 | 33 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | # my $value_bin; # option value in binary format | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | carp("addOptionValue: unknown format for code ($code)") | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 33 | ▶ | unless exists $DHO_FORMATS{$code}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 33 | my $format = $DHO_FORMATS{$code}; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 33 | ▶ | if ( $format eq 'suboption' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | carp 'Use addSubOptionValue to add sub options'; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | # decompose input value into an array | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 33 | my @values; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 33 | ▶ | if ( defined $value && $value ne q|| ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $value and $value ne ""
MC/DC50%1/2
defined $value and $value ne ""
defined $value
$value ne ""
Truth table66%2/3
A and B
A= defined $valueB= $value ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 22 | @values = | |||||||||||||||||||||||||||||||||||||||||
| 158 | split( /[\s\/,;]+/, $value ); # array of values, split by space | ||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | # verify number of parameters | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 33 | ▶ | if ( $format eq 'string' || $format eq 'csr' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$format eq "string" or $format eq "csr"
MC/DC50%1/2
$format eq "string" or $format eq "csr"
$format eq "string"
$format eq "csr"
Truth table66%2/3
A or B
A= $format eq "string"B= $format eq "csr"
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | @values = ($value); # don't change format | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | elsif ( $format =~ m/s$/ ) { # ends with an 's', meaning any number of parameters | ||||||||||||||||||||||||||||||||||||||||||
| 166 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | elsif ( $format =~ m/2$/ ) { # ends with a '2', meaning couples of parameters | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 6 | ▶ | croak( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | "addOptionValue: only pairs of values expected for option '$code'") | ||||||||||||||||||||||||||||||||||||||||||
| 171 | if ( ( @values % 2 ) != 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | else { # only one parameter | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 16 | ▶ | croak("addOptionValue: exactly one value expected for option '$code'") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | if ( @values != 1 ); | ||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | my %options = ( | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | ▶ | inet => sub { return packinet(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 5 | ▶ | inets => sub { return packinets_array(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 5 | ▶ | inets2 => sub { return packinets_array(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | ▶ | int => sub { return pack( 'N', shift ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | ▶ | short => sub { return pack( 'n', shift ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | # 255 & trims the input to single octet | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 4 | ▶ | byte => sub { return pack( 'C', 255 & shift ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | bytes => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | ▶ | return pack( 'C*', map { 255 & $_ } @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | ▶ | string => sub { return shift }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | clientid => sub { return packclientid(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | sipserv => sub { return packsipserv(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | csr => sub { return packcsr(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | suboptions => sub { return packsuboptions(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 26 | ); | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | # } elsif ($format eq 'ids') { | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # $value_bin = $values[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # # TBM bad format | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | # decode the option if we know how, otherwise use the original value | ||||||||||||||||||||||||||||||||||||||||||
| 203 | $self->addOptionRaw( $code, $options{$format} | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 26 | ▶ | ? $options{$format}->(@values) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | : $value ); | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | } # end AddOptionValue | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | sub addSubOptionRaw { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | ▶ | my ( $self, $key, $subkey, $value_bin ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addSubOptionRaw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | $self->{options}->{$key}->{$subkey} = $value_bin; | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 4 | ▶ | if ( none { $_ == $key } @{$self->{options_order}} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 3 | push @{ $self->{options_order} }, $key; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 4 | push @{ $self->{sub_options_order}{$key} }, ($subkey); | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | sub addSubOptionValue { | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addSubOptionValue: called CC=14 SCAR=35.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | my $code = shift; # option code | |||||||||||||||||||||||||||||||||||||||||
| 223 | 4 | my $subcode = shift; # sub option code | |||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 225 | # my $value_bin; # option value in binary format | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | carp("addSubOptionValue: unknown format for code ($code)") | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | ▶ | unless exists $DHO_FORMATS{$code}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | carp("addSubOptionValue: not a suboption parameter for code ($code)") | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 4 | ▶ | unless ( $DHO_FORMATS{$code} eq 'suboptions' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | carp( | ||||||||||||||||||||||||||||||||||||||||||
| 234 | "addSubOptionValue: unknown format for subcode ($subcode) on code ($code)" | ||||||||||||||||||||||||||||||||||||||||||
| 235 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 4 | ▶ | unless ( $DHO_FORMATS{$code} eq 'suboptions' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | carp("addSubOptionValue: no suboptions defined for code ($code)?") | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | ▶ | unless exists $SUBOPTION_CODES{$code}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | carp( | ||||||||||||||||||||||||||||||||||||||||||
| 242 | "addSubOptionValue: suboption ($subcode) not defined for code ($code)?") | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | ▶ | unless exists $SUBOPTION_CODES{$code}->{$subcode}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | my $format = $SUBOPTION_FORMATS{$code}->{$subcode}; | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | # decompose input value into an array | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | my @values; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 4 | ▶ | if ( defined $value && $value ne q|| ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $value and $value ne ""
MC/DC0%0/2
defined $value and $value ne ""
defined $value
$value ne ""
Truth table33%1/3
A and B
A= defined $valueB= $value ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 4 | @values = | |||||||||||||||||||||||||||||||||||||||||
| 251 | split( /[\s\/,;]+/, $value ); # array of values, split by space | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | # verify number of parameters | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | ▶ | if ( $format eq 'string' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | @values = ($value); # don't change format | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | elsif ( $format =~ m/s$/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 259 | { # ends with an 's', meaning any number of parameters | ||||||||||||||||||||||||||||||||||||||||||
| 260 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | elsif ( $format =~ m/2$/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 263 | { # ends with a '2', meaning couples of parameters | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | croak( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | "addSubOptionValue: only pairs of values expected for option '$code'" | ||||||||||||||||||||||||||||||||||||||||||
| 266 | ) if ( ( @values % 2 ) != 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | else { # only one parameter | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 4 | ▶ | croak( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | "addSubOptionValue: exactly one value expected for option '$code'") | ||||||||||||||||||||||||||||||||||||||||||
| 271 | if ( @values != 1 ); | ||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | my %options = ( | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | inet => sub { return packinet(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | inets => sub { return packinets_array(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | inets2 => sub { return packinets_array(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | int => sub { return pack( 'N', shift ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | short => sub { return pack( 'n', shift ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | byte => sub { return pack( 'C', 255 & shift ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | , # 255 & trims the input to single octet | ||||||||||||||||||||||||||||||||||||||||||
| 282 | bytes => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | return pack( 'C*', map { 255 & $_ } @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | string => sub { return shift }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 4 | ▶ | hexa => sub { return pack( 'H*', shift ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | # } elsif ($format eq 'ids') { | ||||||||||||||||||||||||||||||||||||||||||
| 290 | # $value_bin = $values[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 291 | # # TBM bad format | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | # decode the option if we know how, otherwise use the original value | ||||||||||||||||||||||||||||||||||||||||||
| 294 | $self->addSubOptionRaw( $code, $subcode, $options{$format} | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 4 | ▶ | ? $options{$format}->(@values) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | : $value ); | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | sub getOptionRaw { | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 66 | ▶ | my ( $self, $key ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getOptionRaw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | return $self->{options}->{$key} | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 66 | ▶ | if exists( $self->{options}->{$key} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | return | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | sub getOptionValue { | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 48 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getOptionValue: called CC=12 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 48 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | carp("getOptionValue: unknown format for code ($code)") | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 48 | ▶ | unless exists( $DHO_FORMATS{$code} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 48 | my $format = $DHO_FORMATS{$code}; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 48 | my $subcodes; | |||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 48 | ▶ | if (defined $format && $format eq 'suboptions') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $format and $format eq "suboptions"
MC/DC50%1/2
defined $format and $format eq "suboptions"
defined $format
$format eq "suboptions"
Truth table66%2/3
A and B
A= defined $formatB= $format eq "suboptions"
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 17 | ▶ | $subcodes = $REV_SUBOPTION_CODES{$code} || {} | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Net::DHCP::Packet::REV_SUBOPTION_CODES{$code} || {}
MC/DC0%0/1
$Net::DHCP::Packet::REV_SUBOPTION_CODES{$code} || {}
$Net::DHCP::Packet::REV_SUBOPTION_CODES{$code}
Truth table50%1/2
A
A= $Net::DHCP::Packet::REV_SUBOPTION_CODES{$code}
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 48 | my $value_bin = $self->getOptionRaw($code); | |||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 48 | ▶ | return unless defined $value_bin; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | # my @values; | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | # hash out these options for speed and sanity | ||||||||||||||||||||||||||||||||||||||||||
| 328 | my %options = ( | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 4 | ▶ | inet => sub { return unpackinets_array(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 3 | ▶ | inets => sub { return unpackinets_array(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | ▶ | inets2 => sub { return unpackinets_array(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 2 | ▶ | int => sub { return unpack( 'N', shift ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | ▶ | short => sub { return unpack( 'n', shift ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | shorts => sub { return unpack( 'n*', shift ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 6 | ▶ | byte => sub { return unpack( 'C', shift ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 3 | ▶ | bytes => sub { return unpack( 'C*', shift ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 3 | ▶ | string => sub { return shift }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | clientid => sub { return unpackclientid(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | sipserv => sub { return unpacksipserv(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | csr => sub { return unpackcsr(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 17 | ▶ | suboptions => sub { return unpacksuboptions(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 41 | ); | |||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | # } elsif ($format eq 'ids') { | ||||||||||||||||||||||||||||||||||||||||||
| 346 | # $values[0] = $value_bin; | ||||||||||||||||||||||||||||||||||||||||||
| 347 | # # TBM, bad format | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | # decode the options if we know the format | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 41 | ▶ | if (defined $format && $options{$format}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $format and $options{$format}
MC/DC0%0/2
defined $format and $options{$format}
defined $format
$options{$format}
Truth table33%1/3
A and B
A= defined $formatB= $options{$format}
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | $value_bin = join(q|, |, | ||||||||||||||||||||||||||||||||||||||||||
| 352 | map { ref $_ ? sprintf '%s => %s', $subcodes->{$_->[0]} || $_->[0], | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 53 | ▶ | do { my $v = $_->[1]; if ($v =~ m/[ ,"]/) { $v =~ s/\\/\\\\/g; $v =~ s/"/\\"/g } $v = _printable($v); $v = qq("$v") if $v =~ m/[ ,"]/; $v } : $_ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$$subcodes{$_->[0]} || $_->[0]
MC/DC0%0/2
$$subcodes{$_->[0]} || $_->[0]
$$subcodes{$_->[0]}
$_->[0]
Truth table66%2/3
A || B
A= $$subcodes{$_->[0]}B= $_->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 41 | ( $options{$format}->($value_bin) )) | |||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | # if we cant work out the format | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 41 | return $value_bin | |||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | } # getOptionValue | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | sub getSubOptionRaw { | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 5 | ▶ | my ( $self, $key, $subkey ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getSubOptionRaw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | return $self->{options}->{$key}->{$subkey} | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 5 | ▶ | if exists( $self->{options}->{$key}->{$subkey} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | my %unpack = ( | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | inet => sub { return unpackinets_array(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | inets => sub { return unpackinets_array(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | inets2 => sub { return unpackinets_array(shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | int => sub { return unpack('N', shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | short => sub { return unpack('n', shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | shorts => sub { return unpack('n*', shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | byte => sub { return unpack('C', shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | bytes => sub { return unpack('C*', shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | string => sub { return shift }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 2 | ▶ | hexa => sub { return unpack('H*', shift) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 13 | ); | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | sub getSubOptionValue { | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getSubOptionValue: called CC=9 SCAR=22.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 7 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 7 | my $subcode = shift; | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | croak("getSubOptionValue: unknown format for code ($code)") | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 7 | ▶ | unless exists $DHO_FORMATS{$code}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | croak("getSubOptionValue: not a suboption parameter for code ($code)") | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 6 | ▶ | unless $DHO_FORMATS{$code} eq 'suboptions'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | croak("getSubOptionValue: no suboptions defined for code ($code)") | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 5 | ▶ | unless exists $SUBOPTION_CODES{$code}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | croak("getSubOptionValue: suboption ($subcode) not defined for code ($code)") | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 4 | ▶ | unless exists $REV_SUBOPTION_CODES{$code}->{$subcode}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 3 | ▶ | my $format = exists $SUBOPTION_FORMATS{$code} ? $SUBOPTION_FORMATS{$code}->{$subcode} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 3 | my $value_bin = $self->getSubOptionRaw($code, $subcode); | |||||||||||||||||||||||||||||||||||||||||
| 398 | 3 | ▶ | return unless defined $value_bin; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 2 | ▶ | if ( defined $format && $unpack{$format} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $format and $unpack{$format}
MC/DC0%0/2
defined $format and $unpack{$format}
defined $format
$unpack{$format}
Truth table33%1/3
A and B
A= defined $formatB= $unpack{$format}
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 2 | return join(q|, |, $unpack{$format}->($value_bin)); | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return $value_bin | |||||||||||||||||||||||||||||||||||||||||
| 405 | } # getSubOptionValue | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | sub removeOption { | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 5 | ▶ | my ( $self, $key ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removeOption: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 5 | ▶ | if ( exists( $self->{options}->{$key} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | my $i = | ||||||||||||||||||||||||||||||||||||||||||
| 411 | 5 | ▶ | first { $self->{options_order}->[$_] == $key } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 3 | 0 .. $#{ $self->{options_order} }; | |||||||||||||||||||||||||||||||||||||||||
| 413 | 3 | ▶ | if ( defined $i && $i < @{ $self->{options_order} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $i and $i < @{$self->{"options_order"};}
MC/DC0%0/2
defined $i and $i < @{$self->{"options_order"};}
defined $i
$i < @{$self->{"options_order"};}
Truth table33%1/3
A and B
A= defined $iB= $i < @{$self->{"options_order"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 3 | splice @{ $self->{options_order} }, $i, 1; | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 3 | delete( $self->{options}->{$key} ); | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | sub removeSubOption { | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 2 | ▶ | my ($self, $code, $subcode) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removeSubOption: called CC=5 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 2 | ▶ | if (exists $self->{options}->{$code} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $self->{"options"}{$code} and ref $self->{"options"}{$code} eq "HASH" and exists $self->{"options"}{$code}{$subcode}
exists $self->{"options"}{$code} and ref $self->{"options"}{$code} eq "HASH"
MC/DC0%0/3
exists $self->{"options"}{$code} and ref $self->{"options"}{$code} eq "HASH" and exists $self->{"options"}{$code}{$subcode}
exists $self->{"options"}{$code}
ref $self->{"options"}{$code} eq "HASH"
exists $self->{"options"}{$code}{$subcode}
Truth table25%1/4
A and B and C
A= exists $self->{"options"}{$code}B= ref $self->{"options"}{$code} eq "HASH"C= exists $self->{"options"}{$code}{$subcode}
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | && ref $self->{options}->{$code} eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 424 | && exists $self->{options}->{$code}->{$subcode}) { | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 2 | delete $self->{options}->{$code}->{$subcode}; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 2 | @{ $self->{sub_options_order}->{$code} } = grep { $_ != $subcode } @{ $self->{sub_options_order}->{$code} }; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 2 | ▶ | unless (keys %{ $self->{options}->{$code} }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 1 | delete $self->{options}->{$code}; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | delete $self->{sub_options_order}->{$code}; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | @{ $self->{options_order} } = grep { $_ != $code } @{ $self->{options_order} }; | |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 13 | my $BOOTP_FORMAT = 'C C C C N n n a4 a4 a4 a4 a16 Z64 Z128 a*'; | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | #my $DHCP_MIN_LENGTH = length(pack($BOOTP_FORMAT)); | ||||||||||||||||||||||||||||||||||||||||||
| 439 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 440 | sub serialize { | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 8 | ▶ | my ($self) = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize: called CC=14 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 8 | my $options = shift; # reference to an options hash for special options | |||||||||||||||||||||||||||||||||||||||||
| 443 | 8 | my $bytes = undef; | |||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | $bytes = pack( $BOOTP_FORMAT, | ||||||||||||||||||||||||||||||||||||||||||
| 446 | $self->{op}, $self->{htype}, $self->{hlen}, $self->{hops}, | ||||||||||||||||||||||||||||||||||||||||||
| 447 | $self->{xid}, $self->{secs}, $self->{flags}, $self->{ciaddr}, | ||||||||||||||||||||||||||||||||||||||||||
| 448 | $self->{yiaddr}, $self->{siaddr}, $self->{giaddr}, $self->{chaddr}, | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 8 | $self->{sname}, $self->{file} ); | |||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 8 | ▶ | if ( $self->{isDhcp} ) { # add MAGIC_COOKIE and options | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 8 | $bytes .= MAGIC_COOKIE(); | |||||||||||||||||||||||||||||||||||||||||
| 453 | 8 | for my $key ( reorder_options( @{ $self->{options_order} } ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 454 | 8 | ▶ | if ( ref($self->{options}->{$key}) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | for my $value ( @{$self->{options}->{$key}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $bytes .= pack( 'C', $key ); | |||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $bytes .= pack( 'C/a*', $value ); | |||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | elsif ( ref($self->{options}->{$key}) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my $subbytes = q{}; | |||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | for my $subkey ( @{ $self->{sub_options_order}->{$key} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | $subbytes .= pack( 'C', $subkey ); | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | $subbytes .= pack( 'C/a*', $self->{options}->{$key}->{$subkey} ); | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $bytes .= pack( 'C', $key ); | |||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $bytes .= pack( 'C', byte_len($subbytes) ) . $subbytes; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 8 | $bytes .= pack( 'C', $key ); | |||||||||||||||||||||||||||||||||||||||||
| 471 | 8 | $bytes .= pack( 'C/a*', $self->{options}->{$key} ); | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 8 | $bytes .= pack( 'C', 255 ); | |||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 8 | $bytes .= $self->{padding}; # add optional padding | |||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | # add padding if packet is less than minimum size | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 8 | my $min_padding = BOOTP_MIN_LEN() - byte_len($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 481 | 8 | ▶ | if ( $min_padding > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 2 | $bytes .= "\0" x $min_padding; | |||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | 8 | ▶ | if ( byte_len($bytes) > DHCP_MAX_MTU() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | croak( 'serialize: packet too big (' | |||||||||||||||||||||||||||||||||||||||||
| 487 | . byte_len($bytes) | ||||||||||||||||||||||||||||||||||||||||||
| 488 | . ' greater than max MAX_MTU (' | ||||||||||||||||||||||||||||||||||||||||||
| 489 | . DHCP_MAX_MTU() ); | ||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | # test if packet length is not bigger than DHO_DHCP_MAX_MESSAGE_SIZE | ||||||||||||||||||||||||||||||||||||||||||
| 493 | 7 | ▶ | if ( $options | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$options and exists $options->{57}
MC/DC50%1/2
$options and exists $options->{57}
$options
exists $options->{57}
Truth table66%2/3
A and B
A= $optionsB= exists $options->{57}
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | && exists( $options->{ DHO_DHCP_MAX_MESSAGE_SIZE() } ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 495 | { | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | # maximum packet size is specified | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 4 | my $max_message_size = $options->{ DHO_DHCP_MAX_MESSAGE_SIZE() }; | |||||||||||||||||||||||||||||||||||||||||
| 499 | 4 | ▶ | if ( ( $max_message_size >= BOOTP_MIN_LEN() ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$max_message_size >= 300 and $max_message_size < 1500
MC/DC100%2/2
$max_message_size >= 300 and $max_message_size < 1500
$max_message_size >= 300
$max_message_size < 1500
Truth table100%3/3
A and B
A= $max_message_size >= 300B= $max_message_size < 1500
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | && ( $max_message_size < DHCP_MAX_MTU() ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 501 | { | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | # relevant message size | ||||||||||||||||||||||||||||||||||||||||||
| 504 | 2 | ▶ | if ( byte_len($bytes) > $max_message_size ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 1 | croak( 'serialize: message is bigger than allowed (' | |||||||||||||||||||||||||||||||||||||||||
| 506 | . byte_len($bytes) | ||||||||||||||||||||||||||||||||||||||||||
| 507 | . '), max specified :' | ||||||||||||||||||||||||||||||||||||||||||
| 508 | . $max_message_size ); | ||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | 6 | return $bytes | |||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | } # end sub serialize | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 518 | sub min_len_handling { | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 15 | ▶ | my ( $self, $level ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min_len_handling: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 15 | ▶ | return $self->{min_len_handling} || 0 if @_ == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{'min_len_handling'} || 0
MC/DC100%1/1
$self->{'min_len_handling'} || 0
$self->{'min_len_handling'}
Truth table100%2/2
A
A= $self->{'min_len_handling'}
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | croak( sprintf q(Invalid handle level '%s', use 0, 1, or 2.), $level ) | ||||||||||||||||||||||||||||||||||||||||||
| 523 | 3 | ▶ | unless $level =~ m/^[0-9]+$/ && any { $level eq $_ } 0, 1, 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition66%2/3
$level =~ /^[0-9]+$/ and &any(sub {
$level eq $_;
}
, 0, 1, 2)
MC/DC50%1/2
$level =~ /^[0-9]+$/ and &any(sub {
$level eq $_;
}
, 0, 1, 2)
$level =~ /^[0-9]+$/
&any(sub {
$level eq $_;
}
, 0, 1, 2)
Truth table66%2/3
A and B
A= $level =~ /^[0-9]+$/B= &any(sub {
$level eq $_;
}
, 0, 1, 2)
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 2 | $self->{min_len_handling} = $level; | |||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 528 | sub marshall { | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 9 | ▶ | my ( $self, $buf ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
marshall: called CC=17 SCAR=28.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 9 | my $opt_buf; | |||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | 9 | my $min_len_handling = $self->min_len_handling; | |||||||||||||||||||||||||||||||||||||||||
| 534 | 9 | ▶ | if ( $min_len_handling != 2 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$min_len_handling != 2 and byte_len($buf) < 236
MC/DC100%2/2
$min_len_handling != 2 and byte_len($buf) < 236
$min_len_handling != 2
byte_len($buf) < 236
Truth table100%3/3
A and B
A= $min_len_handling != 2B= byte_len($buf) < 236
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | && byte_len($buf) < BOOTP_ABSOLUTE_MIN_LEN() | ||||||||||||||||||||||||||||||||||||||||||
| 536 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 2 | my $message = sprintf | |||||||||||||||||||||||||||||||||||||||||
| 538 | 'marshall: packet too small (%d), absolute minimum size is %d', | ||||||||||||||||||||||||||||||||||||||||||
| 539 | byte_len($buf), | ||||||||||||||||||||||||||||||||||||||||||
| 540 | BOOTP_ABSOLUTE_MIN_LEN(); | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 2 | ▶ | croak($message) unless $min_len_handling; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 1 | warn($message); | |||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 8 | ▶ | if ( $min_len_handling != 2 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$min_len_handling != 2 and byte_len($buf) < 300
MC/DC100%2/2
$min_len_handling != 2 and byte_len($buf) < 300
$min_len_handling != 2
byte_len($buf) < 300
Truth table100%3/3
A and B
A= $min_len_handling != 2B= byte_len($buf) < 300
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | && byte_len($buf) < BOOTP_MIN_LEN() | ||||||||||||||||||||||||||||||||||||||||||
| 546 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 547 | 1 | my $message = sprintf | |||||||||||||||||||||||||||||||||||||||||
| 548 | 'marshall: packet too small (%d), minimum size is %d', | ||||||||||||||||||||||||||||||||||||||||||
| 549 | byte_len($buf), | ||||||||||||||||||||||||||||||||||||||||||
| 550 | BOOTP_MIN_LEN(); | ||||||||||||||||||||||||||||||||||||||||||
| 551 | 1 | carp($message); | |||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 8 | ▶ | if ( byte_len($buf) > DHCP_MAX_MTU() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 1 | croak( sprintf | |||||||||||||||||||||||||||||||||||||||||
| 555 | 'marshall: packet too big (%d), max MTU size is %s', | ||||||||||||||||||||||||||||||||||||||||||
| 556 | byte_len($buf), | ||||||||||||||||||||||||||||||||||||||||||
| 557 | DHCP_MAX_MTU() ); | ||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | # if we are re-using this object, then we need to clear out these arrays | ||||||||||||||||||||||||||||||||||||||||||
| 561 | delete $self->{options} | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 7 | ▶ | if $self->{options}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | delete $self->{options_order} | ||||||||||||||||||||||||||||||||||||||||||
| 564 | 7 | ▶ | if $self->{options_order}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 567 | $self->{op}, $self->{htype}, $self->{hlen}, $self->{hops}, | ||||||||||||||||||||||||||||||||||||||||||
| 568 | $self->{xid}, $self->{secs}, $self->{flags}, $self->{ciaddr}, | ||||||||||||||||||||||||||||||||||||||||||
| 569 | $self->{yiaddr}, $self->{siaddr}, $self->{giaddr}, $self->{chaddr}, | ||||||||||||||||||||||||||||||||||||||||||
| 570 | 7 | $self->{sname}, $self->{file}, $opt_buf | |||||||||||||||||||||||||||||||||||||||||
| 571 | ) = unpack( $BOOTP_FORMAT, $buf ); | ||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 7 | $self->{isDhcp} = 0; # default to BOOTP | |||||||||||||||||||||||||||||||||||||||||
| 574 | 7 | ▶ | if ( ( byte_len( $opt_buf ) > 4 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
byte_len($opt_buf) > 4 and substr($opt_buf, 0, 4) eq "c\202Sc"
MC/DC50%1/2
byte_len($opt_buf) > 4 and substr($opt_buf, 0, 4) eq "c\202Sc"
byte_len($opt_buf) > 4
substr($opt_buf, 0, 4) eq "c\202Sc"
Truth table66%2/3
A and B
A= byte_len($opt_buf) > 4B= substr($opt_buf, 0, 4) eq "c\202Sc"
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | && ( substr( $opt_buf, 0, 4 ) eq MAGIC_COOKIE() ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 576 | { | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | # it is definitely DHCP | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 5 | $self->{isDhcp} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 5 | my $pos = 4; # Skip magic cookie | |||||||||||||||||||||||||||||||||||||||||
| 582 | 5 | my $total = length($opt_buf); | |||||||||||||||||||||||||||||||||||||||||
| 583 | 5 | my $type; | |||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | 5 | ▶ | while ( $pos < $total ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 80 | $type = ord( substr( $opt_buf, $pos++, 1 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 588 | 80 | ▶ | next if ( $type eq DHO_PAD() ); # Skip padding bytes | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | 20 | ▶ | last if ( $type eq DHO_END() ); # Type 'FF' signals end of options. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | 16 | my $len = ord( substr( $opt_buf, $pos++, 1 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 591 | 16 | ▶ | $len = $total - $pos if $pos + $len > $total; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 16 | my $option = substr( $opt_buf, $pos, $len ); | |||||||||||||||||||||||||||||||||||||||||
| 593 | 16 | $pos += $len; | |||||||||||||||||||||||||||||||||||||||||
| 594 | 16 | $self->addOptionRaw( $type, $option ); | |||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | # verify that we ended with an "END" code | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 5 | ▶ | if ( $type != DHO_END() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 1 | croak('marshall: unexpected end of options'); | |||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | # put remaining bytes in the padding attribute | ||||||||||||||||||||||||||||||||||||||||||
| 604 | 4 | ▶ | if ( $pos < $total ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | 4 | $self->{padding} = substr( $opt_buf, $pos, $total - $pos ); | |||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | $self->{padding} = q||; | |||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | # in bootp, everything is padding | ||||||||||||||||||||||||||||||||||||||||||
| 615 | 2 | $self->{padding} = $opt_buf; | |||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | 6 | return $self | |||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | } # end sub marshall | ||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 624 | sub toString { | ||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toString: not called CC=20 SCAR=60.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | my $s; | |||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | $s .= sprintf( "comment = %s\n", $self->comment() ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | if defined( $self->comment() ); | ||||||||||||||||||||||||||||||||||||||||||
| 630 | $s .= sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 631 | "op = %s\n", | ||||||||||||||||||||||||||||||||||||||||||
| 632 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 633 | exists( $REV_BOOTP_CODES{ $self->op() } ) | ||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | && $REV_BOOTP_CODES{ $self->op() } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
exists $Net::DHCP::Packet::REV_BOOTP_CODES{$self->op} && $Net::DHCP::Packet::REV_BOOTP_CODES{$self->op} || $self->op
exists $Net::DHCP::Packet::REV_BOOTP_CODES{$self->op} and $Net::DHCP::Packet::REV_BOOTP_CODES{$self->op}
MC/DC0%0/3
exists $Net::DHCP::Packet::REV_BOOTP_CODES{$self->op} && $Net::DHCP::Packet::REV_BOOTP_CODES{$self->op} || $self->op
exists $Net::DHCP::Packet::REV_BOOTP_CODES{$self->op}
$Net::DHCP::Packet::REV_BOOTP_CODES{$self->op}
$self->op
Truth table0%0/5
A and B || C
A= exists $Net::DHCP::Packet::REV_BOOTP_CODES{$self->op}B= $Net::DHCP::Packet::REV_BOOTP_CODES{$self->op}C= $self->op
| |||||||||||||||||||||||||||||||||||||||||||
| 635 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 636 | || $self->op() | ||||||||||||||||||||||||||||||||||||||||||
| 637 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 638 | $s .= sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 639 | "htype = %s\n", | ||||||||||||||||||||||||||||||||||||||||||
| 640 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 641 | exists( $REV_HTYPE_CODES{ $self->htype() } ) | ||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | ▶ | && $REV_HTYPE_CODES{ $self->htype() } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
exists $Net::DHCP::Packet::REV_HTYPE_CODES{$self->htype} && $Net::DHCP::Packet::REV_HTYPE_CODES{$self->htype} || $self->htype
exists $Net::DHCP::Packet::REV_HTYPE_CODES{$self->htype} and $Net::DHCP::Packet::REV_HTYPE_CODES{$self->htype}
MC/DC0%0/3
exists $Net::DHCP::Packet::REV_HTYPE_CODES{$self->htype} && $Net::DHCP::Packet::REV_HTYPE_CODES{$self->htype} || $self->htype
exists $Net::DHCP::Packet::REV_HTYPE_CODES{$self->htype}
$Net::DHCP::Packet::REV_HTYPE_CODES{$self->htype}
$self->htype
Truth table0%0/5
A and B || C
A= exists $Net::DHCP::Packet::REV_HTYPE_CODES{$self->htype}B= $Net::DHCP::Packet::REV_HTYPE_CODES{$self->htype}C= $self->htype
| |||||||||||||||||||||||||||||||||||||||||||
| 643 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 644 | || $self->htype() | ||||||||||||||||||||||||||||||||||||||||||
| 645 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | $s .= sprintf( "hlen = %s\n", $self->hlen() ); | |||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | $s .= sprintf( "hops = %s\n", $self->hops() ); | |||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | $s .= sprintf( "xid = %x\n", $self->xid() ); | |||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | $s .= sprintf( "secs = %i\n", $self->secs() ); | |||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | $s .= sprintf( "flags = %x\n", $self->flags() ); | |||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | $s .= sprintf( "ciaddr = %s\n", $self->ciaddr() ); | |||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | $s .= sprintf( "yiaddr = %s\n", $self->yiaddr() ); | |||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | $s .= sprintf( "siaddr = %s\n", $self->siaddr() ); | |||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | $s .= sprintf( "giaddr = %s\n", $self->giaddr() ); | |||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | $s .= sprintf( "chaddr = %s\n", | |||||||||||||||||||||||||||||||||||||||||
| 656 | substr( $self->chaddr(), 0, 2 * $self->hlen() ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | $s .= sprintf( "sname = %s\n", $self->sname() ); | |||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | $s .= sprintf( "file = %s\n", $self->file() ); | |||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | $s .= "Options : \n"; | |||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | for my $key ( @{ $self->{options_order} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | my $value; | |||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | ▶ | if ( exists $DHO_FORMATS{$key} && $DHO_FORMATS{$key} eq 'suboptions' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $Net::DHCP::Packet::DHO_FORMATS{$key} and $Net::DHCP::Packet::DHO_FORMATS{$key} eq "suboptions"
MC/DC0%0/2
exists $Net::DHCP::Packet::DHO_FORMATS{$key} and $Net::DHCP::Packet::DHO_FORMATS{$key} eq "suboptions"
exists $Net::DHCP::Packet::DHO_FORMATS{$key}
$Net::DHCP::Packet::DHO_FORMATS{$key} eq "suboptions"
Truth table0%0/3
A and B
A= exists $Net::DHCP::Packet::DHO_FORMATS{$key}B= $Net::DHCP::Packet::DHO_FORMATS{$key} eq "suboptions"
| |||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | for my $subkey ( @{ $self->{sub_options_order}->{$key} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | my $subvalue; | |||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | eval { $subvalue = join(q| |, $self->getSubOptionValue($key, $subkey)) }; | |||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | my $raw = $self->getSubOptionRaw($key, $subkey); | |||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | ▶ | $subvalue = defined $raw ? unpack('H*', $raw) : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | $subvalue = _printable($subvalue); | |||||||||||||||||||||||||||||||||||||||||
| 673 | $s .= sprintf(" %s(%d) = %s\n", | ||||||||||||||||||||||||||||||||||||||||||
| 674 | exists $SUBOPTION_CODES{$key} && exists $REV_SUBOPTION_CODES{$key}{$subkey} | ||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | ▶ | ? $REV_SUBOPTION_CODES{$key}{$subkey} : '', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $Net::DHCP::Packet::SUBOPTION_CODES{$key} and exists $Net::DHCP::Packet::REV_SUBOPTION_CODES{$key}{$subkey}
MC/DC0%0/2
exists $Net::DHCP::Packet::SUBOPTION_CODES{$key} and exists $Net::DHCP::Packet::REV_SUBOPTION_CODES{$key}{$subkey}
exists $Net::DHCP::Packet::SUBOPTION_CODES{$key}
exists $Net::DHCP::Packet::REV_SUBOPTION_CODES{$key}{$subkey}
Truth table0%0/3
A and B
A= exists $Net::DHCP::Packet::SUBOPTION_CODES{$key}B= exists $Net::DHCP::Packet::REV_SUBOPTION_CODES{$key}{$subkey}
| |||||||||||||||||||||||||||||||||||||||||||
| 676 | $key, $subvalue); | ||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | $value = 'see above'; | |||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||
| 680 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | $value = $self->getOptionValue($key); | |||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | ▶ | $value = $self->getOptionRaw($key) unless defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | ▶ | if ( defined $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | if ($key == DHO_DHCP_MESSAGE_TYPE() && exists $REV_DHCP_MESSAGE{$value}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key == 53 and exists $Net::DHCP::Packet::REV_DHCP_MESSAGE{$value}
MC/DC0%0/2
$key == 53 and exists $Net::DHCP::Packet::REV_DHCP_MESSAGE{$value}
$key == 53
exists $Net::DHCP::Packet::REV_DHCP_MESSAGE{$value}
Truth table0%0/3
A and B
A= $key == 53B= exists $Net::DHCP::Packet::REV_DHCP_MESSAGE{$value}
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | $value = $REV_DHCP_MESSAGE{$value}; | |||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | $value = _printable($value); | |||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | $value = '' unless defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | $s .= sprintf(" %s(%d) = %s\n", | ||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | ▶ | exists $REV_DHO_CODES{$key} ? $REV_DHO_CODES{$key} : '', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 694 | $key, $value); | ||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||
| 696 | $s .= sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 697 | "padding [%s] = %s\n", | ||||||||||||||||||||||||||||||||||||||||||
| 698 | length( $self->{padding} ), | ||||||||||||||||||||||||||||||||||||||||||
| 699 | unpack( 'H*', $self->{padding} ) | ||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | return $s | |||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | } # end toString | ||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 707 | # internal utility functions | ||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||
| 709 | sub _printable { | ||||||||||||||||||||||||||||||||||||||||||
| 710 | 19 | ▶ | my $str = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_printable: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | 19 | $str =~ s/([[:^print:]])/ sprintf q[\x%02X], ord $1 /eg; | |||||||||||||||||||||||||||||||||||||||||
| 712 | 19 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | sub packsuboptions { | ||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | ▶ | my @relay_opt = @_ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
packsuboptions: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 717 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | my $buf = ''; | |||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | for my $opt (@relay_opt) { | |||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | my $value = pack( 'C/a*', $opt->[1]); | |||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | $buf .= pack( 'C', $opt->[0]) | |||||||||||||||||||||||||||||||||||||||||
| 723 | . pack( 'C', length($value)) | ||||||||||||||||||||||||||||||||||||||||||
| 724 | . $value; | ||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | return pack( 'C', length($buf) ) . $buf | |||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||
| 730 | sub unpacksuboptions { | ||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||
| 732 | 17 | ▶ | my $opt_buf = shift or return; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpacksuboptions: called CC=4 SCAR=13.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||
| 734 | 17 | my @relay_opt; | |||||||||||||||||||||||||||||||||||||||||
| 735 | 17 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||
| 736 | 17 | my $total = byte_len($opt_buf); | |||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | 17 | ▶ | while ( $pos < $total ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 739 | 19 | my $type = ord( substr( $opt_buf, $pos++, 1 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 740 | 19 | my $len = ord( substr( $opt_buf, $pos++, 1 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 741 | 19 | ▶ | $len = $total - $pos if $pos + $len > $total; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 742 | 19 | my $option = substr( $opt_buf, $pos, $len ); | |||||||||||||||||||||||||||||||||||||||||
| 743 | 19 | $pos += $len; | |||||||||||||||||||||||||||||||||||||||||
| 744 | 19 | push @relay_opt, [ $type, $option ]; | |||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||
| 747 | return @relay_opt | ||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||
| 749 | 17 | } | |||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | sub packclientid { | ||||||||||||||||||||||||||||||||||||||||||
| 753 | return shift | ||||||||||||||||||||||||||||||||||||||||||
| 754 | # croak('pack clientid field still WIP'); | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
packclientid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||
| 757 | sub unpackclientid { | ||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | ▶ | my $clientid = shift | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpackclientid: not called CC=4 SCAR=30.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 760 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | ## See https://tools.ietf.org/html/rfc2132#section-9.14 | ||||||||||||||||||||||||||||||||||||||||||
| 764 | ## See also https://tools.ietf.org/html/rfc4361 | ||||||||||||||||||||||||||||||||||||||||||
| 765 | # The code for this option is 61, and its minimum length is 2. | ||||||||||||||||||||||||||||||||||||||||||
| 766 | # | ||||||||||||||||||||||||||||||||||||||||||
| 767 | # Code Len Type Client-Identifier | ||||||||||||||||||||||||||||||||||||||||||
| 768 | # +-----+-----+-----+-----+-----+--- | ||||||||||||||||||||||||||||||||||||||||||
| 769 | # | 61 | n | t1 | i1 | i2 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 770 | # +-----+-----+-----+-----+-----+--- | ||||||||||||||||||||||||||||||||||||||||||
| 771 | # | ||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | my $type = unpack('C',substr( $clientid, 0, 1 )); | |||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | ▶ | if ($type == 0) { # fqdn i.e. text | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | return substr( $clientid, 1, length($clientid) ) | |||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | # Types from here on down are from 'Address Resolution Protocol' section in RFC1700 | ||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | ▶ | if ($type == 1) { # ethernet | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | return unpack('H*',substr( $clientid, 1, length($clientid) )) | |||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | # Copied here for future reference | ||||||||||||||||||||||||||||||||||||||||||
| 785 | # Number Hardware Type (hrd) References | ||||||||||||||||||||||||||||||||||||||||||
| 786 | # ------ ----------------------------------- ---------- | ||||||||||||||||||||||||||||||||||||||||||
| 787 | # 1 Ethernet (10Mb) [JBP] | ||||||||||||||||||||||||||||||||||||||||||
| 788 | # 2 Experimental Ethernet (3Mb) [JBP] | ||||||||||||||||||||||||||||||||||||||||||
| 789 | # 3 Amateur Radio AX.25 [PXK] | ||||||||||||||||||||||||||||||||||||||||||
| 790 | # 4 Proteon ProNET Token Ring [JBP] | ||||||||||||||||||||||||||||||||||||||||||
| 791 | # 5 Chaos [GXP] | ||||||||||||||||||||||||||||||||||||||||||
| 792 | # 6 IEEE 802 Networks [JBP] | ||||||||||||||||||||||||||||||||||||||||||
| 793 | # 7 ARCNET [JBP] | ||||||||||||||||||||||||||||||||||||||||||
| 794 | # 8 Hyperchannel [JBP] | ||||||||||||||||||||||||||||||||||||||||||
| 795 | # 9 Lanstar [TU] | ||||||||||||||||||||||||||||||||||||||||||
| 796 | # 10 Autonet Short Address [MXB1] | ||||||||||||||||||||||||||||||||||||||||||
| 797 | # 11 LocalTalk [JKR1] | ||||||||||||||||||||||||||||||||||||||||||
| 798 | # 12 LocalNet (IBM PCNet or SYTEK LocalNET) [JXM] | ||||||||||||||||||||||||||||||||||||||||||
| 799 | # 13 Ultra link [RXD2] | ||||||||||||||||||||||||||||||||||||||||||
| 800 | # 14 SMDS [GXC1] | ||||||||||||||||||||||||||||||||||||||||||
| 801 | # 15 Frame Relay [AGM] | ||||||||||||||||||||||||||||||||||||||||||
| 802 | # 16 Asynchronous Transmission Mode (ATM) [JXB2] | ||||||||||||||||||||||||||||||||||||||||||
| 803 | # 17 HDLC [JBP] | ||||||||||||||||||||||||||||||||||||||||||
| 804 | # 18 Fibre Channel [Yakov Rekhter] | ||||||||||||||||||||||||||||||||||||||||||
| 805 | # 19 Asynchronous Transmission Mode (ATM) [Mark Laubach] | ||||||||||||||||||||||||||||||||||||||||||
| 806 | # 20 Serial Line [JBP] | ||||||||||||||||||||||||||||||||||||||||||
| 807 | # 21 Asynchronous Transmission Mode (ATM) [MXB1] | ||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | return $clientid | |||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | sub packsipserv { | ||||||||||||||||||||||||||||||||||||||||||
| 814 | return shift | ||||||||||||||||||||||||||||||||||||||||||
| 815 | # croak('pack sipserv field still WIP'); | ||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
packsipserv: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | sub unpacksipserv { | ||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | ▶ | my $sipserv = shift | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpacksipserv: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 821 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | my $type = unpack('C',substr( $sipserv, 0, 1 )); | |||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||
| 825 | # if ($type == 0) { # text | ||||||||||||||||||||||||||||||||||||||||||
| 826 | # return substr( $sipserv, 1, length($clientid) ) | ||||||||||||||||||||||||||||||||||||||||||
| 827 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | if ($type == 1) { # ipv4 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | return unpackinet(substr( $sipserv, 1, length($sipserv) )) | |||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | return $sipserv | |||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | } | ||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||
| 836 | sub packcsr { | ||||||||||||||||||||||||||||||||||||||||||
| 837 | # catch empty value | ||||||||||||||||||||||||||||||||||||||||||
| 838 | 0 | ▶ | my $results = [ '' ]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
packcsr: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | for my $pair ( @{$_[0]} ) { | |||||||||||||||||||||||||||||||||||||||||
| 841 | 0 | ▶ | push @$results, '' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 842 | if (length($results->[-1]) > 255 - 8); | ||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | my ($ip, $mask) = split /\//, $pair->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | ▶ | $mask = '32' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 846 | unless (defined($mask)); | ||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | my $addr = packinet($ip); | |||||||||||||||||||||||||||||||||||||||||
| 849 | 0 | $addr = substr $addr, 0, int(($mask - 1)/8 + 1); | |||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | $results->[-1] .= pack('C', $mask) . $addr; | |||||||||||||||||||||||||||||||||||||||||
| 852 | 0 | $results->[-1] .= packinet($pair->[1]); | |||||||||||||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | return $results; | |||||||||||||||||||||||||||||||||||||||||
| 856 | } | ||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | sub unpackcsr { | ||||||||||||||||||||||||||||||||||||||||||
| 859 | 0 | ▶ | my $csr = shift | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpackcsr: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 860 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | croak('unpack csr field still WIP'); | |||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||
| 866 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | __END__ | ||||||||||||||||||||||||||||||||||||||||||