pub fn local_ipv6() -> Result<IpAddr, Error>
Expand description

Retrieves the local IPv6 address of the machine in the local network from the AF_INET6 family.

A different approach is taken based on the operative system.

For linux based systems the Netlink socket communication is used to retrieve the local network interface.

For BSD-based systems the getifaddrs approach is taken using libc

For Windows systems Win32’s IP Helper is used to gather the Local IP address

Examples found in repository?
examples/show_ip_and_ifs.rs (line 9)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    match local_ip() {
        Ok(ip) => println!("Local IPv4: {}", ip),
        Err(err) => println!("Failed to get local IPv4: {}", err),
    };

    match local_ipv6() {
        Ok(ip) => println!("Local IPv6: {}", ip),
        Err(err) => println!("Failed to get local IPv6: {}", err),
    };

    match list_afinet_netifas() {
        Ok(netifs) => {
            println!("Got {} interfaces", netifs.len());
            for netif in netifs {
                println!("IF: {}, IP: {}", netif.0, netif.1);
            }
        }
        Err(err) => println!("Failed to get list of network interfaces: {}", err),
    };
}