fix: prioritize DNS resolution over hostname -f for hostname lookup
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user