2023-06-19 20:31:27 +02:00
|
|
|
let dns_header (header : Types.dns_header) =
|
|
|
|
Printf.sprintf
|
2023-06-19 20:44:32 +02:00
|
|
|
"{ \"id\": %d, \"flags\": %d, \"num_questions\": %d, \"num_answers\": %d, \
|
|
|
|
\"num_authorities\": %d, \"num_additionals\": %d }"
|
2023-06-14 16:35:14 +02:00
|
|
|
header.id
|
|
|
|
header.flags
|
|
|
|
header.num_questions
|
|
|
|
header.num_answers
|
|
|
|
header.num_authorities
|
|
|
|
header.num_additionals
|
|
|
|
;;
|
|
|
|
|
2023-06-19 20:31:27 +02:00
|
|
|
let dns_question (question : Types.dns_question) =
|
|
|
|
Printf.sprintf
|
2023-06-19 20:44:32 +02:00
|
|
|
"{ \"name\": \"%s\", \"type_\": %d, \"class_\": %d }"
|
2023-06-14 16:35:14 +02:00
|
|
|
(Bytes.to_string question.name)
|
|
|
|
question.type_
|
|
|
|
question.class_
|
|
|
|
;;
|
2023-06-14 16:54:55 +02:00
|
|
|
|
2023-06-19 22:33:05 +02:00
|
|
|
let dns_record ?(json = false) (record : Types.dns_record) =
|
2023-06-19 20:31:27 +02:00
|
|
|
Printf.sprintf
|
2023-06-19 20:44:32 +02:00
|
|
|
"{ \"name\": \"%s\", \"type_\": %d, \"class_\": %d, \"ttl\": %d, \"data\": \"%s\" }"
|
2023-06-14 16:54:55 +02:00
|
|
|
(Bytes.to_string record.name)
|
|
|
|
record.type_
|
|
|
|
record.class_
|
|
|
|
record.ttl
|
2023-06-19 22:33:05 +02:00
|
|
|
(Utils.get_bytecode ~json record.data)
|
2023-06-14 16:54:55 +02:00
|
|
|
;;
|
2023-06-19 21:52:39 +02:00
|
|
|
|
|
|
|
let dns_packet (record : Types.dns_packet) =
|
2023-06-19 22:51:52 +02:00
|
|
|
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
|
2023-06-19 21:52:39 +02:00
|
|
|
Printf.sprintf
|
|
|
|
"{ \"header\": %s, \"questions\": [%s], \"answers\": [%s], \"authorities\": [%s], \
|
|
|
|
\"additionals\": [%s] }"
|
|
|
|
(dns_header record.header)
|
2023-06-19 22:51:52 +02:00
|
|
|
(list (`Question record.questions))
|
|
|
|
(list (`Record record.answers))
|
|
|
|
(list (`Record record.authorities))
|
|
|
|
(list (`Record record.additionals))
|
2023-06-19 21:52:39 +02:00
|
|
|
;;
|