Skip to main content

net_wire/ipv6/
ethernet.rs

1use super::packet::{Ipv6Packet, Ipv6PacketMut};
2use crate::error::ParseError;
3use crate::ethernet::{
4    ether_type::EtherType,
5    frame::{EthernetFrame, EthernetFrameMut},
6};
7
8impl<'a> EthernetFrame<'a> {
9    /// Parses IPv6 only when this frame's EtherType is IPv6.
10    #[inline]
11    pub fn ipv6(&self) -> Result<Option<Ipv6Packet<'a>>, ParseError> {
12        if self.ether_type() != EtherType::IPV6 {
13            return Ok(None);
14        }
15        Ipv6Packet::parse(self.payload()).map(Some)
16    }
17}
18
19impl<'a> EthernetFrameMut<'a> {
20    /// Parses mutable IPv6 only when this frame's EtherType is IPv6.
21    #[inline]
22    pub fn ipv6_mut(&mut self) -> Result<Option<Ipv6PacketMut<'_>>, ParseError> {
23        if self.ether_type() != EtherType::IPV6 {
24            return Ok(None);
25        }
26        Ipv6PacketMut::parse(self.payload_mut()).map(Some)
27    }
28}