13 unstable releases

0.7.0 Aug 7, 2022
0.6.0 Aug 28, 2021
0.5.0 Apr 2, 2021
0.4.6 Jan 24, 2021
0.1.0 Apr 29, 2020

#1293 in Parser implementations

Download history 223/week @ 2024-05-26 321/week @ 2024-06-02 495/week @ 2024-06-09 520/week @ 2024-06-16 469/week @ 2024-06-23 339/week @ 2024-06-30 639/week @ 2024-07-07 641/week @ 2024-07-14 658/week @ 2024-07-21 700/week @ 2024-07-28 668/week @ 2024-08-04 647/week @ 2024-08-11 497/week @ 2024-08-18 244/week @ 2024-08-25 423/week @ 2024-09-01 419/week @ 2024-09-08

1,650 downloads per month
Used in 6 crates

BSD-3-Clause

230KB
6K SLoC

dns-message-parser

A library to encode and decode DNS packets (RFC1035, RFC2535).

Build status Dependency status Code coverage Latest version License

This library is not completed yet.

Usage

Add this to your Cargo.toml:

[dependencies]
dns-message-parser = "0.7.0"

Example

use bytes::Bytes;
use dns_message_parser::{Dns, DomainName, Flags, Opcode, RCode};
use dns_message_parser::question::{QClass, QType, Question};

fn decode_example() {
    let msg = b"\xdb\x1c\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x01\x00\x01\xc0\x0c\x00\x01\x00\x01\x00\x00\x0e\x10\x00\x04\x0a\x00\
    \x00\x0a";

    let bytes = Bytes::copy_from_slice(&msg[..]);

    let dns = Dns::decode(bytes).unwrap();
    println!("{:?}", dns);
}

fn encode_example() {
    let id = 56092;
    let flags = Flags {
        qr: true,
        opcode: Opcode::Query,
        aa: true,
        tc: false,
        rd: true,
        ra: true,
        ad: false,
        cd: false,
        rcode: RCode::NoError,
    };
    let question = {
        let domain_name = "example.org.".parse().unwrap();
        let q_class = QClass::IN;
        let q_type = QType::A;

        Question {
            domain_name,
            q_class,
            q_type,
        }
    };

    let questions = vec![question];
    let dns = Dns {
        id,
        flags,
        questions,
        answers: Vec::new(),
        authorities: Vec::new(),
        additionals: Vec::new(),
    };
    let bytes = dns.encode().unwrap();
    println!("{:?}", bytes);
}

Dependencies

~0.6–1.1MB
~24K SLoC