Module:IP: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
6,269 bytes added ,  7 years ago
need to use __index to have a unique key which is really private - if outside code gets uniqueKey with getmetatable then they can set it in another table's __eq metamethod, thus foiling isSubnetObject
(Collection is good (I've always meant to fix it) but in case you don't have other plans, here is a change to make it work)
(need to use __index to have a unique key which is really private - if outside code gets uniqueKey with getmetatable then they can set it in another table's __eq metamethod, thus foiling isSubnetObject)
 
(33 intermediate revisions by 2 users not shown)
Line 3:
 
-- Load modules
require('Module:No globals')
local bit32 = require('bit32')
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local checkTypeMulti = libraryUtil.checkTypeMulti
local makeCheckSelfFunction = libraryUtil.makeCheckSelfFunction
 
-- Constants
Line 12 ⟶ 15:
 
--------------------------------------------------------------------------------
-- Helper functions
-- Collection class
-- A table to hold items. Used internally.
--------------------------------------------------------------------------------
 
local function makeValidationFunction(className, isObjectFunc)
local Collection
-- Make a function for validating a specific object.
do
return function (methodName, argIdx, arg)
local mt = {
if not isObjectFunc(arg) then
__index = {
error(string.format(
add = function (self, item)
"bad argument #%d to '%s' (not a valid %s object)",
self.n = self.n + 1
argIdx, methodName, className
self[self.n] = item
end), 3)
end
join = function (self, sep)
return table.concat(self, sep)
end,
}
}
Collection = function ()
return setmetatable({n = 0}, mt)
end
end
Line 45 ⟶ 41:
RawIP.__index = RawIP
 
do
function RawIP.newFromIPv4(ipStr)
-- Collection class.
-- If ipStr is a valid IPv4 string, return a collection of its parts.
-- This is a table used to hold items.
-- Otherwise, return nil.
local Collection
-- This representation is for compatibility with IPv6 addresses.
do
local octets = Collection()
local mt = {
local s = ipStr:match('^%s*(.-)%s*$') .. '.'
__index = {
for item in s:gmatch('(.-)%.') do
octets: add = function (self, item)
self.n = self.n + 1
self[self.n] = item
end,
join = function (self, sep)
return table.concat(self, sep)
end,
}
}
Collection = function ()
return setmetatable({n = 0}, mt)
end
end
 
if octets.n == 4 then
-- Constructors
for i, s in ipairs(octets) do
function RawIP.newFromIPv4(ipStr)
if s:match('^%d+$') then
-- Return a RawIP object if ipStr is a valid IPv4 string. Otherwise,
local num = tonumber(s)
-- return nil.
if 0 <= num and num <= 255 then
-- This representation is for compatibility with IPv6 addresses.
if num > 0 and s:match('^0') then
local octets = Collection()
-- A redundant leading zero is for an IP in octal.
local s = ipStr:match('^%s*(.-)%s*$') .. '.'
return false
for item in s:gmatch('(.-)%.') do
octets:add(item)
end
if octets.n == 4 then
for i, s in ipairs(octets) do
if s:match('^%d+$') then
local num = tonumber(s)
if 0 <= num and num <= 255 then
if num > 0 and s:match('^0') then
-- A redundant leading zero is for an IP in octal.
return nil
end
octets[i] = num
else
return nil
end
octets[i] = num
else
return falsenil
end
else
return false
end
local parts = Collection()
for i = 1, 3, 2 do
parts:add(octets[i] * 256 + octets[i+1])
end
return setmetatable(parts, RawIP)
end
return nil
end
 
function RawIP.newFromIPv6(ipStr)
-- Return a RawIP object if ipStr is a valid IPv6 string. Otherwise,
-- return nil.
ipStr = ipStr:match('^%s*(.-)%s*$')
local _, n = ipStr:gsub(':', ':')
if n < 7 then
ipStr, n = ipStr:gsub('::', string.rep(':', 9 - n))
end
local parts = Collection()
for iitem =in 1,(ipStr 3,.. 2':'):gmatch('(.-):') do
parts:add(octets[i] * 256 + octets[i+1]item)
end
returnif setmetatable(parts,.n RawIP)== 8 then
for i, s in ipairs(parts) do
if s == '' then
parts[i] = 0
else
local num = tonumber(s, 16)
if num and 0 <= num and num <= 65535 then
parts[i] = num
else
return nil
end
end
end
return setmetatable(parts, RawIP)
end
return nil
end
return nil
end
 
function RawIP.newFromIPv6newFromIP(ipStr)
-- Return a new RawIP object from either an IPv4 string or an IPv6
-- If ipStr is a valid IPv6 string, return a collection of its parts.
-- string. If ipStr is not a valid IPv4 or IPv6 string, then return
-- Otherwise, return nil.
-- nil.
ipStr = ipStr:match('^%s*(.-)%s*$')
return RawIP.newFromIPv4(ipStr) or RawIP.newFromIPv6(ipStr)
local _, n = ipStr:gsub(':', ':')
if n < 7 then
ipStr, n = ipStr:gsub('::', string.rep(':', 9 - n))
end
 
local parts = Collection()
-- Methods
for item in (ipStr .. ':'):gmatch('(.-):') do
function RawIP:getVersion()
parts:add(item)
-- Return a string with the version of the IP protocol we are using.
return self.n == 2 and V4 or V6
end
 
if parts.n == 8 then
function RawIP:isIPv4()
for i, s in ipairs(parts) do
-- Return true if this is an IPv4 representation, and false otherwise.
if s == '' then
parts[i]return self.n == 02
end
 
function RawIP:isIPv6()
-- Return true if this is an IPv6 representation, and false otherwise.
return self.n == 8
end
 
function RawIP:getAdjacent(previous)
-- Return a RawIP object for an adjacent IP address. If previous is true
-- then the previous IP is returned; otherwise the next IP is returned.
-- Will wraparound:
-- next 255.255.255.255 → 0.0.0.0
-- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff → ::
-- previous 0.0.0.0 → 255.255.255.255
-- :: → ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
local result = Collection()
result.n = self.n
local carry = previous and 0xffff or 1
for i = self.n, 1, -1 do
local sum = self[i] + carry
if sum >= 0x10000 then
carry = previous and 0x10000 or 1
sum = sum - 0x10000
else
local numcarry = tonumber('0x'previous and 0xffff ..or s)0
end
if num and 0 <= num and num <= 65535 then
partsresult[i] = numsum
end
return setmetatable(result, RawIP)
end
 
function RawIP:getPrefix(bitLength)
-- Return a RawIP object for the prefix of the current IP Address with a
-- bit length of bitLength.
local result = Collection()
result.n = self.n
for i = 1, self.n do
if bitLength > 0 then
if bitLength >= 16 then
result[i] = self[i]
bitLength = bitLength - 16
else
result[i] = bit32.replace(self[i], 0, 0, 16 - bitLength)
return false
bitLength = 0
end
else
result[i] = 0
end
end
return setmetatable(partsresult, RawIP)
end
return nil
end
 
function RawIP:copyChangedgetHighestHost(downbitLength)
-- Return a copyRawIP ofobject IPv4for orthe IPv6highest parts,IP incrementedwith orthe prefix of decremented.length
-- bitLength. In other words, the network (the most-significant bits)
-- Will wraparound:
-- is the same as the current IP's, but the host bits (the
-- increment 255.255.255.255 → 0.0.0.0
-- least-significant bits) are all set to 1.
-- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff → ::
local bits = self.n * 16
-- decrement 0.0.0.0 → 255.255.255.255
local width
-- :: → ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
if bitLength <= 0 then
local result = Collection()
width = bits
result.n = self.n
elseif bitLength >= bits then
local carry = down and 0xffff or 1
width = 0
for i = self.n, 1, -1 do
local sum = self[i] + carry
if sum >= 0x10000 then
carry = down and 0x10000 or 1
sum = sum - 0x10000
else
carrywidth = downbits and- 0xffff or 0bitLength
end
local result[i] = sumCollection()
result.n = self.n
for i = self.n, 1, -1 do
if width > 0 then
if width >= 16 then
result[i] = 0xffff
width = width - 16
else
result[i] = bit32.replace(self[i], 0xffff, 0, width)
width = 0
end
else
result[i] = self[i]
end
end
return setmetatable(result, RawIP)
end
return setmetatable(result, RawIP)
end
 
function RawIP:copyPrefix_makeIPv6String(length)
-- Return aan copyIPv6 ofstring IPv4representation orof IPv6the parts,object. maskedBehavior to length.is
-- undefined if the current object is IPv4.
local result = Collection()
local z1, z2 -- indices of run of zeros to be displayed as "::"
result.n = self.n
local zstart, zcount
for i = 1, self.n do
iffor lengthi >= 01, then9 do
-- Find left-most occurrence of longest run of two or more zeros.
if length >= 16 then
result[if i] =< 9 and self[i] == 0 then
lengthif =zstart length - 16then
zcount = zcount + 1
else
zstart = i
zcount = 1
end
else
if zcount and zcount > 1 then
result[i] = bit32.band(self[i],
if not z1 or zcount > z2 - z1 + 1 then
bit32.arshift(0xffff8000, length - 1))
length z1 = 0zstart
z2 = zstart + zcount - 1
end
end
zstart = nil
zcount = nil
end
else
result[i] = 0
end
local parts = Collection()
for i = 1, 8 do
if z1 and z1 <= i and i <= z2 then
if i == z1 then
if z1 == 1 or z2 == 8 then
if z1 == 1 and z2 == 8 then
return '::'
end
parts:add(':')
else
parts:add('')
end
end
else
parts:add(string.format('%x', self[i]))
end
end
return parts:join(':')
end
return setmetatable(result, RawIP)
end
 
function RawIP:setHostBits_makeIPv4String(length)
-- Return a copy ofan IPv4 orstring IPv6representation parts, withof the least-significantobject. Behavior bitsis
-- undefined if the current object is IPv6.
-- (host bits) set to 1.
local parts = Collection()
-- The most-significant length bits identify the network.
local for bitsi = self.n1, *2 16do
local widthw = self[i]
parts:add(math.floor(w / 256))
if length <= 0 then
parts:add(w % 256)
width = bits
end
elseif length >= bits then
return parts:join('.')
width = 0
else
width = bits - length
end
 
local result = Collection()
function RawIP:__tostring()
result.n = self.n
-- Return a string equivalent to given IP address (IPv4 or IPv6).
for i = self.n, 1, -1 do
if widthself.n >== 02 then
return self:_makeIPv4String()
if width >= 16 then
result[i] = 0xffff
width = width - 16
else
result[i] = bit32.replace(self[i], 0xffff, width - 1, width)
width = 0
end
else
result[i] =return self[i]:_makeIPv6String()
end
end
return setmetatable(result, rawIP)
end
 
function RawIP:_makeIPv6String__lt(obj)
if self.n == obj.n then
-- Return an IPv6 string representation of the object. Behavior is undefined
for i = 1, self.n do
-- if the current object is IPv4.
if self[i] ~= obj[i] then
local z1, z2 -- indices of run of zeros to be displayed as "::"
return self[i] < obj[i]
local zstart, zcount
for i = 1, 9 do
-- Find left-most occurrence of longest run of two or more zeros.
if i < 9 and self[i] == 0 then
if zstart then
zcount = zcount + 1
else
zstart = i
zcount = 1
end
else
if zcount and zcount > 1 then
if not z1 or zcount > z2 - z1 + 1 then
z1 = zstart
z2 = zstart + zcount - 1
end
end
zstartreturn = nilfalse
zcount = nil
end
return self.n < obj.n
end
 
local parts = Collection()
function RawIP:__eq(obj)
for i = 1, 8 do
if z1self.n and z1 <= i and i <= z2obj.n then
iffor i == z11, self.n thendo
if z1self[i] == 1 or z2 =~= 8obj[i] then
return false
if z1 == 1 and z2 == 8 then
return '::'
end
parts:add(':')
else
parts:add('')
end
end
return true
else
parts:add(string.format('%x', self[i]))
end
return false
end
return parts:join(':')
end
 
--------------------------------------------------------------------------------
function RawIP:_makeIPv4String()
-- Initialize private methods available to IPAddress and Subnet
-- Return an IPv4 string representation of the object. Behavior is undefined
--------------------------------------------------------------------------------
-- if the current object is IPv6.
local parts = Collection()
for i = 1, 2 do
local w = self[i]
parts:add(math.floor(w / 256))
parts:add(w % 256)
end
return parts:join('.')
end
 
-- Both IPAddress and Subnet need access to each others' private constructor
function RawIP:__tostring()
-- functions. IPAddress must be able to make Subnet objects from CIDR strings
-- Return a string equivalent to given IP address (IPv4 or IPv6).
-- and from RawIP objects, and Subnet must be able to make IPAddress objects
if self.n == 2 then
-- from IP strings and from RawIP objects. These constructors must all be
return self:_makeIPv4String()
-- private to ensure correct error levels and to stop other modules from having
else
-- to worry about RawIP objects. Because they are private, they must be
return self:_makeIPv6String()
-- initialized here.
end
local makeIPAddress, makeIPAddressFromRaw, makeSubnet, makeSubnetFromRaw
end
 
-- IPAddress and Subnet also need to be able to validate Subnet and IPAddress
-- objects that they are passed as input, so initialize those functions here
-- as well.
local validateIPAddress, validateSubnet
 
--------------------------------------------------------------------------------
Line 257 ⟶ 343:
 
local IPAddress = {}
 
-- newIPFromParts constructs a new IPAddress object from its parts. It needs to
-- be accessible from the Subnet object but it should not be public.
local newIPFromParts
 
do
local-- dataKey =is {} -- Aa unique key to access objects' internal data. This is needed
-- to access the RawIP objects contained in other IPAddress objects so that
-- they can be compared with the current object's RawIP object. This data
-- is not available to other classes or other modules.
local dataKey = {}
 
-- Private static methods
local function isIPAddressObject(val)
return type(val) == 'table' and val[dataKey] ~= nil
end
 
validateIPAddress = makeValidationFunction('IPAddress', isIPAddressObject)
 
-- Metamethods that don't need upvalues
local function ipEquals(ip1, ip2)
localreturn lhsip1[dataKey].rawIP == ip1ip2[dataKey].partsrawIP
local rhs = ip2[dataKey].parts
if lhs.n == rhs.n then
for i = 1, lhs.n do
if lhs[i] ~= rhs[i] then
return false
end
end
return true
end
return false
end
 
local function ipLessThan(ip1, ip2)
localreturn lhsip1[dataKey].rawIP =< ip1ip2[dataKey].partsrawIP
local rhs = ip2[dataKey].parts
if lhs.n == rhs.n then
for i = 1, lhs.n do
if lhs[i] ~= rhs[i] then
return lhs[i] < rhs[i]
end
end
return false
end
return lhs.n < rhs.n
end
 
local function concatIPsconcatIP(ip1ip, ip2val)
return tostring(ip1ip) .. tostring(ip2val)
end
 
local function ipToString(ip)
return ipString(ip[dataKey].parts:getIP()
end
 
-- Constructors
newIPFromPartsmakeIPAddressFromRaw = function (partsrawIP)
-- Constructs a new IPAddress object from itsa partsrawIP object. This function is
-- is for internal use; it is called by IPAddress.new and canfrom be calledother
-- fromIPAddress the Subnet classmethods, butand itshould is notbe available to otherthe modules.Subnet class, but
-- should not be available to other modules.
assert(type(parts) == 'table', 'parts was type ' .. type(parts) .. '; expected type table')
assert(type(rawIP) == 'table', 'rawIP was type ' .. type(rawIP) .. '; expected type table')
 
-- Set up structure
local obj = {}
local data = {}
partsdata.rawIP = parts,rawIP
 
version = parts.n == 2 and V4 or V6,
-- A function to check whether methods are called with a valid self
}
-- parameter.
local checkSelf = makeCheckSelfFunction(
'IP',
'ipAddress',
obj,
'IPAddress object'
)
 
-- Public methods
function obj:getIP()
checkSelf(self, 'getIP')
return ipString(data.parts)
return tostring(data.rawIP)
end
 
function obj:getVersion()
checkSelf(self, 'getVersion')
return data.version
return data.rawIP:getVersion()
end
 
function obj:getHighestIP(bitLength)
return newIPFromParts(setHostBits(data.parts, bitLength))
end
 
function obj:getPrefix(bitLength)
return newIPFromParts(copyPrefix(data.parts, bitLength))
end
 
function obj:isIPv4()
checkSelf(self, 'isIPv4')
return data.version == V4
return data.rawIP:isIPv4()
end
 
function obj:isIPv6()
checkSelf(self, 'isIPv6')
return data.version == V6
return data.rawIP:isIPv6()
end
 
function obj:isInSubnet(subnet)
checkSelf(self, 'isInSubnet')
-- TODO Consider alternative of checking:
local tp = type(subnet)
-- (ipFirst <= self and self <= ipLast)
if self:getVersion()tp == subnet:getVersion()'string' then
local prefixsubnet = self:getPrefixmakeSubnet(subnet:getBitLength())
returnelseif prefixtp == subnet:getPrefix()'table' then
validateSubnet('isInSubnet', 1, subnet)
else
checkTypeMulti('isInSubnet', 1, subnet, {'string', 'table'})
end
return falsesubnet:containsIP(self)
end
 
function obj:getSubnet(bitLength)
checkSelf(self, 'getSubnet')
checkType('getSubnet', 1, bitLength, 'number')
return makeSubnetFromRaw(data.rawIP, bitLength)
end
 
function obj:getNextIP()
checkSelf(self, 'getNextIP')
return newIPFromParts(copyChanged(data.parts))
return makeIPAddressFromRaw(data.rawIP:getAdjacent())
end
 
function obj:getPreviousIP()
checkSelf(self, 'getPreviousIP')
return newIPFromParts(copyChanged(data.parts, true))
return makeIPAddressFromRaw(data.rawIP:getAdjacent(true))
end
 
Line 363 ⟶ 451:
__eq = ipEquals,
__lt = ipLessThan,
__concat = concatIPsconcatIP,
__tostring = ipToString,
__index = function (self, key)
-- If any code knows the unique data key, allow it to access
-- the data table.
if key == dataKey then
return data
end
end,
__metatable = false, -- Don't allow access to the metatable
})
end
 
