Repository: GyulyVGC/sniffnet (language: rust)

Issue:
Show more information when domain name is short (e.g., "com.au")
### Is there an existing issue for this?

- [x] I have searched the existing issues.

### Describe the solution you'd like

Show more information when domain is like com.au. It isn't helpful seeing only com.au

![Image](https://github.com/user-attachments/assets/26b7cd78-b67b-4c4a-8c3a-89393afc517b)

### Is your feature request related to a problem?

_No response_
Show more information when domain name is short (e.g., "com.au")
### Is there an existing issue for this?

- [x] I have searched the existing issues.

### Describe the solution you'd like

Show more information when domain is like com.au. It isn't helpful seeing only com.au

![Image](https://github.com/user-attachments/assets/26b7cd78-b67b-4c4a-8c3a-89393afc517b)

### Is your feature request related to a problem?

_No response_


Discussion / hints:
Thanks for the advice.
Thanks for the advice.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e6900c37..9d7f7187 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,9 +8,10 @@ All Sniffnet releases with the relative changes are documented in this file.
 - Updated some of the existing translations to v1.3: 
   - Portuguese ([#690](https://github.com/GyulyVGC/sniffnet/pull/690))
   - Ukrainian ([#692](https://github.com/GyulyVGC/sniffnet/pull/692))
+- Show more information when domain name is short ([#720](https://github.com/GyulyVGC/sniffnet/pull/720) — fixes [#696](https://github.com/GyulyVGC/sniffnet/issues/696))
 - Added new themes _OLED (Night)_ and _OLED (Day)_ based on palettes optimized for OLED displays and users with visual impairments ([#708](https://github.com/GyulyVGC/sniffnet/pull/708))
-- Fix _crates.io_ package for Windows ([#718](https://github.com/GyulyVGC/sniffnet/pull/718) — fixes [#681](https://github.com/GyulyVGC/sniffnet/issues/681))
 - Add icon to window title bar ([#719](https://github.com/GyulyVGC/sniffnet/pull/719) — fixes [#715](https://github.com/GyulyVGC/sniffnet/issues/715))
+- Fix _crates.io_ package for Windows ([#718](https://github.com/GyulyVGC/sniffnet/pull/718) — fixes [#681](https://github.com/GyulyVGC/sniffnet/issues/681))
 - Remove pre-uninstall script on Linux (fixes [#644](https://github.com/GyulyVGC/sniffnet/issues/644))
 
 ## [1.3.2] - 2025-01-06
diff --git a/src/utils/formatted_strings.rs b/src/utils/formatted_strings.rs
index dde3c686..88c6bf93 100644
--- a/src/utils/formatted_strings.rs
+++ b/src/utils/formatted_strings.rs
@@ -107,16 +107,19 @@ pub fn get_domain_from_r_dns(r_dns: String) -> String {
         r_dns
     } else {
         let parts: Vec<&str> = r_dns.split('.').collect();
-        if parts.len() >= 2 {
-            parts
-                .get(parts.len() - 2..)
-                .unwrap_or(&parts)
-                .iter()
-                .fold(Vec::new(), |mut vec, part| {
-                    vec.push((*part).to_string());
-                    vec
-                })
-                .join(".")
+        let len = parts.len();
+        if len >= 2 {
+            let last = parts.get(len - 1).unwrap_or(&"");
+            let second_last = parts.get(len - 2).unwrap_or(&"");
+            if last.len() > 3 || second_last.len() > 3 {
+                format!("{second_last}.{last}")
+            } else {
+                let third_last_opt = len.checked_sub(3).and_then(|i| parts.get(i));
+                match third_last_opt {
+                    Some(third_last) => format!("{third_last}.{second_last}.{last}"),
+                    None => format!("{second_last}.{last}"),
+                }
+            }
         } else {
             r_dns
         }
@@ -232,4 +235,33 @@ mod tests {
         assert!(file_path.is_absolute());
         assert_eq!(file_path.file_name().unwrap(), "logs.txt");
     }
+
+    #[test]
+    fn test_get_domain_from_r_dns() {
+        let f = |s: &str| get_domain_from_r_dns(s.to_string());
+        assert_eq!(f(""), "");
+        assert_eq!(f("8.8.8.8"), "8.8.8.8");
+        assert_eq!(f("a.b.c.d"), "b.c.d");
+        assert_eq!(f("ciao.xyz"), "ciao.xyz");
+        assert_eq!(f("bye.ciao.xyz"), "ciao.xyz");
+        assert_eq!(f("ciao.bye.xyz"), "ciao.bye.xyz");
+        assert_eq!(f("hola.ciao.bye.xyz"), "ciao.bye.xyz");
+        assert_eq!(f(".bye.xyz"), ".bye.xyz");
+        assert_eq!(f("bye.xyz"), "bye.xyz");
+        assert_eq!(f("hola.ciao.b"), "ciao.b");
+        assert_eq!(f("hola.b.ciao"), "b.ciao");
+        assert_eq!(f("ciao."), "ciao.");
+        assert_eq!(f("ciao.."), "ciao..");
+        assert_eq!(f(".ciao."), "ciao.");
+        assert_eq!(f("ciao.bye."), "ciao.bye.");
+        assert_eq!(f("ciao..."), "..");
+        assert_eq!(f("..bye"), "..bye");
+        assert_eq!(f("ciao..bye"), "ciao..bye");
+        assert_eq!(f("..ciao"), ".ciao");
+        assert_eq!(f("bye..ciao"), ".ciao");
+        assert_eq!(f("."), ".");
+        assert_eq!(f(".."), "..");
+        assert_eq!(f("..."), "..");
+        assert_eq!(f("no_dots_in_this"), "no_dots_in_this");
+    }
 }


Test patch: