Struct etherparse::Ipv4Header
source · pub struct Ipv4Header {Show 13 fields
pub header_length: u8,
pub differentiated_services_code_point: u8,
pub explicit_congestion_notification: u8,
pub total_length: u16,
pub identification: u16,
pub dont_fragment: bool,
pub more_fragments: bool,
pub fragments_offset: u16,
pub time_to_live: u8,
pub protocol: u8,
pub header_checksum: u16,
pub source: [u8; 4],
pub destination: [u8; 4],
}
Expand description
IPv4 header without options.
Fields§
§header_length: u8
§differentiated_services_code_point: u8
§explicit_congestion_notification: u8
§total_length: u16
§identification: u16
§dont_fragment: bool
§more_fragments: bool
§fragments_offset: u16
§time_to_live: u8
§protocol: u8
§header_checksum: u16
§source: [u8; 4]
§destination: [u8; 4]
Implementations§
source§impl Ipv4Header
impl Ipv4Header
sourcepub fn new(
payload_and_options_length: usize,
time_to_live: u8,
protocol: IpTrafficClass,
source: [u8; 4],
destination: [u8; 4]
) -> Result<Ipv4Header, ValueError>
pub fn new(
payload_and_options_length: usize,
time_to_live: u8,
protocol: IpTrafficClass,
source: [u8; 4],
destination: [u8; 4]
) -> Result<Ipv4Header, ValueError>
Constructs an Ipv4Header with standard values for non specified values. Note: This header calculates the checksum assuming that there are no ipv4 options. In case there are calculate the checksum using the “calc_header_checksum” method.
sourcepub fn read<T: Read + Seek + Sized>(
reader: &mut T
) -> Result<Ipv4Header, ReadError>
pub fn read<T: Read + Seek + Sized>(
reader: &mut T
) -> Result<Ipv4Header, ReadError>
Reads an IPv4 header from the current position.
sourcepub fn read_without_version<T: Read + Seek + Sized>(
reader: &mut T,
version_rest: u8
) -> Result<Ipv4Header, Error>
pub fn read_without_version<T: Read + Seek + Sized>(
reader: &mut T,
version_rest: u8
) -> Result<Ipv4Header, Error>
Reads an IPv4 header assuming the version & ihl field have already been read.
sourcepub fn skip_options<T: Read + Seek + Sized>(
&self,
reader: &mut T
) -> Result<(), ReadError>
pub fn skip_options<T: Read + Seek + Sized>(
&self,
reader: &mut T
) -> Result<(), ReadError>
Skips the ipv4 header options based on the header length.
sourcepub fn write<T: Write + Sized>(
&self,
writer: &mut T,
options: &[u8]
) -> Result<(), WriteError>
pub fn write<T: Write + Sized>(
&self,
writer: &mut T,
options: &[u8]
) -> Result<(), WriteError>
Writes a given IPv4 header to the current position (this method automatically calculates the header length and checksum).
sourcepub fn write_raw<T: Write + Sized>(
&self,
writer: &mut T,
options: &[u8]
) -> Result<(), WriteError>
pub fn write_raw<T: Write + Sized>(
&self,
writer: &mut T,
options: &[u8]
) -> Result<(), WriteError>
Writes a given IPv4 header to the current position (this method just writes the specified checksum and header_length and does note compute it).
sourcepub fn calc_header_checksum(&self, options: &[u8]) -> Result<u16, ValueError>
pub fn calc_header_checksum(&self, options: &[u8]) -> Result<u16, ValueError>
Calculate header checksum of the current ipv4 header.
sourcepub fn set_payload_and_options_length(
&mut self,
size: usize
) -> Result<(), ValueError>
pub fn set_payload_and_options_length(
&mut self,
size: usize
) -> Result<(), ValueError>
Sets the field total_length based on the size of the payload and the options. Returns an error if the payload is too big to fit.
Trait Implementations§
source§impl Clone for Ipv4Header
impl Clone for Ipv4Header
source§fn clone(&self) -> Ipv4Header
fn clone(&self) -> Ipv4Header
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Ipv4Header
impl Debug for Ipv4Header
source§impl Default for Ipv4Header
impl Default for Ipv4Header
source§fn default() -> Ipv4Header
fn default() -> Ipv4Header
source§impl PartialEq<Ipv4Header> for Ipv4Header
impl PartialEq<Ipv4Header> for Ipv4Header
source§fn eq(&self, other: &Ipv4Header) -> bool
fn eq(&self, other: &Ipv4Header) -> bool
source§impl SerializedSize for Ipv4Header
impl SerializedSize for Ipv4Header
source§const SERIALIZED_SIZE: usize = 20usize
const SERIALIZED_SIZE: usize = 20usize
Size of the header itself (without options) in bytes.