Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the NetPacket CPAN distribution.

Report information
The Basics
Id: 18941
Status: resolved
Priority: 0/
Queue: NetPacket

People
Owner: Nobody in particular
Requestors: corion [...] corion.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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;
I forgot to mention how I work around it in my code: my $i = NetPacket::IP->decode($ip); # Safeguard against malformed IP headers $i->{hlen} = 5 if $i->{hlen} < 5; #warn sprintf "Data length: %d/%d", length $i->{data}, $i->{len} - ($i->{hlen}*4); my $payload = substr($i->{data}, 0, $i->{len}-($i->{hlen}*4));
From: Perl n00b
I don't get it, why is $i-{hlen} always 5? On Wed Apr 26 16:42:54 2006, CORION wrote: Show quoted text
> I forgot to mention how I work around it in my code: > > my $i = NetPacket::IP->decode($ip); > > # Safeguard against malformed IP headers > $i->{hlen} = 5 > if $i->{hlen} < 5; > #warn sprintf "Data length: %d/%d", length $i->{data}, $i->{len} - > ($i->{hlen}*4); > > my $payload = substr($i->{data}, 0, $i->{len}-($i->{hlen}*4));
Subject: Re: [rt.cpan.org #18941] NetPacket::IP includes trailing trash bytes in $ip->{data}
Date: Tue, 23 May 2006 21:56:57 +0200
To: bug-NetPacket [...] rt.cpan.org
From: Max Maischein <corion [...] corion.net>
Show quoted text
> I don't get it, why is $i-{hlen} always 5?
Just in the case that $i->{hlen} is shorter than 5 I set it to 5. -max