+(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))))
+
+(defun dns-read-txt (string)
+ (if (> (length string) 1)
+ (substring string 1)
+ string))
+
+(defun dns-get-txt-answer (answers)
+ (let ((result "")
+ (do-next nil))
+ (dolist (answer answers)
+ (dolist (elem answer)
+ (when (consp elem)
+ (cond
+ ((eq (car elem) 'type)
+ (setq do-next (eq (cadr elem) 'TXT)))
+ ((eq (car elem) 'data)
+ (when do-next
+ (setq result (concat result (dns-read-txt (cadr elem))))))))))
+ result))
+
+;;; Interface functions.