1
1
//! Device discovery manager.
2
2
3
- use std:: time:: Duration ;
4
-
5
3
use cidr:: Ipv4Cidr ;
6
4
7
5
use neli:: err:: NlError ;
@@ -38,16 +36,14 @@ impl DeviceManager {
38
36
///
39
37
/// # Parameters
40
38
/// - `range` (`Ipv4Cidr`): the CIDR range of the network
41
- /// - `refresh` (`Duration`): the amount of time after which to refresh
42
- /// the ARP cache
43
39
///
44
40
/// # Returns
45
41
/// The result type `NetlinkResult<DeviceManager>` containing the device
46
42
/// manager, if its initialization was successful.
47
- pub fn new ( range : Ipv4Cidr , refresh : Duration ) -> NetlinkResult < Self > {
43
+ pub fn new ( range : Ipv4Cidr ) -> NetlinkResult < Self > {
48
44
Ok ( Self {
49
45
socket : Socket :: connect ( ) ?,
50
- arp_manager : ArpManager :: new ( range, refresh ) ,
46
+ arp_manager : ArpManager :: new ( range) ,
51
47
} )
52
48
}
53
49
@@ -59,7 +55,12 @@ impl DeviceManager {
59
55
/// # Returns
60
56
/// The result type `NetlinkResult<Vec<Device>>` containing a list of
61
57
/// connected devices.
62
- pub fn scan ( & mut self , ifname : & str ) -> NetlinkResult < Vec < Device > > {
58
+ pub async fn scan ( & mut self , ifname : & str ) -> NetlinkResult < Vec < Device > > {
59
+ // Perform an ARP scan of the network to get IPs
60
+ if self . arp_manager . scan ( ) . await . is_err ( ) {
61
+ return Err ( NlError :: Msg ( "could not scan network" . to_string ( ) ) ) ;
62
+ } ;
63
+
63
64
// Determine Wi-Fi device by name
64
65
let check_wifi_device = |iface : & Interface | parse_string ( & iface. name . clone ( ) . unwrap_or_default ( ) ) == ifname;
65
66
0 commit comments