Struct rustdns::Message[][src]

pub struct Message {
Show 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>,
}
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 function 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

Checking Disabled. See RFC4035 and RFC6840.

ad: bool

Authentic Data. See RFC4035 and RFC6840.

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.

authoritys: Vec<Record>

The authoritive records.

additionals: Vec<Record>

The additional records.

extension: Option<Extension>

Optional EDNS(0) record.

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.

Adds a EDNS(0) extension record, as defined by rfc6891.

Encodes this DNS Message as a Vec<u8> ready to be sent, as defined by rfc1035.

Trait Implementations

Defaults to a Message with sensibles values for querying.

Returns the “default value” for a type. Read more

Displays this message in a format resembling dig output.

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.