From 1f617cbfcffa4b9c1f92128f867e9f2ba7042770 Mon Sep 17 00:00:00 2001 From: shellrow <81893184+shellrow@users.noreply.github.com> Date: Fri, 10 Mar 2023 00:47:36 +0900 Subject: [PATCH 1/2] #19 Upgrade windows dependency --- Cargo.toml | 2 +- src/interface/windows.rs | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1015603..b19f42d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ libc = "0.2" memalloc = "0.1.0" [target.'cfg(windows)'.dependencies.windows] -version = "0.30.0" +version = "0.32.0" features = ["Win32_Foundation","Win32_NetworkManagement_IpHelper", "Win32_Networking_WinSock"] [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] diff --git a/src/interface/windows.rs b/src/interface/windows.rs index 0d34a00..9bb712e 100644 --- a/src/interface/windows.rs +++ b/src/interface/windows.rs @@ -32,7 +32,7 @@ fn get_mac_through_arp(src_ip: Ipv4Addr, dst_ip: Ipv4Addr) -> MacAddr { let mut out_buf_len : u32 = 6; let mut target_mac_addr: [u8; 6] = [0; 6]; let res = unsafe { SendARP(dst_ip_int, src_ip_int, target_mac_addr.as_mut_ptr() as *mut c_void, &mut out_buf_len) }; - if res == NO_ERROR { + if res == NO_ERROR.0 { MacAddr::new(target_mac_addr) }else{ MacAddr::zero() @@ -47,19 +47,17 @@ pub fn interfaces() -> Vec { let mut mem = unsafe { allocate(dwsize as usize) } as *mut IP_ADAPTER_ADDRESSES_LH; let mut retries = 3; let mut ret_val; - let family: u32 = AF_UNSPEC; - let flags: u32 = GAA_FLAG_INCLUDE_GATEWAYS; loop { let old_size = dwsize as usize; - ret_val = unsafe { GetAdaptersAddresses(family, flags, std::ptr::null_mut::(), mem, &mut dwsize) }; - if ret_val != ERROR_BUFFER_OVERFLOW || retries <= 0 { + ret_val = unsafe { GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_GATEWAYS, std::ptr::null_mut::(), mem, &mut dwsize) }; + if ret_val != ERROR_BUFFER_OVERFLOW.0 || retries <= 0 { break; } unsafe { deallocate(mem as *mut u8, old_size as usize) }; mem = unsafe { allocate(dwsize as usize) as *mut IP_ADAPTER_ADDRESSES_LH }; retries -= 1; } - if ret_val == NO_ERROR { + if ret_val == NO_ERROR.0 { // Enumerate all adapters let mut cur = mem; while !cur.is_null() { @@ -108,7 +106,7 @@ pub fn interfaces() -> Vec { let addr = unsafe { (*cur_a).Address }; let prefix_len = unsafe{ (*cur_a).OnLinkPrefixLength }; let sockaddr = unsafe { *addr.lpSockaddr }; - if sockaddr.sa_family == AF_INET as u16 { + if sockaddr.sa_family == AF_INET.0 as u16{ let sockaddr: *mut SOCKADDR_IN = addr.lpSockaddr as *mut SOCKADDR_IN; let a = unsafe { (*sockaddr).sin_addr.S_un.S_addr }; let ipv4 = if cfg!(target_endian = "little") { @@ -118,7 +116,7 @@ pub fn interfaces() -> Vec { }; let ipv4_net: Ipv4Net = Ipv4Net::new(ipv4, prefix_len); ipv4_vec.push(ipv4_net); - } else if sockaddr.sa_family == AF_INET6 as u16 { + } else if sockaddr.sa_family == AF_INET6.0 as u16 { let sockaddr: *mut SOCKADDR_IN6 = addr.lpSockaddr as *mut SOCKADDR_IN6; let a = unsafe { (*sockaddr).sin6_addr.u.Byte }; let ipv6 = Ipv6Addr::from(a); @@ -134,7 +132,7 @@ pub fn interfaces() -> Vec { while !cur_g.is_null() { let addr = unsafe { (*cur_g).Address }; let sockaddr = unsafe { *addr.lpSockaddr }; - if sockaddr.sa_family == AF_INET as u16 { + if sockaddr.sa_family == AF_INET.0 as u16 { let sockaddr: *mut SOCKADDR_IN = addr.lpSockaddr as *mut SOCKADDR_IN; let a = unsafe { (*sockaddr).sin_addr.S_un.S_addr }; let ipv4 = if cfg!(target_endian = "little") { From 8e3f713ac892752adc476b00d227a30a0d6259b7 Mon Sep 17 00:00:00 2001 From: shellrow <81893184+shellrow@users.noreply.github.com> Date: Fri, 10 Mar 2023 00:57:09 +0900 Subject: [PATCH 2/2] Bump version to 0.13.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b19f42d..ae2dfcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "default-net" -version = "0.12.0" +version = "0.13.0" authors = ["shellrow "] edition = "2021" description = "Cross-platform library for network interface and gateway"