Skip to content

Commit

Permalink
Add support for ipv6 if_index
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Feb 28, 2023
1 parent 45e74a6 commit 07b8f6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,14 @@ mod getifaddrs_windows {
}
};

let index = match addr {
IfAddr::V4(_) => ifaddr.ipv4_index(),
IfAddr::V6(_) => ifaddr.ipv6_index(),
};
ret.push(Interface {
name: ifaddr.name(),
addr,
index: ifaddr.index(),
index,
});
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl IpAdapterAddresses {
.into_owned()
}

pub fn index(&self) -> Option<u32> {
pub fn ipv4_index(&self) -> Option<u32> {
let if_index = unsafe { (*self.0).Anonymous1.Anonymous.IfIndex };
if if_index == 0 {
None
Expand All @@ -37,6 +37,15 @@ impl IpAdapterAddresses {
}
}

pub fn ipv6_index(&self) -> Option<u32> {
let if_index = unsafe { (*self.0).Ipv6IfIndex };
if if_index == 0 {
None
} else {
Some(if_index)
}
}

pub fn prefixes(&self) -> PrefixesIterator {
PrefixesIterator {
_head: unsafe { &*self.0 },
Expand Down

0 comments on commit 07b8f6b

Please sign in to comment.