makeIPAddress = function IPAddress.new(ip)
local rawIP = RawIP.newFromIP(ip)
checkType('IPAddress.new', 1, ip, 'string')
if not rawIP then
local parts = parseIPv4(ip) or parseIPv6(ip)
error(string.format("'%s' is an invalid IP address", ip), 3)
if not parts then
error('invalid IP', 2)
end
return newIPFromPartsmakeIPAddressFromRaw(partsrawIP)
end
end
 
local function makeSubnetIPAddress.new(data, cidrStrip)
checkType('IPAddress.new', 1, ip, 'string')
-- If cidrStr is a valid IPv4 or IPv6 CIDR specification, store its
return makeIPAddress(ip)
-- information in data and return its version. Otherwise, return nil.
local lhs, rhs = cidrStr:match('^%s*(.-)/(%d+)%s*$')
if lhs then
local bits = lhs:find(':', 1, true) and 128 or 32
local n = tonumber(rhs)
if n and n <= bits then
local base = IPAddress.new(lhs)
local prefix = base:getPrefix(n)
if base == prefix then
data.bitLength = n
data.prefix = prefix
data.highestIP = base:getHighestIP(n)
return bits == 32 and V4 or V6
end
end
end
return nil
end
 
Line 412 ⟶ 486:
 
