From cef046ac2d04ef192203a2e7d3cce576beefd7cc Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Fri, 22 Feb 2019 15:37:13 +0200 Subject: model: fix netmasks with Lua 5.3 --- aconf/model/net.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'aconf/model/net.lua') diff --git a/aconf/model/net.lua b/aconf/model/net.lua index 57eb3ea..f01c4c6 100644 --- a/aconf/model/net.lua +++ b/aconf/model/net.lua @@ -1,5 +1,5 @@ --[[ -Copyright (c) 2012-2016 Kaarle Ritvanen +Copyright (c) 2012-2019 Kaarle Ritvanen See LICENSE file for license details --]] @@ -108,7 +108,7 @@ end function M.IPv4Address:mask2cidr(mask) local acc = 0 for i, comp in ipairs(stringy.split(mask, '.')) do - acc = acc + math.pow(256, 4 - i) * tonumber(comp) + acc = acc + math.floor(256 ^ (4 - i)) * tonumber(comp) end local res = 32 while acc % 2 == 0 do @@ -120,7 +120,7 @@ function M.IPv4Address:mask2cidr(mask) end function M.IPv4Address:cidr2mask(cidr) - local acc = (math.pow(2, cidr) - 1) * math.pow(2, 32 - cidr) + local acc = (math.floor(2 ^ cidr) - 1) * math.floor(2 ^ (32 - cidr)) local comps = {} for i = 4,1,-1 do comps[i] = acc % 256 -- cgit v1.2.3