From 07afc0afa5680308c653f66bb0192514303c9118 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 19 Jun 2023 23:15:49 +0200 Subject: [PATCH] add ip utils and print ip when its probably an IP adress in data field --- lib/debug.ml | 4 +++- lib/utils.ml | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/debug.ml b/lib/debug.ml index e10e5f1..6f73b32 100644 --- a/lib/debug.ml +++ b/lib/debug.ml @@ -25,7 +25,9 @@ let dns_record ?(json = false) (record : Types.dns_record) = record.type_ record.class_ record.ttl - (Utils.get_bytecode ~json record.data) + (if Bytes.length record.data = 4 + then Utils.get_ip record.data + else Utils.get_bytecode ~json record.data) ;; let dns_packet (record : Types.dns_packet) = diff --git a/lib/utils.ml b/lib/utils.ml index 797cd2f..2533d0f 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -21,6 +21,14 @@ let get_bytecode ?(json = false) data = else result ;; +let get_ip ip = + Bytes.fold_left + (fun acc n -> + Printf.sprintf "%s%s%d" acc (if acc = "" then "" else ".") (int_of_char n)) + "" + ip +;; + let get_obj_size obj = Obj.size (Obj.repr obj) let new_buffer size list =