Skip to main content

DnsRecord

Struct DnsRecord 

Source
pub struct DnsRecord { /* private fields */ }
Expand description

An owned DNS record (message), wrapping ares_dns_record_t.

A DnsRecord represents a complete DNS message including header fields, question section, and resource record sections (answer, authority, additional).

Created by parsing wire-format data with DnsRecord::parse().

Implementations§

Source§

impl DnsRecord

Source

pub fn parse(data: &[u8], flags: DnsParseFlags) -> Result<DnsRecord>

Parse a complete DNS message from wire-format bytes.

flags controls parsing behaviour; use DnsParseFlags::empty() for default parsing.

Source

pub fn id(&self) -> u16

Returns the DNS query ID.

Source

pub fn flags(&self) -> DnsFlags

Returns the DNS record flags.

Source

pub fn opcode(&self) -> DnsOpcode

Returns the DNS record opcode.

Source

pub fn rcode(&self) -> DnsRcode

Returns the DNS record rcode.

Source

pub fn query_count(&self) -> usize

Returns the count of queries in the DNS record.

Source

pub fn query_get(&self, idx: usize) -> Result<(&str, DnsRecordType, DnsCls)>

Get the query at the given index.

Returns (name, record_type, class) on success.

Source

pub fn queries(&self) -> impl Iterator<Item = (&str, DnsRecordType, DnsCls)>

Returns an iterator over the queries in the DNS record.

Source

pub fn rr_count(&self, section: DnsSection) -> usize

Returns the count of resource records in the given section.

Source

pub fn rr(&self, section: DnsSection, idx: usize) -> Option<&DnsRr>

Fetch a non-writable resource record by section and index.

Returns None if the index is out of range.

Source

pub fn rrs(&self, section: DnsSection) -> impl Iterator<Item = &DnsRr>

Returns an iterator over the resource records in the given section.

Source

pub fn new( id: u16, flags: DnsFlags, opcode: DnsOpcode, rcode: DnsRcode, ) -> Result<DnsRecord>

Create a new DNS record object.

When building a query to send via Channel::send_dnsrec(), set id to 0.

§Examples
use c_ares::{DnsRecord, DnsFlags, DnsOpcode, DnsRcode, DnsRecordType, DnsCls};

let mut record = DnsRecord::new(
    0,
    DnsFlags::RD,
    DnsOpcode::Query,
    DnsRcode::NoError,
).unwrap();
record.query_add("example.com", DnsRecordType::A, DnsCls::IN).unwrap();
Source

pub fn set_id(&mut self, id: u16) -> &mut Self

Overwrite the DNS query id.

Source

pub fn query_add( &mut self, name: &str, qtype: DnsRecordType, qclass: DnsCls, ) -> Result<&mut Self>

Add a query to the DNS record.

Typically a record will have only one query. Most DNS servers will reject queries with more than one question.

Source

pub fn query_set_name(&mut self, idx: usize, name: &str) -> Result<&mut Self>

Replace the question name at the given index.

This may be used when performing a search with aliases.

Source

pub fn query_set_type( &mut self, idx: usize, qtype: DnsRecordType, ) -> Result<&mut Self>

Replace the question type at the given index.

This may be used when needing to query more than one address class (e.g. A and AAAA).

Source

pub fn rr_add( &mut self, section: DnsSection, name: &str, rr_type: DnsRecordType, rclass: DnsCls, ttl: u32, ) -> Result<&mut DnsRr>

Add a resource record to the DNS record.

Returns a mutable reference to the created resource record for setting RR-specific fields.

Source

pub fn rr_mut(&mut self, section: DnsSection, idx: usize) -> Option<&mut DnsRr>

Fetch a writable resource record by section and index.

Returns None if the index is out of range.

Source

pub fn rrs_mut( &mut self, section: DnsSection, ) -> impl Iterator<Item = &mut DnsRr>

Returns an iterator over mutable resource records in the given section.

Source

pub fn rr_del(&mut self, section: DnsSection, idx: usize) -> Result<&mut Self>

Remove the resource record at the given section and index.

Source

pub fn write(&self) -> Result<AresBuf>

Write a complete DNS message to wire format.

Source

pub fn try_clone(&self) -> Result<DnsRecord>

Create a deep copy of this DNS record.

Trait Implementations§

Source§

impl Debug for DnsRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for DnsRecord

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for DnsRecord

Source§

impl Sync for DnsRecord

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.