Module:IP: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
m
comment and variable tweaks
(some more style changes (it's still broken but I'll fix it later; also, sorry for the edit conflict))
m (comment and variable tweaks)
Line 108:
return nil
end
 
-- Methods
function RawIP:getAdjacent(previous)
-- Return a RawIP object for an adjacent IP address. If previous is true
Line 133 ⟶ 134:
end
 
function RawIP:getPrefix(lengthbitLength)
-- Methods
-- Return a RawIP object for the prefix of the current IP Address with a
function RawIP:getPrefix(length)
-- bit length of bitLength.
-- Return a copy of IPv4 or IPv6 parts, masked to length.
local result = Collection()
result.n = self.n
for i = 1, self.n do
if lengthbitLength > 0 then
if lengthbitLength >= 16 then
result[i] = self[i]
lengthbitLength = lengthbitLength - 16
else
result[i] = bit32.band(self[i],
bit32.arshift(0xffff8000, lengthbitLength - 1))
lengthbitLength = 0
end
else
Line 155 ⟶ 156:
end
 
function RawIP:setHostBitsgetHighestHost(lengthbitLength)
-- Return a copyRawIP ofobject IPv4for orthe IPv6highest parts,IP with the least-significantprefix of bitslength
-- bitLength. In other words, the network (the most-significant bits)
-- (host bits) set to 1.
-- is the same as the current IP's, but the host bits (the
-- The most-significant length bits identify the network.
-- (hostleast-significant bits) are all set to 1.
local bits = self.n * 16
local width
if lengthbitLength <= 0 then
width = bits
elseif lengthbitLength >= bits then
width = 0
else
width = bits - lengthbitLength
end
local result = Collection()
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu