Struct libarp::client::ArpClient

source ·
pub struct ArpClient { /* private fields */ }
Expand description

Struct that encapsulates interaction with (R)ARP messages, such as sending and receiving.

Implementations§

source§

impl ArpClient

source

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

Create an ARP client on a guessed, “best-suited” interface.

source

pub fn new_with_iface_name(iface_name: &str) -> Result<Self, Error>

Create an ARP client on the interface with the name iface_name.

source

pub fn new_with_iface(interface: &Interface) -> Result<Self, Error>

Create an ARP client on the interface given.

source

pub async fn send_message( &mut self, timeout: Option<Duration>, message: ArpMessage ) -> Result<ArpMessage, Error>

Send an ARP message with the given timeout. Returns the next ARP message received. (must not necessarily be related to your message sent)

source

pub async fn send_message_with_check<T>( &mut self, timeout: Option<Duration>, message: ArpMessage, check_answer: impl Fn(ArpMessage) -> Option<T> ) -> Result<T, Error>

Send an ARP message with the given timeout, and perform an arbitrary check check_answer on the answer. Using check_answer, you can check if the received tmessage is related to your previously sent message if needed. Returns the first ARP message received that satisfies check_answer.

source

pub async fn ip_to_mac( &mut self, ip_addr: Ipv4Addr, timeout: Option<Duration> ) -> Result<MacAddr, Error>

Resolves a given ip_addr to a MAC address. To achieve this, sends an ARP request with a timeout.

source

pub async fn mac_to_ip( &mut self, mac_addr: MacAddr, timeout: Option<Duration> ) -> Result<Ipv4Addr, Error>

Resolves a given mac_addr to an IPv4 address. To achieve this, sends an RARP request with a timeout.

source

pub async fn send(&self, arp_message: &ArpMessage) -> Result<(), Error>

Sends arp_message on the interface belonging to this client.

source

pub async fn receive_next(&mut self) -> Option<ArpMessage>

Returns when the next Ethernet frame has been received. If this frame contains an ARP message, returns this message, else returns None.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.