annotate lisp/net/dns.el @ 95765:bc86b276908a

Correct copyright years to reflect the original newsticker.el from which most of this code was extracted, not the year it was moved into this file. Header formatting fix.
author Glenn Morris <rgm@gnu.org>
date Tue, 10 Jun 2008 03:20:18 +0000
parents 91e5880a36c1
children a9dc0e7c3f2b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1 ;;; dns.el --- Domain Name Service lookups
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2
87649
107ccd98fa12 Merge from emacs--rel--22
Miles Bader <miles@gnu.org>
parents: 86917
diff changeset
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
86917
439fa1afe05a Refill copyright.
Glenn Morris <rgm@gnu.org>
parents: 86915
diff changeset
4 ;; Free Software Foundation, Inc.
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
5
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
7 ;; Keywords: network
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
10
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93364
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93364
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93364
diff changeset
14 ;; (at your option) any later version.
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93364
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93364
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26 ;;; Code:
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 (defvar dns-timeout 5
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 "How many seconds to wait when doing DNS queries.")
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 (defvar dns-servers nil
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32 "Which DNS servers to query.
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 If nil, /etc/resolv.conf will be consulted.")
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 ;;; Internal code:
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 (defvar dns-query-types
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38 '((A 1)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 (NS 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40 (MD 3)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 (MF 4)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 (CNAME 5)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 (SOA 6)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 (MB 7)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 (MG 8)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 (MR 9)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 (NULL 10)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 (WKS 11)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 (PTR 12)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 (HINFO 13)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 (MINFO 14)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 (MX 15)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 (TXT 16)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 (AAAA 28) ; RFC3596
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 (SRV 33) ; RFC2782
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 (AXFR 252)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 (MAILB 253)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 (MAILA 254)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 (* 255))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 "Names of query types and their values.")
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 (defvar dns-classes
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 '((IN 1)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 (CS 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 (CH 3)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 (HS 4))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 "Classes of queries.")
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 (defun dns-write-bytes (value &optional length)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 (let (bytes)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 (dotimes (i (or length 1))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 (push (% value 256) bytes)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 (setq value (/ value 256)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 (dolist (byte bytes)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 (insert byte))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 (defun dns-read-bytes (length)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 (let ((value 0))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 (dotimes (i length)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 (setq value (logior (* value 256) (following-char)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 (forward-char 1))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 value))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 (defun dns-get (type spec)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 (cadr (assq type spec)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87 (defun dns-inverse-get (value spec)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
88 (let ((found nil))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
89 (while (and (not found)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90 spec)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91 (if (eq value (cadr (car spec)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 (setq found (caar spec))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 (pop spec)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94 found))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96 (defun dns-write-name (name)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97 (dolist (part (split-string name "\\."))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98 (dns-write-bytes (length part))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99 (insert part))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
100 (dns-write-bytes 0))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102 (defun dns-read-string-name (string buffer)
92781
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
103 (with-temp-buffer
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
104 (set-buffer-multibyte nil)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
105 (insert string)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
106 (goto-char (point-min))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
107 (dns-read-name buffer)))
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 (defun dns-read-name (&optional buffer)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110 (let ((ended nil)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 (name nil)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 length)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 (while (not ended)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114 (setq length (dns-read-bytes 1))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 (if (= 192 (logand length (lsh 3 6)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116 (let ((offset (+ (* (logand 63 length) 256)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 (dns-read-bytes 1))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118 (save-excursion
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119 (when buffer
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
120 (set-buffer buffer))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 (goto-char (1+ offset))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122 (setq ended (dns-read-name buffer))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 (if (zerop length)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124 (setq ended t)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125 (push (buffer-substring (point)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
126 (progn (forward-char length) (point)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 name))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128 (if (stringp ended)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129 (if (null name)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
130 ended
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 (concat (mapconcat 'identity (nreverse name) ".") "." ended))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 (mapconcat 'identity (nreverse name) "."))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134 (defun dns-write (spec &optional tcp-p)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 "Write a DNS packet according to SPEC.
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136 If TCP-P, the first two bytes of the package with be the length field."
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137 (with-temp-buffer
93364
ed215625a8cb (dns-write): Use set-buffer-multibyte.
Magnus Henoch <mange@freemail.hu>
parents: 92781
diff changeset
138 (set-buffer-multibyte nil)
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139 (dns-write-bytes (dns-get 'id spec) 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 (dns-write-bytes
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141 (logior
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 (lsh (if (dns-get 'response-p spec) 1 0) -7)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143 (lsh
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 (cond
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145 ((eq (dns-get 'opcode spec) 'query) 0)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146 ((eq (dns-get 'opcode spec) 'inverse-query) 1)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147 ((eq (dns-get 'opcode spec) 'status) 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 (t (error "No such opcode: %s" (dns-get 'opcode spec))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149 -3)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 (lsh (if (dns-get 'authoritative-p spec) 1 0) -2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 (lsh (if (dns-get 'truncated-p spec) 1 0) -1)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 (lsh (if (dns-get 'recursion-desired-p spec) 1 0) 0)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153 (dns-write-bytes
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154 (cond
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 ((eq (dns-get 'response-code spec) 'no-error) 0)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 ((eq (dns-get 'response-code spec) 'format-error) 1)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157 ((eq (dns-get 'response-code spec) 'server-failure) 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158 ((eq (dns-get 'response-code spec) 'name-error) 3)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 ((eq (dns-get 'response-code spec) 'not-implemented) 4)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 ((eq (dns-get 'response-code spec) 'refused) 5)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161 (t 0)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
162 (dns-write-bytes (length (dns-get 'queries spec)) 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
163 (dns-write-bytes (length (dns-get 'answers spec)) 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
164 (dns-write-bytes (length (dns-get 'authorities spec)) 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
165 (dns-write-bytes (length (dns-get 'additionals spec)) 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
166 (dolist (query (dns-get 'queries spec))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
167 (dns-write-name (car query))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
168 (dns-write-bytes (cadr (assq (or (dns-get 'type query) 'A)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
169 dns-query-types)) 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
170 (dns-write-bytes (cadr (assq (or (dns-get 'class query) 'IN)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
171 dns-classes)) 2))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
172 (dolist (slot '(answers authorities additionals))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
173 (dolist (resource (dns-get slot spec))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
174 (dns-write-name (car resource))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
175 (dns-write-bytes (cadr (assq (dns-get 'type resource) dns-query-types))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
176 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
177 (dns-write-bytes (cadr (assq (dns-get 'class resource) dns-classes))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
178 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
179 (dns-write-bytes (dns-get 'ttl resource) 4)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
180 (dns-write-bytes (length (dns-get 'data resource)) 2)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
181 (insert (dns-get 'data resource))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
182 (when tcp-p
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
183 (goto-char (point-min))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
184 (dns-write-bytes (buffer-size) 2))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
185 (buffer-string)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
186
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
187 (defun dns-read (packet)
92781
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
188 (with-temp-buffer
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
189 (set-buffer-multibyte nil)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
190 (let ((spec nil)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
191 queries answers authorities additionals)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
192 (insert packet)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
193 (goto-char (point-min))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
194 (push (list 'id (dns-read-bytes 2)) spec)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
195 (let ((byte (dns-read-bytes 1)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
196 (push (list 'response-p (if (zerop (logand byte (lsh 1 7))) nil t))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
197 spec)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
198 (let ((opcode (logand byte (lsh 7 3))))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
199 (push (list 'opcode
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
200 (cond ((eq opcode 0) 'query)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
201 ((eq opcode 1) 'inverse-query)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
202 ((eq opcode 2) 'status)))
86917
439fa1afe05a Refill copyright.
Glenn Morris <rgm@gnu.org>
parents: 86915
diff changeset
203 spec))
92781
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
204 (push (list 'authoritative-p (if (zerop (logand byte (lsh 1 2)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
205 nil t)) spec)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
206 (push (list 'truncated-p (if (zerop (logand byte (lsh 1 2))) nil t))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
207 spec)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
208 (push (list 'recursion-desired-p
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
209 (if (zerop (logand byte (lsh 1 0))) nil t)) spec))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
210 (let ((rc (logand (dns-read-bytes 1) 15)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
211 (push (list 'response-code
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
212 (cond
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
213 ((eq rc 0) 'no-error)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
214 ((eq rc 1) 'format-error)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
215 ((eq rc 2) 'server-failure)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
216 ((eq rc 3) 'name-error)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
217 ((eq rc 4) 'not-implemented)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
218 ((eq rc 5) 'refused)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
219 spec))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
220 (setq queries (dns-read-bytes 2))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
221 (setq answers (dns-read-bytes 2))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
222 (setq authorities (dns-read-bytes 2))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
223 (setq additionals (dns-read-bytes 2))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
224 (let ((qs nil))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
225 (dotimes (i queries)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
226 (push (list (dns-read-name)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
227 (list 'type (dns-inverse-get (dns-read-bytes 2)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
228 dns-query-types))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
229 (list 'class (dns-inverse-get (dns-read-bytes 2)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
230 dns-classes)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
231 qs))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
232 (push (list 'queries qs) spec))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
233 (dolist (slot '(answers authorities additionals))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
234 (let ((qs nil)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
235 type)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
236 (dotimes (i (symbol-value slot))
86917
439fa1afe05a Refill copyright.
Glenn Morris <rgm@gnu.org>
parents: 86915
diff changeset
237 (push (list (dns-read-name)
92781
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
238 (list 'type
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
239 (setq type (dns-inverse-get (dns-read-bytes 2)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
240 dns-query-types)))
86917
439fa1afe05a Refill copyright.
Glenn Morris <rgm@gnu.org>
parents: 86915
diff changeset
241 (list 'class (dns-inverse-get (dns-read-bytes 2)
92781
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
242 dns-classes))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
243 (list 'ttl (dns-read-bytes 4))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
244 (let ((length (dns-read-bytes 2)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
245 (list 'data
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
246 (dns-read-type
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
247 (buffer-substring
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
248 (point)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
249 (progn (forward-char length) (point)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
250 type))))
86917
439fa1afe05a Refill copyright.
Glenn Morris <rgm@gnu.org>
parents: 86915
diff changeset
251 qs))
92781
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
252 (push (list slot qs) spec)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
253 (nreverse spec))))
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
254
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
255 (defun dns-read-int32 ()
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
256 ;; Full 32 bit Integers can't be handled by Emacs. If we use
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
257 ;; floats, it works.
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
258 (format "%.0f" (+ (* (dns-read-bytes 1) 16777216.0)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
259 (dns-read-bytes 3))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
260
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
261 (defun dns-read-type (string type)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
262 (let ((buffer (current-buffer))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
263 (point (point)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
264 (prog1
92781
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
265 (with-temp-buffer
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
266 (set-buffer-multibyte nil)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
267 (insert string)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
268 (goto-char (point-min))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
269 (cond
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
270 ((eq type 'A)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
271 (let ((bytes nil))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
272 (dotimes (i 4)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
273 (push (dns-read-bytes 1) bytes))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
274 (mapconcat 'number-to-string (nreverse bytes) ".")))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
275 ((eq type 'AAAA)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
276 (let (hextets)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
277 (dotimes (i 8)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
278 (push (dns-read-bytes 2) hextets))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
279 (mapconcat (lambda (n) (format "%x" n))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
280 (nreverse hextets) ":")))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
281 ((eq type 'SOA)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
282 (list (list 'mname (dns-read-name buffer))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
283 (list 'rname (dns-read-name buffer))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
284 (list 'serial (dns-read-int32))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
285 (list 'refresh (dns-read-int32))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
286 (list 'retry (dns-read-int32))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
287 (list 'expire (dns-read-int32))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
288 (list 'minimum (dns-read-int32))))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
289 ((eq type 'SRV)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
290 (list (list 'priority (dns-read-bytes 2))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
291 (list 'weight (dns-read-bytes 2))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
292 (list 'port (dns-read-bytes 2))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
293 (list 'target (dns-read-name buffer))))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
294 ((eq type 'MX)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
295 (cons (dns-read-bytes 2) (dns-read-name buffer)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
296 ((or (eq type 'CNAME) (eq type 'NS) (eq type 'PTR))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
297 (dns-read-string-name string buffer))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
298 (t string)))
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
299 (goto-char point))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
300
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
301 (defun dns-parse-resolv-conf ()
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
302 (when (file-exists-p "/etc/resolv.conf")
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
303 (with-temp-buffer
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
304 (insert-file-contents "/etc/resolv.conf")
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
305 (goto-char (point-min))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
306 (while (re-search-forward "^nameserver[\t ]+\\([^ \t\n]+\\)" nil t)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
307 (push (match-string 1) dns-servers))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
308 (setq dns-servers (nreverse dns-servers)))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
309
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
310 (defun dns-read-txt (string)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
311 (if (> (length string) 1)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
312 (substring string 1)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
313 string))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
314
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
315 (defun dns-get-txt-answer (answers)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
316 (let ((result "")
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
317 (do-next nil))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
318 (dolist (answer answers)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
319 (dolist (elem answer)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
320 (when (consp elem)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
321 (cond
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
322 ((eq (car elem) 'type)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
323 (setq do-next (eq (cadr elem) 'TXT)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
324 ((eq (car elem) 'data)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
325 (when do-next
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
326 (setq result (concat result (dns-read-txt (cadr elem))))))))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
327 result))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
328
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
329 ;;; Interface functions.
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
330 (defmacro dns-make-network-process (server)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
331 (if (featurep 'xemacs)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
332 `(let ((coding-system-for-read 'binary)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
333 (coding-system-for-write 'binary))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
334 (open-network-stream "dns" (current-buffer)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
335 ,server "domain" 'udp))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
336 `(let ((server ,server)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
337 (coding-system-for-read 'binary)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
338 (coding-system-for-write 'binary))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
339 (if (fboundp 'make-network-process)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
340 (make-network-process
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
341 :name "dns"
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
342 :coding 'binary
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
343 :buffer (current-buffer)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
344 :host server
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
345 :service "domain"
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
346 :type 'datagram)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
347 ;; Older versions of Emacs doesn't have
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
348 ;; `make-network-process', so we fall back on opening a TCP
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
349 ;; connection to the DNS server.
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
350 (open-network-stream "dns" (current-buffer) server "domain")))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
351
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
352 (defvar dns-cache (make-vector 4096 0))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
353
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
354 (defun query-dns-cached (name &optional type fullp reversep)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
355 (let* ((key (format "%s:%s:%s:%s" name type fullp reversep))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
356 (sym (intern-soft key dns-cache)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
357 (if (and sym
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
358 (boundp sym))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
359 (symbol-value sym)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
360 (let ((result (query-dns name type fullp reversep)))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
361 (set (intern key dns-cache) result)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
362 result))))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
363
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
364 (defun query-dns (name &optional type fullp reversep)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
365 "Query a DNS server for NAME of TYPE.
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
366 If FULLP, return the entire record returned.
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
367 If REVERSEP, look up an IP address."
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
368 (setq type (or type 'A))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
369 (unless dns-servers
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
370 (dns-parse-resolv-conf))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
371
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
372 (when reversep
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
373 (setq name (concat
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
374 (mapconcat 'identity (nreverse (split-string name "\\.")) ".")
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
375 ".in-addr.arpa")
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
376 type 'PTR))
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
377
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
378 (if (not dns-servers)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
379 (message "No DNS server configuration found")
92781
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
380 (with-temp-buffer
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
381 (set-buffer-multibyte nil)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
382 (let ((process (condition-case ()
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
383 (dns-make-network-process (car dns-servers))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
384 (error
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
385 (message
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
386 "dns: Got an error while trying to talk to %s"
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
387 (car dns-servers))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
388 nil)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
389 (tcp-p (and (not (fboundp 'make-network-process))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
390 (not (featurep 'xemacs))))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
391 (step 100)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
392 (times (* dns-timeout 1000))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
393 (id (random 65000)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
394 (when process
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
395 (process-send-string
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
396 process
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
397 (dns-write `((id ,id)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
398 (opcode query)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
399 (queries ((,name (type ,type))))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
400 (recursion-desired-p t))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
401 tcp-p))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
402 (while (and (zerop (buffer-size))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
403 (> times 0))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
404 (sit-for (/ step 1000.0))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
405 (accept-process-output process 0 step)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
406 (setq times (- times step)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
407 (condition-case nil
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
408 (delete-process process)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
409 (error nil))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
410 (when (and tcp-p
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
411 (>= (buffer-size) 2))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
412 (goto-char (point-min))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
413 (delete-region (point) (+ (point) 2)))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
414 (when (and (>= (buffer-size) 2)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
415 ;; We had a time-out.
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
416 (> times 0))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
417 (let ((result (dns-read (buffer-string))))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
418 (if fullp
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
419 result
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
420 (let ((answer (car (dns-get 'answers result))))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
421 (when (eq type (dns-get 'type answer))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
422 (if (eq type 'TXT)
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
423 (dns-get-txt-answer (dns-get 'answers result))
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
424 (dns-get 'data answer))))))))))))
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
425
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
426 (provide 'dns)
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
427
92781
f231a5d1706d (dns-read-string-name, dns-read, dns-read-type, query-dns):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
428 ;; arch-tag: d0edd0c4-4cce-4538-ae92-06c3356ee80a
86915
b48d018b85e2 Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
429 ;;; dns.el ends here