Changeset

12289:3a655adf1d0d

util.dns: Remove compat for pre-0.11 lack of inet_ntop binding The inet_ntop binding was added in 8b612ec00e4a and included in 0.11.0
author Kim Alvefur <zash@zash.se>
date Tue, 15 Feb 2022 13:04:24 +0100
parents 12288:08a933450922
children 12290:aa7a8aa64d3f
files util/dns.lua
diffstat 1 files changed, 3 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/util/dns.lua	Tue Feb 15 13:03:02 2022 +0100
+++ b/util/dns.lua	Tue Feb 15 13:04:24 2022 +0100
@@ -10,19 +10,11 @@
 local t_insert = table.insert;
 local s_byte = string.byte;
 local s_format = string.format;
-local s_gsub = string.gsub;
 local s_sub = string.sub;
-local s_match = string.match;
-local s_gmatch = string.gmatch;
-
-local have_net, net_util = pcall(require, "util.net");
 
 local iana_data = require "util.dnsregistry";
-if have_net and not net_util.ntop then -- Added in Prosody 0.11
-	have_net = false;
-end
-
 local tohex = require "util.hex".to;
+local inet_ntop = require "util.net".ntop;
 
 -- Simplified versions of Waqas DNS parsers
 -- Only the per RR parsers are needed and only feed a single RR
@@ -78,29 +70,8 @@
 	}, soa_mt);
 end
 
-function parsers.A(packet)
-	return s_format("%d.%d.%d.%d", s_byte(packet, 1, 4));
-end
-
-local aaaa = { nil, nil, nil, nil, nil, nil, nil, nil, };
-function parsers.AAAA(packet)
-	local hi, lo, ip, len, token;
-	for i = 1, 8 do
-		hi, lo = s_byte(packet, i * 2 - 1, i * 2);
-		aaaa[i] = s_format("%x", hi * 256 + lo); -- skips leading zeros
-	end
-	ip = t_concat(aaaa, ":", 1, 8);
-	len = (s_match(ip, "^0:[0:]+()") or 1) - 1;
-	for s in s_gmatch(ip, ":0:[0:]+") do
-		if len < #s then len, token = #s, s; end -- find longest sequence of zeros
-	end
-	return (s_gsub(ip, token or "^0:[0:]+", "::", 1));
-end
-
-if have_net then
-	parsers.A = net_util.ntop;
-	parsers.AAAA = net_util.ntop;
-end
+parsers.A = inet_ntop;
+parsers.AAAA = inet_ntop;
 
 local mx_mt = {
 	__tostring = function(rr)