feat: implement hostname resolution using gethostname and dns-lookup
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user