From c1a3569da707fe316db29c3e8f8dc1f9047584e0 Mon Sep 17 00:00:00 2001 From: zhangyh <717572325@qq.com> Date: Wed, 15 Oct 2025 16:29:22 +0800 Subject: [PATCH 1/3] Include IPv4 link-local addresses in the regular field --- netwatch/src/ip.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/netwatch/src/ip.rs b/netwatch/src/ip.rs index 2580aae..0d97078 100644 --- a/netwatch/src/ip.rs +++ b/netwatch/src/ip.rs @@ -83,15 +83,8 @@ impl LocalAddresses { } } - if regular4.is_empty() && regular6.is_empty() { - // if we have no usable IP addresses then be willing to accept - // addresses we otherwise wouldn't, like: - // + 169.254.x.x (AWS Lambda uses NAT with these) - // + IPv6 ULA (Google Cloud Run uses these with address translation) - regular4 = linklocal4; - regular6 = ula6; - } let mut regular = regular4; + regular.extend(linklocal4); regular.extend(regular6); regular.sort(); From 09d215aad26378c855498a32198e97be4c7a0610 Mon Sep 17 00:00:00 2001 From: zhangyh <717572325@qq.com> Date: Thu, 16 Oct 2025 09:49:46 +0800 Subject: [PATCH 2/3] use chain to combine extend operations --- netwatch/src/ip.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/netwatch/src/ip.rs b/netwatch/src/ip.rs index 0d97078..a892e2c 100644 --- a/netwatch/src/ip.rs +++ b/netwatch/src/ip.rs @@ -84,8 +84,7 @@ impl LocalAddresses { } let mut regular = regular4; - regular.extend(linklocal4); - regular.extend(regular6); + regular.extend(linklocal4.into_iter().chain(regular6)); regular.sort(); loopback.sort(); From 5f367fe81fea940f3b18ceb08ec63a1f2dc122fc Mon Sep 17 00:00:00 2001 From: zhangyh <717572325@qq.com> Date: Thu, 16 Oct 2025 10:16:35 +0800 Subject: [PATCH 3/3] update comments --- netwatch/src/ip.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netwatch/src/ip.rs b/netwatch/src/ip.rs index a892e2c..cd2e6ca 100644 --- a/netwatch/src/ip.rs +++ b/netwatch/src/ip.rs @@ -29,8 +29,8 @@ impl Default for LocalAddresses { #[cfg(not(wasm_browser))] impl LocalAddresses { /// Returns the machine's IP addresses. - /// If there are no regular addresses it will return any IPv4 linklocal or IPv6 unique local - /// addresses because we know of environments where these are used with NAT to provide connectivity. + /// Regular includes all non-loopback IPv4 (including link-local). + /// IPv6 link-local and unique local are excluded from regular. pub fn new() -> Self { let ifaces = netdev::interface::get_interfaces(); Self::from_raw_interfaces(&ifaces)