Compare commits

...
This repository has been archived on 2024-05-23. You can view files and clone it, but cannot push or open issues or pull requests.

1 commit

Author SHA1 Message Date
317d89301c
WIP: try to implement cname 2023-07-05 02:14:14 +02:00
3 changed files with 19 additions and 3 deletions

View file

@ -1,3 +1,3 @@
open Dnstoy open Dnstoy
let () = print_endline (Network.resolve "www.mylloon.fr" Types.DNSType.a) let () = print_endline (Network.resolve "www.facebook.com" Types.DNSType.a)

View file

@ -40,7 +40,12 @@ and resolve_aux nameserver domain_name record_type =
(match get_nameserver response with (match get_nameserver response with
| Some ns_domain -> | Some ns_domain ->
resolve_aux (resolve ns_domain DNSType.a) domain_name record_type resolve_aux (resolve ns_domain DNSType.a) domain_name record_type
| None -> raise (Failure "Something went wrong"))) | None ->
(match get_alias response with
| Some cname_domain ->
resolve_aux (resolve cname_domain DNSType.a) domain_name record_type
| None ->
raise (Failure ("Something went wrong - " ^ Debug.dns_packet response)))))
and get_answer packet = and get_answer packet =
match List.find_opt (fun el -> el.type_ = DNSType.a) packet.answers with match List.find_opt (fun el -> el.type_ = DNSType.a) packet.answers with
@ -53,7 +58,16 @@ and get_nameserver_ip packet =
| None -> None | None -> None
and get_nameserver packet = and get_nameserver packet =
match List.find_opt (fun el -> el.type_ = DNSType.ns) packet.authorities with match
List.find_opt
(fun el -> el.type_ = DNSType.ns || el.type_ = DNSType.soa)
packet.authorities
with
| Some record -> Some (String.of_bytes record.data)
| None -> None
and get_alias packet =
match List.find_opt (fun el -> el.type_ = DNSType.cname) packet.answers with
| Some record -> Some (String.of_bytes record.data) | Some record -> Some (String.of_bytes record.data)
| None -> None | None -> None
;; ;;

View file

@ -37,5 +37,7 @@ type dns_packet =
module DNSType = struct module DNSType = struct
let a = 1 let a = 1
let ns = 2 let ns = 2
let cname = 5
let soa = 6
let txt = 16 let txt = 16
end end