mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
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.
41 lines
1.3 KiB
Rust
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(())
|
|
}
|
|
}
|