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

People
Owner: Nobody in particular
Requestors: guh [...] open.ch
Cc:
AdminCc:

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



Subject: IP encoding reports an error / Ethernet encoding not existing
Date: Mon, 17 Mar 2014 17:00:47 +1100
To: bug-NetPacket [...] rt.cpan.org
From: Guido Hungerbuehler <guh [...] open.ch>
Hi I just encountered some un-nice behaviour of NetPacket when calling either $ip_obj->encode() or $eth_obj->encode(). NetPacket/Ethernet.pm: $eth_obj->encode() seems not being implemented. Could you add the following code? --- /opt/OSAGperlm/lib/NetPacket/Ethernet.pm 2014-03-17 05:47:37.000000000 +0100 +++ Ethernet.pm 2014-03-17 05:34:36.000000000 +0100 @@ -130,7 +130,14 @@ # sub encode { - die("Not implemented"); + my ($self) = shift; + + (my $dest = $self->{src_mac}) =~ s/://g; + (my $src = $self->{dest_mac}) =~ s/://g; + + my $frame = pack('H12H12n a*', $dest, $src, 0x0800, $self->{data}); + return $frame; } # NetPacket/IP.pm: $ip_obj->encode() complains if no IP-Options are present (e.g. undef): diff -Naur /opt/OSAGperlm/lib/NetPacket/IP.pm IP.pm --- /opt/OSAGperlm/lib/NetPacket/IP.pm 2013-07-04 10:34:56.000000000 +0200 +++ IP.pm 2014-03-17 06:58:53.000000000 +0100 @@ -188,21 +188,28 @@ $src_ip = gethostbyname($self->{src_ip}); $dest_ip = gethostbyname($self->{dest_ip}); + my $fmt = 'CCnnnCCna4a4a*'; + my @pkt = ($tmp, $self->{tos},$self->{len}, + $self->{id}, $offset, $self->{ttl}, $self->{proto}, + $zero, $src_ip, $dest_ip); + # change format and package in case of IP options + if(defined $self->{options}){ + $fmt = 'CCnnnCCna4a4a*a*'; + push(@pkt, $self->{options}); + } + # construct header to calculate the checksum - $hdr = pack('CCnnnCCna4a4a*', $tmp, $self->{tos},$self->{len}, - $self->{id}, $offset, $self->{ttl}, $self->{proto}, - $zero, $src_ip, $dest_ip, $self->{options}); - + $hdr = pack($fmt, @pkt); $self->{cksum} = NetPacket::htons(NetPacket::in_cksum($hdr)); + $pkt[7] = $self->{cksum}; # make the entire packet - $packet = pack('CCnnnCCna4a4a*a*', $tmp, $self->{tos},$self->{len}, - $self->{id}, $offset, $self->{ttl}, $self->{proto}, - $self->{cksum}, $src_ip, $dest_ip, $self->{options}, - $self->{data}); + if(defined $self->{data}){ + push(@pkt, $self->{data}); + } + $packet = pack($fmt, @pkt); return($packet); - } # Would be great to see this patches in the official CPAN module :-) Or if you like, any variation of it. cheers guido
Download smime.p7s
application/pkcs7-signature 3.9k

Message body not shown because it is not plain text.

On Mon Mar 17 02:01:49 2014, guh@open.ch wrote: Show quoted text
> Hi > > I just encountered some un-nice behaviour of NetPacket when calling > either $ip_obj->encode() or $eth_obj->encode(). > > NetPacket/Ethernet.pm: $eth_obj->encode() seems not being implemented. > Could you add the following code?
Sorry for the delay. Patch added, and new version of NetPacket on its way to CPAN. Thanks! Joy, `/anick