dns-message-parser 0.2.0

Libary to encode and decode DNS packets
Documentation
use bytes::Bytes;

use dns_message_parser::Dns;

fn decode_msg_error(msg: &[u8]) {
    // Decode BytesMut to message
    let bytes = Bytes::copy_from_slice(&msg[..]);
    // Decode the DNS message
    let dns = Dns::decode(&bytes);
    // Check the result
    assert!(dns.is_err())
}

#[test]
fn a_example_org_response() {
    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\x05\x0a\x00\
    \x00\x0a\x00";
    decode_msg_error(&msg[..]);
}

#[test]
fn ns_example_org_response() {
    let msg = b"\x03\x78\x85\x80\x00\x01\x00\x02\x00\x00\x00\x02\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x02\x00\x01\xc0\x0c\x00\x02\x00\x01\x00\x00\x0e\x10\x00\x06\x03\x6e\
    \x73\x31\xc0\x0c\xc0\x0c\x00\x02\x00\x01\x00\x00\x0e\x10\x00\x07\x03\x6e\x73\x32\xc0\x0c\x00\
    \xc0\x29\x00\x01\x00\x01\x00\x00\x0e\x10\x00\x04\x7f\x00\x00\x01\xc0\x3b\x00\x01\x00\x01\x00\
    \x00\x0e\x10\x00\x04\x0a\x00\x00\x01";
    decode_msg_error(&msg[..]);
}

#[test]
fn cname_example_org_response() {
    let msg = b"\xe2\x7b\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x05\x63\x6e\x61\x6d\x65\x07\x65\
    \x78\x61\x6d\x70\x6c\x65\x03\x6f\x72\x67\x00\x00\x05\x00\x01\xc0\x0c\x00\x05\x00\x01\x00\x00\
    \x0e\x10\x00\x03\xc0\x12\x00";
    decode_msg_error(&msg[..]);
}

#[test]
fn mb_example_org_response() {
    let msg = b"\x36\x8b\x85\x80\x00\x01\x00\x01\x00\x00\x00\x01\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x07\x00\x01\xc0\x0c\x00\x07\x00\x01\x00\x00\x0e\x10\x00\x08\x04\x6d\
    \x61\x69\x6c\xc0\x0c\x00\xc0\x29\x00\x01\x00\x01\x00\x00\x0e\x10\x00\x04\x0a\x00\x00\x0c";
    decode_msg_error(&msg[..]);
}

#[test]
fn mg_example_org_request_error() {
    let msg = b"\x7d\x35\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x08\x00\x01\xc0\x0c\x00\x08\x00\x01\x00\x00\x0e\x10\x00\x06\x04\x6d\
    \x61\x69\x6c\xc0\x0c";
    decode_msg_error(&msg[..]);
}

#[test]
fn mr_example_org_response() {
    let msg = b"\xa3\xc4\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x09\x00\x01\xc0\x0c\x00\x09\x00\x01\x00\x00\x0e\x10\x00\x06\x04\x6d\
    \x61\x69\x6c\xc0\x0c";
    decode_msg_error(&msg[..]);
}

#[test]
fn wks_example_org_response_1() {
    let msg = b"\xd9\xc6\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x0b\x00\x01\xc0\x0c\x00\x0b\x00\x01\x00\x00\x0e\x10\x00\x04\x0a\x00\
    \x00\x0a";
    decode_msg_error(&msg[..]);
}

#[test]
fn wks_example_org_response_2() {
    let msg = b"\xd9\xc6\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x0b\x00\x01\xc0\x0c\x00\x0b\x00\x01\x00\x00\x0e\x10\x00\x08\x0a\x00\
    \x00\x0a\x06\x01";
    decode_msg_error(&msg[..]);
}

#[test]
fn ptr_example_org_response() {
    let msg = b"\x0c\x72\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x02\x31\x30\x01\x30\x01\x30\x02\
    \x31\x30\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x6f\x72\x67\x00\x00\x0c\x00\x01\xc0\x0c\x00\x0c\
    \x00\x01\x00\x00\x0e\x10\x00\x0c\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x6f\x72\x67\x00";
    decode_msg_error(&msg[..]);
}

#[test]
fn hinfo_example_org_response_1() {
    let msg = b"\x78\x99\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x0d\x00\x01\xc0\x0c\x00\x0d\x00\x01\x00\x00\x0e\x10\x00\x01\x00";
    decode_msg_error(&msg[..]);
}

#[test]
fn hinfo_example_org_response_2() {
    let msg = b"\x78\x99\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x0d\x00\x01\xc0\x0c\x00\x0d\x00\x01\x00\x00\x0e\x10\x00\x05\x04\x54\
    \x45\x53\x54";
    decode_msg_error(&msg[..]);
}

#[test]
fn hinfo_example_org_response_3() {
    let msg = b"\x78\x99\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x0d\x00\x01\xc0\x0c\x00\x0d\x00\x01\x00\x00\x0e\x10\x00\x0c\x04\x54\
    \x45\x53\x54\x05\x4c\x69\x6e\x75\x78\x00";
    decode_msg_error(&msg[..]);
}

#[test]
fn soa_example_org_response_1() {
    let msg = b"\xeb\x9c\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x06\x00\x01\xc0\x0c\x00\x06\x00\x01\x00\x00\x0e\x10\x00\x02\x03\x6e";
    decode_msg_error(&msg[..]);
}

#[test]
fn soa_example_org_response_2() {
    let msg = b"\xeb\x9c\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x06\x00\x01\xc0\x0c\x00\x06\x00\x01\x00\x00\x0e\x10\x00\x19\x03\x6e\
    \x73\x31\x07\x65\x78\x61\x6d\x70\x6c\x65\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x6f\x72\x67\x00";
    decode_msg_error(&msg[..]);
}

#[test]
fn soa_example_org_response_3() {
    let msg = b"\xeb\x9c\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x06\x00\x01\xc0\x0c\x00\x06\x00\x01\x00\x00\x0e\x10\x00\x1b\x03\x6e\
    \x73\x31\xc0\x0c\x07\x65\x78\x61\x6d\x70\x6c\x65\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x6f\x72\
    \x67\x00";
    decode_msg_error(&msg[..]);
}

#[test]
fn minfo_example_org_response_1() {
    let msg = b"\x03\x10\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x0e\x00\x01\xc0\x0c\x00\x0e\x00\x01\x00\x00\x0e\x10\x00\x00";
    decode_msg_error(&msg[..]);
}

#[test]
fn minfo_example_org_response_2() {
    let msg = b"\x03\x10\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x0e\x00\x01\xc0\x0c\x00\x0e\x00\x01\x00\x00\x0e\x10\x00\x08\x05\x61\
    \x64\x6d\x69\x6e\xc0\x0c";
    decode_msg_error(&msg[..]);
}

#[test]
fn minfo_example_org_response_3() {
    let msg = b"\x03\x10\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07\x65\x78\x61\x6d\x70\x6c\x65\
    \x03\x6f\x72\x67\x00\x00\x0e\x00\x01\xc0\x0c\x00\x0e\x00\x01\x00\x00\x0e\x10\x00\x11\x05\x61\
    \x64\x6d\x69\x6e\xc0\x0c\x05\x65\x72\x72\x6f\x72\xc0\x0c\x00";
    decode_msg_error(&msg[..]);
}