From 2865b80ebdac7343fac499a978a32863a02ca96c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 2 Sep 2011 18:54:42 +0200 Subject: net.dns: Shorten AAAA records --- net/dns.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'net') diff --git a/net/dns.lua b/net/dns.lua index 3f1cb4f6..7bf5653b 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -395,7 +395,18 @@ function resolver:AAAA(rr) 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 -- cgit v1.2.3