From 98f2058da60d2f27a5d55457b856eee1f5768229 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 14 Jun 2023 16:35:14 +0200 Subject: [PATCH] Add debugging stuff --- bin/main.ml | 7 ++++++- lib/debug.ml | 19 +++++++++++++++++++ lib/dune | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 lib/debug.ml diff --git a/bin/main.ml b/bin/main.ml index 8835820..613cf14 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,5 +1,10 @@ open Dnstoy let () = - print_endline (Utils.get_bytecode (Network.send_request "8.8.8.8" "www.example.com")) + let response = Network.send_request "8.8.8.8" "www.example.com" in + print_endline (Utils.get_bytecode response); + let response', dns_header = Response.parse_header response in + let dns_question = Response.parse_question response' in + Debug.print_dns_header dns_header; + Debug.print_dns_question dns_question ;; diff --git a/lib/debug.ml b/lib/debug.ml new file mode 100644 index 0000000..f79f738 --- /dev/null +++ b/lib/debug.ml @@ -0,0 +1,19 @@ +let print_dns_header (header : Types.dns_header) = + Printf.printf + "{ id = %d; flags = %d; num_questions = %d; num_answers = %d; num_authorities = %d; \ + num_additionals = %d }\n" + header.id + header.flags + header.num_questions + header.num_answers + header.num_authorities + header.num_additionals +;; + +let print_dns_question (question : Types.dns_question) = + Printf.printf + "{ name = '%s'; type_ = %d; class_ = %d }\n" + (Bytes.to_string question.name) + question.type_ + question.class_ +;; diff --git a/lib/dune b/lib/dune index b1e0c0a..944f3ad 100644 --- a/lib/dune +++ b/lib/dune @@ -1,4 +1,4 @@ (library (name dnstoy) - (modules types utils network query response) + (modules types utils debug network query response) (libraries unix))