initial hawk dns server
This commit is contained in:
parent
a69b2a62d3
commit
3f7462a98e
|
@ -0,0 +1 @@
|
|||
Copyright (C) 2017 Johan Ceuppens
|
|
@ -0,0 +1 @@
|
|||
hawk-dns-server : a DNS server
|
|
@ -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.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
version 0.1
|
||||
* sending and receiving bytes
|
|
@ -0,0 +1,3 @@
|
|||
,load big-scheme
|
||||
,open byte-vectors
|
||||
run as a daemon
|
|
@ -0,0 +1,2 @@
|
|||
,load big-scheme
|
||||
,open byte-vectors
|
|
@ -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))
|
|
@ -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))
|
|
@ -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))
|
|
@ -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))
|
|
@ -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))))))
|
Loading…
Reference in New Issue