dns/src/proto.rs

85 lines
2.0 KiB
Rust
Raw Normal View History

2022-03-13 21:56:17 +01:00
#[derive(Debug)]
pub enum DNSOpCode {
QUERY = 0,
IQUERY = 1, // obsolete
STATUS = 2,
NOTIFY = 4,
UPDATE = 5,
}
impl From<u16> for DNSOpCode {
fn from(val: u16) -> Self {
match val {
0 => DNSOpCode::QUERY,
1 => DNSOpCode::IQUERY,
2 => DNSOpCode::STATUS,
4 => DNSOpCode::NOTIFY,
5 => DNSOpCode::UPDATE,
_ => panic!("KACKE"),
}
}
}
// TODO: FIXME: TECHNISCHE SCHULD (alle pubs weg und gucken wie es richtig geht)
#[derive(Debug)]
pub enum DNSRCode {
NOERROR = 0,
FORMERR = 1,
SERVFAIL = 2,
NXDOMAIN = 3,
NOTIMP = 4,
REFUSED = 5,
XYDOMAIN = 6,
XYRRSET = 7,
NXRRSET = 8,
NOTAUTH = 9,
NOTINZONE = 10,
}
impl From<u16> for DNSRCode {
fn from(val: u16) -> Self {
match val {
0 => DNSRCode::NOERROR,
1 => DNSRCode::FORMERR,
2 => DNSRCode::SERVFAIL,
3 => DNSRCode::NXDOMAIN,
4 => DNSRCode::NOTIMP,
5 => DNSRCode::REFUSED,
6 => DNSRCode::XYDOMAIN,
7 => DNSRCode::XYRRSET,
8 => DNSRCode::NXRRSET,
9 => DNSRCode::NOTAUTH,
10 => DNSRCode::NOTINZONE,
_ => panic!("KACKE"),
}
}
}
#[derive(Debug)]
pub struct DNSHeader {
/// used by the requester to match up replies to outstanding queries
pub id: u16,
/// specifies whether this message is a query (false), or a response (true)
pub qr: bool,
pub opcode: DNSOpCode,
pub authoritative_answer: bool,
pub truncated: bool,
pub recursion_desired: bool,
pub recursion_available: bool,
pub authentic_data: bool,
pub checking_disabled: bool,
pub response_code: DNSRCode,
pub qd_zo_count: u16,
pub an_pr_count: u16,
pub ns_up_count: u16,
pub ar_count: u16,
}
#[derive(Debug)]
pub struct DNSQuery {
pub hdr: DNSHeader,
pub name: String,
pub qclass: u16,
pub qtype: u16,
}