aboutsummaryrefslogtreecommitdiffstats
path: root/util/ip.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2013-05-18 15:29:31 +0100
committerMatthew Wild <mwild1@gmail.com>2013-05-18 15:29:31 +0100
commitae3f10826d62c09f5ee5a7ac5be2a0746ae23c08 (patch)
treefda21a54555298a2369737f472bf288fcff6dce9 /util/ip.lua
parente3dd43d3a9975de0d8a5a211610af72926b2e5ca (diff)
parent7681e34f83898993205274a416718dc3db56333d (diff)
downloadprosody-ae3f10826d62c09f5ee5a7ac5be2a0746ae23c08.tar.gz
prosody-ae3f10826d62c09f5ee5a7ac5be2a0746ae23c08.zip
Merge
Diffstat (limited to 'util/ip.lua')
-rw-r--r--util/ip.lua7
1 files changed, 7 insertions, 0 deletions
diff --git a/util/ip.lua b/util/ip.lua
index 6ebc023b..20ea3dd7 100644
--- a/util/ip.lua
+++ b/util/ip.lua
@@ -23,6 +23,13 @@ local function new_ip(ipStr, proto)
elseif 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