Simple DNS
Pure Rust implementation to work with DNS packets
You can parse or write a DNS packet by using Packet or PacketBuf structs
Packet
Packet holds references for the original data and it is more suitable for situations where you need to manipulate the packet before generating the final bytes buffer
use *;
use *;
let question = new;
let resource = new;
let mut packet = new_query;
packet.questions.push;
packet.additional_records.push;
let bytes = packet.build_bytes_vec;
assert!;
// Same as above, but Names are compressed
let bytes = packet.build_bytes_vec_compressed;
assert!;
It doesn't matter what order the resources are added, the packet will be built only when build_bytes_vec
is called
To parse the contents of a buffer into a packet, you need call call [Packet::parse]
use Packet;
let bytes = b"\x00\x03\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x06\x67\x6f\x6f\x67\x6c\x65\x03\x63\x6f\x6d\x00\x00\x01\x00\x01";
let packet = parse;
assert!;
PacketBuf
PacketBuf holds an internal buffer that is populated right when a resource is added.
It DOES matter the order in which the resources are added
use *;
use *;
let question = new;
let resource = new;
let mut packet = new;
assert!;
assert!; //This will fail, since an answer is already added
It is possible to create a PacketBuf from a buffer by calling PacketBuf::from, but be aware that this will clone the contents from the buffer
DNS Packet Parser/Builder
The Packet structure provides parsing e building of a DNS packet, it aims to be fully compliant with the RFCs bellow:
Other Resource Records defined by other RFCs that are not in this list will be implemented over time