diff options
author | Kim Alvefur <zash@zash.se> | 2011-09-02 18:54:42 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2011-09-02 18:54:42 +0200 |
commit | 2865b80ebdac7343fac499a978a32863a02ca96c (patch) | |
tree | 2cfd45cb6375a40a24e8e4e722d5ef398e916f1b | |
parent | 3ecd52430f326023cbf4bfd3dfc8d8ab24efa9e4 (diff) | |
download | prosody-2865b80ebdac7343fac499a978a32863a02ca96c.tar.gz prosody-2865b80ebdac7343fac499a978a32863a02ca96c.zip |
net.dns: Shorten AAAA records
-rw-r--r-- | net/dns.lua | 13 |
1 files changed, 12 insertions, 1 deletions
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 |