aboutsummaryrefslogtreecommitdiffstats
path: root/util/ip.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-12-01 04:33:49 +0100
committerKim Alvefur <zash@zash.se>2017-12-01 04:33:49 +0100
commit405739ef2fa69475e6e961cb1a437c7fb5b7b0b9 (patch)
treee6ac8de6de746d0202ad9abccdd48af5504c4a5a /util/ip.lua
parent84da11d50e5627c84b5b85f262530d80bf107685 (diff)
downloadprosody-405739ef2fa69475e6e961cb1a437c7fb5b7b0b9.tar.gz
prosody-405739ef2fa69475e6e961cb1a437c7fb5b7b0b9.zip
util.ip: Simplify creation of IPv6-mapped IPv4 addresses
Diffstat (limited to 'util/ip.lua')
-rw-r--r--util/ip.lua15
1 files changed, 1 insertions, 14 deletions
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