From 8a1c52cd90cc2de09ac68aa82e80305607b22ee8 Mon Sep 17 00:00:00 2001 From: Neshura Date: Mon, 4 Mar 2024 16:23:19 +0100 Subject: [PATCH] Bugfix: IP could be set to '::' or '0.0.0.0' --- src/main.rs | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 10ad192..1808249 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,12 +61,21 @@ impl Addresses { match self.get_v4() { Ok(ip) => { if ip != self.ipv4 { - let info_msg = format!("IPv4 changed from '{}' to '{}'", self.ipv4, ip); - match connected_to_journal() { - true => info!("[INFO] {info_msg}"), - false => println!("[INFO] {info_msg}"), + if ip == Ipv4Addr::new(0,0,0,0) { + let warn_msg = "'0.0.0.0' detected as new IPv4, skipping changes".to_owned(); + match connected_to_journal() { + true => warn!("[WARN] {warn_msg}"), + false => println!("[WARN] {warn_msg}"), + } + } + else { + let info_msg = format!("IPv4 changed from '{}' to '{}'", self.ipv4, ip); + match connected_to_journal() { + true => info!("[INFO] {info_msg}"), + false => println!("[INFO] {info_msg}"), + } + self.ipv4 = ip; } - self.ipv4 = ip; } } Err(e) => { @@ -81,12 +90,21 @@ impl Addresses { match self.get_v6() { Ok(ip) => { if ip != self.ipv6 { - let info_msg = format!("IPv6 changed from '{}' to '{}'", self.ipv6, ip); - match connected_to_journal() { - true => info!("[INFO] {info_msg}"), - false => println!("[INFO] {info_msg}"), + if ip == Ipv6Addr::new(0,0,0,0,0,0,0,0) { + let warn_msg = "'::' detected as new IPv6, skipping changes".to_owned(); + match connected_to_journal() { + true => warn!("[WARN] {warn_msg}"), + false => println!("[WARN] {warn_msg}"), + } + } + else { + let info_msg = format!("IPv6 changed from '{}' to '{}'", self.ipv6, ip); + match connected_to_journal() { + true => info!("[INFO] {info_msg}"), + false => println!("[INFO] {info_msg}"), + } + self.ipv6 = ip; } - self.ipv6 = ip; } } Err(e) => {