From d7c4b781c5b0abb7e5785413333d06df559eab78 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 11 Jun 2023 10:54:58 +0200 Subject: [PATCH] part 1 done! --- bin/main.ml | 6 +++++- lib/dune | 3 ++- lib/network.ml | 13 +++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 lib/network.ml diff --git a/bin/main.ml b/bin/main.ml index 306831a..8835820 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1 +1,5 @@ -let () = () +open Dnstoy + +let () = + print_endline (Utils.get_bytecode (Network.send_request "8.8.8.8" "www.example.com")) +;; diff --git a/lib/dune b/lib/dune index 07319ae..a51dcb1 100644 --- a/lib/dune +++ b/lib/dune @@ -1,3 +1,4 @@ (library (name dnstoy) - (modules types utils query)) + (modules types utils query network) + (libraries unix)) diff --git a/lib/network.ml b/lib/network.ml new file mode 100644 index 0000000..9c2a125 --- /dev/null +++ b/lib/network.ml @@ -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 +;;