X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Fdns.el;h=ea1c805c6b9f10b2466b1eb7fba28bd00d6e470d;hb=99648d27eedbdead431411bfa31edd18c4ad5db4;hp=4469a544c3c582842030234d3b0b96e03beb6d32;hpb=4c2a7a1c25d5b10316f35f28c972ef3e70225f25;p=gnus diff --git a/lisp/dns.el b/lisp/dns.el index 4469a544c..ea1c805c6 100644 --- a/lisp/dns.el +++ b/lisp/dns.el @@ -1,7 +1,6 @@ ;;; dns.el --- Domain Name Service lookups -;; Copyright (C) 2002-2011 -;; Free Software Foundation, Inc. +;; Copyright (C) 2002-2014 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Keywords: network comm @@ -32,6 +31,12 @@ "List of DNS servers to query. If nil, /etc/resolv.conf and nslookup will be consulted.") +(defvar dns-servers-valid-for-interfaces nil + "The return value of `network-interface-list' when `dns-servers' was set. +If the set of network interfaces and/or their IP addresses +change, then presumably the list of DNS servers needs to be +updated. Set this variable to t to disable the check.") + ;;; Internal code: (defvar dns-query-types @@ -253,8 +258,8 @@ If TCP-P, the first two bytes of the package with be the length field." (nreverse spec)))) (defun dns-read-int32 () - ;; Full 32 bit Integers can't be handled by Emacs. If we use - ;; floats, it works. + ;; Full 32 bit Integers can't be handled by 32-bit Emacsen. If we + ;; use floats, it works. (format "%.0f" (+ (* (dns-read-bytes 1) 16777216.0) (dns-read-bytes 3)))) @@ -298,6 +303,17 @@ If TCP-P, the first two bytes of the package with be the length field." (t string))) (goto-char point)))) +(declare-function network-interface-list "process.c") + +(defun dns-servers-up-to-date-p () + "Return false if we need to recheck the list of DNS servers." + (and dns-servers + (or (eq dns-servers-valid-for-interfaces t) + ;; `network-interface-list' was introduced in Emacs 22.1. + (not (fboundp 'network-interface-list)) + (equal dns-servers-valid-for-interfaces + (network-interface-list))))) + (defun dns-set-servers () "Set `dns-servers' to a list of DNS servers or nil if none are found. Parses \"/etc/resolv.conf\" or calls \"nslookup\"." @@ -315,7 +331,9 @@ Parses \"/etc/resolv.conf\" or calls \"nslookup\"." (goto-char (point-min)) (re-search-forward "^Address:[ \t]*\\([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\)" nil t) - (setq dns-servers (list (match-string 1))))))) + (setq dns-servers (list (match-string 1)))))) + (when (fboundp 'network-interface-list) + (setq dns-servers-valid-for-interfaces (network-interface-list)))) (defun dns-read-txt (string) (if (> (length string) 1) @@ -379,7 +397,7 @@ Parses \"/etc/resolv.conf\" or calls \"nslookup\"." If FULLP, return the entire record returned. If REVERSEP, look up an IP address." (setq type (or type 'A)) - (unless dns-servers + (unless (dns-servers-up-to-date-p) (dns-set-servers)) (when reversep