Skip to content

Commit

Permalink
Syntax fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Jan 31, 2024
1 parent 9784647 commit 076d8b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
33 changes: 19 additions & 14 deletions commons/zenoh-util/src/std_only/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ pub fn get_interface_by_addr(addr: IpAddr) -> Vec<String> {
#[cfg(windows)]
{
// TODO(sashacmc): check and fix
let mut result = vec![];
unsafe {
use crate::ffi;
use winapi::um::iptypes::IP_ADAPTER_ADDRESSES_LH;
Expand All @@ -469,25 +470,29 @@ pub fn get_interface_by_addr(addr: IpAddr) -> Vec<String> {
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
}
}

Expand Down
6 changes: 1 addition & 5 deletions zenoh/src/net/routing/interceptor/downsampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 076d8b0

Please sign in to comment.