do
-- uniqueKey is a unique, private key used to test whether a given object
-- Initialize metatable
-- is a Subnet object.
local mt = {}
local uniqueKey = setmetatable({}, {__metatable = false})
 
-- Private static methods
-- Constructor
local function Subnet.newisSubnetObject(cidrval)
-- Return true if val is a Subnet object, and false otherwise.
return getmetatable(val) == uniqueKey
end
 
-- Function to validate subnet objects.
-- Params:
-- methodName (string) - the name of the method being validated
-- argIdx (number) - the position of the argument in the argument list
-- arg - the argument to be validated
validateSubnet = makeValidationFunction('Subnet', isSubnetObject)
 
-- Metamethods that don't need upvalues
local function subnetEquals(subnet1, subnet2)
return subnet1:getCIDR() == subnet2:getCIDR()
end
 
local function concatenateSubnets(subnet1, subnet2)
return tostring(subnet1) .. tostring(subnet2)
end
 
local function subnetToString(subnet)
return subnet:getCIDR()
end
 
-- Constructors
makeSubnetFromRaw = function (rawIP, bitLength)
-- Set up structure
local obj = setmetatable({}, mt)
local data = {}
rawIP = rawIP,
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(
data.rawIP:getPrefix(data.bitLength)
)
end
return data.prefix
end
 
