From 81ac8fcfbb21841e5db882b92e000dd190b59ccc Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Tue, 26 Aug 2025 21:16:51 -0300 Subject: [PATCH] feat: implement hostname resolution using gethostname and dns-lookup Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) --- src/meta_plugin/hostname.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) 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;