Skip to main content

Socket

Struct Socket 

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

Sends and receives the payloads of Ethernet frames of one ethertype on one interface. The kernel adds and removes the Ethernet header.

Implementations§

Source§

impl Socket

Source

pub fn open(interface: &str, ethertype: u16) -> Result<Self>

Opens interface for frames of ethertype. On Linux this needs CAP_NET_RAW.

Source

pub fn mac(&self) -> MacAddress

The interface’s MAC address, the source of every frame sent.

Source

pub fn join_multicast(&self, group: MacAddress) -> Result<()>

Receives frames sent to group as well.

Source

pub fn set_promiscuous(&self, on: bool) -> Result<()>

Hears frames of every VLAN and address the interface receives, on, or no longer. An interface that drops tagged frames of VLANs not registered with it, as Intel’s igb and igc do (see crate::interfaces::filters_vlans), hears them only so, since registering a VLAN takes an administrator. On macOS it stays so until the socket closes; Windows’ capture always does.

Source

pub fn send(&self, destination: MacAddress, payload: &[u8]) -> Result<()>

Source

pub fn ignore_outgoing(&self) -> Result<()>

Leaves out every frame this computer sends, other programs’ and what a bridge forwards out of the interface too, which would otherwise come as if received on it: as a bridge port’s own protocols want. Linux only; elsewhere an Unsupported error.

Source

pub fn keep_payloads_starting(&self, first: RangeInclusive<u8>) -> Result<()>

Keeps only frames whose payload starts with an octet in first, such as the AVTP subtypes of ATDECC, dropped before they reach the program.

Source

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

Waits up to timeout (forever when None) for a frame and writes its payload to buffer, cut short if the buffer is. None when the time ran out or a signal interrupted the wait. Frames this socket sent are left out; those other programs on this computer send are not, so entities and controllers on the same computer hear each other.

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.