Struct rustdns::Message [−][src]
pub struct Message {Show 17 fields
pub id: u16,
pub rd: bool,
pub tc: bool,
pub aa: bool,
pub opcode: Opcode,
pub qr: QR,
pub rcode: Rcode,
pub cd: bool,
pub ad: bool,
pub z: bool,
pub ra: bool,
pub questions: Vec<Question>,
pub answers: Vec<Record>,
pub authoritys: Vec<Record>,
pub additionals: Vec<Record>,
pub extension: Option<Extension>,
pub stats: Option<Stats>,
}
Expand description
DNS Message that serves as the root of all DNS requests and responses.
Examples
For constructing a message and encoding:
use rustdns::Message;
use rustdns::types::*;
use std::net::UdpSocket;
use std::time::Duration;
// Setup some UDP socket for sending to a DNS server.
let socket = UdpSocket::bind("0.0.0.0:0").expect("couldn't bind to address");
socket.set_read_timeout(Some(Duration::new(5, 0))).expect("set_read_timeout call failed");
socket.connect("8.8.8.8:53").expect("connect call failed");
// Construct a simple query.
let mut m = Message::default();
m.add_question("bramp.net", Type::A, Class::Internet);
// Encode the query as a Vec<u8>.
let req = m.to_vec().expect("failed to encode DNS request");
// Send to the server
socket.send(&req).expect("failed to send request");
// Some time passes
// Receive a response from the DNS server
let mut resp = [0; 4096];
let len = socket.recv(&mut resp).expect("failed to receive response");
// Take a Vec<u8> and turn it into a message.
let m = Message::from_slice(&resp[0..len]).expect("invalid response");
// Now do something with `m`, in this case print it!
println!("DNS Response:\n{}", m);
Fields
id: u16
16-bit identifier assigned by the program that generates any kind of query. This identifier is copied into the corresponding reply and can be used by the requester to match up replies to outstanding queries.
rd: bool
Recursion Desired - this bit directs the name server to pursue the query recursively.
tc: bool
Truncation - specifies that this message was truncated.
aa: bool
Authoritative Answer - Specifies that the responding name server is an authority for the domain name in question section.
opcode: Opcode
Specifies kind of query in this message. 0 represents a standard query. See https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-5
qr: QR
Specifies whether this message is a query (0), or a response (1).
rcode: Rcode
Response code.
cd: bool
ad: bool
z: bool
Z Reserved for future use. You must set this field to 0.
ra: bool
Recursion Available - this be is set or cleared in a response, and denotes whether recursive query support is available in the name server.
questions: Vec<Question>
The questions.
answers: Vec<Record>
The answer records.
The authoritive records.
additionals: Vec<Record>
The additional records.
extension: Option<Extension>
Optional EDNS(0) record.
stats: Option<Stats>
Optional stats about this request, populated by the DNS client. TODO Maybe this field should be elsewhere, as it’s metadata about a request
Implementations
Returns a random u16 suitable for the Message
id field.
This is generated with the rand::rngs::StdRng
which is a suitable
cryptographically secure pseudorandom number generator.
Decodes the supplied buffer and returns a Message
.
Adds a question to the message.
Note: DNS servers typically do not support more than one question. There is ambiguity in how to handle rcode, etc. See §4.1.2 of rfc1035 or https://datatracker.ietf.org/doc/html/draft-bellis-dnsext-multi-qtypes-03
Adds a EDNS(0) extension record, as defined by rfc6891.
Trait Implementations
Defaults to a Message
with sensibles values for querying.
Displays this message in a format resembling dig
output.
Auto Trait Implementations
impl RefUnwindSafe for Message
impl UnwindSafe for Message
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more