Software /
code /
prosody
Changeset
8434:ec8f37baffaa
util.ip: Simplify creation of IPv6-mapped IPv4 addresses
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 01 Dec 2017 04:33:49 +0100 |
parents | 8433:ca7f8e60410a |
children | 8435:47195f035d2f |
files | util/ip.lua |
diffstat | 1 files changed, 1 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/util/ip.lua Fri Dec 01 04:33:27 2017 +0100 +++ b/util/ip.lua Fri Dec 01 04:33:49 2017 +0100 @@ -155,22 +155,9 @@ 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