pub struct Ipv4Layer {
pub index: LayerIndex,
}Expand description
A view into an IPv4 packet header.
Fields§
§index: LayerIndexImplementations§
Source§impl Ipv4Layer
impl Ipv4Layer
Sourcepub const fn new(start: usize, end: usize) -> Self
pub const fn new(start: usize, end: usize) -> Self
Create a new IPv4 layer view with specified bounds.
Sourcepub const fn at_offset(offset: usize) -> Self
pub const fn at_offset(offset: usize) -> Self
Create a layer at the specified offset with minimum header length.
Sourcepub fn at_offset_dynamic(buf: &[u8], offset: usize) -> Result<Self, FieldError>
pub fn at_offset_dynamic(buf: &[u8], offset: usize) -> Result<Self, FieldError>
Create a layer at offset, calculating actual header length from IHL.
Sourcepub fn validate(buf: &[u8], offset: usize) -> Result<(), FieldError>
pub fn validate(buf: &[u8], offset: usize) -> Result<(), FieldError>
Validate that the buffer contains a valid IPv4 header at the offset.
Sourcepub fn calculate_header_len(&self, buf: &[u8]) -> usize
pub fn calculate_header_len(&self, buf: &[u8]) -> usize
Calculate the actual header length from the buffer.
Sourcepub fn options_len(&self, buf: &[u8]) -> usize
pub fn options_len(&self, buf: &[u8]) -> usize
Get the options length (header length - 20).
Sourcepub fn version(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn version(&self, buf: &[u8]) -> Result<u8, FieldError>
Read the version field (should be 4).
Sourcepub fn ihl(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn ihl(&self, buf: &[u8]) -> Result<u8, FieldError>
Read the Internet Header Length (in 32-bit words).
Sourcepub fn header_len_bytes(&self, buf: &[u8]) -> Result<usize, FieldError>
pub fn header_len_bytes(&self, buf: &[u8]) -> Result<usize, FieldError>
Read the header length in bytes.
Sourcepub fn dscp(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn dscp(&self, buf: &[u8]) -> Result<u8, FieldError>
Read the DSCP (Differentiated Services Code Point).
Sourcepub fn ecn(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn ecn(&self, buf: &[u8]) -> Result<u8, FieldError>
Read the ECN (Explicit Congestion Notification).
Sourcepub fn flags(&self, buf: &[u8]) -> Result<Ipv4Flags, FieldError>
pub fn flags(&self, buf: &[u8]) -> Result<Ipv4Flags, FieldError>
Read the flags as a structured type.
Sourcepub fn flags_raw(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn flags_raw(&self, buf: &[u8]) -> Result<u8, FieldError>
Read the raw flags byte (upper 3 bits of flags/frag field).
Sourcepub fn frag_offset(&self, buf: &[u8]) -> Result<u16, FieldError>
pub fn frag_offset(&self, buf: &[u8]) -> Result<u16, FieldError>
Read the fragment offset (in 8-byte units).
Sourcepub fn frag_offset_bytes(&self, buf: &[u8]) -> Result<u32, FieldError>
pub fn frag_offset_bytes(&self, buf: &[u8]) -> Result<u32, FieldError>
Read the fragment offset in bytes.
Sourcepub fn options_bytes<'a>(&self, buf: &'a [u8]) -> Result<&'a [u8], FieldError>
pub fn options_bytes<'a>(&self, buf: &'a [u8]) -> Result<&'a [u8], FieldError>
Read the options bytes (if any).
Sourcepub fn options(&self, buf: &[u8]) -> Result<Ipv4Options, FieldError>
pub fn options(&self, buf: &[u8]) -> Result<Ipv4Options, FieldError>
Parse and return the options.
Sourcepub fn set_version(&self, buf: &mut [u8], version: u8) -> Result<(), FieldError>
pub fn set_version(&self, buf: &mut [u8], version: u8) -> Result<(), FieldError>
Set the version field.
Sourcepub fn set_total_len(&self, buf: &mut [u8], len: u16) -> Result<(), FieldError>
pub fn set_total_len(&self, buf: &mut [u8], len: u16) -> Result<(), FieldError>
Set the total length field.
Sourcepub fn set_id(&self, buf: &mut [u8], id: u16) -> Result<(), FieldError>
pub fn set_id(&self, buf: &mut [u8], id: u16) -> Result<(), FieldError>
Set the identification field.
Sourcepub fn set_flags(
&self,
buf: &mut [u8],
flags: Ipv4Flags,
) -> Result<(), FieldError>
pub fn set_flags( &self, buf: &mut [u8], flags: Ipv4Flags, ) -> Result<(), FieldError>
Set the flags field.
Sourcepub fn set_frag_offset(
&self,
buf: &mut [u8],
offset_val: u16,
) -> Result<(), FieldError>
pub fn set_frag_offset( &self, buf: &mut [u8], offset_val: u16, ) -> Result<(), FieldError>
Set the fragment offset (in 8-byte units).
Sourcepub fn set_protocol(&self, buf: &mut [u8], proto: u8) -> Result<(), FieldError>
pub fn set_protocol(&self, buf: &mut [u8], proto: u8) -> Result<(), FieldError>
Set the protocol field.
Sourcepub fn set_checksum(
&self,
buf: &mut [u8],
checksum: u16,
) -> Result<(), FieldError>
pub fn set_checksum( &self, buf: &mut [u8], checksum: u16, ) -> Result<(), FieldError>
Set the checksum field.
Sourcepub fn set_src(&self, buf: &mut [u8], src: Ipv4Addr) -> Result<(), FieldError>
pub fn set_src(&self, buf: &mut [u8], src: Ipv4Addr) -> Result<(), FieldError>
Set the source IP address.
Sourcepub fn set_dst(&self, buf: &mut [u8], dst: Ipv4Addr) -> Result<(), FieldError>
pub fn set_dst(&self, buf: &mut [u8], dst: Ipv4Addr) -> Result<(), FieldError>
Set the destination IP address.
Sourcepub fn compute_checksum(&self, buf: &mut [u8]) -> Result<u16, FieldError>
pub fn compute_checksum(&self, buf: &mut [u8]) -> Result<u16, FieldError>
Compute and set the header checksum.
Sourcepub fn verify_checksum(&self, buf: &[u8]) -> Result<bool, FieldError>
pub fn verify_checksum(&self, buf: &[u8]) -> Result<bool, FieldError>
Verify the header checksum.
Sourcepub fn get_field(
&self,
buf: &[u8],
name: &str,
) -> Option<Result<FieldValue, FieldError>>
pub fn get_field( &self, buf: &[u8], name: &str, ) -> Option<Result<FieldValue, FieldError>>
Get a field value by name.
Sourcepub fn set_field(
&self,
buf: &mut [u8],
name: &str,
value: FieldValue,
) -> Option<Result<(), FieldError>>
pub fn set_field( &self, buf: &mut [u8], name: &str, value: FieldValue, ) -> Option<Result<(), FieldError>>
Set a field value by name.
Sourcepub fn field_names() -> &'static [&'static str]
pub fn field_names() -> &'static [&'static str]
Get list of field names.
Sourcepub fn is_fragment(&self, buf: &[u8]) -> bool
pub fn is_fragment(&self, buf: &[u8]) -> bool
Check if this is a fragment.
Sourcepub fn is_first_fragment(&self, buf: &[u8]) -> bool
pub fn is_first_fragment(&self, buf: &[u8]) -> bool
Check if this is the first fragment.
Sourcepub fn is_last_fragment(&self, buf: &[u8]) -> bool
pub fn is_last_fragment(&self, buf: &[u8]) -> bool
Check if this is the last fragment.
Sourcepub fn is_dont_fragment(&self, buf: &[u8]) -> bool
pub fn is_dont_fragment(&self, buf: &[u8]) -> bool
Check if the Don’t Fragment flag is set.
Sourcepub fn payload_len(&self, buf: &[u8]) -> Result<usize, FieldError>
pub fn payload_len(&self, buf: &[u8]) -> Result<usize, FieldError>
Get the payload length (total_len - header_len).
Sourcepub fn payload<'a>(&self, buf: &'a [u8]) -> Result<&'a [u8], FieldError>
pub fn payload<'a>(&self, buf: &'a [u8]) -> Result<&'a [u8], FieldError>
Get a slice of the payload data.
Sourcepub fn header_bytes<'a>(&self, buf: &'a [u8]) -> &'a [u8] ⓘ
pub fn header_bytes<'a>(&self, buf: &'a [u8]) -> &'a [u8] ⓘ
Get the header bytes.
Sourcepub fn protocol_name(&self, buf: &[u8]) -> &'static str
pub fn protocol_name(&self, buf: &[u8]) -> &'static str
Get the protocol name.
Sourcepub fn next_layer(&self, buf: &[u8]) -> Option<LayerKind>
pub fn next_layer(&self, buf: &[u8]) -> Option<LayerKind>
Determine the next layer kind based on protocol.
Sourcepub fn hashret(&self, buf: &[u8]) -> Vec<u8> ⓘ
pub fn hashret(&self, buf: &[u8]) -> Vec<u8> ⓘ
Compute hash for packet matching (like Scapy’s hashret).
Sourcepub fn answers(&self, buf: &[u8], other: &Ipv4Layer, other_buf: &[u8]) -> bool
pub fn answers(&self, buf: &[u8], other: &Ipv4Layer, other_buf: &[u8]) -> bool
Check if this packet answers another (for sr() matching).
Sourcepub fn extract_padding<'a>(&self, buf: &'a [u8]) -> (&'a [u8], &'a [u8])
pub fn extract_padding<'a>(&self, buf: &'a [u8]) -> (&'a [u8], &'a [u8])
Extract padding from the packet. Returns (payload, padding) tuple.
Sourcepub fn original_ttl(&self, buf: &[u8]) -> u8
pub fn original_ttl(&self, buf: &[u8]) -> u8
Estimate the original TTL.
Trait Implementations§
Source§impl Layer for Ipv4Layer
impl Layer for Ipv4Layer
Source§fn header_len(&self, buf: &[u8]) -> usize
fn header_len(&self, buf: &[u8]) -> usize
Source§fn answers(&self, buf: &[u8], other: &Self, other_buf: &[u8]) -> bool
fn answers(&self, buf: &[u8], other: &Self, other_buf: &[u8]) -> bool
Source§fn extract_padding<'a>(&self, buf: &'a [u8]) -> (&'a [u8], &'a [u8])
fn extract_padding<'a>(&self, buf: &'a [u8]) -> (&'a [u8], &'a [u8])
Source§fn field_names(&self) -> &'static [&'static str]
fn field_names(&self) -> &'static [&'static str]
Source§impl LayerDispatch for Ipv4Layer
impl LayerDispatch for Ipv4Layer
Source§fn dispatch_kind(&self) -> LayerKind
fn dispatch_kind(&self) -> LayerKind
Source§fn dispatch_index(&self) -> &LayerIndex
fn dispatch_index(&self) -> &LayerIndex
Source§fn dispatch_summary(&self, buf: &[u8]) -> String
fn dispatch_summary(&self, buf: &[u8]) -> String
Source§fn dispatch_header_len(&self, buf: &[u8]) -> usize
fn dispatch_header_len(&self, buf: &[u8]) -> usize
Source§fn dispatch_field_names(&self) -> &'static [&'static str]
fn dispatch_field_names(&self) -> &'static [&'static str]
Source§fn dispatch_get_field(
&self,
buf: &[u8],
name: &str,
) -> Option<Result<FieldValue, FieldError>>
fn dispatch_get_field( &self, buf: &[u8], name: &str, ) -> Option<Result<FieldValue, FieldError>>
Source§fn dispatch_set_field(
&self,
buf: &mut [u8],
name: &str,
value: FieldValue,
) -> Option<Result<(), FieldError>>
fn dispatch_set_field( &self, buf: &mut [u8], name: &str, value: FieldValue, ) -> Option<Result<(), FieldError>>
Auto Trait Implementations§
impl Freeze for Ipv4Layer
impl RefUnwindSafe for Ipv4Layer
impl Send for Ipv4Layer
impl Sync for Ipv4Layer
impl Unpin for Ipv4Layer
impl UnsafeUnpin for Ipv4Layer
impl UnwindSafe for Ipv4Layer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more