Skip to content

Commit

Permalink
Merge pull request rustdesk#4668 from fufesou/refact/lan_discovery_mac
Browse files Browse the repository at this point in the history
lan discovery, try get ip addr only when 0.0.0.0
  • Loading branch information
rustdesk committed Jun 16, 2023
2 parents a565c12 + 5dc0917 commit fe8ab49
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/lan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ fn wait_response(
) -> ResultType<()> {
let mut last_recv_time = Instant::now();

let local_addr = socket.local_addr();
let try_get_ip_by_peer = match local_addr.as_ref() {
Err(..) => true,
Ok(addr) => addr.ip().is_unspecified(),
};
let mut mac: Option<String> = None;

socket.set_read_timeout(timeout)?;
loop {
let mut buf = [0; 2048];
Expand All @@ -211,13 +218,28 @@ fn wait_response(
Some(rendezvous_message::Union::PeerDiscovery(p)) => {
last_recv_time = Instant::now();
if p.cmd == "pong" {
let mac = if let Some(self_addr) = get_ipaddr_by_peer(&addr) {
get_mac(&self_addr)
let local_mac = if try_get_ip_by_peer {
if let Some(self_addr) = get_ipaddr_by_peer(&addr) {
get_mac(&self_addr)
} else {
"".to_owned()
}
} else {
"".to_owned()
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 mac != p.mac {
if local_mac.is_empty() && p.mac.is_empty() || local_mac != p.mac {
allow_err!(tx.send(config::DiscoveryPeer {
id: p.id.clone(),
ip_mac: HashMap::from([
Expand Down

0 comments on commit fe8ab49

Please sign in to comment.