util/ip.lua
changeset 5597 6fe09707c73b
parent 5552 40e7a6cf15ff
child 5599 34e9f237b915
child 7055 306aabf2d57d
--- a/util/ip.lua	Sat May 18 13:11:44 2013 +0200
+++ b/util/ip.lua	Sat May 18 13:14:19 2013 +0200
@@ -15,6 +15,13 @@
 	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