Comparison

util/ip.lua @ 8441:e6e69be59233

util.ip: Do equality checking by comparing packed representation to avoid any variations
author Kim Alvefur <zash@zash.se>
date Fri, 01 Dec 2017 05:13:28 +0100
parent 8439:293dbb08427b
child 8468:5bfe58539b6c
comparison
equal deleted inserted replaced
8440:4e6710b4f873 8441:e6e69be59233
17 local ret = method(ip); 17 local ret = method(ip);
18 ip[key] = ret; 18 ip[key] = ret;
19 return ret; 19 return ret;
20 end, 20 end,
21 __tostring = function (ip) return ip.addr; end, 21 __tostring = function (ip) return ip.addr; end,
22 __eq = function (ipA, ipB) return ipA.addr == ipB.addr; end 22 __eq = function (ipA, ipB) return ipA.packed == ipB.packed; end
23 }; 23 };
24 24
25 local hex2bits = { 25 local hex2bits = {
26 ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011", 26 ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011",
27 ["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111", 27 ["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111",