Comparison

util/ip.lua @ 7061:eda0feeaf759

Merge 0.9->0.10
author Kim Alvefur <zash@zash.se>
date Fri, 08 Jan 2016 16:16:08 +0100
parent 6926:d96b2aa7a11d
parent 7055:23de70d19e77
child 7481:b3a864df32ef
comparison
equal deleted inserted replaced
7050:ae044691de0f 7061:eda0feeaf759
23 return nil, "invalid address"; 23 return nil, "invalid address";
24 end 24 end
25 elseif proto ~= "IPv4" and proto ~= "IPv6" then 25 elseif proto ~= "IPv4" and proto ~= "IPv6" then
26 return nil, "invalid protocol"; 26 return nil, "invalid protocol";
27 end 27 end
28 local zone;
29 if proto == "IPv6" and ipStr:find('%', 1, true) then
30 ipStr, zone = ipStr:match("^(.-)%%(.*)");
31 end
28 if proto == "IPv6" and ipStr:find('.', 1, true) then 32 if proto == "IPv6" and ipStr:find('.', 1, true) then
29 local changed; 33 local changed;
30 ipStr, changed = ipStr:gsub(":(%d+)%.(%d+)%.(%d+)%.(%d+)$", function(a,b,c,d) 34 ipStr, changed = ipStr:gsub(":(%d+)%.(%d+)%.(%d+)%.(%d+)$", function(a,b,c,d)
31 return (":%04X:%04X"):format(a*256+b,c*256+d); 35 return (":%04X:%04X"):format(a*256+b,c*256+d);
32 end); 36 end);
33 if changed ~= 1 then return nil, "invalid-address"; end 37 if changed ~= 1 then return nil, "invalid-address"; end
34 end 38 end
35 39
36 return setmetatable({ addr = ipStr, proto = proto }, ip_mt); 40 return setmetatable({ addr = ipStr, proto = proto, zone = zone }, ip_mt);
37 end 41 end
38 42
39 local function toBits(ip) 43 local function toBits(ip)
40 local result = ""; 44 local result = "";
41 local fields = {}; 45 local fields = {};