pub mod parser;
mod transaction;
pub use self::transaction::*;
use serde::Serialize;
#[derive(Clone, Debug, Serialize)]
pub struct Dns {
pub transaction_id: u16,
pub query: Option<DnsQuery>,
pub response: Option<DnsResponse>,
}
impl Dns {
pub fn query_domain(&self) -> &str {
if let Some(query) = &self.query {
if !query.queries.is_empty() {
return &query.queries[0];
}
}
""
}
pub fn answers(&self) -> String {
if let Some(resp) = &self.response {
if !resp.answers.is_empty() {
return serde_json::to_string(&resp.answers).unwrap_or(String::new());
}
}
String::new()
}
pub fn nameservers(&self) -> String {
if let Some(resp) = &self.response {
if !resp.nameservers.is_empty() {
return serde_json::to_string(&resp.nameservers).unwrap_or(String::new());
}
}
String::new()
}
pub fn additionals(&self) -> String {
if let Some(resp) = &self.response {
if !resp.additionals.is_empty() {
return serde_json::to_string(&resp.additionals).unwrap_or(String::new());
}
}
String::new()
}
pub fn response(&self) -> String {
if let Some(resp) = &self.response {
return serde_json::to_string(&resp).unwrap_or(String::new());
}
String::new()
}
}