Could Maisafe add the following line in crust lib.rs?
pub use common::get_if_addrs::get_if_addrs;
Listing local interfaces and getting their IP details is a hard thing to do in rust. The only implementation I found is pnet but it needs an addon on Windows (WinPcap).
This function is provided by crust, it would be a pity to not expose it for the general rust community.
An example of usage would be:
extern crate crust;
fn main() {
for iface in crust::get_if_addrs().unwrap() {
println!("{:?}", iface.addr);
}
}
The results would be like the following screen shots:
- On Windows behind a router:
V6(Ifv6Addr { ip: 2a01:cb00:5f0:800:c5a8:b0af:9c22:d592, netmask: ffff:ffff:ffff:ffff::, broadcast: None })
V6(Ifv6Addr { ip: 2a01:cb00:5f0:800:654b:c810:e1b1:1b28, netmask: ffff:ffff:ffff:ffff::, broadcast: None })
V4(Ifv4Addr { ip: 192.168.1.55, netmask: 255.255.255.0, broadcast: Some(192.168.1.255) })
V6(Ifv6Addr { ip: ::1, netmask: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff, broadcast: None })
V4(Ifv4Addr { ip: 127.0.0.1, netmask: 255.0.0.0, broadcast: Some(127.255.255.255) })
V6(Ifv6Addr { ip: 2001:0:9d38:6abd:2062:cf6:a5b0:f9c6, netmask: ffff:ffff::, broadcast: None })
- On Linux on a server of a cloud provider:
V4(Ifv4Addr { ip: 127.0.0.1, netmask: 255.0.0.0, broadcast: None })
V4(Ifv4Addr { ip: 45.32.151.63, netmask: 255.255.252.0, broadcast: Some(45.32.151.255) })
V6(Ifv6Addr { ip: ::1, netmask: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff, broadcast: None })