From 3f7462a98e0e1de6d4081c74bf8311ebfa617179 Mon Sep 17 00:00:00 2001 From: erana Date: Sun, 22 Jan 2017 01:32:36 -0500 Subject: [PATCH] initial hawk dns server --- s48/hawk-dns-server/AUTHORS | 1 + s48/hawk-dns-server/BLURB | 1 + s48/hawk-dns-server/COPYING | 13 +++++++ s48/hawk-dns-server/NEWS | 2 ++ s48/hawk-dns-server/README | 3 ++ s48/hawk-dns-server/init.scm | 2 ++ s48/hawk-dns-server/packages.scm | 8 +++++ s48/hawk-dns-server/pkg-def.scm | 15 ++++++++ s48/hawk-dns-server/server-dns.scm | 47 +++++++++++++++++++++++++ s48/hawk-dns-server/server.scm | 56 ++++++++++++++++++++++++++++++ s48/hawk-dns-server/util.scm | 5 +++ 11 files changed, 153 insertions(+) create mode 100644 s48/hawk-dns-server/AUTHORS create mode 100644 s48/hawk-dns-server/BLURB create mode 100644 s48/hawk-dns-server/COPYING create mode 100644 s48/hawk-dns-server/NEWS create mode 100644 s48/hawk-dns-server/README create mode 100644 s48/hawk-dns-server/init.scm create mode 100644 s48/hawk-dns-server/packages.scm create mode 100644 s48/hawk-dns-server/pkg-def.scm create mode 100644 s48/hawk-dns-server/server-dns.scm create mode 100644 s48/hawk-dns-server/server.scm create mode 100644 s48/hawk-dns-server/util.scm diff --git a/s48/hawk-dns-server/AUTHORS b/s48/hawk-dns-server/AUTHORS new file mode 100644 index 0000000..77f5599 --- /dev/null +++ b/s48/hawk-dns-server/AUTHORS @@ -0,0 +1 @@ +Copyright (C) 2017 Johan Ceuppens diff --git a/s48/hawk-dns-server/BLURB b/s48/hawk-dns-server/BLURB new file mode 100644 index 0000000..94a879e --- /dev/null +++ b/s48/hawk-dns-server/BLURB @@ -0,0 +1 @@ +hawk-dns-server : a DNS server diff --git a/s48/hawk-dns-server/COPYING b/s48/hawk-dns-server/COPYING new file mode 100644 index 0000000..5557b1c --- /dev/null +++ b/s48/hawk-dns-server/COPYING @@ -0,0 +1,13 @@ +Copyright (c) 2015, Johan Ceuppens (goon) +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/s48/hawk-dns-server/NEWS b/s48/hawk-dns-server/NEWS new file mode 100644 index 0000000..eab6a3a --- /dev/null +++ b/s48/hawk-dns-server/NEWS @@ -0,0 +1,2 @@ +version 0.1 +* sending and receiving bytes diff --git a/s48/hawk-dns-server/README b/s48/hawk-dns-server/README new file mode 100644 index 0000000..bba66e9 --- /dev/null +++ b/s48/hawk-dns-server/README @@ -0,0 +1,3 @@ +,load big-scheme +,open byte-vectors +run as a daemon diff --git a/s48/hawk-dns-server/init.scm b/s48/hawk-dns-server/init.scm new file mode 100644 index 0000000..088e43b --- /dev/null +++ b/s48/hawk-dns-server/init.scm @@ -0,0 +1,2 @@ +,load big-scheme +,open byte-vectors diff --git a/s48/hawk-dns-server/packages.scm b/s48/hawk-dns-server/packages.scm new file mode 100644 index 0000000..ad9d6c1 --- /dev/null +++ b/s48/hawk-dns-server/packages.scm @@ -0,0 +1,8 @@ +(define-interface cavespider-interface + (export + ask-server)) + +(define-structure cavespider + cavespider-interface + (open scheme) + (files load file-util hash-util html-util string-util util client)) diff --git a/s48/hawk-dns-server/pkg-def.scm b/s48/hawk-dns-server/pkg-def.scm new file mode 100644 index 0000000..94bd5c0 --- /dev/null +++ b/s48/hawk-dns-server/pkg-def.scm @@ -0,0 +1,15 @@ +(define-package "heap-images" + (0 1) + ((install-lib-version (1 3 0))) + (write-to-load-script + `((config) + (load ,(absolute-file-name "packages.scm" + (get-directory 'scheme #f))))) + (install-file "README" 'doc) + (install-file "NEWS" 'doc) + (install-string (COPYING) "COPYING" 'doc) + (install-file "packages.scm" 'scheme) + (install-file "init.scm" 'scheme)) + (install-file "util.scm" 'scheme)) + (install-file "server.scm" 'scheme)) + (install-file "server-dns.scm" 'scheme)) diff --git a/s48/hawk-dns-server/server-dns.scm b/s48/hawk-dns-server/server-dns.scm new file mode 100644 index 0000000..6f2fe46 --- /dev/null +++ b/s48/hawk-dns-server/server-dns.scm @@ -0,0 +1,47 @@ +;;Copyright (c) 2015, Johan Ceuppens (goon) +;;All rights reserved. + +;;Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +;;1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +;;2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +;;3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +;;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +(load "init.scm") +(load "util.scm") +(load "server.scm") + +(define (make-server-dns) + (define (loopfunc in out) + (let ((dns-question (string->byte-vector (read in))) + (name #f) + (let ((n (byte-vector-ref dns-question 1))) + (if (= n 11) + (let ((m 0)) + (do ((i n+2 (+ i 1)) + ((= i (byte-vector-length dns-question)) (display "received domain name lookup"))) + (if (= (bytevector-ref i) 0) + (set! m (+ m 1)) + (if (>= m 7) + (display "EOT"))) + (set! name (string-append name (byte-vector-ref i))) + + ) + )))))) + + + + (let ((*server (make-server loopfunc))) + + + (define (dispatch msg) + (cond ((eq? msg 'start) (*server 'start)) + ((eq? msg 'stop) (*server 'stop)) + ((eq? msg 'restart) (*server 'restart)) + (else (display "make-server-dns : message not understood.")))) + + dispatch)) diff --git a/s48/hawk-dns-server/server.scm b/s48/hawk-dns-server/server.scm new file mode 100644 index 0000000..8c13f31 --- /dev/null +++ b/s48/hawk-dns-server/server.scm @@ -0,0 +1,56 @@ + +;;Copyright (c) 2015, Johan Ceuppens (goon) +;;All rights reserved. + +;;Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +;;1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +;;2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +;;3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +;;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +(define (make-server loopfunc) + (let ((*socket #f) + (*in #f) + (*out #f) + (*lastport #f) + (*loopfunc loopfunc)) + + (define (open port) + (set! *lastport port) + (set! *socket (open-socket port))) + + (define (start port) + (open port) + (let loop ((s #f)) + (lambda () + (socket-accept *socket)) + (lambda (in out) + (set! *in in) + (set! *out out) + (*loopfunc in out) + ))) + + (define (stop) + (close-input-port *in) + (close-output-port *out) + ) + + (define (restart) + (stop) + (if *lastport + (start *lastport) + (display "Could not restart - use start"))) + + (define (dispatch msg) + (cond ((eq? msg 'start) start) + ((eq? msg 'stop) stop) + ((eq? msg 'restart) restart) + (else (display "make-server : message not understood")))) + + dispatch)) diff --git a/s48/hawk-dns-server/util.scm b/s48/hawk-dns-server/util.scm new file mode 100644 index 0000000..0a9adc5 --- /dev/null +++ b/s48/hawk-dns-server/util.scm @@ -0,0 +1,5 @@ +(define (string->byte-vector str) + (let ((vec (make-byte-vector 0 0))) + (do ((i 0 (+ i 1))) + ((= i (string-length str)) vec) + (byte-vector-set! vec (char->integer (string-ref str i))))))