# HG changeset patch # User Kim Alvefur # Date 1314982482 -7200 # Node ID 9a20acf315c96e8f40da94d219f030788c760c77 # Parent 052aeb22c645aac66ad9cb3f0e3f3ef4e7de3a96 net.dns: Shorten AAAA records diff -r 052aeb22c645 -r 9a20acf315c9 net/dns.lua --- a/net/dns.lua Wed Aug 31 20:25:13 2011 -0400 +++ b/net/dns.lua Fri Sep 02 18:54:42 2011 +0200 @@ -395,7 +395,18 @@ local b1, b2 = self:byte(2); table.insert(addr, ("%02x%02x"):format(b1, b2)); end - rr.aaaa = table.concat(addr, ":"); + addr = table.concat(addr, ":"):gsub("%f[%x]0+(%x)","%1"); + local zeros = {}; + for item in addr:gmatch(":[0:]+:") do + table.insert(zeros, item) + end + if #zeros == 0 then + rr.aaaa = addr; + return + elseif #zeros > 1 then + table.sort(zeros, function(a, b) return #a > #b end); + end + rr.aaaa = addr:gsub(zeros[1], "::", 1):gsub("^0::", "::"):gsub("::0$", "::"); end function resolver:CNAME(rr) -- - - - - - - - - - - - - - - - - - - - CNAME