summaryrefslogtreecommitdiffstats
path: root/src/network/dns/resolver.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/dns/resolver.rs')
-rw-r--r--src/network/dns/resolver.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/network/dns/resolver.rs b/src/network/dns/resolver.rs
index 074f46e..1bdaf78 100644
--- a/src/network/dns/resolver.rs
+++ b/src/network/dns/resolver.rs
@@ -1,6 +1,9 @@
use async_trait::async_trait;
use std::net::IpAddr;
+use std::net::SocketAddr;
+use std::net::{Ipv4Addr, SocketAddrV4};
use tokio::runtime::Handle;
+use trust_dns_resolver::config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts};
use trust_dns_resolver::{error::ResolveErrorKind, TokioAsyncResolver};
#[async_trait]
@@ -11,8 +14,25 @@ pub trait Lookup {
pub struct Resolver(TokioAsyncResolver);
impl Resolver {
- pub async fn new(runtime: Handle) -> Result<Self, failure::Error> {
- let resolver = TokioAsyncResolver::from_system_conf(runtime).await?;
+ pub async fn new(
+ runtime: Handle,
+ dns_server: &Option<Ipv4Addr>,
+ ) -> Result<Self, failure::Error> {
+ let resolver = match dns_server {
+ Some(dns_server_address) => {
+ let mut config = ResolverConfig::new();
+ let options = ResolverOpts::default();
+ let socket = SocketAddr::V4(SocketAddrV4::new(*dns_server_address, 53));
+ let nameserver_config = NameServerConfig {
+ socket_addr: socket,
+ protocol: Protocol::Udp,
+ tls_dns_name: None,
+ };
+ config.add_name_server(nameserver_config);
+ TokioAsyncResolver::new(config, options, runtime).await?
+ }
+ None => TokioAsyncResolver::from_system_conf(runtime).await?,
+ };
Ok(Self(resolver))
}
}