net_wire/ipv4/
ethernet.rs1use super::packet::{Ipv4Packet, Ipv4PacketMut};
4use crate::error::ParseError;
5use crate::ethernet::{
6 ether_type::EtherType,
7 frame::{EthernetFrame, EthernetFrameMut},
8};
9
10impl<'a> EthernetFrame<'a> {
11 #[inline]
13 pub fn ipv4(&self) -> Result<Option<Ipv4Packet<'a>>, ParseError> {
14 if self.ether_type() != EtherType::IPV4 {
15 return Ok(None);
16 }
17 Ipv4Packet::parse(self.payload()).map(Some)
18 }
19}
20
21impl<'a> EthernetFrameMut<'a> {
22 #[inline]
24 pub fn ipv4_mut(&mut self) -> Result<Option<Ipv4PacketMut<'_>>, ParseError> {
25 if self.ether_type() != EtherType::IPV4 {
26 return Ok(None);
27 }
28 Ipv4PacketMut::parse(self.payload_mut()).map(Some)
29 }
30}