@@ -24,7 +24,7 @@ pub struct Interface {
24
24
/// The address details of the interface.
25
25
pub addr : IfAddr ,
26
26
/// The index of the interface.
27
- pub idx : Option < u32 > ,
27
+ pub index : Option < u32 > ,
28
28
}
29
29
30
30
impl Interface {
@@ -192,19 +192,19 @@ mod getifaddrs_posix {
192
192
let name = unsafe { CStr :: from_ptr ( ifaddr. ifa_name ) }
193
193
. to_string_lossy ( )
194
194
. into_owned ( ) ;
195
- let idx = {
196
- let idx = unsafe { if_nametoindex ( ifaddr. ifa_name ) } ;
195
+ let index = {
196
+ let index = unsafe { if_nametoindex ( ifaddr. ifa_name ) } ;
197
197
198
198
// From `man if_nametoindex 3`:
199
199
// The if_nametoindex() function maps the interface name specified in ifname to its
200
200
// corresponding index. If the specified interface does not exist, it returns 0.
201
- if idx == 0 {
201
+ if index == 0 {
202
202
None
203
203
} else {
204
- Some ( idx )
204
+ Some ( index )
205
205
}
206
206
} ;
207
- ret. push ( Interface { name, addr, idx } ) ;
207
+ ret. push ( Interface { name, addr, index } ) ;
208
208
}
209
209
210
210
Ok ( ret)
@@ -337,10 +337,14 @@ mod getifaddrs_windows {
337
337
}
338
338
} ;
339
339
340
+ let index = match addr {
341
+ IfAddr :: V4 ( _) => ifaddr. ipv4_index ( ) ,
342
+ IfAddr :: V6 ( _) => ifaddr. ipv6_index ( ) ,
343
+ } ;
340
344
ret. push ( Interface {
341
345
name : ifaddr. name ( ) ,
342
346
addr,
343
- idx : None ,
347
+ index ,
344
348
} ) ;
345
349
}
346
350
}
@@ -454,7 +458,7 @@ mod tests {
454
458
) ;
455
459
// if index is set, it is non-zero
456
460
for interface in & ifaces {
457
- if let Some ( idx) = interface. idx {
461
+ if let Some ( idx) = interface. index {
458
462
assert ! ( idx > 0 ) ;
459
463
}
460
464
}
@@ -475,8 +479,7 @@ mod tests {
475
479
listed = true ;
476
480
}
477
481
478
- #[ cfg( not( windows) ) ]
479
- assert ! ( interface. idx. is_some( ) ) ;
482
+ assert ! ( interface. index. is_some( ) ) ;
480
483
}
481
484
assert ! ( listed) ;
482
485
}
0 commit comments