diff --git a/src/meta_plugin/hostname.rs b/src/meta_plugin/hostname.rs index 83d62a7..8fb1b00 100644 --- a/src/meta_plugin/hostname.rs +++ b/src/meta_plugin/hostname.rs @@ -48,14 +48,28 @@ impl HostnameMetaPlugin { } fn get_hostname(&self) -> String { - match hostname::get() { - Ok(hostname_os) => { - match hostname_os.into_string() { - Ok(hostname) => hostname, - Err(_) => "unknown".to_string(), + // First get the short hostname + let short_hostname = match gethostname::gethostname().into_string() { + Ok(hostname) => hostname, + Err(_) => return "unknown".to_string(), + }; + + // Try to get the full hostname using DNS lookup + // This will work if the hostname can be resolved + match dns_lookup::lookup_host(&short_hostname) { + Ok(addrs) => { + for addr in addrs { + if let std::net::IpAddr::V4(ipv4) = addr { + match dns_lookup::lookup_addr(&ipv4) { + Ok(full_hostname) => return full_hostname, + Err(_) => continue, + } + } } + // Fall back to short hostname if resolution fails + short_hostname } - Err(_) => "unknown".to_string(), + Err(_) => short_hostname, } } } @@ -187,3 +201,4 @@ impl MetaPlugin for HostnameMetaPlugin { Ok(()) } } +use gethostname::gethostname;