Merge branch 'master' of git+ssh://metalzone.distorted.org.uk/~mdw/public-git/zone
authorMark Wooding <mdw@distorted.org.uk>
Sat, 23 Dec 2006 14:54:24 +0000 (14:54 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 23 Dec 2006 14:54:24 +0000 (14:54 +0000)
net.lisp
zone
zone.asd
zone.lisp

index 08efe56..61b5978 100644 (file)
--- a/net.lisp
+++ b/net.lisp
@@ -75,8 +75,7 @@
    `stringify'.  The START and END arguments may be used to parse out a
    substring."
   (setf str (stringify str))
-  (unless end
-    (setf end (length str)))
+  (setf-default end (length str))
   (let ((addr 0) (noct 0))
     (loop
       (let* ((pos (position #\. str :start start :end end))
 (defun string-ipnet (str &key (start 0) (end nil))
   "Parse an IP-network from the string STR."
   (setf str (stringify str))
-  (unless end (setf end (length str)))
+  (setf-default end (length str))
   (let ((sl (position #\/ str :start start :end end)))
     (if sl
        (make-ipnet (parse-ipaddr (subseq str start sl))
 (defun resolve-hostname (name)
   "Resolve a hostname to an IP address using the DNS, or return nil."
   #+cmu (let ((he (ext:lookup-host-entry name)))
-         (and he
-              (ext:host-entry-addr he)))
-  #-cmu nil
-)
+         (and he (ext:host-entry-addr he)))
+  #+clisp (let ((he (ext:resolve-host-ipaddr name)))
+           (and he (string-ipaddr (car (ext:hostent-addr-list he)))))
+  #+ecl (nth-value 2 (ext:lookup-host-entry name))
+  #-(or cmu clisp ecl) nil)
 
 (defun canonify-hostname (name)
   "Resolve a hostname to canonical form using the DNS, or return nil."
   #+cmu (let ((he (ext:lookup-host-entry name)))
-         (and he
-              (ext:host-entry-name he)))
-  #-cmu nil)
+         (and he (ext:host-entry-name he)))
+  #+clisp (let ((he (ext:resolve-host-ipaddr name)))
+           (and he (ext:hostent-name he)))
+  #+ecl (nth-value 0 (ext:lookup-host-entry name))
+  #-(or cmu clisp ecl) name)
 
 ;;;--------------------------------------------------------------------------
 ;;; Host names and specifiers.
diff --git a/zone b/zone
index de68201..8befb1d 100755 (executable)
--- a/zone
+++ b/zone
@@ -1,6 +1,5 @@
 #! /usr/local/bin/runlisp
 ;;; -*-lisp-*-
 
-(clc:clc-require "mdw")
 (clc:clc-require "zone")
 (zone.frontend:main)
index b49cc79..0396a19 100644 (file)
--- a/zone.asd
+++ b/zone.asd
@@ -4,7 +4,7 @@
   :description "Generation of DNS zone files"
   :version "1.0.0"
   :author "Mark Wooding <mdw@distorted.org.uk>"
-  :depends-on ("mdw")
+  :depends-on ("mdw" #+ecl "cffi")
   :components ((:file "net")
               (:file "zone")
               (:file "frontend"))
index 64488c2..adcfb7e 100644 (file)
--- a/zone.lisp
+++ b/zone.lisp
 ;;;--------------------------------------------------------------------------
 ;;; Zone defaults.  It is intended that scripts override these.
 
+#+ecl
+(cffi:defcfun gethostname :int
+  (name :pointer)
+  (len :uint))
+
 (defvar *default-zone-source*
   (let ((hn #+cmu (unix:unix-gethostname)
-           #+clisp (unix:get-host-name)))
+           #+clisp (unix:get-host-name)
+           #+ecl (cffi:with-foreign-pointer-as-string (buffer 256 len)
+                   (let ((rc (gethostname buffer len)))
+                     (unless (zerop rc)
+                       (error "gethostname(2) failed (rc = ~A)." rc))))))
     (and hn (concatenate 'string (canonify-hostname hn) ".")))
   "The default zone source: the current host's name.")
 
   (setf types (listify types))
   (let* ((type (car types))
         (func (intern (format nil "ZONE-PARSE/~:@(~A~)" type))))
-    (multiple-value-bind (doc decls body) (parse-body body)
+    (with-parsed-body (doc decls body body)
       (with-gensyms (col tname ttype tttl tdata tdefsubp i)
        `(progn
           (dolist (,i ',types)