Skip to main content

Capture

Struct Capture 

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

Takes the frames of chosen ethertypes crossing one interface.

Implementations§

Source§

impl Capture

Source

pub fn open( interface: &str, ethertypes: &[u16], snap: u32, promiscuous: bool, room: usize, ) -> Result<Self>

Opens interface for frames of any of ethertypes, tagged or not, or of every ethertype when there are none, keeping at most snap octets of each. Frames wait to be read in a ring of about room octets, memory the kernel lends the program; when it fills, frames are dropped and counted. promiscuous has the interface hear frames for other computers too, as long as the capture is open; a bridge port already does. On Linux this needs CAP_NET_RAW.

Source

pub fn receive( &self, buffer: &mut [u8], timeout: Option<Duration>, ) -> Result<Option<Captured>>

Writes the next frame to buffer, waiting up to timeout (forever when None) for one. None when the time ran out or a signal interrupted the wait. A zero timeout never waits, for taking every frame already there.

Source

pub fn ready( captures: &[&Capture], timeout: Option<Duration>, ) -> Result<Vec<usize>>

Waits up to timeout (forever when None) for frames at any of captures, giving the places of those that have some.

Source

pub fn statistics(&self) -> Result<Statistics>

What the capture took since last asked.

Source

pub fn open_stamped( interface: &str, ethertypes: &[u16], snap: u32, promiscuous: bool, ) -> Result<Self>

Opens interface as open does, but timing received frames by the interface’s PTP hardware clock, as they crossed the wire, rather than by when the kernel saw them, which interrupt moderation and a busy computer delay. The interface must stamp received frames: ptp4l, for one, turns that on, for every frame on interfaces that stamp all or none. Frames sent, and any the interface did not stamp, keep the system clock’s time.

The kernel hands such frames over one at a time rather than in a shared ring, as some drivers’ time stamps (Intel’s igc among them) reach the program no other way, so it costs more for a busy interface: it suits measuring, not long captures.

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.