UNPKG

1.4 kBJavaScriptView Raw
1'use strict'
2
3exports.toString = function (type) {
4 switch (type) {
5 // list at
6 // https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-11
7 case 1: return 'LLQ'
8 case 2: return 'UL'
9 case 3: return 'NSID'
10 case 5: return 'DAU'
11 case 6: return 'DHU'
12 case 7: return 'N3U'
13 case 8: return 'CLIENT_SUBNET'
14 case 9: return 'EXPIRE'
15 case 10: return 'COOKIE'
16 case 11: return 'TCP_KEEPALIVE'
17 case 12: return 'PADDING'
18 case 13: return 'CHAIN'
19 case 14: return 'KEY_TAG'
20 case 26946: return 'DEVICEID'
21 }
22 if (type < 0) {
23 return null
24 }
25 return `OPTION_${type}`
26}
27
28exports.toCode = function (name) {
29 if (typeof name === 'number') {
30 return name
31 }
32 if (!name) {
33 return -1
34 }
35 switch (name.toUpperCase()) {
36 case 'OPTION_0': return 0
37 case 'LLQ': return 1
38 case 'UL': return 2
39 case 'NSID': return 3
40 case 'OPTION_4': return 4
41 case 'DAU': return 5
42 case 'DHU': return 6
43 case 'N3U': return 7
44 case 'CLIENT_SUBNET': return 8
45 case 'EXPIRE': return 9
46 case 'COOKIE': return 10
47 case 'TCP_KEEPALIVE': return 11
48 case 'PADDING': return 12
49 case 'CHAIN': return 13
50 case 'KEY_TAG': return 14
51 case 'DEVICEID': return 26946
52 case 'OPTION_65535': return 65535
53 }
54 const m = name.match(/_(\d+)$/)
55 if (m) {
56 return parseInt(m[1], 10)
57 }
58 return -1
59}