Struct etherparse::Ipv4Header [−][src]
IPv4 header without options.
Fields
differentiated_services_code_point: u8explicit_congestion_notification: u8payload_len: u16Length of the payload of the ipv4 packet in bytes (does not contain the options).
This field does not directly exist in an ipv4 header but instead is decoded from & encoded to the total_size field together with the options length (using the ihl). If the total_length field in a ipv4 header is smaller then
identification: u16dont_fragment: boolmore_fragments: boolfragments_offset: u16time_to_live: u8protocol: u8header_checksum: u16source: [u8; 4]destination: [u8; 4]Implementations
impl Ipv4Header[src]
pub fn new(
payload_len: u16,
time_to_live: u8,
protocol: IpTrafficClass,
source: [u8; 4],
destination: [u8; 4]
) -> Ipv4Header[src]
payload_len: u16,
time_to_live: u8,
protocol: IpTrafficClass,
source: [u8; 4],
destination: [u8; 4]
) -> Ipv4Header
Constructs an Ipv4Header with standard values for non specified values.
pub fn ihl(&self) -> u8[src]
Length of the header in 4 bytes (often also called IHL - Internet Header Lenght).
The minimum allowed length of a header is 5 (= 20 bytes) and the maximum length is 15 (= 60 bytes).
pub fn options(&self) -> &[u8][src]
Returns a slice to the options part of the header (empty if no options are present).
pub fn header_len(&self) -> usize[src]
Length of the header (includes options) in bytes.
pub fn total_len(&self) -> u16[src]
Returns the total length of the header + payload in bytes.
pub fn set_payload_len(&mut self, value: usize) -> Result<(), ValueError>[src]
Sets the payload length if the value is not too big. Otherwise an error is returned.
pub fn max_payload_len(&self) -> u16[src]
Returns the maximum payload size based on the current options size.
pub fn set_options(&mut self, data: &[u8]) -> Result<(), ValueError>[src]
Sets the options & header_length based on the provided length. The length of the given slice must be a multiple of 4 and maximum 40 bytes. If the length is not fullfilling these constraints, no data is set and an error is returned.
pub fn read_from_slice(slice: &[u8]) -> Result<(Ipv4Header, &[u8]), ReadError>[src]
Read an Ipv4Header from a slice and return the header & unused parts of the slice.
pub fn read<T: Read + Seek + Sized>(
reader: &mut T
) -> Result<Ipv4Header, ReadError>[src]
reader: &mut T
) -> Result<Ipv4Header, ReadError>
Reads an IPv4 header from the current position.
pub fn read_without_version<T: Read + Seek + Sized>(
reader: &mut T,
version_rest: u8
) -> Result<Ipv4Header, ReadError>[src]
reader: &mut T,
version_rest: u8
) -> Result<Ipv4Header, ReadError>
Reads an IPv4 header assuming the version & ihl field have already been read.
pub fn check_ranges(&self) -> Result<(), ValueError>[src]
Checks if the values in this header are valid values for an ipv4 header.
Specifically it will be checked, that:
- payload_len + options_len is not too big to be encoded in the total_size header field
- differentiated_services_code_point is not greater then 0x3f
- explicit_congestion_notification is not greater then 0x3
- fragments_offset is not greater then 0x1fff
pub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), WriteError>[src]
Writes a given IPv4 header to the current position (this method automatically calculates the header length and checksum).
pub fn write_raw<T: Write + Sized>(
&self,
writer: &mut T
) -> Result<(), WriteError>[src]
&self,
writer: &mut T
) -> Result<(), WriteError>
Writes a given IPv4 header to the current position (this method just writes the specified checksum and does note compute it).
pub fn calc_header_checksum(&self) -> Result<u16, ValueError>[src]
Calculate header checksum of the current ipv4 header.
Trait Implementations
impl Clone for Ipv4Header[src]
fn clone(&self) -> Ipv4Header[src]
pub fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Debug for Ipv4Header[src]
impl Default for Ipv4Header[src]
fn default() -> Ipv4Header[src]
impl Eq for Ipv4Header[src]
impl PartialEq<Ipv4Header> for Ipv4Header[src]
fn eq(&self, other: &Ipv4Header) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl SerializedSize for Ipv4Header[src]
const SERIALIZED_SIZE: usize[src]
Size of the header itself (without options) in bytes.
Auto Trait Implementations
impl RefUnwindSafe for Ipv4Header[src]
impl Send for Ipv4Header[src]
impl Sync for Ipv4Header[src]
impl Unpin for Ipv4Header[src]
impl UnwindSafe for Ipv4Header[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,