From f6aaf8f84d2308e2000422d2fd81715766907a3d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 4 Jul 2023 10:50:15 +0200 Subject: [PATCH] make it compatible with new changes --- lib/network.ml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/network.ml b/lib/network.ml index a0ab612..db83c46 100644 --- a/lib/network.ml +++ b/lib/network.ml @@ -1,8 +1,8 @@ open Unix open Query -let send_request dns url = - let query = build url 1 in +let send_request dns url record_type = + let query = build url record_type in let sock = socket PF_INET SOCK_DGRAM 0 in let server_addr = ADDR_INET (inet_addr_of_string dns, 53) in ignore (sendto sock query 0 (Bytes.length query) [] server_addr); @@ -13,7 +13,14 @@ let send_request dns url = ;; let lookup_domain domain = - let response = send_request "8.8.8.8" domain in + let response = send_request "8.8.8.8" domain Types.DNSType.a in let dns_packet = Response.parse_dns_packet response in - Utils.get_ip (List.nth (List.rev dns_packet.answers) 0).data + if dns_packet.header.num_answers > 0 + then Some (List.nth dns_packet.answers 0).data + else None +;; + +let send ip_address domain_name record_type = + let query = send_request ip_address domain_name record_type in + Response.parse_dns_packet query ;;