make it compatible with new changes

This commit is contained in:
Mylloon 2023-07-04 10:50:15 +02:00
parent 48589ff6e0
commit f6aaf8f84d
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -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
;;