mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-11 07:10:54 +03:00
* removed redundant dns lookups * frontend now correctly reflects the state of the backend * config.toml is loaded when starting gtk frontend
21 lines
535 B
Rust
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())
|
|
}
|
|
}
|