mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-08 13:41:29 +03:00
Epoll (#20)
major update: - remove threading overhead by resorting to an event driven design with mio as a backend for epoll - Clients can now have an arbitrary amount of ip adresses and lan-mouse will automatically choose the correct one - -> seemless switching between ethernet and wifi - cli frontend + frontend adapter for future frontends
This commit is contained in:
committed by
GitHub
parent
22e6c531af
commit
1a4d0e05be
26
src/dns.rs
26
src/dns.rs
@@ -1,27 +1,9 @@
|
||||
use std::{error::Error, fmt::Display, net::IpAddr};
|
||||
use std::{error::Error, net::IpAddr};
|
||||
|
||||
use trust_dns_resolver::Resolver;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct InvalidConfigError;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct DnsError {
|
||||
host: String,
|
||||
}
|
||||
|
||||
impl Error for DnsError {}
|
||||
|
||||
impl Display for DnsError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "couldn't resolve host \"{}\"", self.host)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolve(host: &String) -> Result<IpAddr, Box<dyn Error>> {
|
||||
pub fn resolve(host: &str) -> Result<Vec<IpAddr>, Box<dyn Error>> {
|
||||
log::info!("resolving {host} ...");
|
||||
let response = Resolver::from_system_conf()?.lookup_ip(host)?;
|
||||
match response.iter().next() {
|
||||
Some(ip) => Ok(ip),
|
||||
None => Err(DnsError { host: host.clone() }.into()),
|
||||
}
|
||||
Ok(response.iter().collect())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user