Crate toluol_proto
source · [−]Expand description
toluol-proto
provides the definition of the DNS protocol’s data types as well as the means to
de-/serialize them from/to the wire format. In simpler terms, you can construct, encode, and
decode DNS queries and responses with it.
It is used as the backend for toluol
, a DNS client that aims to
replace dig
, but you can use this library on its own as well. It is possible to compile it to
WASM, so you can even make DNS queries from the browser with it (using DNS over HTTPS).
Basic usage example
use toluol_proto::{EdnsConfig, HeaderFlags, Message, Name, Opcode, RecordType};
let flags = HeaderFlags { aa: false, tc: false, rd: true, ra: false, ad: true, cd: true };
let msg = Message::new_query(
Name::from_ascii("example.com").unwrap(),
RecordType::A,
Opcode::QUERY,
flags,
Some(EdnsConfig {
do_flag: false,
bufsize: 4096,
client_cookie: None,
}),
).unwrap();
let _encoded = msg.encode().unwrap();
If you’re also looking for utilities to actually send and receive DNS queries and responses,
please take a look at toluol
.
Usage note
You can construct most structs directly, without using any new()
method. In some cases, this
can lead to inconsistencies, e.g. manually creating a Message
where the record counts in the
header don’t match the actual number of records.
In these cases, you should prefer using the appropriate constructor of the struct (if there is none, please file a bug). However, this library does not force you to do so, so that you have as much freedom using it as possible. It won’t stop you if you really want to create inconsistent messages, for whatever reason.
Re-exports
Modules
Macros
Rdata
variant and execute a block for it.Structs
Header
.NONOPT
variant of Record
.