Software /
code /
prosody
Changeset
4373:9a20acf315c9
net.dns: Shorten AAAA records
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 02 Sep 2011 18:54:42 +0200 |
parents | 4372:052aeb22c645 |
children | 4374:c38f20f172b3 |
files | net/dns.lua |
diffstat | 1 files changed, 12 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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