Crates.io | detect_dns_packet |
lib.rs | detect_dns_packet |
version | 0.1.6 |
source | src |
created_at | 2024-07-18 22:26:21.295615 |
updated_at | 2024-11-12 17:38:13.161279 |
description | A Rust library to detect DNS packets |
homepage | https://github.com/Akmot9/detect_dns_packet |
repository | https://github.com/Akmot9/detect_dns_packet |
max_upload_size | |
id | 1308087 |
size | 84,917 |
detect_dns_packet
is a Rust library for parsing DNS packets. This library provides a way to decode DNS packets from raw bytes into structured data, enabling easy inspection and analysis of DNS packet contents.
Add detect_dns_packet
to your Cargo.toml
:
[dependencies]
detect_dns_packet = "0.1.0"
Below is a basic example demonstrating how to parse a DNS packet using this library.
use detect_dns_packet::DnsPacket;
use std::convert::TryFrom;
fn main() {
// Example DNS packet data in hex
let data = hex::decode("002b81800001000f0006000202757304706f6f6c036e7470036f72670000010001c00c0001000100000d87000443814409c00c0001000100000d870004452c393cc00c0001000100000d870004cfead1b5c00c0001000100000d870004d184b004c00c0001000100000d870004d81bb92ac00c0001000100000d87000418224f2ac00c0001000100000d870004187bcae6c00c0001000100000d8700043fa43ef9c00c0001000100000d8700044070bd0bc00c0001000100000d870004417de9cec00c0001000100000d8700044221ce05c00c0001000100000d8700044221d80bc00c0001000100000d870004425c44f6c00c0001000100000d870004426f2ec8c00c0001000100000d8700044273880404504f4f4c036e7470036f72670000020001000010d60012036e7331086d61696c776f7278036e657400c11100020001000010d6000f067573656e6574036e6574026e7a00c11100020001000010d60014067a626173656c08666f72747974776f02636800c11100020001000010d60018086176656e747572610a62686d732d67726f6570026e6c00c11100020001000010d600110e736c617274696261727466617374c18bc11100020001000010d6000f0161026e73076d61646475636bc136c12900010001000272a500044501c844c1470001000100000daf0004ca313b06").expect("Invalid hex string");
match DnsPacket::try_from(data.as_slice()) {
Ok(packet) => {
println!("{:?}", packet);
}
Err(e) => {
println!("Error parsing DNS packet: {}", e);
}
}
}
dns_header
: Contains the DnsHeader
struct and related functionality.dns_queries
: Contains the DnsQueries
struct and related functionality.utils
: Contains utility functions and types such as DnsClass
and DnsType
.DnsPacket
: Represents a DNS packet, containing the header, queries, answers, authorities, and additional records.Answer
: Represents a DNS answer record.AuthoritativeNameServer
: Represents an authoritative name server record.AdditionalRecord
: Represents an additional record.The library uses Rust's standard Result
and Error
traits for error handling. Errors encountered during parsing will be returned as Result::Err
.
This project is licensed under the MIT or Apache-2.0 license.
Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.
To run the tests, use the following command:
cargo test
Special thanks to the Rust community for their valuable resources and support.
For any inquiries or feedback, please contact Your Name.