aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2013-05-18 13:14:19 +0200
committerKim Alvefur <zash@zash.se>2013-05-18 13:14:19 +0200
commitf57e2f727b11185ee19f854f378a51c6efa114d7 (patch)
tree3df69a5e48a60a2599eb80bedd528ae0ee621257 /util
parent191e1f2b0f4102e3062a2e9267e8f5cd7db32b07 (diff)
downloadprosody-f57e2f727b11185ee19f854f378a51c6efa114d7.tar.gz
prosody-f57e2f727b11185ee19f854f378a51c6efa114d7.zip
util.ip: Convert IPv4 mapped addresses to hex.
Diffstat (limited to 'util')
-rw-r--r--util/ip.lua7
1 files changed, 7 insertions, 0 deletions
diff --git a/util/ip.lua b/util/ip.lua
index de287b16..856bf034 100644
--- a/util/ip.lua
+++ b/util/ip.lua
@@ -15,6 +15,13 @@ local function new_ip(ipStr, proto)
if proto ~= "IPv4" and proto ~= "IPv6" then
return nil, "invalid protocol";
end
+ if proto == "IPv6" and ipStr:find('.', 1, true) then
+ local changed;
+ ipStr, changed = ipStr:gsub(":(%d+)%.(%d+)%.(%d+)%.(%d+)$", function(a,b,c,d)
+ return (":%04X:%04X"):format(a*256+b,c*256+d);
+ end);
+ if changed ~= 1 then return nil, "invalid-address"; end
+ end
return setmetatable({ addr = ipStr, proto = proto }, ip_mt);
end