diff options
author | Kim Alvefur <zash@zash.se> | 2017-12-01 04:33:49 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2017-12-01 04:33:49 +0100 |
commit | 3fcb0706d6afd25c350662b1e248e301625a22db (patch) | |
tree | e6ac8de6de746d0202ad9abccdd48af5504c4a5a | |
parent | b8212a93db0341869f127ee43150650d6b9c8bac (diff) | |
download | prosody-3fcb0706d6afd25c350662b1e248e301625a22db.tar.gz prosody-3fcb0706d6afd25c350662b1e248e301625a22db.zip |
util.ip: Simplify creation of IPv6-mapped IPv4 addresses
-rw-r--r-- | util/ip.lua | 15 |
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 |