Struct etherparse::checksum::Sum16BitWords
source · pub struct Sum16BitWords { /* private fields */ }
Expand description
Helper for calculating the sum of all 16 bit words checksums used in in checksum fields in TCP and UDP headers.
Implementations§
source§impl Sum16BitWords
impl Sum16BitWords
pub fn new() -> Sum16BitWords
sourcepub fn add_slice(self, slice: &[u8]) -> Sum16BitWords
pub fn add_slice(self, slice: &[u8]) -> Sum16BitWords
Add the given slice to the checksum. In case the slice has a length that is not multiple of 2 the last byte will be padded with 0.
sourcepub fn add_2bytes(self, value: [u8; 2]) -> Sum16BitWords
pub fn add_2bytes(self, value: [u8; 2]) -> Sum16BitWords
Add a 2 byte word.
sourcepub fn add_4bytes(&mut self, value: [u8; 4]) -> Sum16BitWords
pub fn add_4bytes(&mut self, value: [u8; 4]) -> Sum16BitWords
Add a 4 byte word.
sourcepub fn add_8bytes(&mut self, value: [u8; 8]) -> Sum16BitWords
pub fn add_8bytes(&mut self, value: [u8; 8]) -> Sum16BitWords
Add a 8 byte word.
sourcepub fn add_16bytes(&mut self, value: [u8; 16]) -> Sum16BitWords
pub fn add_16bytes(&mut self, value: [u8; 16]) -> Sum16BitWords
Add a 16 bytes.
sourcepub fn ones_complement(&self) -> u16
pub fn ones_complement(&self) -> u16
Converts summed up words from an u32 to an u16 ones complement which can be used in a ipv4 checksum.
sourcepub fn to_ones_complement_with_no_zero(&self) -> u16
pub fn to_ones_complement_with_no_zero(&self) -> u16
Converts summed up words from an u32 to an u16 ones complement with 0 beeing replaced by 0xffff (usefull for TCP and UDP).
This kind of checksum is used in TCP and UDP headers.
Trait Implementations§
source§impl Clone for Sum16BitWords
impl Clone for Sum16BitWords
source§fn clone(&self) -> Sum16BitWords
fn clone(&self) -> Sum16BitWords
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for Sum16BitWords
impl Debug for Sum16BitWords
source§impl Default for Sum16BitWords
impl Default for Sum16BitWords
source§fn default() -> Sum16BitWords
fn default() -> Sum16BitWords
Returns the “default value” for a type. Read more