aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2024-01-28 10:10:05 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2024-01-28 10:10:05 +0100
commitf89212af659095563ce1b3d848d16bdfcd6d37ad (patch)
tree3050c2c11b4ec0177b5913e6b47552effaca31c2
parentb0ac189ea994b1be1dd4db4910e9b79e41d7cd53 (diff)
print questions to failed requests for debugging
-rw-r--r--src/main.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 8b4c748..809838c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -126,12 +126,30 @@ fn main() -> Result<()> {
thread::spawn(
move || match handle_query(&domain2, sock2, &buf, raddr, leases3) {
Ok(_) => {}
- Err(e) => println!("[warn] query from {}: {}", raddr, e),
+ Err(e) => print_query_error(&buf, raddr, e),
},
);
}
}
+fn print_query_error(buf: &[u8], raddr: SocketAddr, e: Error) {
+ match extract_questions(buf) {
+ Ok(questions) => {
+ for q in questions {
+ println!("[warn] {} => {}: {}", raddr, q, e);
+ }
+ }
+ Err(eprint) => println!("[warn] {}: {}; printing error: {}", raddr, e, eprint),
+ }
+}
+
+fn extract_questions(buf: &[u8]) -> Result<Vec<Question>> {
+ let bytes = Bytes::copy_from_slice(buf);
+ let msg = Dns::decode(bytes)?;
+
+ Ok(msg.questions)
+}
+
fn handle_query(
domain: &Option<Name>,
sock: UdpSocket,