Skip to content

Commit 07b8f6b

Browse files
committed
Add support for ipv6 if_index
1 parent 45e74a6 commit 07b8f6b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,14 @@ mod getifaddrs_windows {
337337
}
338338
};
339339

340+
let index = match addr {
341+
IfAddr::V4(_) => ifaddr.ipv4_index(),
342+
IfAddr::V6(_) => ifaddr.ipv6_index(),
343+
};
340344
ret.push(Interface {
341345
name: ifaddr.name(),
342346
addr,
343-
index: ifaddr.index(),
347+
index,
344348
});
345349
}
346350
}

src/windows.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl IpAdapterAddresses {
2828
.into_owned()
2929
}
3030

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

40+
pub fn ipv6_index(&self) -> Option<u32> {
41+
let if_index = unsafe { (*self.0).Ipv6IfIndex };
42+
if if_index == 0 {
43+
None
44+
} else {
45+
Some(if_index)
46+
}
47+
}
48+
4049
pub fn prefixes(&self) -> PrefixesIterator {
4150
PrefixesIterator {
4251
_head: unsafe { &*self.0 },

0 commit comments

Comments
 (0)