Struct etherparse::Ipv4Header[][src]

pub struct Ipv4Header {
    pub differentiated_services_code_point: u8,
    pub explicit_congestion_notification: u8,
    pub payload_len: 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],
    // some fields omitted
}
Expand description

IPv4 header without options.

Fields

differentiated_services_code_point: u8explicit_congestion_notification: u8payload_len: u16

Length 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).

Headers where the total length is smaller then then the minimum header size itself are not representable in this struct.

identification: u16dont_fragment: boolmore_fragments: boolfragments_offset: u16time_to_live: u8protocol: u8header_checksum: u16source: [u8; 4]destination: [u8; 4]

Implementations

Constructs an Ipv4Header with standard values for non specified values.

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).

Returns a slice to the options part of the header (empty if no options are present).

Length of the header (includes options) in bytes.

Returns the total length of the header + payload in bytes.

Sets the payload length if the value is not too big. Otherwise an error is returned.

Returns the maximum payload size based on the current options size.

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.

👎 Deprecated since 0.10.1:

Renamed to Ipv4Header::from_slice

Renamed to Ipv4Header::from_slice

Read an Ipv4Header from a slice and return the header & unused parts of the slice.

Reads an IPv4 header from the current position.

Reads an IPv4 header assuming the version & ihl field have already been read.

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

Writes a given IPv4 header to the current position (this method automatically calculates the header length and checksum).

Writes a given IPv4 header to the current position (this method just writes the specified checksum and does note compute it).

Calculate header checksum of the current ipv4 header.

Returns true if the payload is fragmented.

Either data is missing (more_fragments set) or there is an fragment offset.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Size of the header itself (without options) in bytes.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.