chaddr => 'XX:XX:XX:XX:XX:XX', # MAC Address of sending interface
####
sleep 5; # allow capture process to establish
sleep 10; # allow capture
####
#my @macaddr = split(/:/, $chaddr);
my @chaddr = split(/:/, $chaddr);
#push(@macaddr, 0) for (1..10);
push(@chaddr,(0)x10);
#my @chaddr = map { hex($_) } @macaddr;
@chaddr = map { hex } @chaddr;
# or combined, using the clearer(?) @macaddr:
@macaddr = map { hex } (split/:/,'10:FF:2B:40:8C:FE'), (0)x10;
####
for (my $i = 0; $i <= $#options; $i++) {
my $option = hex($options[$i++]);
last if ($option == 255); # end of DHCP Options
my $length = $options[$i++]; # i = 0
my $offset = hex($length) + $i;
for (my $k = $i; $k <= ($offset - 1); $k++ ) {
push(@{$opts{$option}}, $options[$k]);
}
$i = $offset - 1;
}
####
for my $key (keys %opts) {
print $key, " ", dhcp_option($key),"\t";
if (ref($opts{$key}) =~ m/ARRAY/) {
print $_, " " foreach (@{$opts{$key}});
}
# NOTE: elsif can just be else, as a string
# necessarily does or does not match /ARRAY/
elsif (ref($opts{$key}) !~ /ARRAY/) {
print $opts{$key};
}
print "\n";
}
# OR (untested):
for my $key (keys %opts) {
print "$key ", dhcp_option($key), "\t",
( ref($opts{$key}) =~ /ARRAY/
? join" ", @{$opts{$key}}
: $opts{$key}
)
"\n";
}