(tests) Implement tests for DNS header parsing

* implemented 3 tests
  * valid opcodes
  * invalid opcodes
  * header too short
* fixed byteorder and bit shifting for flags
* added hexdump for main function for testing purposes
This commit is contained in:
2022-04-03 20:49:47 +02:00
parent cccdf5b5e9
commit 0dc41ef845
4 changed files with 287 additions and 32 deletions

View File

@ -32,10 +32,18 @@ fn listen() -> (
)
}
fn print_hex(bytes: &[u8]) {
let stdout = std::io::stdout();
let mut stdout = stdout.lock();
let mut hxp = hexyl::Printer::new(&mut stdout, true, hexyl::BorderStyle::None, false);
let _ = hxp.print_all(bytes);
}
fn main() {
let (thread_udp, _thread_udp_tx, thread_udp_rx) = listen();
for msg in thread_udp_rx.iter() {
print_hex(&msg);
let hdr_struct = DNSHeader::from_udp_datagram(&msg).unwrap();
dbg!(hdr_struct);
}