fix ipv6 showing
This commit is contained in:
parent
af71cc3579
commit
0de57f2e49
@ -5,6 +5,8 @@ use std::default::Default;
|
|||||||
pub struct LocalIp {
|
pub struct LocalIp {
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
|
pub show4: bool,
|
||||||
|
pub show6: bool,
|
||||||
pub delay: f64,
|
pub delay: f64,
|
||||||
pub interface: String,
|
pub interface: String,
|
||||||
}
|
}
|
||||||
@ -14,6 +16,8 @@ impl Default for LocalIp {
|
|||||||
LocalIp {
|
LocalIp {
|
||||||
icon: String::from(""),
|
icon: String::from(""),
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
show4: true,
|
||||||
|
show6: false,
|
||||||
delay: 120.0,
|
delay: 120.0,
|
||||||
interface: String::from("wlan0"),
|
interface: String::from("wlan0"),
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ pub async fn get_local_ip() -> ThreadsData {
|
|||||||
let addrs = nix::ifaddrs::getifaddrs().unwrap();
|
let addrs = nix::ifaddrs::getifaddrs().unwrap();
|
||||||
let mut ip = String::new();
|
let mut ip = String::new();
|
||||||
let mut ip6 = String::new();
|
let mut ip6 = String::new();
|
||||||
let mut found4 = false;
|
let mut found4 = !CONFIG.local_ip.show4;
|
||||||
let mut found6 = false;
|
let mut found6 = !CONFIG.local_ip.show4;
|
||||||
for ifaddr in addrs {
|
for ifaddr in addrs {
|
||||||
match ifaddr.address {
|
match ifaddr.address {
|
||||||
Some(address) => {
|
Some(address) => {
|
||||||
@ -15,12 +15,20 @@ pub async fn get_local_ip() -> ThreadsData {
|
|||||||
match address.family() {
|
match address.family() {
|
||||||
nix::sys::socket::AddressFamily::Inet => {
|
nix::sys::socket::AddressFamily::Inet => {
|
||||||
if found4 { continue; }
|
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;
|
found4 = true;
|
||||||
}
|
}
|
||||||
nix::sys::socket::AddressFamily::Inet6 => {
|
nix::sys::socket::AddressFamily::Inet6 => {
|
||||||
if found6 { continue; }
|
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;
|
found6 = true;
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
|
Loading…
Reference in New Issue
Block a user