aboutsummaryrefslogtreecommitdiffstats
path: root/net/dns.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-11-29 08:02:14 +0100
committerKim Alvefur <zash@zash.se>2017-11-29 08:02:14 +0100
commitc8323e953da67ee363bc6eac02a5be49239db97f (patch)
treea45a85d8732730309ea872dc9d01538b3f67dcfe /net/dns.lua
parent4816e879f813575818814f4fd785e9fb50567923 (diff)
downloadprosody-c8323e953da67ee363bc6eac02a5be49239db97f.tar.gz
prosody-c8323e953da67ee363bc6eac02a5be49239db97f.zip
net.dns: Use inet_ntop from util.net if available
Diffstat (limited to 'net/dns.lua')
-rw-r--r--net/dns.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/net/dns.lua b/net/dns.lua
index 5ba3db0e..fa570af1 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -15,6 +15,7 @@
local socket = require "socket";
local timer = require "util.timer";
local new_ip = require "util.ip".new_ip;
+local have_util_net, util_net = pcall(require, "util.net");
local _, windows = pcall(require, "util.windows");
local is_windows = (_ and windows) or os.getenv("WINDIR");
@@ -382,6 +383,12 @@ function resolver:A(rr) -- - - - - - - - - - - - - - - - - - - - - - - - A
rr.a = string.format('%i.%i.%i.%i', b1, b2, b3, b4);
end
+if have_util_net and util_net.ntop then
+ function resolver:A(rr)
+ rr.a = util_net.ntop(self:sub(4));
+ end
+end
+
function resolver:AAAA(rr)
local addr = {};
for _ = 1, rr.rdlength, 2 do
@@ -402,6 +409,12 @@ function resolver:AAAA(rr)
rr.aaaa = addr:gsub(zeros[1], "::", 1):gsub("^0::", "::"):gsub("::0$", "::");
end
+if have_util_net and util_net.ntop then
+ function resolver:AAAA(rr)
+ rr.aaaa = util_net.ntop(self:sub(16));
+ end
+end
+
function resolver:CNAME(rr) -- - - - - - - - - - - - - - - - - - - - CNAME
rr.cname = self:name();
end