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: 85361
Status: resolved
Priority: 0/
Queue: NetPacket

People
Owner: Nobody in particular
Requestors: koncept1 [...] gmail.com
Cc:
AdminCc:

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



Subject: UDP Encode Method issue
Date: Thu, 16 May 2013 18:20:54 -0400
To: bug-NetPacket [...] rt.cpan.org
From: Ben Magistro <koncept1 [...] gmail.com>
There appears to be an issue in the NetPacket::UDP module where it is looking in $self for the parameters but they are stored in $ip unless I am calling this function incorrectly. The fix appears to be changing $self-> to $ip-> in the encode and checksum functions. Thanks
As a follow up to this, if it is called as NetPacket::UDP->encode($l4 ,$l3) returns "Can't use string ("NetPacket::UDP") as a HASH ref while "strict refs" in use" however calling it as NetPacket::UDP::encode($l4, $l3); appears to work so one optioin would be updating the POD another would fixing the module to properly bless things into the class. I may take a shot at that and post a patch. On Thu May 16 18:21:14 2013, koncept1@gmail.com wrote: Show quoted text
> There appears to be an issue in the NetPacket::UDP module where it is > looking in $self for the parameters but they are stored in $ip unless I am > calling this function incorrectly. The fix appears to be changing $self-> > to $ip-> in the encode and checksum functions. > > Thanks
Final follow up, bug is likely more of a desired feature/behavior and looks to have existed since the begining. Attached is a untested patch (did not test applying), changes in it have been tested against 1.3.3 on perl 5.14.2 to allow arbitrary packet creation. At present it appears that encode expects a packet to have been decoded by this module previously which does not allow packets to be generated by providing the L3, L4 and payload information. On Thu May 16 22:01:26 2013, http://openid-provider.appspot.com/koncept1 wrote: Show quoted text
> As a follow up to this, if it is called as NetPacket::UDP->encode($l4 > ,$l3) returns "Can't use string ("NetPacket::UDP") as a HASH ref > while "strict refs" in use" however calling it as > NetPacket::UDP::encode($l4, $l3); appears to work so one optioin > would be updating the POD another would fixing the module to > properly bless things into the class. I may take a shot at that > and post a patch. > > On Thu May 16 18:21:14 2013, koncept1@gmail.com wrote:
> > There appears to be an issue in the NetPacket::UDP module where it
> is
> > looking in $self for the parameters but they are stored in $ip
> unless I am
> > calling this function incorrectly. The fix appears to be changing
> $self->
> > to $ip-> in the encode and checksum functions. > > > > Thanks
> >
Subject: UDP.pm.patch
--- /usr/local/share/perl/5.14.2/NetPacket/UDP.pm 2013-05-16 22:45:39.517348883 -0400 +++ /tmp/UDP.pm 2013-05-15 23:36:38.000000000 -0400 @@ -83,21 +83,20 @@ # sub encode { - my $class = shift; - my $self = {}; - bless($self, $class); - my ($udp, $ip) = @_; + + my $self = shift; + my ($ip) = @_; my ($packet); - + # Adjust the length accodingly - $udp->{len} = 8 + length($udp->{data}); + $self->{len} = 8 + length($self->{data}); # First of all, fix the checksum $self->checksum($ip); # Put the packet together - $packet = pack("nnnna*", $udp->{src_port},$udp->{dest_port}, - $udp->{len}, $udp->{cksum}, $udp->{data}); + $packet = pack("nnnna*", $self->{src_port},$self->{dest_port}, + $self->{len}, $self->{cksum}, $self->{data}); return($packet); } @@ -152,7 +151,7 @@ use NetPacket::UDP; $udp_obj = NetPacket::UDP->decode($raw_pkt); - $udp_pkt = NetPacket::UDP->encode($l4_obj, $l3_obj); + $udp_pkt = NetPacket::UDP->encode($ip_obj); $udp_data = NetPacket::UDP::strip($raw_pkt); =head1 DESCRIPTION @@ -171,12 +170,11 @@ It is the responsibility of the programmer to ensure valid packet data is passed to this method. -=item C<NetPacket::UDP-E<gt>encode($l4_obj, $l3_obj)> +=item C<NetPacket::UDP-E<gt>encode($ip_obj)> -Return a UDP packet encoded with the instance data specified in $l4_obj. Needs -part of the IP header contained (src_ip and dest_ip specifically) in $l3_obj, -in order to calculate the UDP checksum. The length field will also be set -automatically based on values provided. +Return a UDP packet encoded with the instance data specified. Needs parts +of the IP header contained in $ip_obj, the IP object, in order to calculate +the UDP checksum. The length field will also be set automatically. =back @@ -225,24 +223,6 @@ =back -=head2 IP data - -The IP data for the $l3_obj object consists of the following fields. -Additional items may be supplied as well as passing the whole -object returned by NetPacket::IP->decode but are unnecessary. - -=over - -=item src_ip - -The source IP for the datagram - -=item dest_ip - -The destination IP for the datagram - -=back - =head2 Exports =over @@ -327,7 +307,7 @@ $udp_obj->{data} =~ s/foo/bar/g; # reencode the packet - $ip_obj->{data} = $udp_obj->encode($udp_obj, $ip_obj); + $ip_obj->{data} = $udp_obj->encode($ip_obj); $data = $ip_obj->encode; }
Patched in master. Thanks! And yes, the module is slightly limited if one wants to create the packet from scratches. I'll try to fix that in an upcoming iteration.
I talked to one of my friends after I sent this patch to get their take and they suggested calling ->decode(undef); then go ahead and update the values desired/necessary at which point calling ->encode works and provide similar functionality to the patch which would just be POD updates. I'm thinking the patch is a better solution but figured you should know about both. If I get ambitious I'll see if I can put similar patches together for other parts of this module. On Fri May 17 19:57:33 2013, YANICK wrote: Show quoted text
> Patched in master. Thanks! > > And yes, the module is slightly limited if one wants to create the > packet from scratches. I'll try to fix that in an upcoming iteration.