use crate::packets::ip::v4::Ipv4;
use crate::packets::ip::v6::{Ipv6, SegmentRouting};
use crate::packets::{Ethernet, Packet, Tcp, Tcp4, Tcp6, Udp4, Udp6};
pub trait PacketExt: Packet + Sized {
fn into_eth(self) -> Ethernet {
self.reset().parse::<Ethernet>().unwrap()
}
fn into_v4(self) -> Ipv4 {
self.into_eth().parse::<Ipv4>().unwrap()
}
fn into_v4_tcp(self) -> Tcp4 {
self.into_v4().parse::<Tcp4>().unwrap()
}
fn into_v4_udp(self) -> Udp4 {
self.into_v4().parse::<Udp4>().unwrap()
}
fn into_v6(self) -> Ipv6 {
self.into_eth().parse::<Ipv6>().unwrap()
}
fn into_v6_tcp(self) -> Tcp6 {
self.into_v6().parse::<Tcp6>().unwrap()
}
fn into_v6_udp(self) -> Udp6 {
self.into_v6().parse::<Udp6>().unwrap()
}
fn into_sr(self) -> SegmentRouting<Ipv6> {
self.into_v6().parse::<SegmentRouting<Ipv6>>().unwrap()
}
fn into_sr_tcp(self) -> Tcp<SegmentRouting<Ipv6>> {
self.into_sr().parse::<Tcp<SegmentRouting<Ipv6>>>().unwrap()
}
}
impl<T> PacketExt for T where T: Packet + Sized {}