diff --git a/dsk/tmp/lisp/fetch.lsp b/dsk/tmp/lisp/fetch.lsp new file mode 100644 index 00000000..917c5b3b --- /dev/null +++ b/dsk/tmp/lisp/fetch.lsp @@ -0,0 +1,15 @@ +# HTTP/0.9 Proxy (https://github.com/vinc/fetch) + +(load "/lib/lisp/core.lsp") + +(var proxy-host "10.0.2.2") +(var proxy-port 8888) + +(var stdout 1) +(var socket (socket.connect "tcp" proxy-host proxy-port)) +(file.write socket (str->bin (str "GET " (nth args 0) "\n"))) +(var open true) +(while open (do + (var buf (file.read socket 2048)) + (file.write stdout buf) + (set open (not (nil? buf))))) diff --git a/dsk/tmp/lisp/ntp.lsp b/dsk/tmp/lisp/ntp.lsp new file mode 100644 index 00000000..fbee4d15 --- /dev/null +++ b/dsk/tmp/lisp/ntp.lsp @@ -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) diff --git a/src/usr/install.rs b/src/usr/install.rs index 9568e16d..7ff941f4 100644 --- a/src/usr/install.rs +++ b/src/usr/install.rs @@ -64,8 +64,10 @@ pub fn copy_files(verbose: bool) { create_dir("/tmp/lisp", verbose); copy_file("/tmp/lisp/colors.lsp", include_bytes!("../../dsk/tmp/lisp/colors.lsp"), verbose); copy_file("/tmp/lisp/factorial.lsp", include_bytes!("../../dsk/tmp/lisp/factorial.lsp"), verbose); + //copy_file("/tmp/lisp/fetch.lsp", include_bytes!("../../dsk/tmp/lisp/ntp.lsp"), verbose); copy_file("/tmp/lisp/fibonacci.lsp", include_bytes!("../../dsk/tmp/lisp/fibonacci.lsp"), verbose); copy_file("/tmp/lisp/geotime.lsp", include_bytes!("../../dsk/tmp/lisp/geotime.lsp"), verbose); + //copy_file("/tmp/lisp/ntp.lsp", include_bytes!("../../dsk/tmp/lisp/ntp.lsp"), verbose); copy_file("/tmp/lisp/pi.lsp", include_bytes!("../../dsk/tmp/lisp/pi.lsp"), verbose); copy_file("/tmp/lisp/sum.lsp", include_bytes!("../../dsk/tmp/lisp/sum.lsp"), verbose);