From dbd13f24ab10533c29a883cf4b66829718c98ef7 Mon Sep 17 00:00:00 2001 From: cresh Date: Mon, 30 Jun 2003 10:57:26 +0000 Subject: [PATCH] Minor changes in parse-resolv.conf. --- scheme/lib/dns.scm | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/scheme/lib/dns.scm b/scheme/lib/dns.scm index 36e9e1b..d66a3ed 100644 --- a/scheme/lib/dns.scm +++ b/scheme/lib/dns.scm @@ -1057,16 +1057,17 @@ (define *resolv.conf-cache*) (define *resolv.conf-cache-date* 0) +(define *resolv.conf-file* "/etc/resolv.conf") (define (resolv.conf) - (let ((actual-m-time (file-info:mtime (file-info "/etc/resolv.conf")))) + (let ((actual-m-time (file-info:mtime (file-info *resolv.conf-file*)))) (if (> actual-m-time *resolv.conf-cache-date*) (parse-resolv.conf!)) *resolv.conf-cache*)) (define (parse-resolv.conf!) - (let ((actual-m-time (file-info:mtime (file-info "/etc/resolv.conf"))) - (contents (really-parse-resolv.conf "/etc/resolv.conf"))) + (let ((actual-m-time (file-info:mtime (file-info *resolv.conf-file*))) + (contents (really-parse-resolv.conf *resolv.conf-file*))) (set! *resolv.conf-cache* contents) (set! *resolv.conf-cache-date* actual-m-time))) @@ -1111,7 +1112,11 @@ ((eof-object? l) (adjust-result rev-result #f '())) ((regexp-search - (rx (: "nameserver" (+ (| " " "\t") + (rx (: bos ("#;"))) + l) + (loop rev-result)) + ((regexp-search + (rx (: bos "nameserver" (+ (| " " "\t") (submatch (* any)) eos))) l) @@ -1119,7 +1124,7 @@ (loop (cons (parse-nameserver (match:substring match 1)) rev-result)))) ((regexp-search - (rx (: "domain" (+ (| " " "\t") + (rx (: bos "domain" (+ (| " " "\t") (submatch (* any)) eos))) l) @@ -1127,7 +1132,7 @@ (loop (cons (parse-domain (match:substring match 1)) rev-result)))) ((regexp-search - (rx (: "search" (+ (| " " "\t") + (rx (: bos "search" (+ (| " " "\t") (submatch (* any)) eos))) l) @@ -1136,22 +1141,27 @@ rev-result)))) ((regexp-search - (rx (: "sortlist" (+ (| " " "\t") + (rx (: bos "sortlist" (+ (| " " "\t") (submatch (* any)) eos))) l) => (lambda (match) - (parse-sortlist (match:substring match 1)))) + (loop (cons (parse-sortlist (match:substring match 1)) + rev-result)))) ((regexp-search - (rx (: "options" (+ (| " " "\t") + (rx (: bos "options" (+ (| " " "\t") (submatch (* any)) eos))) l) => (lambda (match) - (parse-options (match:substring match 1)))) - (else (signal 'resolv.conf-parse-error)))))))) + (loop (cons (parse-options (match:substring match 1)) + rev-result)))) + ;; skips lines with parse errors, instead of + ;; raising a 'resolv.conf-parse-error + (else (loop rev-result)))))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Figure out the default name servers @@ -1160,7 +1170,7 @@ (cond ((assoc 'nameserver (resolv.conf)) => (lambda (nameserver.list) (cdr nameserver.list))) - (else '()))) + (else '("127.0.0.1")))) ;; returns the first found nameserver (define (dns-find-nameserver)