diff options
author | Özgür Kesim <oec@codeblau.de> | 2022-01-31 17:35:56 +0100 |
---|---|---|
committer | Özgür Kesim <oec@codeblau.de> | 2022-01-31 17:35:56 +0100 |
commit | 0de57f2e49a1aeeb47cf82ece0b0ad158f477da7 (patch) | |
tree | 8e5dbf9c9089d0d02a2e9c105a5abb3b22c9204d /src/utils/local_ip.rs | |
parent | af71cc35793c6757c19c619226a62f46e3288a57 (diff) |
Diffstat (limited to 'src/utils/local_ip.rs')
-rw-r--r-- | src/utils/local_ip.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/utils/local_ip.rs b/src/utils/local_ip.rs index 07f5c19..f42dc61 100644 --- a/src/utils/local_ip.rs +++ b/src/utils/local_ip.rs @@ -5,8 +5,8 @@ pub async fn get_local_ip() -> ThreadsData { let addrs = nix::ifaddrs::getifaddrs().unwrap(); let mut ip = String::new(); let mut ip6 = String::new(); - let mut found4 = false; - let mut found6 = false; + let mut found4 = !CONFIG.local_ip.show4; + let mut found6 = !CONFIG.local_ip.show4; for ifaddr in addrs { match ifaddr.address { Some(address) => { @@ -15,12 +15,20 @@ pub async fn get_local_ip() -> ThreadsData { match address.family() { nix::sys::socket::AddressFamily::Inet => { if found4 { continue; } - ip = address.to_string().split(':').next().unwrap().to_string(); + ip = if CONFIG.local_ip.show4 { + address.to_string().split(':').next().unwrap().to_string() + } else { + String::from(" ") + }; found4 = true; } nix::sys::socket::AddressFamily::Inet6 => { if found6 { continue; } - ip6 = address.to_string().rsplit_once(':').unwrap().0.to_string(); + ip6 = if CONFIG.local_ip.show6 { + address.to_string().rsplit_once(':').unwrap().0.to_string() + } else { + String::from(" ") + }; found6 = true; } _ => continue, |