From 3fcb0706d6afd25c350662b1e248e301625a22db Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 1 Dec 2017 04:33:49 +0100 Subject: util.ip: Simplify creation of IPv6-mapped IPv4 addresses --- util/ip.lua | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'util/ip.lua') diff --git a/util/ip.lua b/util/ip.lua index 7c438593..7ccbf300 100644 --- a/util/ip.lua +++ b/util/ip.lua @@ -155,22 +155,9 @@ local function precedence(ip) end end -local function toV4mapped(ip) - local fields = {}; - local ret = "::ffff:"; - ip:gsub("([^.]*).?", function (c) fields[#fields + 1] = tonumber(c) end); - ret = ret .. ("%02x"):format(fields[1]); - ret = ret .. ("%02x"):format(fields[2]); - ret = ret .. ":" - ret = ret .. ("%02x"):format(fields[3]); - ret = ret .. ("%02x"):format(fields[4]); - return new_ip(ret, "IPv6"); -end - function ip_methods:toV4mapped() if self.proto ~= "IPv4" then return nil, "No IPv4 address" end - local value = toV4mapped(self.addr); - self.toV4mapped = value; + local value = new_ip("::ffff:" .. self.normal); return value; end -- cgit v1.2.3