dns_server/dns_response_code.rs
1/// > `RCODE` Response code - this 4 bit field is set as part of responses. The values have the
2/// > following interpretation:
3/// > - `0` No error condition
4/// > - `1` Format error - The name server was unable to interpret the query.
5/// > - `2` Server failure - The name server was unable to process this query due to a problem with
6/// > the name server.
7/// > - `3` Name Error - Meaningful only for responses from an authoritative name server, this code
8/// > signifies that the domain name referenced in the query does not exist.
9/// > - `4` Not Implemented - The name server does not support the requested kind of query.
10/// > - `5` Refused - The name server refuses to perform the specified operation for policy reasons.
11/// > For example, a name server may not wish to provide the information to the particular
12/// > requester, or a name server may not wish to perform a particular operation (e.g., zone
13/// > transfer) for particular data.
14/// > - `6-15` Reserved for future use.
15///
16/// <https://datatracker.ietf.org/doc/html/rfc1035#section-4.1.1>
17#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
18pub enum DnsResponseCode {
19 NoError,
20 FormatError,
21 ServerFailure,
22 NameError,
23 NotImplemented,
24 Refused,
25 Reserved(u8),
26}
27impl DnsResponseCode {
28 #[must_use]
29 pub fn new(value: u8) -> Self {
30 match value {
31 0 => DnsResponseCode::NoError,
32 1 => DnsResponseCode::FormatError,
33 2 => DnsResponseCode::ServerFailure,
34 3 => DnsResponseCode::NameError,
35 4 => DnsResponseCode::NotImplemented,
36 5 => DnsResponseCode::Refused,
37 other => DnsResponseCode::Reserved(other),
38 }
39 }
40
41 #[must_use]
42 pub fn num(&self) -> u8 {
43 match self {
44 DnsResponseCode::NoError => 0,
45 DnsResponseCode::FormatError => 1,
46 DnsResponseCode::ServerFailure => 2,
47 DnsResponseCode::NameError => 3,
48 DnsResponseCode::NotImplemented => 4,
49 DnsResponseCode::Refused => 5,
50 DnsResponseCode::Reserved(other) => *other,
51 }
52 }
53}