Skip to content

Commit

Permalink
Add ntp client
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc committed Nov 12, 2023
1 parent de8000b commit 255a6cb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dsk/tmp/lisp/ntp.lsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(load "/lib/lisp/core.lsp")

(var addr (nth args 0)) # Run `host pool.ntp.org` to get an address
(var port 123)
(var socket (socket.connect "udp" addr port))

(var req (map (fun (i) (if (eq? i 0) 0x33 0)) (range 0 48)))
(file.write socket req)
(var res (file.read socket 48))

(var buf (slice res 40 4))
(var time (- (bin->num (concat '(0 0 0 0) buf) "int") 2208988800))
(print time)

0 comments on commit 255a6cb

Please sign in to comment.