pub struct ArpClient { /* private fields */ }
Expand description
Struct that encapsulates interaction with (R)ARP messages, such as sending and receiving.
Implementations§
source§impl ArpClient
impl ArpClient
sourcepub fn new() -> Result<Self, Error>
pub fn new() -> Result<Self, Error>
Create an ARP client on a guessed, “best-suited” interface.
sourcepub fn new_with_iface_name(iface_name: &str) -> Result<Self, Error>
pub fn new_with_iface_name(iface_name: &str) -> Result<Self, Error>
Create an ARP client on the interface with the name iface_name
.
sourcepub fn new_with_iface(interface: &Interface) -> Result<Self, Error>
pub fn new_with_iface(interface: &Interface) -> Result<Self, Error>
Create an ARP client on the interface
given.
sourcepub async fn send_message(
&mut self,
timeout: Option<Duration>,
message: ArpMessage
) -> Result<ArpMessage, Error>
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)
sourcepub async fn send_message_with_check<T>(
&mut self,
timeout: Option<Duration>,
message: ArpMessage,
check_answer: impl Fn(ArpMessage) -> Option<T>
) -> Result<T, Error>
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
.
sourcepub async fn ip_to_mac(
&mut self,
ip_addr: Ipv4Addr,
timeout: Option<Duration>
) -> Result<MacAddr, Error>
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
.
sourcepub async fn mac_to_ip(
&mut self,
mac_addr: MacAddr,
timeout: Option<Duration>
) -> Result<Ipv4Addr, Error>
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
.
sourcepub async fn send(&self, arp_message: &ArpMessage) -> Result<(), Error>
pub async fn send(&self, arp_message: &ArpMessage) -> Result<(), Error>
Sends arp_message
on the interface belonging to this client.
sourcepub async fn receive_next(&mut self) -> Option<ArpMessage>
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.