diff --git a/src/message.rs b/src/message.rs index 3d215afe..f820f175 100644 --- a/src/message.rs +++ b/src/message.rs @@ -686,14 +686,17 @@ impl DnsMessage { impl fmt::Display for DnsMessage { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut result = String::new(); + let question = self.get_question(); let answers = self.get_answer().into_iter(); let authority = self.get_authority().into_iter(); let additional = self.get_additional().into_iter(); - result.push_str(&format!("Answer\n")); + result.push_str(&format!("Question section\n")); + result.push_str(&format!("{}\n", question)); + result.push_str(&format!("Answer section\n")); answers.for_each(|answer| result.push_str(&format!("{}\n", answer))); - result.push_str(&format!("Authority\n")); + result.push_str(&format!("Authority section\n")); authority.for_each(|authority| result.push_str(&format!("{}\n", authority))); - result.push_str(&format!("Additional\n")); + result.push_str(&format!("Additional section\n")); additional.for_each(|additional| result.push_str(&format!("{}\n", additional))); write!(f, "{}", result) } diff --git a/src/message/question.rs b/src/message/question.rs index af445d7a..bc9f4cd5 100644 --- a/src/message/question.rs +++ b/src/message/question.rs @@ -4,6 +4,8 @@ use crate::message::rclass::Rclass; use super::rrtype::Rrtype; +use std::fmt; + #[derive(Default, Clone)] /// An struct that represents the question section from a dns message /// ```text @@ -29,6 +31,20 @@ pub struct Question { rclass: Rclass, } + +impl fmt::Display for Question { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + let name = self.get_qname().get_name(); + let rtype = self.get_rrtype(); + let rclass = self.get_rclass(); + + formatter.write_fmt(format_args!( + "{} {} {} ", + name, rclass, rtype + )) + } +} + // Methods impl Question { /// Creates a new Question with default values