# HG changeset patch # User Kim Alvefur # Date 1511938934 -3600 # Node ID 1371518f70ffac3711ed58ea6abb824a98bdf67e # Parent 8b612ec00e4a7d977c3140335700d28fe90392ba net.dns: Use inet_ntop from util.net if available diff -r 8b612ec00e4a -r 1371518f70ff net/dns.lua --- a/net/dns.lua Sun Nov 26 02:26:13 2017 +0100 +++ b/net/dns.lua Wed Nov 29 08:02:14 2017 +0100 @@ -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 @@ 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 @@ 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