Rusdig
A lightweight DNS message parsing and encoding library written in Rust. This library allows you to create DNS queries, parse DNS responses, and handle various DNS record types such as A, AAAA, CNAME, NS, MX, TXT, and SRV.
Features
-
DNS Message Construction: Easily build DNS queries for a given hostname and record type.
-
DNS Message Parsing: Parse raw DNS response bytes into structured queries, answers, and authority sections.
-
Record Type Support: Built-in support for common DNS record types:
- A (IPv4 addresses)
- AAAA (IPv6 addresses)
- CNAME (Canonical names)
- NS (Nameservers)
- MX (Mail exchange)
- TXT (Text records)
- SRV (Service location)
-
Robust Error Handling: Comprehensive error types (
DNSParseError) to handle invalid data, decoding issues, and malformed responses. -
Name Encoding and Decoding: Encode and decode DNS names, including compressed names, with recursion protection to avoid infinite loops.
Getting Started
Prerequisites
- Rust 1.60 or newer (recommended).
- A network transport for sending and receiving DNS messages (e.g.,
std::net::UdpSocket) if you intend to resolve hostnames via a DNS server. This library focuses on message construction and parsing; it does not itself handle I/O.- If you would like to see an example implementation, view the examples folder.
Usage Example
Constructing a Query:
use ;
Parsing a Response:
use ;
Limitations and Future Enhancements
- Currently focuses on a subset of common DNS record types.
- Does not include EDNS(0) or DNSSEC support.
- I/O operations for sending/receiving DNS queries are not included (you must handle these on your own).
- Further error handling and validation might be added in future revisions.
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests with improvements, bug fixes, or additional features.
License
This project is licensed under the MIT License.