Exposing an internal crust function

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 })
2 Likes

The line must be completed with the associated data structures needed to get the IP details:

pub use common::get_if_addrs::{get_if_addrs, Interface, IfAddr, Ifv4Addr, Ifv6Addr};

I did a fork of crust repository with the added line. I can issue a PR if Maidsafe whishes it.

That makes sense as it’s easier to decide and merge. I think I can see no reason not to do this, but the guys also need to chime in, just in case we missed anything, I am not sure we have though.

2 Likes

Let the guys decide it and manage it, in case some complementary work is needed.

In the mean time I found that this function is exposed in an independent crate (get_if_addrs) and this is fine with me (except maybe code duplication).

I will delete my fork because I don’t need it any more. Nothing important will be lost because I only added one line (the one in post #2).

2 Likes