From 0c411468d12cbc2552f678f9610cd3146f6095c1 Mon Sep 17 00:00:00 2001 From: Ishan Jain Date: Tue, 12 Dec 2023 04:21:13 +0530 Subject: [PATCH] debug: dns proxy --- src/main.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index baf8e51..a808662 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,14 +50,10 @@ fn main() { recv_packet.header.reserved = 0; recv_packet.header.rcode = if recv_packet.header.opcode == 0 { 0 } else { 4 }; - recv_packet.header.an_count = recv_packet.header.qd_count; + recv_packet.header.an_count = upstream_packet.header.an_count; recv_packet.header.authority_records = 0; recv_packet.header.additional_records = 0; - for question in recv_packet.questions.iter() { - println!("{}", question.name); - } - recv_packet.answers = upstream_packet.answers; let mut response = vec![]; @@ -133,6 +129,27 @@ impl<'a> Packet<'a> { mod test { use crate::Packet; + #[test] + fn parse_multiple_questions() { + let data = [ + 0xc2, 0xa5, 0x1, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x61, 0x62, 0x63, + 0x11, 0x6c, 0x6f, 0x6e, 0x67, 0x61, 0x73, 0x73, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, + 0x6e, 0x61, 0x6d, 0x65, 0x3, 0x63, 0x6f, 0x6d, 0x0, 0x0, 0x1, 0x0, 0x1, 0x3, 0x64, + 0x65, 0x66, 0xc0, 0x10, 0x0, 0x1, 0x0, 0x1, + ]; + + let packet = match Packet::parse(&data) { + Ok(v) => v, + Err(e) => { + panic!("error in parsing packet: {}", e); + } + }; + + for question in packet.questions { + println!("{}", question.name); + } + } + #[test] fn parse_compressed_packet() { let data = [