fix reader pointer issue

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

View file

@ -59,14 +59,23 @@ let parse_record reader =
;; ;;
let parse_dns_packet data = let parse_dns_packet data =
let reader, dns_header = parse_header { data; pointer = 0 } in let rec create_list reader n fn acc =
(* Quid du pointeur du reader, pas récupéré à chaque itération... *) print_int n;
{ header = dns_header if n = 0
; questions = List.init dns_header.num_questions (fun _ -> snd (parse_question reader)) then reader, List.rev acc
; answers = List.init dns_header.num_answers (fun _ -> snd (parse_record reader)) else (
; authorities = let next_reader, res = fn reader in
List.init dns_header.num_authorities (fun _ -> snd (parse_record reader)) create_list next_reader (n - 1) fn (res :: acc))
; additionals = in
List.init dns_header.num_additionals (fun _ -> snd (parse_record reader)) let reader, header = parse_header { data; pointer = 0 } in
} let reader2, questions = create_list reader header.num_questions parse_question [] in
let reader3, answers = create_list reader2 header.num_answers parse_record [] in
let reader4, authorities = create_list reader3 header.num_authorities parse_record [] in
let _, additionals = create_list reader4 header.num_additionals parse_record [] in
(* print_endline (Debug.dns_header header);
List.iter (fun el -> print_endline (Debug.dns_question el)) questions;
List.iter (fun el -> print_endline (Debug.dns_record el)) answers;
List.iter (fun el -> print_endline (Debug.dns_record el)) authorities;
List.iter (fun el -> print_endline (Debug.dns_record el)) additionals; *)
{ header; questions; answers; authorities; additionals }
;; ;;