apply json fix only when printing dns packet

This commit is contained in:
Mylloon 2023-06-19 22:51:52 +02:00
parent b9015b2c55
commit d745f3f0be
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -29,13 +29,19 @@ let dns_record ?(json = false) (record : Types.dns_record) =
;; ;;
let dns_packet (record : Types.dns_packet) = 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 Printf.sprintf
"{ \"header\": %s, \"questions\": [%s], \"answers\": [%s], \"authorities\": [%s], \ "{ \"header\": %s, \"questions\": [%s], \"answers\": [%s], \"authorities\": [%s], \
\"additionals\": [%s] }" \"additionals\": [%s] }"
(dns_header record.header) (dns_header record.header)
(list dns_question record.questions) (list (`Question record.questions))
(list dns_record record.answers) (list (`Record record.answers))
(list dns_record record.authorities) (list (`Record record.authorities))
(list dns_record record.additionals) (list (`Record record.additionals))
;; ;;