cl-rw

Layered streams for Common Lisp
git clone https://logand.com/git/cl-rw.git/
Log | Files | Refs

commit dbf287b8ba5c7d00259bb25597fbc5ae8477b4a0
parent 07d64dadd509ce3a0ab1a5d9bcb447161d984c65
Author: Tomas Hlavaty <tom@logand.com>
Date:   Mon, 29 Dec 2014 13:06:38 +0100

parse-/etc/hosts added

Diffstat:
Mdns.lisp | 32++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)

diff --git a/dns.lisp b/dns.lisp @@ -645,6 +645,38 @@ unless (eql #\; (char line 0)) collect (parse-root.zone-line line)))) +(defun parse-/etc/hosts-line (x) + (let ((r (rw:peek-reader (rw:reader x)))) + (flet ((str () + (rw:skip r) + (coerce (rw:till r '(#\space #\tab #\newline #\return)) + 'string))) + (let ((ip (let ((x (str))) + (if (find #\: x) + (rw.socket:make-ipv6-address x) + (rw.socket:make-ipv4-address x))))) + (loop + while (rw:peek r) + collect (make-$resource + :name (str) + :type (etypecase ip + (rw.socket:ipv4-address 'A) + (rw.socket:ipv6-address 'AAAA)) + :class 'IN + :ttl 3600 ;; TODO something else? + :data ip)))))) + +(defun parse-/etc/hosts (&optional (pathname "/etc/hosts")) + (with-open-file (s pathname) + (loop + for line = nil + while (setq line (read-line s nil)) + when (and (plusp (length line)) + (not (eql #\# (char line 0)))) + appending (parse-/etc/hosts-line line)))) + +;;(car (parse-/etc/hosts)) + #+nil ;; TODO dns over tcp doesnt seem to work, depends on server? (defun tcp-query (name server &key (port 53)) (with-open-stream (s (rw.socket:make-tcp-client-socket server port))