Subject: | NetPacket::IP includes trailing trash bytes in $ip->{data} |
Date: | Wed, 26 Apr 2006 22:40:59 +0200 |
To: | bug-NetPacket [...] rt.cpan.org |
From: | Max Maischein <corion [...] corion.net> |
Hello,
I'm not completely sure that this is a bug in NetPacket::IP, but the
behaviour was contrary to my expectation. Maybe the documentation should
be expanded.
I found that NetPacket::IP doesn't check the payload length entry in the
IP header but includes everything after the header in the $ip->{data}
string, even if $ip->{len} claims there is less data than what was sent.
The attached test program includes a sample IP packet which Ethereal
decodes as one byte shorter than NetPacket::IP.
I think it should be either documented that $ip->{data} contains
everything that was sent, or the code should be changed so
length $ip->{data} == $ip->{len}
is always true.
Hope that helps,
-max
#!/usr/bin/perl -w
use strict;
use Test::More tests => 3;
use Data::Dumper;
use_ok 'NetPacket::IP';
my $raw_packet = <<PACKET; # hex-encoded
45 10
00 2d d1 8a 00 00 31 06 fc 28 40 e9 b9 13 c0 a8
01 63 00 50 d8 7b 65 a4 13 f8 6d 4d 81 b7 50 19
3e 2d 30 0a 00 00 30 0d 0a 0d 0a 15
PACKET
# Convert the above dump to the original Ethernet frame
$raw_packet =~ s!^\d{4}!!mg;
$raw_packet =~ s!\s!!g;
$raw_packet =~ s!([a-f0-9]{2})!chr hex $1!eg;
my $ip = NetPacket::IP->decode($raw_packet);
warn Dumper $ip;
is length $ip->{data}, $ip->{len}- $ip->{hlen}*4;