Skip to content

Commit

Permalink
family takes values based on IP type
Browse files Browse the repository at this point in the history
  • Loading branch information
vnt-dev committed Jan 16, 2025
1 parent 9cd37ac commit b47128a
Showing 1 changed file with 3 additions and 2 deletions.
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 b47128a

Please sign in to comment.