end
local borderl = address:sub(1, 1) == ":" and 2 or 1
- local borderh, zeroh, chunk, block
+ local borderh, zeroh, chunk, block, i
if #address > 45 then return nil end
local len = __maxlen(family)
local tmp = ""
local data = { }
+ local i
for i = 1, (len/4) - #hex do tmp = tmp .. '0' end
-- @see cidr.equal
function cidr.lower( self, addr )
assert( self[1] == addr[1], "Can't compare IPv4 and IPv6 addresses" )
+ local i
for i = 1, #self[2] do
if self[2][i] ~= addr[2][i] then
return self[2][i] < addr[2][i]
-- @see cidr.equal
function cidr.higher( self, addr )
assert( self[1] == addr[1], "Can't compare IPv4 and IPv6 addresses" )
+ local i
for i = 1, #self[2] do
if self[2][i] ~= addr[2][i] then
return self[2][i] > addr[2][i]
-- @see cidr.higher
function cidr.equal( self, addr )
assert( self[1] == addr[1], "Can't compare IPv4 and IPv6 addresses" )
+ local i
for i = 1, #self[2] do
if self[2][i] ~= addr[2][i] then
return false
if not obj then return nil end
+ local _, word
for _, word in ipairs(obj[2]) do
if word == 0xFFFF then
prefix = prefix + 16
local data = { }
bits = bits or self[3]
+ local i
for i = 1, math.floor( bits / 16 ) do
data[#data+1] = self[2][i]
end
-- @return CIDR representing the new address or nil on overflow error
-- @see cidr.sub
function cidr.add( self, amount, inplace )
+ local pos
local data = { unpack(self[2]) }
local shorts = __array16( amount, self[1] )
-- @return CIDR representing the new address or nil on underflow error
-- @see cidr.add
function cidr.sub( self, amount, inplace )
+ local pos
local data = { unpack(self[2]) }
local shorts = __array16( amount, self[1] )
-- @see cidr.minhost
function cidr.maxhost( self )
if self[3] <= __sublen(self[1]) then
+ local i
local data = { unpack(self[2]) }
local offset = math.floor( self[3] / 16 ) + 1