From e40a511ee99d9585becf656c49bcc3ff30ade01c Mon Sep 17 00:00:00 2001 From: Xnoe Date: Mon, 31 Oct 2022 22:38:55 +0000 Subject: [PATCH] Identify links by their index rather than by their MAC address to cope with name and MAC addresses changes properly in the main thread. --- src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3302cb0..4bb6908 100644 --- a/src/main.rs +++ b/src/main.rs @@ -588,7 +588,7 @@ fn zascii(slice: &[libc::c_char]) -> String { } fn main() { - let mut thread_map: HashMap<[u8; 6], libc::c_int> = HashMap::new(); + let mut thread_map: HashMap = HashMap::new(); let iterator = rtnetlink::new_interface_iterator().unwrap(); for message in iterator { @@ -600,7 +600,7 @@ fn main() { let name = zascii(&interface.name); println!("New Link"); - if let None = thread_map.get(&interface.hwaddr) { + if let None = thread_map.get(&interface.index) { println!("Starting DHCP on {}", name); unsafe { match libc::fork() { @@ -608,7 +608,7 @@ fn main() { 0 => dhcp_client(name, interface.index, interface.hwaddr), pid => { println!("Started DHCP on {} PID {}", name, pid); - thread_map.insert(interface.hwaddr, pid); + thread_map.insert(interface.index, pid); } } } @@ -619,12 +619,12 @@ fn main() { let name = zascii(&interface.name); println!("Del Link"); - if let Some(pid) = thread_map.get(&interface.hwaddr) { + if let Some(pid) = thread_map.get(&interface.index) { println!("Stopping DHCP on {}", name); unsafe { libc::kill(*pid, libc::SIGTERM); } - thread_map.remove(&interface.hwaddr); + thread_map.remove(&interface.index); } } }