xous-core/services/dns/src/api.rs
bunnie cee4e83746 add a DNS parser. that was fun. :-|
yes, i know there is some fancy way to code this with iterators.
i don't like that way. this ways is easier for me to understand
and verify. It works now.

Sometimes, Rust sucks a bit. It's ok, you can cry.
2021-10-20 20:06:08 +08:00

45 lines
1.3 KiB
Rust

pub(crate) const SERVER_NAME_DNS: &str = "_DNS Resolver Middleware_";
use net::NetIpAddr;
use rkyv::{Archive, Deserialize, Serialize};
pub(crate) const DNS_NAME_LENGTH_LIMIT: usize = 256;
#[allow(dead_code)]
pub(crate) const DNS_PKT_MAX_LEN: usize = 512;
/// These opcodes can be called by anyone at any time
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
pub(crate) enum Opcode {
Lookup,
Flush,
/// used internally to update the TTL field, and eventually expire the cache (unless cache is frozen)
UpdateTtl,
/// issuing this opcode causes all future attempts to change the DNS server configs to be ignored. This also freezes the cache.
FreezeConfig,
/// this allows automatic updates to the DNS server configs based on DHCP. This is the default state.
ThawConfig,
Quit,
}
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive, Archive, Serialize, Deserialize, Copy, Clone)]
#[repr(u16)]
pub enum DnsResponseCode {
NoError = 0,
FormatError = 1,
ServerFailure = 2,
NameError = 3,
NotImplemented = 4,
Refused = 5,
UnknownError,
NetworkError,
NoServerSpecified,
}
#[derive(Debug, Archive, Serialize, Deserialize, Copy, Clone)]
pub struct DnsResponse {
pub addr: Option<NetIpAddr>,
pub code: DnsResponseCode,
}