pub struct Iface { /* private fields */ }Expand description
Representation of a host network interface.
Implementations§
Source§impl Iface
impl Iface
Sourcepub fn from_system(name: &str) -> Result<Self>
pub fn from_system(name: &str) -> Result<Self>
Resolve an interface from the operating system by its name.
When the interface carries several IPv4 addresses the first one is
used; Iface::from_ipv4 preserves the address that was asked for.
Sourcepub fn from_ipv4(addr: Ipv4Addr) -> Result<Self>
pub fn from_ipv4(addr: Ipv4Addr) -> Result<Self>
Resolve an interface by one of its IPv4 addresses.
The resulting Iface reports addr itself, not whichever address
the OS happens to list last for that interface. A multi-homed NIC —
a stale DHCP lease alongside a link-local address, say — would
otherwise resolve to a different address than the caller selected
and bind the socket to the wrong one (#57).
Sourcepub fn from_remote_ipv4(remote: Ipv4Addr) -> Result<Self>
pub fn from_remote_ipv4(remote: Ipv4Addr) -> Result<Self>
Resolve the local interface selected by the operating system for a remote IPv4 address.
Sourcepub fn list() -> Result<Vec<Self>>
pub fn list() -> Result<Vec<Self>>
Every interface the operating system reports, one entry per name.
This is the library’s own view of the machine, which is the point: #57
was an interface that existed but that we could not see, and no amount
of ipconfig output would have shown that. Ordered by name so two
runs can be diffed.
Sourcepub fn all_ipv4(&self) -> Result<Vec<Ipv4Addr>>
pub fn all_ipv4(&self) -> Result<Vec<Ipv4Addr>>
Every IPv4 address assigned to this interface.
Iface::ipv4 reports the one the socket will bind to; a multi-homed
NIC has more, and which ones they are is exactly the question #57
turned on.
Sourcepub fn index(&self) -> u32
pub fn index(&self) -> u32
Interface index as reported by the kernel. The index is used by some socket options (e.g. multicast subscriptions).