Comparison

net/dns.lua @ 8908:144666d0ad2f

net.dns: Lazily generate unknown RR type names
author Kim Alvefur <zash@zash.se>
date Sun, 10 Jun 2018 17:45:49 +0200
parent 8907:b7b960d30eef
child 8909:dbb5ec6885fe
comparison
equal deleted inserted replaced
8907:b7b960d30eef 8908:144666d0ad2f
84 local function highbyte(i) -- - - - - - - - - - - - - - - - - - - highbyte 84 local function highbyte(i) -- - - - - - - - - - - - - - - - - - - highbyte
85 return (i-(i%0x100))/0x100; 85 return (i-(i%0x100))/0x100;
86 end 86 end
87 87
88 88
89 local function augment (t) -- - - - - - - - - - - - - - - - - - - - augment 89 local function augment (t, prefix) -- - - - - - - - - - - - - - - - - augment
90 local a = {}; 90 local a = {};
91 for i,s in pairs(t) do 91 for i,s in pairs(t) do
92 a[i] = s; 92 a[i] = s;
93 a[s] = s; 93 a[s] = s;
94 a[string.lower(s)] = s; 94 a[string.lower(s)] = s;
95 end 95 end
96 setmetatable(a, {
97 __index = function (_, i)
98 if type(i) == "number" then
99 return ("%s%d"):format(prefix, i);
100 elseif type(i) == "string" then
101 return i:upper();
102 end
103 end;
104 })
96 return a; 105 return a;
97 end 106 end
98 107
99 108
100 local function encode (t) -- - - - - - - - - - - - - - - - - - - - - encode 109 local function encode (t) -- - - - - - - - - - - - - - - - - - - - - encode
117 126
118 127
119 dns.classes = { 'IN', 'CS', 'CH', 'HS', [255] = '*' }; 128 dns.classes = { 'IN', 'CS', 'CH', 'HS', [255] = '*' };
120 129
121 130
122 dns.type = augment (dns.types); 131 dns.type = augment (dns.types, "TYPE");
123 dns.class = augment (dns.classes); 132 dns.class = augment (dns.classes, "CLASS");
124 dns.typecode = encode (dns.types); 133 dns.typecode = encode (dns.types);
125 dns.classcode = encode (dns.classes); 134 dns.classcode = encode (dns.classes);
126 135
127 136
128 137