Skip to main content

Crate ip4sum

Crate ip4sum 

Source
Expand description

IPv4 header checksum calculation.

This crate provides a highly optimized, no_std compatible implementation of the Internet checksum defined in RFC 1071 and used in IPv4, TCP, UDP, and ICMP headers.

§Examples

One-shot computation:

let data = [0x45, 0x00, 0x00, 0x30, 0x00, 0x00, 0x40, 0x00,
            0x40, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x01,
            0x0a, 0x00, 0x00, 0x02];

let csum = ip4sum::checksum(&data);

Incremental computation with Checksum:

use ip4sum::Checksum;

let mut hasher = Checksum::new();
hasher.update(&[0x45, 0x00, 0x00, 0x30, 0x00, 0x00, 0x40, 0x00,
               0x40, 0x01]);
hasher.update(&[0x00, 0x00]); // checksum field placeholder
hasher.update(&[0x0a, 0x00, 0x00, 0x01, 0x0a, 0x00, 0x00, 0x02]);
let csum = hasher.finalize();

Structs§

Checksum
An incremental Internet checksum calculator.

Functions§

checksum
Compute the Internet checksum of a byte slice.