engine/Networking/src/local_address.rs
2024-08-23 13:22:09 +02:00

26 lines
714 B
Rust

pub fn find_local_address() -> Vec<std::net::IpAddr> {
use if_addrs::*;
let mut addresses = Vec::new();
if let Some(interfaces) = get_if_addrs().ok() {
for interface in interfaces {
match interface.addr {
IfAddr::V4(v4) => {
let ip = v4.ip;
let octets = ip.octets();
if octets[0] == 192 && octets[1] == 168 {
addresses.push(std::net::IpAddr::V4(ip));
}
}
IfAddr::V6(_v6) => {
// TODO
// addresses.push(IpAddr::V6(v6.ip));
}
}
}
}
addresses
}