1 | /*
|
---|
2 | * Traditional DNS header OPCODEs (4-bits) defined by IANA in
|
---|
3 | * https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-5
|
---|
4 | */
|
---|
5 |
|
---|
6 | exports.toString = function (opcode) {
|
---|
7 | switch (opcode) {
|
---|
8 | case 0: return 'QUERY'
|
---|
9 | case 1: return 'IQUERY'
|
---|
10 | case 2: return 'STATUS'
|
---|
11 | case 3: return 'OPCODE_3'
|
---|
12 | case 4: return 'NOTIFY'
|
---|
13 | case 5: return 'UPDATE'
|
---|
14 | case 6: return 'OPCODE_6'
|
---|
15 | case 7: return 'OPCODE_7'
|
---|
16 | case 8: return 'OPCODE_8'
|
---|
17 | case 9: return 'OPCODE_9'
|
---|
18 | case 10: return 'OPCODE_10'
|
---|
19 | case 11: return 'OPCODE_11'
|
---|
20 | case 12: return 'OPCODE_12'
|
---|
21 | case 13: return 'OPCODE_13'
|
---|
22 | case 14: return 'OPCODE_14'
|
---|
23 | case 15: return 'OPCODE_15'
|
---|
24 | }
|
---|
25 | return 'OPCODE_' + opcode
|
---|
26 | }
|
---|
27 |
|
---|
28 | exports.toOpcode = function (code) {
|
---|
29 | switch (code.toUpperCase()) {
|
---|
30 | case 'QUERY': return 0
|
---|
31 | case 'IQUERY': return 1
|
---|
32 | case 'STATUS': return 2
|
---|
33 | case 'OPCODE_3': return 3
|
---|
34 | case 'NOTIFY': return 4
|
---|
35 | case 'UPDATE': return 5
|
---|
36 | case 'OPCODE_6': return 6
|
---|
37 | case 'OPCODE_7': return 7
|
---|
38 | case 'OPCODE_8': return 8
|
---|
39 | case 'OPCODE_9': return 9
|
---|
40 | case 'OPCODE_10': return 10
|
---|
41 | case 'OPCODE_11': return 11
|
---|
42 | case 'OPCODE_12': return 12
|
---|
43 | case 'OPCODE_13': return 13
|
---|
44 | case 'OPCODE_14': return 14
|
---|
45 | case 'OPCODE_15': return 15
|
---|
46 | }
|
---|
47 | return 0
|
---|
48 | }
|
---|