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
impl Socket
Sourcepub fn open(interface: &str, ethertype: u16) -> Result<Self>
pub fn open(interface: &str, ethertype: u16) -> Result<Self>
Opens interface for frames of ethertype. On Linux this needs
CAP_NET_RAW.
Sourcepub fn mac(&self) -> MacAddress
pub fn mac(&self) -> MacAddress
The interface’s MAC address, the source of every frame sent.
Sourcepub fn join_multicast(&self, group: MacAddress) -> Result<()>
pub fn join_multicast(&self, group: MacAddress) -> Result<()>
Receives frames sent to group as well.
Sourcepub fn set_promiscuous(&self, on: bool) -> Result<()>
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.
pub fn send(&self, destination: MacAddress, payload: &[u8]) -> Result<()>
Sourcepub fn ignore_outgoing(&self) -> Result<()>
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.
Sourcepub fn keep_payloads_starting(&self, first: RangeInclusive<u8>) -> Result<()>
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.
Sourcepub fn receive(
&self,
buffer: &mut [u8],
timeout: Option<Duration>,
) -> Result<Option<Received>>
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.