Skip to content

Commit

Permalink
Rename idx to index
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Feb 28, 2023
1 parent 56ce5b5 commit 45e74a6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Interface {
/// The address details of the interface.
pub addr: IfAddr,
/// The index of the interface.
pub idx: Option<u32>,
pub index: Option<u32>,
}

impl Interface {
Expand Down Expand Up @@ -192,19 +192,19 @@ mod getifaddrs_posix {
let name = unsafe { CStr::from_ptr(ifaddr.ifa_name) }
.to_string_lossy()
.into_owned();
let idx = {
let idx = unsafe { if_nametoindex(ifaddr.ifa_name) };
let index = {
let index = unsafe { if_nametoindex(ifaddr.ifa_name) };

// From `man if_nametoindex 3`:
// The if_nametoindex() function maps the interface name specified in ifname to its
// corresponding index. If the specified interface does not exist, it returns 0.
if idx == 0 {
if index == 0 {
None
} else {
Some(idx)
Some(index)
}
};
ret.push(Interface { name, addr, idx });
ret.push(Interface { name, addr, index });
}

Ok(ret)
Expand Down Expand Up @@ -340,7 +340,7 @@ mod getifaddrs_windows {
ret.push(Interface {
name: ifaddr.name(),
addr,
idx: ifaddr.index(),
index: ifaddr.index(),
});
}
}
Expand Down Expand Up @@ -454,7 +454,7 @@ mod tests {
);
// if index is set, it is non-zero
for interface in &ifaces {
if let Some(idx) = interface.idx {
if let Some(idx) = interface.index {
assert!(idx > 0);
}
}
Expand All @@ -476,7 +476,7 @@ mod tests {
}

#[cfg(not(windows))]
assert!(interface.idx.is_some());
assert!(interface.index.is_some());
}
assert!(listed);
}
Expand Down

0 comments on commit 45e74a6

Please sign in to comment.