From d745f3f0be8882cd5bc5c083866fc43eecb05689 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 19 Jun 2023 22:51:52 +0200 Subject: [PATCH] apply json fix only when printing dns packet --- lib/debug.ml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/debug.ml b/lib/debug.ml index 3c127da..e10e5f1 100644 --- a/lib/debug.ml +++ b/lib/debug.ml @@ -29,13 +29,19 @@ let dns_record ?(json = false) (record : Types.dns_record) = ;; let dns_packet (record : Types.dns_packet) = - let list fn l = String.concat ", " (List.map (fun el -> fn el) l) in + let list l = + String.concat + ", " + (match l with + | `Question lq -> List.map (fun el -> dns_question el) lq + | `Record lr -> List.map (fun el -> dns_record ~json:true el) lr) + in Printf.sprintf "{ \"header\": %s, \"questions\": [%s], \"answers\": [%s], \"authorities\": [%s], \ \"additionals\": [%s] }" (dns_header record.header) - (list dns_question record.questions) - (list dns_record record.answers) - (list dns_record record.authorities) - (list dns_record record.additionals) + (list (`Question record.questions)) + (list (`Record record.answers)) + (list (`Record record.authorities)) + (list (`Record record.additionals)) ;;