part 1 done!

This commit is contained in:
Mylloon 2023-06-11 10:54:58 +02:00
parent ce7585ac6c
commit d7c4b781c5
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 20 additions and 2 deletions

View file

@ -1 +1,5 @@
let () = () open Dnstoy
let () =
print_endline (Utils.get_bytecode (Network.send_request "8.8.8.8" "www.example.com"))
;;

View file

@ -1,3 +1,4 @@
(library (library
(name dnstoy) (name dnstoy)
(modules types utils query)) (modules types utils query network)
(libraries unix))

13
lib/network.ml Normal file
View file

@ -0,0 +1,13 @@
open Unix
open Query
let send_request dns url =
let query = build url 1 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);
let buffer_size = 1024 in
let response = Bytes.create buffer_size in
let len, _ = recvfrom sock response 0 buffer_size [] in
Bytes.sub response 0 len
;;