Merge 0.9->trunk
[prosody.git] / util / ip.lua
index 6ebc023bae92fca058691f060c3ca316644ac04f..20ea3dd70594e4914116e15e1e8424b5bbd7a96d 100644 (file)
@@ -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