-(defun dns-parse-resolv-conf ()
- (when (file-exists-p "/etc/resolv.conf")
- (with-temp-buffer
- (insert-file-contents "/etc/resolv.conf")
- (goto-char (point-min))
- (while (re-search-forward "^nameserver[\t ]+\\([^ \t\n]+\\)" nil t)
- (push (match-string 1) dns-servers))
- (setq dns-servers (nreverse dns-servers)))))
+(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\"."
+ (or (when (file-exists-p "/etc/resolv.conf")
+ (setq dns-servers nil)
+ (with-temp-buffer
+ (insert-file-contents "/etc/resolv.conf")
+ (goto-char (point-min))
+ (while (re-search-forward "^nameserver[\t ]+\\([^ \t\n]+\\)" nil t)
+ (push (match-string 1) dns-servers))
+ (setq dns-servers (nreverse dns-servers))))
+ (when (executable-find "nslookup")
+ (with-temp-buffer
+ (call-process "nslookup" nil t nil "localhost")
+ (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))))))
+ (when (fboundp 'network-interface-list)
+ (setq dns-servers-valid-for-interfaces (network-interface-list))))