diff --git a/src/meta_plugin/hostname.rs b/src/meta_plugin/hostname.rs index 93b57c2..a52c476 100644 --- a/src/meta_plugin/hostname.rs +++ b/src/meta_plugin/hostname.rs @@ -54,21 +54,7 @@ impl HostnameMetaPlugin { Err(_) => return "unknown".to_string(), }; - // Try to get the FQDN using the system's hostname resolution - // This should give us the full hostname if configured - if let Ok(full_hostname) = std::process::Command::new("hostname") - .arg("-f") - .output() - { - if full_hostname.status.success() { - let full_hostname_str = String::from_utf8_lossy(&full_hostname.stdout).trim().to_string(); - if !full_hostname_str.is_empty() && full_hostname_str != short_hostname { - return full_hostname_str; - } - } - } - - // Fallback: try DNS resolution for both IPv4 and IPv6 addresses + // First try DNS resolution for both IPv4 and IPv6 addresses // lookup_host should handle both A and AAAA records if let Ok(addrs) = dns_lookup::lookup_host(&short_hostname) { // Try each address (both IPv4 and IPv6) @@ -106,6 +92,20 @@ impl HostnameMetaPlugin { } } + // Fallback: try to get the FQDN using the system's hostname resolution + // This should give us the full hostname if configured + if let Ok(full_hostname) = std::process::Command::new("hostname") + .arg("-f") + .output() + { + if full_hostname.status.success() { + let full_hostname_str = String::from_utf8_lossy(&full_hostname.stdout).trim().to_string(); + if !full_hostname_str.is_empty() && full_hostname_str != short_hostname { + return full_hostname_str; + } + } + } + // Final fallback: return the short hostname short_hostname }