1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | "use strict";
|
24 |
|
25 | function reverse_map(src) {
|
26 | var dst = {},
|
27 | k;
|
28 |
|
29 | for (k in src) {
|
30 | if (src.hasOwnProperty(k)) {
|
31 | dst[src[k]] = k;
|
32 | }
|
33 | }
|
34 | return dst;
|
35 | }
|
36 |
|
37 |
|
38 | var NAME_TO_QTYPE = exports.NAME_TO_QTYPE = {
|
39 | A: 1,
|
40 | NS: 2,
|
41 | MD: 3,
|
42 | MF: 4,
|
43 | CNAME: 5,
|
44 | SOA: 6,
|
45 | MB: 7,
|
46 | MG: 8,
|
47 | MR: 9,
|
48 | "NULL": 10,
|
49 | WKS: 11,
|
50 | PTR: 12,
|
51 | HINFO: 13,
|
52 | MINFO: 14,
|
53 | MX: 15,
|
54 | TXT: 16,
|
55 | RP: 17,
|
56 | AFSDB: 18,
|
57 | X25: 19,
|
58 | ISDN: 20,
|
59 | RT: 21,
|
60 | NSAP: 22,
|
61 | "NSAP-PTR": 23,
|
62 | SIG: 24,
|
63 | KEY: 25,
|
64 | PX: 26,
|
65 | GPOS: 27,
|
66 | AAAA: 28,
|
67 | LOC: 29,
|
68 | NXT: 30,
|
69 | EID: 31,
|
70 | NIMLOC: 32,
|
71 | SRV: 33,
|
72 | ATMA: 34,
|
73 | NAPTR: 35,
|
74 | KX: 36,
|
75 | CERT: 37,
|
76 | A6: 38,
|
77 | DNAME: 39,
|
78 | SINK: 40,
|
79 | OPT: 41,
|
80 | APL: 42,
|
81 | DS: 43,
|
82 | SSHFP: 44,
|
83 | IPSECKEY: 45,
|
84 | RRSIG: 46,
|
85 | NSEC: 47,
|
86 | DNSKEY: 48,
|
87 | DHCID: 49,
|
88 | NSEC3: 50,
|
89 | NSEC3PARAM: 51,
|
90 | HIP: 55,
|
91 | NINFO: 56,
|
92 | RKEY: 57,
|
93 | TALINK: 58,
|
94 | CDS: 59,
|
95 | SPF: 99,
|
96 | UINFO: 100,
|
97 | UID: 101,
|
98 | GID: 102,
|
99 | UNSPEC: 103,
|
100 | TKEY: 249,
|
101 | TSIG: 250,
|
102 | IXFR: 251,
|
103 | AXFR: 252,
|
104 | MAILB: 253,
|
105 | MAILA: 254,
|
106 | ANY: 255,
|
107 | URI: 256,
|
108 | CAA: 257,
|
109 | TA: 32768,
|
110 | DLV: 32769,
|
111 | };
|
112 | exports.QTYPE_TO_NAME = reverse_map(NAME_TO_QTYPE);
|
113 |
|
114 | exports.nameToQtype = function (n) {
|
115 | return NAME_TO_QTYPE[n.toUpperCase()];
|
116 | };
|
117 |
|
118 | exports.qtypeToName = function (t) {
|
119 | return exports.QTYPE_TO_NAME[t];
|
120 | };
|
121 |
|
122 | var NAME_TO_QCLASS = exports.NAME_TO_QCLASS = {
|
123 | IN: 1,
|
124 | };
|
125 | exports.QCLASS_TO_NAME = reverse_map(NAME_TO_QCLASS);
|
126 |
|
127 | exports.FAMILY_TO_QTYPE = {
|
128 | 4: NAME_TO_QTYPE.A,
|
129 | 6: NAME_TO_QTYPE.AAAA,
|
130 | };
|
131 | exports.QTYPE_TO_FAMILY = {};
|
132 | exports.QTYPE_TO_FAMILY[exports.NAME_TO_QTYPE.A] = 4;
|
133 | exports.QTYPE_TO_FAMILY[exports.NAME_TO_QTYPE.AAAA] = 6;
|
134 |
|
135 | exports.NAME_TO_RCODE = {
|
136 | NOERROR: 0,
|
137 | FORMERR: 1,
|
138 | SERVFAIL: 2,
|
139 | NOTFOUND: 3,
|
140 | NOTIMP: 4,
|
141 | REFUSED: 5,
|
142 | YXDOMAIN: 6,
|
143 | YXRRSET: 7,
|
144 | NXRRSET: 8,
|
145 | NOTAUTH: 9,
|
146 | NOTZONE: 10,
|
147 | BADVERS: 16,
|
148 | BADSIG: 16,
|
149 | BADKEY: 17,
|
150 | BADTIME: 18,
|
151 | BADMODE: 19,
|
152 | BADNAME: 20,
|
153 | BADALG: 21,
|
154 | BADTRUNC: 22,
|
155 | };
|
156 | exports.RCODE_TO_NAME = reverse_map(exports.NAME_TO_RCODE);
|
157 |
|
158 | exports.BADNAME = 'EBADNAME';
|
159 | exports.BADRESP = 'EBADRESP';
|
160 | exports.CONNREFUSED = 'ECONNREFUSED';
|
161 | exports.DESTRUCTION = 'EDESTRUCTION';
|
162 | exports.REFUSED = 'EREFUSED';
|
163 | exports.FORMERR = 'EFORMERR';
|
164 | exports.NODATA = 'ENODATA';
|
165 | exports.NOMEM = 'ENOMEM';
|
166 | exports.NOTFOUND = 'ENOTFOUND';
|
167 | exports.NOTIMP = 'ENOTIMP';
|
168 | exports.SERVFAIL = 'ESERVFAIL';
|
169 | exports.TIMEOUT = 'ETIMEOUT';
|