Struct pcap::sendqueue::SendQueue

source ·
pub struct SendQueue(/* private fields */);

Implementations§

source§

impl SendQueue

source

pub fn new(memsize: u32) -> Result<Self, Error>

Create a new SendQueue object with a maximum capacity of memsize.

The buffer size memsize must be able to contain both packet headers and actual packet contents.

source

pub fn maxlen(&self) -> u32

source

pub fn is_empty(&self) -> bool

source

pub fn len(&self) -> u32

source

pub fn queue(&mut self, ts: Option<Duration>, buf: &[u8]) -> Result<(), Error>

Add a packet to the queue.

The ts argument only needs to be a Some() value if the transmission mode will be synchronous when calling SendQueue::transmit().

source

pub fn queue_sg( &mut self, ts: Option<Duration>, iov: &[IoSlice<'_>] ) -> Result<(), Error>

Add a (potentially) scattered packet to the queue.

use std::io::IoSlice;
use pcap::sendqueue::SendQueue;
let dstmac: [u8; 6] = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
let srcmac: [u8; 6] = [0, 0, 0, 0, 0, 0];
let ethtype: [u8; 2] = [0x12, 0x34];
let payload: [u8; 5] = [0x00, 0x01, 0x02, 0x03, 0x04];
let iov = [
  IoSlice::new(&dstmac),
  IoSlice::new(&srcmac),
  IoSlice::new(&ethtype),
  IoSlice::new(&payload),
];
let mut sq = SendQueue::new(1024*1024).unwrap();
sq.queue_sg(None, &iov).unwrap();
source

pub fn transmit( &mut self, dev: &mut Capture<Active>, sync: SendSync ) -> Result<(), Error>

Transmit the contents of the queue.

If entire queue was transmitted successfully the queue will be automatically reset.

If sync is set to SendSync::On the difference between packet header timestamps will be used as a delay between sending each packet. If SendSync::Off is used the packets will be transmitted with no delay between packets.

source

pub fn reset(&mut self)

Trait Implementations§

source§

impl Drop for SendQueue

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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>,

§

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>,

§

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.