Changeset

7055:23de70d19e77

util.ip: Support zone id syntax in IPv6 addresses
author Kim Alvefur <zash@zash.se>
date Mon, 04 Jan 2016 17:47:40 +0100
parents 7054:94d5e2f33a10
children 7056:7b0651e4534f
files util/ip.lua
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/util/ip.lua	Tue Jun 18 23:02:20 2013 +0200
+++ b/util/ip.lua	Mon Jan 04 17:47:40 2016 +0100
@@ -25,6 +25,10 @@
 	elseif proto ~= "IPv4" and proto ~= "IPv6" then
 		return nil, "invalid protocol";
 	end
+	local zone;
+	if proto == "IPv6" and ipStr:find('%', 1, true) then
+		ipStr, zone = ipStr:match("^(.-)%%(.*)");
+	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)
@@ -33,7 +37,7 @@
 		if changed ~= 1 then return nil, "invalid-address"; end
 	end
 
-	return setmetatable({ addr = ipStr, proto = proto }, ip_mt);
+	return setmetatable({ addr = ipStr, proto = proto, zone = zone }, ip_mt);
 end
 
 local function toBits(ip)