util.ip: remove unused one-letter loop variables [luacheck]
[prosody.git] / util / ip.lua
index 7dcace5cac35d8ec271a4fd2328ce58b7e020fcc..1f32d1b50e8d532697d05e9bcfca5a84dd7a05b8 100644 (file)
@@ -25,6 +25,10 @@ local function new_ip(ipStr, proto)
        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 @@ local function new_ip(ipStr, proto)
                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)
@@ -47,11 +51,11 @@ local function toBits(ip)
        if not ip:match(":$") then fields[#fields] = nil; end
        for i, field in ipairs(fields) do
                if field:len() == 0 and i ~= 1 and i ~= #fields then
-                       for i = 1, 16 * (9 - #fields) do
+                       for _ = 1, 16 * (9 - #fields) do
                                result = result .. "0";
                        end
                else
-                       for i = 1, 4 - field:len() do
+                       for _ = 1, 4 - field:len() do
                                result = result .. "0000";
                        end
                        for i = 1, field:len() do