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 | 17c863797d0e99aaad95799659687dba2ecf51c2 (patch) | |
tree | 2cfd45cb6375a40a24e8e4e722d5ef398e916f1b | |
parent | b4dbdbc6e75d3ebafdb542fc803c000b514d180d (diff) | |
download | prosody-17c863797d0e99aaad95799659687dba2ecf51c2.tar.gz prosody-17c863797d0e99aaad95799659687dba2ecf51c2.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 |