libpnet icon indicating copy to clipboard operation
libpnet copied to clipboard

'arithmetic operation overflowed' when not calling set_header_length

Open BenKnigge opened this issue 9 years ago • 0 comments

The following code sample will panic with an 'arithmetic operation overflowed' error if set_header_length is not called or if the value is set to 16 or greater

let mut bytes = [0u8; 100];
let mut ethernet : MutableEthernetPacket = ethernet::MutableEthernetPacket::new(&mut bytes).unwrap();
ethernet.set_source(mac);
ethernet.set_destination(mac);

{
    let mut ipv4 = pnet::packet::ipv4::MutableIpv4Packet::new(ethernet.payload_mut()).unwrap();

    ipv4.set_source(source_ip);
    ipv4.set_destination(destination_ip);
    //ipv4.set_header_length(8);
    ipv4.set_dscp(0);

    {
        let mut echo = echo_request::MutableEchoRequestPacket::new(ipv4.payload_mut()).unwrap();

        echo.set_icmp_type(icmp::icmp_types::EchoRequest);
        echo.set_icmp_code(echo_request::icmp_codes::NoCode);
        echo.set_identifier(1);
        echo.set_sequence_number(1);

    }


}

BenKnigge avatar Jun 15 '16 20:06 BenKnigge