Gnus development mailing list
 help / color / mirror / Atom feed
From: Magnus Henoch <magnus.henoch@gmail.com>
To: ding@gnus.org
Subject: dns.el: forget DNS servers in new network
Date: Tue, 10 Sep 2013 22:02:39 +0100	[thread overview]
Message-ID: <m238pccrv4.fsf@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 696 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dns-servers-up-to-date-p.patch --]
[-- Type: text/x-patch, Size: 1992 bytes --]

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

             reply	other threads:[~2013-09-10 21:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-10 21:02 Magnus Henoch [this message]
2013-11-03 11:22 ` Ted Zlatanov
2014-01-30 22:19   ` Lars Ingebrigtsen
2014-02-02 21:56     ` Leonidas Tsampros
2014-02-02 22:17       ` Julien Danjou
2014-01-31 23:53 ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m238pccrv4.fsf@mail.gmail.com \
    --to=magnus.henoch@gmail.com \
    --cc=ding@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).