Skip to content

Commit

Permalink
Add rr_rd() to return the raw RR data
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed Aug 24, 2021
1 parent 075fe5e commit 9dccea1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/rr_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ pub trait TypedIterable {
}
}

/// Raw RR data.
pub enum RawRRData<'t> {
IpAddr(IpAddr),
Data(&'t [u8]),
}

pub trait RdataIterable {
/// Returns the TTL for the current RR.
#[inline]
Expand Down Expand Up @@ -359,6 +365,19 @@ pub trait RdataIterable {
BigEndian::read_u16(&self.rdata_slice()[DNS_RR_RDLEN_OFFSET..]) as usize
}

/// Returns the raw record data for the current RR.
fn rr_rd(&self) -> Result<RawRRData, Error>
where
Self: DNSIterable + TypedIterable,
{
if let Ok(ip_addr) = self.rr_ip() {
return Ok(RawRRData::IpAddr(ip_addr));
}
let rdata_len = self.rr_rdlen();
let rdata = &self.rdata_slice()[DNS_RR_HEADER_SIZE..DNS_RR_HEADER_SIZE + rdata_len];
Ok(RawRRData::Data(rdata))
}

/// Retrieves the IP address of an `A` or `AAAA` record.
fn rr_ip(&self) -> Result<IpAddr, Error>
where
Expand Down

0 comments on commit 9dccea1

Please sign in to comment.