Skip to main content

internet_checksum

Function internet_checksum 

Source
pub fn internet_checksum(data: &[u8]) -> u16
Expand description

Calculate the Internet checksum (RFC 1071).

This is used for IP, ICMP, TCP, and UDP checksums.

§Algorithm

  1. Sum all 16-bit words in the data
  2. Add any odd byte as the high byte of a word
  3. Fold 32-bit sum to 16 bits by adding carry bits
  4. Take one’s complement of the result