Files
lan-mouse/src/dns.rs
Ferdinand Schober 06725f4b14 Frontend improvement (#27)
* removed redundant dns lookups
* frontend now correctly reflects the state of the backend
* config.toml is loaded when starting gtk frontend
2023-09-25 13:03:17 +02:00

21 lines
535 B
Rust

use anyhow::Result;
use std::{error::Error, net::IpAddr};
use trust_dns_resolver::Resolver;
pub(crate) struct DnsResolver {
resolver: Resolver,
}
impl DnsResolver {
pub(crate) fn new() -> Result<Self> {
let resolver = Resolver::from_system_conf()?;
Ok(Self { resolver })
}
pub(crate) fn resolve(&self, host: &str) -> Result<Vec<IpAddr>, Box<dyn Error>> {
log::info!("resolving {host} ...");
let response = self.resolver.lookup_ip(host)?;
Ok(response.iter().collect())
}
}