From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/83765 Path: news.gmane.org!not-for-mail From: Magnus Henoch Newsgroups: gmane.emacs.gnus.general Subject: dns.el: forget DNS servers in new network Date: Tue, 10 Sep 2013 22:02:39 +0100 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1378846988 26059 80.91.229.3 (10 Sep 2013 21:03:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 10 Sep 2013 21:03:08 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M32021@lists.math.uh.edu Tue Sep 10 23:03:10 2013 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VJV5Z-0004Sm-4c for ding-account@gmane.org; Tue, 10 Sep 2013 23:03:09 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1VJV5K-0000rz-Hs; Tue, 10 Sep 2013 16:02:54 -0500 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1VJV5H-0000rj-N4 for ding@lists.math.uh.edu; Tue, 10 Sep 2013 16:02:51 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1VJV5G-0000Ld-7y for ding@lists.math.uh.edu; Tue, 10 Sep 2013 16:02:51 -0500 Original-Received: from mail-wg0-f48.google.com ([74.125.82.48]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1VJV5E-0001Wn-Fx for ding@gnus.org; Tue, 10 Sep 2013 23:02:48 +0200 Original-Received: by mail-wg0-f48.google.com with SMTP id n12so4720003wgh.15 for ; Tue, 10 Sep 2013 14:02:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type; bh=xRzkg/fs2/1ETSHhlIR3eab978XX5vA3MdyaVrEVRXs=; b=A3rjH+4ezmgTF9dkJHJITcHbOLu3wN99kP6J1+0VTPUPL2Coz0s/Ji+djtW1xQnZfh Kkq1XFc3xkrkAJzlM7OTlhh4KApQyaEG3Pw3goU4qWz67uC3rZwv4vfRU8c129tzECNJ 3CbDKbKm8/WlfiIzTk/lmgnyzA/a6ZRtoJogb4Cuqej5/mV23YLoEyvq+o+ul+gisr6V pTG7sMsfOCow3/aVDwf9RE2aZ/IIL0GR57IpeRole1xVWz5yapWx2fXWvt4FgNWiA/md SifBbIDhnUxwbUKHMlggAXeaICcKJ9hQ7fJxaTcmB+8gvS0f7e6iQ8DeyQ1RElZEFwd0 XL7A== X-Received: by 10.194.170.133 with SMTP id am5mr4192305wjc.42.1378846962815; Tue, 10 Sep 2013 14:02:42 -0700 (PDT) Original-Received: from poki-sona.local (94-195-120-112.zone9.bethere.co.uk. [94.195.120.112]) by mx.google.com with ESMTPSA id l9sm6150351wif.10.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 10 Sep 2013 14:02:41 -0700 (PDT) User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (darwin) X-Spam-Score: -3.0 (---) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:83765 Archived-At: --=-=-= Content-Type: text/plain Hi all, I'm using Gnus' dns.el to look up SRV records for Jabber servers in jabber.el. It works fine except when I move my laptop from one network to another, because dns.el caches the list of DNS servers (obtained from /etc/resolv.conf) in the variable dns-servers, but sometimes those DNS servers aren't appropriate/reachable for the new network. Thus the patch below. It checks whether the names and IP addresses of all network interfaces have changed, and if so, rereads /etc/resolv.conf instead of using the value of dns-servers. What do you think about it? (I'm calling fboundp for network-interface-list as I'm not sure if the relevant XEmacs versions support it.) Regards, Magnus --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=dns-servers-up-to-date-p.patch diff --git a/lisp/dns.el b/lisp/dns.el index 1c456eb..ccf0617 100644 --- a/lisp/dns.el +++ b/lisp/dns.el @@ -31,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 @@ -297,6 +303,15 @@ If TCP-P, the first two bytes of the package with be the length field." (t string))) (goto-char point)))) +(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\"." @@ -314,7 +329,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) @@ -378,7 +395,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 --=-=-=--