Skip to content

Commit

Permalink
family takes values based on IP type (#71)
Browse files Browse the repository at this point in the history
* family takes values based on IP type

* remove AF_UNSPEC
  • Loading branch information
vnt-dev authored Jan 16, 2025
1 parent 9cd37ac commit bb286ef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ fn bindgen() {
"Windows.Win32.Foundation.NO_ERROR",
"Windows.Win32.Networking.WinSock.AF_INET",
"Windows.Win32.Networking.WinSock.AF_INET6",
"Windows.Win32.Networking.WinSock.AF_UNSPEC",
"Windows.Win32.Networking.WinSock.SOCKADDR_INET",
"Windows.Win32.NetworkManagement.IpHelper.FreeMibTable",
"Windows.Win32.NetworkManagement.IpHelper.GetBestInterfaceEx",
Expand Down
5 changes: 3 additions & 2 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod bindings {

use bindings::{
if_indextoname, FreeMibTable, GetBestInterfaceEx, GetIpInterfaceTable, AF_INET, AF_INET6,
AF_UNSPEC, IF_MAX_STRING_SIZE, IN6_ADDR, IN6_ADDR_0, IN_ADDR, IN_ADDR_0, MIB_IPINTERFACE_ROW,
IF_MAX_STRING_SIZE, IN6_ADDR, IN6_ADDR_0, IN_ADDR, IN_ADDR_0, MIB_IPINTERFACE_ROW,
MIB_IPINTERFACE_TABLE, NO_ERROR, SOCKADDR, SOCKADDR_IN, SOCKADDR_IN6, SOCKADDR_INET,
};

Expand Down Expand Up @@ -107,7 +107,8 @@ pub fn interface_and_mtu_impl(remote: IpAddr) -> Result<(String, usize)> {
// Get a list of all interfaces with associated metadata.
let mut if_table = MibTablePtr::default();
// GetIpInterfaceTable allocates memory, which MibTablePtr::drop will free.
if unsafe { GetIpInterfaceTable(AF_UNSPEC, if_table.mut_ptr_ptr()) } != NO_ERROR {
let family = if remote.is_ipv4() { AF_INET } else { AF_INET6 };
if unsafe { GetIpInterfaceTable(family, if_table.mut_ptr_ptr()) } != NO_ERROR {
return Err(Error::last_os_error());
}
// Make a slice
Expand Down

0 comments on commit bb286ef

Please sign in to comment.