;;; Interface functions.
+(defmacro dns-make-network-process (server)
+ (if (featurep 'xemacs)
+ `(let ((coding-system-for-read 'binary)
+ (coding-system-for-write 'binary))
+ (open-network-stream "dns" (current-buffer) ,server "domain" 'udp))
+ `(let ((server ,server)
+ (coding-system-for-read 'binary)
+ (coding-system-for-write 'binary))
+ (if (fboundp 'make-network-process)
+ (make-network-process
+ :name "dns"
+ :coding 'binary
+ :buffer (current-buffer)
+ :host server
+ :service "domain"
+ :type 'datagram)
+ ;; Older versions of Emacs doesn't have
+ ;; `make-network-process', so we fall back on opening a TCP
+ ;; connection to the DNS server.
+ (open-network-stream "dns" (current-buffer) server "domain")))))
+
(defun query-dns (name &optional type fullp)
"Query a DNS server for NAME of TYPE.
If FULLP, return the entire record returned."
(unless dns-servers
(error "No DNS server configuration found")))
(mm-with-unibyte-buffer
- (let ((coding-system-for-read 'binary)
- (coding-system-for-write 'binary)
- (tcp-p (not (fboundp 'open-network-stream))))
- (let ((process
- (if tcp-p
- (open-network-stream
- "dns" (current-buffer)
- (car dns-servers) "domain")
- (make-network-process
- :name "dns"
- :coding 'binary
- :buffer (current-buffer)
- :host (car dns-servers)
- :service "domain"
- :type 'datagram)))
- (step 100)
- (times (* dns-timeout 1000))
- (id (random 65000)))
+ (let ((process (condition-case ()
+ (dns-make-network-process (car dns-servers))
+ (error
+ (message "dns: Got an error while trying to talk to %s"
+ (car dns-servers))
+ nil)))
+ (tcp-p (and (not (fboundp 'make-network-process))
+ (not (featurep 'xemacs))))
+ (step 100)
+ (times (* dns-timeout 1000))
+ (id (random 65000)))
+ (when process
(process-send-string
process
(dns-write `((id ,id)
(let ((answer (car (dns-get 'answers result))))
(when (eq type (dns-get 'type answer))
(dns-get 'data answer))))))))))
-
+
(provide 'dns)
;;; dns.el ends here