;;; dig.el --- Domain Name System dig interface
-;; Copyright (c) 2000 Free Software Foundation, Inc.
+;; Copyright (c) 2000, 2001, 2003 Free Software Foundation, Inc.
;; Author: Simon Josefsson <simon@josefsson.org>
;; Keywords: DNS BIND dig
-;; This file is not a part of GNU Emacs, but the same permissions apply.
+;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; For use in elisp programs, call `dig-invoke' and use
;; `dig-extract-rr' to extract resource records.
+;;; Release history:
+
+;; 2000-10-28 posted on gnu.emacs.sources
+
;;; Code:
(eval-when-compile (require 'cl))
"Default expressions to highlight in dig mode."
:type 'sexp
:group 'dig)
-
+
(defun dig-invoke (domain &optional
- query-type query-class query-option
+ query-type query-class query-option
dig-option server)
"Call dig with given arguments and return buffer containing output.
DOMAIN is a string with a DNS domain. QUERY-TYPE is an optional string
(save-excursion
(goto-char (point-min))
(if (re-search-forward
- (concat domain "\\.?[\t ]+[0-9wWdDhHmMsS]+[\t ]+"
+ (concat domain "\\.?[\t ]+[0-9wWdDhHmMsS]+[\t ]+"
(upcase (or class "IN")) "[\t ]+" (upcase (or type "A")))
nil t)
(let (b e)
'(dig-font-lock-keywords t)))
(when (featurep 'font-lock)
(font-lock-set-defaults)))
-
+
(defun dig-exit ()
"Quit dig output buffer."
(interactive)
"Query addresses of a DOMAIN using dig, by calling `dig-invoke'.
Optional arguments are passed to `dig-invoke'."
(interactive "sHost: ")
- (switch-to-buffer
+ (switch-to-buffer
(dig-invoke domain query-type query-class query-option dig-option server))
(goto-char (point-min))
(and (search-forward ";; ANSWER SECTION:" nil t)
(setq buffer-read-only t)
(set-buffer-modified-p nil))
+;; named for consistency with query-dns in dns.el
+(defun query-dig (domain &optional
+ query-type query-class query-option dig-option server)
+ "Query addresses of a DOMAIN using dig.
+It works by calling `dig-invoke' and `dig-extract-rr'. Optional
+arguments are passed to `dig-invoke' and `dig-extract-rr'. Returns
+nil for domain/class/type queries that results in no data."
+(let ((buffer (dig-invoke domain query-type query-class
+ query-option dig-option server)))
+ (when buffer
+ (switch-to-buffer buffer)
+ (let ((digger (dig-extract-rr domain query-type query-class)))
+ (kill-buffer buffer)
+ digger))))
+
(provide 'dig)
;;; dig.el ends here