Struct etherparse::err::LenError
source · pub struct LenError {
pub required_len: usize,
pub len: usize,
pub len_source: LenSource,
pub layer: Layer,
pub layer_start_offset: usize,
}
Expand description
Error when different lengths are conflicting with each other (e.g. not enough data in a slice to decode a header).
This error is triggered whenever there is not enough data to decode an element (e.g. if a slice is too small to decode an header) or if a length that is inhered from an upper layer is too big for the lower layer (e.g. length inherited from an IP header is too big to be used as an ICMP packet length).
When the error is caused by not enough data being available
required_len > len
must be true. While when the length from
the upper layer is too big for the lower layer the inverse
(required_len < len
) must be true.
§Examples:
An example for an error that could be returned when there is not enough data available to decode an UDP header would be:
use etherparse::*;
err::LenError{
// Expected to have at least the length of an UDP header present:
required_len: UdpHeader::LEN,
// Could not decode the UDP header:
layer: err::Layer::UdpHeader,
// There was only 1 byte left (not enough for an UDP header):
len: 1,
// The provided length was determined by the total length field in the
// IPv4 header:
len_source: LenSource::Ipv4HeaderTotalLen,
// Offset in bytes from the start of decoding (ethernet in this) case
// to the expected UDP header start:
layer_start_offset: Ethernet2Header::LEN + Ipv4Header::MIN_LEN
};
Fields§
§required_len: usize
Expected minimum or maximum length conflicting with the
len
value.
len: usize
Length limiting or exceeding the required length.
len_source: LenSource
Source of the outer length (e.g. Slice or a length specified by an upper level protocol).
layer: Layer
Layer in which the length error was encountered.
layer_start_offset: usize
Offset from the start of the parsed data to the layer where the length error occurred.
Implementations§
Trait Implementations§
source§impl Error for LenError
Available on crate feature std
only.
impl Error for LenError
std
only.