COMMON-NET: Added basic DNS communication.
authorFredrik Tolf <fredrik@dolda2000.com>
Sun, 16 May 2010 00:38:33 +0000 (02:38 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Sun, 16 May 2010 00:38:33 +0000 (02:38 +0200)
There does seem to be a strict need for some kind of timeout/selection
mechanism for socket operations, but it is unclear just how it should work
yet.

dns.lisp

index 48def25..cfb1750 100644 (file)
--- a/dns.lisp
+++ b/dns.lisp
                    (concatenate 'string buf "." label)
                    label)))))
 
+;;; Basic communication
+
+(defun dns-do-request (server packet)
+  (declare (type address server)
+          (type dns-packet packet))
+  (with-connection (sk server)
+    (socket-send sk (dns-encode packet))
+    (loop
+       (let ((resp (dns-decode (socket-recv sk))))
+        (when (= (dns-packet-txid resp)
+               (dns-packet-txid packet))
+          (return resp))))))
+
+(defun dns-std-request (queries &key (txid (random 65536)) (recurse t))
+  (let ((qlist (map 'list #'(lambda (o)
+                             (let ((name (first o))
+                                   (type (second o)))
+                               (make-instance 'resource-query
+                                              :name (etypecase name
+                                                      (string (parse-domain-name name))
+                                                      (list name))
+                                              :type type)))
+                   queries)))
+    (make-dns-packet :txid txid
+                    :recurse recurse
+                    :queries qlist)))
+
 ;;; Misc.
 
 (defmethod print-object ((q resource-query) stream)