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