iris_core/protocols/stream/dns/
mod.rs1pub mod parser;
4mod transaction;
5
6pub use self::transaction::*;
7
8use serde::Serialize;
9
10#[derive(Clone, Debug, Serialize)]
14pub struct Dns {
15 pub transaction_id: u16,
17 pub query: Option<DnsQuery>,
19 pub response: Option<DnsResponse>,
21}
22
23impl Dns {
24 pub fn query_domain(&self) -> &str {
26 if let Some(query) = &self.query {
27 if !query.queries.is_empty() {
28 return &query.queries[0];
29 }
30 }
31 ""
32 }
33
34 pub fn answers(&self) -> String {
36 if let Some(resp) = &self.response {
37 if !resp.answers.is_empty() {
38 return serde_json::to_string(&resp.answers).unwrap_or(String::new());
39 }
40 }
41 String::new()
42 }
43
44 pub fn nameservers(&self) -> String {
46 if let Some(resp) = &self.response {
47 if !resp.nameservers.is_empty() {
48 return serde_json::to_string(&resp.nameservers).unwrap_or(String::new());
49 }
50 }
51 String::new()
52 }
53
54 pub fn additionals(&self) -> String {
56 if let Some(resp) = &self.response {
57 if !resp.additionals.is_empty() {
58 return serde_json::to_string(&resp.additionals).unwrap_or(String::new());
59 }
60 }
61 String::new()
62 }
63
64 pub fn response(&self) -> String {
66 if let Some(resp) = &self.response {
67 return serde_json::to_string(&resp).unwrap_or(String::new());
68 }
69 String::new()
70 }
71}