Function local_ip_address::linux::local_broadcast_ip

source ยท
pub fn local_broadcast_ip() -> Result<IpAddr, Error>
Expand description

Retrieves the local broadcast IPv4 address for this system

Examples found in repository?
examples/show_ip_and_ifs.rs (line 19)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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),
    };

    // this is only supported on linux currently
    #[cfg(target_os = "linux")]
    match local_broadcast_ip() {
        Ok(ip) => println!("Local broadcast IPv4: {}", ip),
        Err(err) => println!("Failed to get local broadcast IPv4: {}", 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),
    };
}