pub fn from_bytes(bytes: T, verify_checksum: bool) -> Result<Self, Error> {
        let bytes_len = bytes.len();

        if bytes_len < OPTIONS_OFFSET {
            return Err(Error::SliceTooShort);
        }

        let packet = IPv4Packet::from_bytes_unchecked(bytes);

        let (version, header_len) = packet.version_and_header_len();

        if version != IPV4_VERSION {
            return Err(Error::Version);
        }

        let total_len = packet.total_len() as usize;

        if total_len < header_len {
            return Err(Error::InvalidTotalLen);
        }

        if total_len != bytes_len {
            return Err(Error::SliceExactLen);
        }

        if header_len < OPTIONS_OFFSET {
            return Err(Error::HeaderLen);
        }

        // We ignore the TTL field since only routers should care about it. An end host has no
        // reason really to discard an otherwise valid packet.

        if verify_checksum && packet.compute_checksum_unchecked(header_len) != 0 {
            return Err(Error::Checksum);
        }

        Ok(packet)
    }
/// Attempts to interpret `bytes` as an IPv4 packet, checking the validity of the header fields
/// and the length of the inner byte sequence.
Attempts to interpret `bytes` as an IPv4 packet, checking the validity of the header fields
and the length of the inner byte sequence.
Attempts to interpret ` bytes ` as an IPv4 packet checking the validity of the header fields and the length of the inner byte sequence .
pub fn from_bytes(bytes: T, verify_checksum: bool) -> Result<Self, Error> {
        let bytes_len = bytes.len();
        if bytes_len < OPTIONS_OFFSET {
            return Err(Error::SliceTooShort);
        }
        let packet = IPv4Packet::from_bytes_unchecked(bytes);
        let (version, header_len) = packet.version_and_header_len();
        if version != IPV4_VERSION {
            return Err(Error::Version);
        }
        let total_len = packet.total_len() as usize;
        if total_len < header_len {
            return Err(Error::InvalidTotalLen);
        }
        if total_len != bytes_len {
            return Err(Error::SliceExactLen);
        }
        if header_len < OPTIONS_OFFSET {
            return Err(Error::HeaderLen);
        }
        // We ignore the TTL field since only routers should care about it. An end host has no
        // reason really to discard an otherwise valid packet.
        if verify_checksum && packet.compute_checksum_unchecked(header_len) != 0 {
            return Err(Error::Checksum);
        }
        Ok(packet)
    }
pub fn from_bytes ( bytes : T , verify_checksum : bool ) -> Result < Self , Error > { let bytes_len = bytes . len ( ) ; if bytes_len < OPTIONS_OFFSET { return Err ( Error :: SliceTooShort ) ; } let packet = IPv4Packet :: from_bytes_unchecked ( bytes ) ; let ( version , header_len ) = packet . version_and_header_len ( ) ; if version != IPV4_VERSION { return Err ( Error :: Version ) ; } let total_len = packet . total_len ( ) as usize ; if total_len < header_len { return Err ( Error :: InvalidTotalLen ) ; } if total_len != bytes_len { return Err ( Error :: SliceExactLen ) ; } if header_len < OPTIONS_OFFSET { return Err ( Error :: HeaderLen ) ; } // We ignore the TTL field since only routers should care about it. An end host has no // reason really to discard an otherwise valid packet. if verify_checksum && packet . compute_checksum_unchecked ( header_len ) != 0 { return Err ( Error :: Checksum ) ; } Ok ( packet ) }
Attempts to interpret `bytes` as an IPv4 packet, checking the validity of the header fields
and the length of the inner byte sequence.
Attempts to interpret ` bytes ` as an IPv4 packet checking the validity of the header fields and the length of the inner byte sequence .
bytes
T
verify_checksum
bool
bytes
T
verify_checksum
bool