diff util/ip.lua @ 5602:e8a0e545ee05

Merge
author Matthew Wild <mwild1@gmail.com>
date Sat, 18 May 2013 15:29:31 +0100
parents 34e9f237b915
children e07f4f02e4f9
line wrap: on
line diff
--- a/util/ip.lua	Sat May 18 15:29:10 2013 +0100
+++ b/util/ip.lua	Sat May 18 15:29:31 2013 +0100
@@ -23,6 +23,13 @@
 	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