function obj:getHighestIP()
checkSelf(self, 'getHighestIP')
if not data.highestIP then
data.highestIP = makeIPAddressFromRaw(
data.rawIP:getHighestHost(data.bitLength)
)
end
return data.highestIP
end
 
function obj:getBitLength()
checkSelf(self, 'getBitLength')
return data.bitLength
end
 
function obj:getCIDR()
checkSelf(self, 'getCIDR')
return string.format('%s/%d', self:getPrefix(), self:getBitLength())
return string.format(
'%s/%d',
tostring(self:getPrefix()), self:getBitLength()
)
end
 
function obj:getVersion()
checkSelf(self, 'getVersion')
return data.version
return data.rawIP:getVersion()
end
 
function obj:isIPv4()
checkSelf(self, 'isIPv4')
return data.version == V4
return data.rawIP:isIPv4()
end
 
function obj:isIPv6()
checkSelf(self, 'isIPv6')
return data.version == V6
return data.rawIP:isIPv6()
end
 
function obj:containsIP(ip)
checkSelf(self, 'containsIP')
-- TODO See ip:isInSubnet(subnet); use this technique there?
local tp = type(ip)
if tp == 'string' then
ip = makeIPAddress(ip)
elseif tp == 'table' then
validateIPAddress('containsIP', 1, ip)
else
checkTypeMulti('containsIP', 1, ip, {'string', 'table'})
end
if self:getVersion() == ip:getVersion() then
return self:getPrefix() <= ip and ip <= self:getHighestIP()
Line 459 ⟶ 600:
 
