[NETFRAME] IPv4 checksum not being computed

Carlos Vicente cvicente at network-services.uoregon.edu
Wed Apr 23 23:45:00 CEST 2008


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;



More information about the netframe mailing list