1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#!/usr/bin/perl -wT
use Test::More tests => 11;
BEGIN { use_ok( 'Net::DHCP::Packet' ); }
BEGIN { use_ok( 'Net::DHCP::Constants' ); }
use strict;
my $ip0 = "0.0.0.0";
my $pac0 = "\0\0\0\0";
my $pac;
eval {
$pac = Net::DHCP::Packet->new("");
};
#diag($@);
like( $@, qr/marshall: packet too small/, "packet too small");
eval {
$pac = Net::DHCP::Packet->new("\0" x 2000);
};
#diag($@);
like( $@, qr/marshall: packet too big/, "packet too big");
eval {
$pac = Net::DHCP::Packet->new( Net::DHCP::Packet->new()->serialize());
};
#diag($@);
ok( ! $@, "verifying default packet");
my $pac_without_option_end = pack("H*",
"0101060012345678000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"0000000000000000000000006382536300000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"000000000000000000000000"
);
eval {
$pac = Net::DHCP::Packet->new($pac_without_option_end);
};
#diag($@);
like( $@, qr/marshall: unexpected end of options/, "marshall: unexpected end of options");
# now test serialize
$pac = Net::DHCP::Packet->new();
$pac->padding("\0" x 2000);
eval {
$pac->serialize();
};
#diag($@);
like($@, qr/serialize: packet too big/, "serialize: packet too big");
# testing DHO_DHCP_MAX_MESSAGE_SIZE conformance
my %options = ( DHO_DHCP_MAX_MESSAGE_SIZE() => 200);
my $ref_pac = pack("H*",
"0101060012345678000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"00000000000000000000000063825363ff000000000000000000000000000000".
"0000000000000000000000000000000000000000000000000000000000000000".
"00000000000000000000000000000000"
);
$pac = Net::DHCP::Packet->new($ref_pac);
eval {
$pac->serialize(\%options);
};
#diag($@);
ok( ! $@, "DHO_DHCP_MAX_MESSAGE_SIZE too small");
$options{DHO_DHCP_MAX_MESSAGE_SIZE()} = 2000;
eval {
$pac->serialize(\%options);
};
#diag($@);
ok( ! $@, "DHO_DHCP_MAX_MESSAGE_SIZE too big");
$options{DHO_DHCP_MAX_MESSAGE_SIZE()} = 305;
eval {
$pac->serialize(\%options);
};
#diag($@);
ok( ! $@, "DHO_DHCP_MAX_MESSAGE_SIZE is ok");
$options{DHO_DHCP_MAX_MESSAGE_SIZE()} = 302;
eval {
$pac->serialize(\%options);
};
#diag($@);
like($@, qr/serialize: message is bigger than allowed/, "serialize: packet too big");
|