Struct etherparse::PacketHeaders [−][src]
Decoded packet headers (data link layer and higher). You can use PacketHeaders::from_ethernet_slice or PacketHeader::from_ip_slice to decode and get this struct as a result.
Fields
link: Option<Ethernet2Header>
vlan: Option<VlanHeader>
ip: Option<IpHeader>
transport: Option<TransportHeader>
payload: &'a [u8]
Rest of the packet that could not be decoded as a header (usually the payload).
Implementations
impl<'a> PacketHeaders<'a>
[src]
pub fn from_ethernet_slice(
packet: &[u8]
) -> Result<PacketHeaders<'_>, ReadError>
[src]
packet: &[u8]
) -> Result<PacketHeaders<'_>, ReadError>
Tries to decode as much as possible of a packet.
pub fn from_ip_slice(packet: &[u8]) -> Result<PacketHeaders<'_>, ReadError>
[src]
Tries to decode an ip packet and its transport headers.
Assumes the given slice starts with the first byte of the IP header
Example
// build a UDP packet let payload = [0u8;18]; let builder = PacketBuilder:: ipv4([192,168,1,1], //source ip [192,168,1,2], //desitionation ip 20) //time to life .udp(21, //source port 1234); //desitnation port // serialize the packet let packet = { let mut packet = Vec::<u8>::with_capacity( builder.size(payload.len())); builder.write(&mut packet, &payload).unwrap(); packet }; // parse the ip packet from a slice let p = PacketHeaders::from_ip_slice(&packet) .expect("Failed to decode the packet");
Trait Implementations
impl<'a> Clone for PacketHeaders<'a>
[src]
fn clone(&self) -> PacketHeaders<'a>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Debug for PacketHeaders<'a>
[src]
impl<'a> Eq for PacketHeaders<'a>
[src]
impl<'a> PartialEq<PacketHeaders<'a>> for PacketHeaders<'a>
[src]
fn eq(&self, other: &PacketHeaders<'a>) -> bool
[src]
fn ne(&self, other: &PacketHeaders<'a>) -> bool
[src]
impl<'a> StructuralEq for PacketHeaders<'a>
[src]
impl<'a> StructuralPartialEq for PacketHeaders<'a>
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for PacketHeaders<'a>
[src]
impl<'a> Send for PacketHeaders<'a>
[src]
impl<'a> Sync for PacketHeaders<'a>
[src]
impl<'a> Unpin for PacketHeaders<'a>
[src]
impl<'a> UnwindSafe for PacketHeaders<'a>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,