Skip to content

Commit

Permalink
fixup local address detection
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Mar 9, 2023
1 parent 9d0f025 commit 6f4e2fb
Show file tree
Hide file tree
Showing 7 changed files with 978 additions and 953 deletions.
20 changes: 20 additions & 0 deletions src/hp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,23 @@ mod disco;
mod hostinfo;
pub mod key;
mod netmap;

use std::net::{IpAddr, Ipv6Addr};

// TODO: replace with IpAddr::to_canoncial once stabilized.
pub fn to_canonical(ip: IpAddr) -> IpAddr {
match ip {
ip @ IpAddr::V4(_) => ip,
IpAddr::V6(ip) => {
if let Some(ip) = ip.to_ipv4_mapped() {
IpAddr::V4(ip)
} else {
IpAddr::V6(ip)
}
}
}
}
// Copied from std lib, not stable yet
pub const fn is_unicast_link_local(addr: Ipv6Addr) -> bool {
(addr.segments()[0] & 0xffc0) == 0xfe80
}
2 changes: 1 addition & 1 deletion src/hp/disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{

use anyhow::{anyhow, ensure, Result};

use crate::hp::stun::to_canonical;
use crate::hp::to_canonical;

use super::{key, stun};

Expand Down
Loading

0 comments on commit 6f4e2fb

Please sign in to comment.