Comparison

net/dns.lua @ 4373:9a20acf315c9

net.dns: Shorten AAAA records
author Kim Alvefur <zash@zash.se>
date Fri, 02 Sep 2011 18:54:42 +0200
parent 4267:29d7eb6ff62c
child 4400:ac651265766c
comparison
equal deleted inserted replaced
4372:052aeb22c645 4373:9a20acf315c9
393 local addr = {}; 393 local addr = {};
394 for i = 1, rr.rdlength, 2 do 394 for i = 1, rr.rdlength, 2 do
395 local b1, b2 = self:byte(2); 395 local b1, b2 = self:byte(2);
396 table.insert(addr, ("%02x%02x"):format(b1, b2)); 396 table.insert(addr, ("%02x%02x"):format(b1, b2));
397 end 397 end
398 rr.aaaa = table.concat(addr, ":"); 398 addr = table.concat(addr, ":"):gsub("%f[%x]0+(%x)","%1");
399 local zeros = {};
400 for item in addr:gmatch(":[0:]+:") do
401 table.insert(zeros, item)
402 end
403 if #zeros == 0 then
404 rr.aaaa = addr;
405 return
406 elseif #zeros > 1 then
407 table.sort(zeros, function(a, b) return #a > #b end);
408 end
409 rr.aaaa = addr:gsub(zeros[1], "::", 1):gsub("^0::", "::"):gsub("::0$", "::");
399 end 410 end
400 411
401 function resolver:CNAME(rr) -- - - - - - - - - - - - - - - - - - - - CNAME 412 function resolver:CNAME(rr) -- - - - - - - - - - - - - - - - - - - - CNAME
402 rr.cname = self:name(); 413 rr.cname = self:name();
403 end 414 end