function obj:overlapsSubnet(subnet)
checkSelf(self, 'overlapsSubnet')
local tp = type(subnet)
if tp == 'string' then
subnet = makeSubnet(subnet)
elseif tp == 'table' then
validateSubnet('overlapsSubnet', 1, subnet)
else
checkTypeMulti('overlapsSubnet', 1, subnet, {'string', 'table'})
end
if self:getVersion() == subnet:getVersion() then
return (
Line 468 ⟶ 618:
end
 
function obj:walk()
-- Set initial values
checkSelf(self, 'walk')
checkType('Subnet.new', 1, cidr, 'string')
local started
data.version = makeSubnet(data, cidr)
local current = self:getPrefix()
if not data.version then
local highest = self:getHighestIP()
error('invalid CIDR', 2)
return function ()
if not started then
started = true
return current
end
if current < highest then
current = current:getNextIP()
return current
end
end
end
 
return setmetatable(obj, {
__index = function (self, key)
if key == uniqueKey then
return true
end
end,
__eq = subnetEquals,
__concat = concatenateSubnets,
__tostring = subnetToString,
__metatable = false,
})
end
 
makeSubnet = function (cidr)
-- Metamethods
-- Return a Subnet object from a CIDR string. If the CIDR string is
function mt:__eq(obj)
-- invalid, throw an error.
return self:getCIDR() == obj:getCIDR()
local lhs, rhs = cidr:match('^%s*(.-)/(%d+)%s*$')
if lhs then
local bits = lhs:find(':', 1, true) and 128 or 32
local n = tonumber(rhs)
if n and n <= bits and (n == 0 or not rhs:find('^0')) then
-- The right-hand side is a number between 0 and 32 (for IPv4)
-- or 0 and 128 (for IPv6) and doesn't have any leading zeroes.
local base = RawIP.newFromIP(lhs)
if base then
-- The left-hand side is a valid IP address.
local prefix = base:getPrefix(n)
if base == prefix then
-- The left-hand side is the lowest IP in the subnet.
return makeSubnetFromRaw(prefix, n)
end
end
end
end
error(string.format("'%s' is an invalid CIDR string", cidr), 3)
end
 
function mt:__tostringSubnet.new(cidr)
checkType('Subnet.new', 1, cidr, 'string')
return self:getCIDR()
return makeSubnet(cidr)
end
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu