Struct Packet

Source
pub struct Packet { /* private fields */ }
Expand description

represents a network packet. can be used to build or parse packets.

Implementations§

Source§

impl Packet

Source

pub fn set_payload(&mut self, v: Vec<u8>)

Source§

impl Packet

Source

pub fn new(protos: Vec<Protocol>) -> Self

creates a new Packet with the internal buffer capacity set to the appropriate size for the header data. note that the headers arent created with this method, you still have to add them with add_header.

Source

pub fn new_empty() -> Self

Creates a new Packet with an empty internal buffer and the capacity is 0

Source

pub fn add_header(&mut self, buf: impl Header)

Adds the header into the internal packet buffer. If the header is TCP or UDP, this method will call the set_pseudo_header method for you, as this method is required to be called before calculating the checksum of the header

Source

pub fn update_header(&mut self, new_buf: impl Header)

If the header already exists in the packet, it will be updated with the one passed to this function. if the header doesn’t already exist in the packet, it will be added as if you’d called add_header instead.

Source

pub fn extend_payload<T: IntoIterator<Item = u8>>(&mut self, buf: T)

Appends the given data to the payload of this packet

Source

pub fn into_vec(self) -> Vec<u8>

consumes self and returns the buffer which is the cooked data packet.

Source

pub fn parse(raw_data: &[u8]) -> Result<Self, ParseError>

Try to create a Packet from raw packet data and populate it with the values in the given data packet

Source

pub fn get_header_as_slice(&self, p: Protocol) -> Option<&[u8]>

Returns Option::Some(&[u8]) if the header is found in this packet, else None

Source§

impl Packet

Auto Trait Implementations§

§

impl Freeze for Packet

§

impl RefUnwindSafe for Packet

§

impl Send for Packet

§

impl Sync for Packet

§

impl Unpin for Packet

§

impl UnwindSafe for Packet

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.