diff --git a/commons/zenoh-util/src/std_only/net/mod.rs b/commons/zenoh-util/src/std_only/net/mod.rs index 9562c97ded..4d18476109 100644 --- a/commons/zenoh-util/src/std_only/net/mod.rs +++ b/commons/zenoh-util/src/std_only/net/mod.rs @@ -443,6 +443,7 @@ pub fn get_interface_by_addr(addr: IpAddr) -> Vec { #[cfg(windows)] { // TODO(sashacmc): check and fix + let mut result = vec![]; unsafe { use crate::ffi; use winapi::um::iptypes::IP_ADAPTER_ADDRESSES_LH; @@ -469,25 +470,29 @@ pub fn get_interface_by_addr(addr: IpAddr) -> Vec { retries += 1; } - if ret != 0 { - bail!("GetAdaptersAddresses returned {}", ret) - } - - let mut next_iface = (buffer.as_ptr() as *mut IP_ADAPTER_ADDRESSES_LH).as_ref(); - while let Some(iface) = next_iface { - let mut next_ucast_addr = iface.FirstUnicastAddress.as_ref(); - while let Some(ucast_addr) = next_ucast_addr { - if let Ok(ifaddr) = ffi::win::sockaddr_to_addr(ucast_addr.Address) { - if ifaddr.ip() == addr { - return Ok(iface.AdapterName); + if addr.is_unspecified() { + let mut next_iface = (buffer.as_ptr() as *mut IP_ADAPTER_ADDRESSES_LH).as_ref(); + while let Some(iface) = next_iface { + result.push(iface.AdapterName); + next_iface = iface.Next.as_ref(); + } + } else { + let mut next_iface = (buffer.as_ptr() as *mut IP_ADAPTER_ADDRESSES_LH).as_ref(); + while let Some(iface) = next_iface { + let mut next_ucast_addr = iface.FirstUnicastAddress.as_ref(); + while let Some(ucast_addr) = next_ucast_addr { + if let Ok(ifaddr) = ffi::win::sockaddr_to_addr(ucast_addr.Address) { + if ifaddr.ip() == addr { + result.push(iface.AdapterName); + } } + next_ucast_addr = ucast_addr.Next.as_ref(); } - next_ucast_addr = ucast_addr.Next.as_ref(); + next_iface = iface.Next.as_ref(); } - next_iface = iface.Next.as_ref(); } - bail!("No interface found with address {addr}") } + result } } diff --git a/zenoh/src/net/routing/interceptor/downsampling.rs b/zenoh/src/net/routing/interceptor/downsampling.rs index 31e5544970..4492f1338a 100644 --- a/zenoh/src/net/routing/interceptor/downsampling.rs +++ b/zenoh/src/net/routing/interceptor/downsampling.rs @@ -122,11 +122,7 @@ impl InterceptorFactoryTrait for DownsamplerInterceptor { "New downsampler transport unicast link interfaces: {:?}", link.interfaces ); - if !link - .interfaces - .iter() - .any(|interface| interfaces.contains(&interface)) - { + if !link.interfaces.iter().any(|x| interfaces.contains(x)) { return (None, None); } }