diff --git a/src/message/rdata.rs b/src/message/rdata.rs index 2aa10fe5..485986c2 100644 --- a/src/message/rdata.rs +++ b/src/message/rdata.rs @@ -38,6 +38,7 @@ use dnskey_rdata::DnskeyRdata; use nsec3_rdata::Nsec3Rdata; use nsec3param_rdata::Nsec3ParamRdata; use tsig_rdata::TSigRdata; +use srv_rdata::SrvRdata; #[derive(Clone, PartialEq, Debug)] /// Enumerates the differents types of `Rdata` struct. @@ -52,6 +53,7 @@ pub enum Rdata { CNAME(CnameRdata), HINFO(HinfoRdata), AAAA(AAAARdata), + SRV(SrvRdata), OPT(OptRdata), DS(DsRdata), RRSIG(RRSIGRdata), @@ -87,6 +89,7 @@ impl ToBytes for Rdata { Rdata::SOA(val) => val.to_bytes(), Rdata::TXT(val) => val.to_bytes(), Rdata::AAAA(val) => val.to_bytes(), + Rdata::SRV(val) => val.to_bytes(), Rdata::CNAME(val) => val.to_bytes(), Rdata::HINFO(val) => val.to_bytes(), Rdata::OPT(val) => val.to_bytes(), @@ -229,6 +232,18 @@ impl FromBytes> for Rdata { Ok(Rdata::AAAA(rdata.unwrap())) } + 33 => { + let rdata = SrvRdata::from_bytes(&bytes[..bytes.len() - 4], full_msg); + + match rdata { + Ok(_) => {} + Err(e) => { + return Err(e); + } + } + + Ok(Rdata::SRV(rdata.unwrap())) + } 39 => { let rdata = CnameRdata::from_bytes(&bytes[..bytes.len() - 4], full_msg); @@ -348,6 +363,7 @@ impl fmt::Display for Rdata { Rdata::SOA(val) => write!(f, "{}", val), Rdata::TXT(val) => write!(f, "{}", val), Rdata::AAAA(val) => write!(f, "{}", val), + Rdata::SRV(val) => write!(f, "{}", val), Rdata::CNAME(val) => write!(f, "{}", val), Rdata::HINFO(val) => write!(f, "{}", val), Rdata::OPT(val) => write!(f, "{}", val), diff --git a/src/message/rdata/srv_rdata.rs b/src/message/rdata/srv_rdata.rs index 34e9770f..95180c6e 100644 --- a/src/message/rdata/srv_rdata.rs +++ b/src/message/rdata/srv_rdata.rs @@ -1,3 +1,5 @@ +use core::fmt; + use crate::domain_name::DomainName; use crate::message::resource_record::{FromBytes, ToBytes}; @@ -5,6 +7,7 @@ use crate::message::resource_record::{FromBytes, ToBytes}; /// RFC 2782: https://datatracker.ietf.org/doc/html/rfc2782 /// An struct that represents the `Rdata` for srv type. +#[derive(Clone, Debug, PartialEq)] pub struct SrvRdata { /// The priority of this target host. A client MUST attempt to contact the target host with the lowest-numbered priority it can reach; target hosts with the same priority SHOULD be tried in an order defined by the weight field. priority: u16, @@ -142,6 +145,20 @@ impl SrvRdata { } } +impl fmt::Display for SrvRdata { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Priority: {}, + Weight: {}, + Port: {}, + Target: {}", + self.get_priority(), + self.get_weight(), + self.get_port(), + self.get_target()) + + } +} + #[cfg(test)] mod srv_rdata_tests { use super::*;