pub struct Capture { /* private fields */ }Expand description
Takes the frames of chosen ethertypes crossing one interface.
Implementations§
Source§impl Capture
impl Capture
Sourcepub fn open(
interface: &str,
ethertypes: &[u16],
snap: u32,
promiscuous: bool,
room: usize,
) -> Result<Self>
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.
Sourcepub fn receive(
&self,
buffer: &mut [u8],
timeout: Option<Duration>,
) -> Result<Option<Captured>>
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.
Sourcepub fn ready(
captures: &[&Capture],
timeout: Option<Duration>,
) -> Result<Vec<usize>>
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.
Sourcepub fn statistics(&self) -> Result<Statistics>
pub fn statistics(&self) -> Result<Statistics>
What the capture took since last asked.
Sourcepub fn open_stamped(
interface: &str,
ethertypes: &[u16],
snap: u32,
promiscuous: bool,
) -> Result<Self>
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.