pub struct Ipv4Packet<'a> { /* private fields */ }Expand description
A structurally validated immutable RFC 791 packet view.
Parsing validates version, IHL, and declared total length, then excludes trailing capture bytes. It deliberately accepts bad checksums and reserved flags for capture/offload and malformed-packet inspection.
Implementations§
Source§impl<'a> Ipv4Packet<'a>
impl<'a> Ipv4Packet<'a>
Sourcepub fn icmpv4(&self) -> Result<Option<Icmpv4Message<'a>>, ParseError>
pub fn icmpv4(&self) -> Result<Option<Icmpv4Message<'a>>, ParseError>
Parses ICMPv4 only when this is an unfragmented ICMP packet.
Sourcepub fn udp(&self) -> Result<Option<UdpDatagram<'a>>, ParseError>
pub fn udp(&self) -> Result<Option<UdpDatagram<'a>>, ParseError>
Parses UDP only when this is an unfragmented UDP packet.
Sourcepub fn tcp(&self) -> Result<Option<TcpSegment<'a>>, ParseError>
pub fn tcp(&self) -> Result<Option<TcpSegment<'a>>, ParseError>
Parses TCP only when this is an unfragmented TCP packet.
Source§impl<'a> Ipv4Packet<'a>
impl<'a> Ipv4Packet<'a>
Sourcepub fn parse(bytes: &'a [u8]) -> Result<Self, ParseError>
pub fn parse(bytes: &'a [u8]) -> Result<Self, ParseError>
Validates RFC 791 structural bounds; use checksum_is_valid for checksum acceptance.
Sourcepub fn total_length(&self) -> u16
pub fn total_length(&self) -> u16
Returns the RFC 791 total-length field.
Sourcepub fn identification(&self) -> u16
pub fn identification(&self) -> u16
Returns the identification field.
Sourcepub fn flags_fragment_offset(&self) -> u16
pub fn flags_fragment_offset(&self) -> u16
Returns the raw flags and fragment-offset field, including the reserved flag.
Sourcepub fn protocol(&self) -> Ipv4Protocol
pub fn protocol(&self) -> Ipv4Protocol
Returns the protocol field while preserving unknown values.
Sourcepub fn header_checksum(&self) -> u16
pub fn header_checksum(&self) -> u16
Returns the encoded RFC 791 header checksum.
Sourcepub fn source(&self) -> Ipv4Address
pub fn source(&self) -> Ipv4Address
Returns the source address.
Sourcepub fn destination(&self) -> Ipv4Address
pub fn destination(&self) -> Ipv4Address
Returns the destination address.
Sourcepub fn payload(&self) -> &'a [u8]
pub fn payload(&self) -> &'a [u8]
Returns declared payload bytes; they are not header-checksum covered.
Sourcepub fn checksum_is_valid(&self) -> bool
pub fn checksum_is_valid(&self) -> bool
Checks the one’s-complement checksum across the complete IHL, including options.