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
impl DnsRecord
Sourcepub fn parse(data: &[u8], flags: DnsParseFlags) -> Result<DnsRecord>
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.
Sourcepub fn query_count(&self) -> usize
pub fn query_count(&self) -> usize
Returns the count of queries in the DNS record.
Sourcepub fn query_get(&self, idx: usize) -> Result<(&str, DnsRecordType, DnsCls)>
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.
Sourcepub fn queries(&self) -> impl Iterator<Item = (&str, DnsRecordType, DnsCls)>
pub fn queries(&self) -> impl Iterator<Item = (&str, DnsRecordType, DnsCls)>
Returns an iterator over the queries in the DNS record.
Sourcepub fn rr_count(&self, section: DnsSection) -> usize
pub fn rr_count(&self, section: DnsSection) -> usize
Returns the count of resource records in the given section.
Sourcepub fn rr(&self, section: DnsSection, idx: usize) -> Option<&DnsRr>
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.
Sourcepub fn rrs(&self, section: DnsSection) -> impl Iterator<Item = &DnsRr>
pub fn rrs(&self, section: DnsSection) -> impl Iterator<Item = &DnsRr>
Returns an iterator over the resource records in the given section.
Sourcepub fn new(
id: u16,
flags: DnsFlags,
opcode: DnsOpcode,
rcode: DnsRcode,
) -> Result<DnsRecord>
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();Sourcepub fn query_add(
&mut self,
name: &str,
qtype: DnsRecordType,
qclass: DnsCls,
) -> Result<&mut Self>
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.
Sourcepub fn query_set_name(&mut self, idx: usize, name: &str) -> Result<&mut Self>
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.
Sourcepub fn query_set_type(
&mut self,
idx: usize,
qtype: DnsRecordType,
) -> Result<&mut Self>
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).
Sourcepub fn rr_add(
&mut self,
section: DnsSection,
name: &str,
rr_type: DnsRecordType,
rclass: DnsCls,
ttl: u32,
) -> Result<&mut DnsRr>
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.
Sourcepub fn rr_mut(&mut self, section: DnsSection, idx: usize) -> Option<&mut DnsRr>
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.
Sourcepub fn rrs_mut(
&mut self,
section: DnsSection,
) -> impl Iterator<Item = &mut DnsRr>
pub fn rrs_mut( &mut self, section: DnsSection, ) -> impl Iterator<Item = &mut DnsRr>
Returns an iterator over mutable resource records in the given section.
Sourcepub fn rr_del(&mut self, section: DnsSection, idx: usize) -> Result<&mut Self>
pub fn rr_del(&mut self, section: DnsSection, idx: usize) -> Result<&mut Self>
Remove the resource record at the given section and index.
Trait Implementations§
impl Send for DnsRecord
impl Sync for DnsRecord
Auto Trait Implementations§
impl Freeze for DnsRecord
impl RefUnwindSafe for DnsRecord
impl Unpin for DnsRecord
impl UnsafeUnpin for DnsRecord
impl UnwindSafe for DnsRecord
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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