xous-core/services/dns/src/hosted.rs
bunnie 0dbf1661cb add TCP to hosted mode emulation
Total bodge -- we lop off the TCP stack at the Xous API level, and
substitute it with a native host TCP stack.

Caveat hacker: this means that a lot of OS-specific net properties
will carry through to the hosted mode emulation. This is adequate
for "smoke testing" a build but do not be shocked, *shocked* if
there are more bugs to be found because of some weird host integration
issue.
2022-02-20 21:31:32 +08:00

41 lines
1.3 KiB
Rust

use net::NetIpAddr;
use std::net::ToSocketAddrs;
use crate::DnsResponseCode;
#[derive(Debug)]
pub struct Dns {
}
impl Dns {
pub fn new(_xns: &xous_names::XousNames) -> Result<Self, xous::Error> {
Ok(Dns {
})
}
/// Checks first to see if the name could be just an IPv4 or IPv6 in string form,
/// then tries to pass it to the DNS resolver.
pub fn lookup(&self, name: &str) -> Result<NetIpAddr, DnsResponseCode> {
log::debug!("looking up {}", name);
match (name, 80).to_socket_addrs() { // we throw away the port because we just want the IP address...
Ok(mut iter) => {
match iter.next() {
Some(addr) => {
log::debug!("{:?}", addr);
Ok(NetIpAddr::from(addr))
},
None => {
log::debug!("name error");
Err(DnsResponseCode::NameError)
}
}
}
Err(e) => {
log::debug!("format error: {:?}", e);
Err(DnsResponseCode::FormatError)
}
}
}
pub fn flush_cache(&self) -> Result<(), xous::Error> {
log::warn!("DNS cache flush not implemented in hosted mode!");
Ok(())
}
}