dns-parser
dns-parser copied to clipboard
Builder generates invalide packets
I have a minium reproducible example where the Builder fails to generate correct packets.
use dns_parser::{Builder, Packet, QueryClass, QueryType};
fn main() {
let mut builder = Builder::new_query(0, false);
builder.add_question(
"_adb-tls-connect._tcp.local.",
false,
QueryType::All,
QueryClass::Any,
);
let query = builder.build();
match query {
Ok(buf) => {
println!("DNS query: {:?}", buf);
let Ok(packet) = Packet::parse(&buf) else {
println!("Failed to parse DNS packet");
return;
};
println!("Parsed packet {:#?}", packet);
},
Err(error) => println!("Error: {:?}", error),
}
}
Running this example leads to Failed to parse DNS packet. It seems the issue is the trailing dot (in local.). I am not sure if this is legal or not but the lib should probably warn the user they are doing something wrong when building the packet if this is the case.