Module:IP: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
add check self functions to Subnet
(use libraryUtil for the checkSelf function)
(add check self functions to Subnet)
Line 522:
bitLength = bitLength,
}
 
-- A function to check whether methods are called with a valid self
-- parameter.
local checkSelf = makeCheckSelfFunction(
'IP',
'subnet',
obj,
'Subnet object'
)
 
-- Public methods
function obj:getPrefix()
checkSelf(self, 'getPrefix')
if not data.prefix then
data.prefix = makeIPAddressFromRaw(
Line 534 ⟶ 544:
 
function obj:getHighestIP()
checkSelf(self, 'getHighestIP')
if not data.highestIP then
data.highestIP = makeIPAddressFromRaw(
Line 543 ⟶ 554:
 
function obj:getBitLength()
checkSelf(self, 'getBitLength')
return data.bitLength
end
 
function obj:getCIDR()
checkSelf(self, 'getCIDR')
return string.format(
'%s/%d',
Line 554 ⟶ 567:
 
function obj:getVersion()
checkSelf(self, 'getVersion')
return data.rawIP:getVersion()
end
 
function obj:isIPv4()
checkSelf(self, 'isIPv4')
return data.rawIP:isIPv4()
end
 
function obj:isIPv6()
checkSelf(self, 'isIPv6')
return data.rawIP:isIPv6()
end
 
function obj:containsIP(ip)
checkSelf(self, 'containsIP')
if self:getVersion() == ip:getVersion() then
return self:getPrefix() <= ip and ip <= self:getHighestIP()
Line 573 ⟶ 590:
 
function obj:overlapsSubnet(subnet)
checkSelf(self, 'overlapsSubnet')
if self:getVersion() == subnet:getVersion() then
return (
Line 583 ⟶ 601:
 
function obj:walk()
checkSelf(self, 'walk')
local started
local current = self:getPrefix()
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu