[NETFRAME] IPv4 checksum not being computed

GomoR gomor at gomor.org
Thu Apr 24 10:10:06 CEST 2008


Hi Carlos,

that's because you create a custom Net::Packet::Env object, but do 
not use it. You may also replace values from the default $Env object, 
like this:

--- src.pl      2008-04-24 09:59:19.000000000 +0200
+++ dst.pl      2008-04-24 10:00:17.000000000 +0200
@@ -1,6 +1,6 @@
     # Build custom environment object
-    my $env = Net::Packet::Env->new( dev            => $interface,
-                     mac            => $srcmac,
-                     ip             => '0.0.0.0',
-                     doIPv4Checksum => 1,
-                     ip6            => '::' );
+    $Env->dev($interface);
+    $Env->mac($srcmac);
+    $Env->ip('0.0.0.0');
+    $Env->doIPv4Checksum(1);
+    $Env->ip6('::');
+    $Env->debug(3);

That should do it. Also, you should consider switching to Net::Frame, 
it is the now prefered framework.


On Wed, Apr 23, 2008 at 02:45:00PM -0700, Carlos Vicente wrote:
> Hi Patrice,
> 
> I have updated Net::Packet on a server where I have been runing a rogue
> dhcp detection script for a while now.  I noticed the API changed
> slightly: the "doChecksum"
> parameter is no longer passed to Net::Packet::IPv4->new(), but now there
> is a "doIPv4Checksum" in Net::Packet::Env which looks like does the same.
> 
> However, after adapting the code to the new API, I find that my IPv4
> packets are coming out with a checksum of 0:
> 
> 14:19:10.083593 IP (tos 0x0, ttl 128, id 2943, offset 0, flags [none],
> proto: UDP (17), length: 328, bad cksum 0 (->2e27)!) 0.0.0.0.bootpc >
> 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:30:48:83:9c:5f (oui
> Unknown), length: 300, xid:0xc175093c, flags: [none] (0x0000)
>           Client Ethernet Address: 00:30:48:83:9c:5f (oui Unknown) [|bootp]
>         0x0000:  4500 0148 0b7f 0000 8011 0000 0000 0000  E..H............
>         0x0010:  ffff ffff 0044 0043 0134 5854 0101 0600  .....D.C.4XT....
>         0x0020:  c175 093c 0000 0000 0000 0000 0000 0000  .u.<............
>         0x0030:  0000 0000 0000 0000 0030 4883 9c5f 0000  .........0H.._..
>         0x0040:  0000 0000 0000 0000 0000 0000 0000 0000  ................
>         0x0050:  0000                                     ..
> 
> I also tried other tricks, like computing the checksum and passing it
> explicitly, but that did not help.  Any ideas?
> 
> For reference, I'm copying the relevant sections of code below.  Any
> help with this is much appreciated.
> 
> Regards,
> 
> cv
> 
> 
> 
>     # Build custom environment object
>     my $env = Net::Packet::Env->new( dev            => $interface,
>                      mac            => $srcmac,
>                      ip             => '0.0.0.0',
>                      doIPv4Checksum => 1,
>                      ip6            => '::' );
> 
>     # Build Layer2 descriptor object
>     # This is also necessary to get the packets leaving
>     # on the right interface, if it is not the default one
>     my $desc = Net::Packet::DescL2->new( dev   => $interface,
>                      mac   => $srcmac,
>                      ip    => '0.0.0.0',
>                      ip6   => '::' );
> 
>     # Build IPv4 header
>     my $ip = Net::Packet::IPv4->new( src        => '0.0.0.0',
>                      dst        => '255.255.255.255',
>                      protocol   => NP_IPv4_PROTOCOL_UDP,
>                     );
> 
>     # Build UDP header
>     my $udp = Net::Packet::UDP->new( src  => 68, dst  => 67 );
> 
>     # Build the DHCP REQUEST packet
>     my $dhcpreq = Net::DHCP::Packet->new( Xid                     =>
> int(rand(0xFFFFFFFF)), # random xid
>                       Flags                   => 0x0000,
>                       Hlen                    => 6,
>                       Htype                   => 1,
>                       Chaddr                  => $srcmac,
>                       DHO_DHCP_MESSAGE_TYPE() => DHCPDISCOVER() );
> 
>     # Build the application layer object
>     my $dhcp = Net::Packet::Layer7->new( data => $dhcpreq->serialize );
> 
>     # Assemble Ethernet Frame
>     my $eth = Net::Packet::ETH->new( src  => $srcmac, dst  =>
> "ff:ff:ff:ff:ff:ff" );
> 
>     # Now put everything together
>     my $frame = Net::Packet::Frame->new( l2  => $eth,
>                      l3  => $ip,
>                      l4  => $udp,
>                      l7  => $dhcp );
>     $frame->send;
> 
> _______________________________________________
> netframe site list
> netframe at lists.gomor.org
> http://lists.gomor.org/mailman/listinfo/netframe
> 

-- 
  ^  ___  ___             http://www.GomoR.org/          <-+
  | / __ |__/               Research Engineer              |
  | \__/ |  \     ---[ zsh$ alias psed='perl -pe ' ]---    |
  +-->  Net::Frame <=> http://search.cpan.org/~gomor/  <---+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 1728 bytes
Desc: not available
Url : http://lists.gomor.org/pipermail/netframe/attachments/20080424/67238e8b/attachment.bin 


More information about the netframe mailing list