lan discovery, refact mac

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-06-16 23:31:37 +08:00
parent 1759d7f762
commit 5dc0917ea9

View File

@ -207,11 +207,7 @@ fn wait_response(
Err(..) => true, Err(..) => true,
Ok(addr) => addr.ip().is_unspecified(), Ok(addr) => addr.ip().is_unspecified(),
}; };
let mac = if let Ok(local_addr) = local_addr { let mut mac: Option<String> = None;
get_mac(&local_addr.ip())
} else {
"".to_owned()
};
socket.set_read_timeout(timeout)?; socket.set_read_timeout(timeout)?;
loop { loop {
@ -229,7 +225,18 @@ fn wait_response(
"".to_owned() "".to_owned()
} }
} else { } else {
mac.clone() match mac.as_ref() {
Some(m) => m.clone(),
None => {
let m = if let Ok(local_addr) = local_addr {
get_mac(&local_addr.ip())
} else {
"".to_owned()
};
mac = Some(m.clone());
m
}
}
}; };
if local_mac.is_empty() && p.mac.is_empty() || local_mac != p.mac { if local_mac.is_empty() && p.mac.is_empty() || local_mac != p.mac {