From 8304ca71e2335bdc58cc9a7318cc352ede7f0b3a Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 12 Nov 2023 17:20:50 +0100 Subject: [PATCH 1/3] Add ntp client --- dsk/tmp/lisp/ntp.lsp | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 dsk/tmp/lisp/ntp.lsp diff --git a/dsk/tmp/lisp/ntp.lsp b/dsk/tmp/lisp/ntp.lsp new file mode 100644 index 000000000..fbee4d158 --- /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) From a061cfcbbc7314266123a74c35f8e5c1f1bdacff Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 12 Nov 2023 17:33:25 +0100 Subject: [PATCH 2/3] Add ntp to install --- src/usr/install.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/install.rs b/src/usr/install.rs index 9568e16df..d64114352 100644 --- a/src/usr/install.rs +++ b/src/usr/install.rs @@ -66,6 +66,7 @@ pub fn copy_files(verbose: bool) { copy_file("/tmp/lisp/factorial.lsp", include_bytes!("../../dsk/tmp/lisp/factorial.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); From 99887ae56707dc9ae7d6485c54ecc49c097c0eff Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 12 Nov 2023 19:56:50 +0100 Subject: [PATCH 3/3] Add fetch example --- dsk/tmp/lisp/fetch.lsp | 15 +++++++++++++++ src/usr/install.rs | 1 + 2 files changed, 16 insertions(+) create mode 100644 dsk/tmp/lisp/fetch.lsp diff --git a/dsk/tmp/lisp/fetch.lsp b/dsk/tmp/lisp/fetch.lsp new file mode 100644 index 000000000..917c5b3b7 --- /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/src/usr/install.rs b/src/usr/install.rs index d64114352..7ff941f4b 100644 --- a/src/usr/install.rs +++ b/src/usr/install.rs @@ -64,6 +64,7 @@ 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);