From 1f2c6d833c579c8c3169e22ef8af00265a438406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Thu, 18 Jul 2019 21:35:33 +0000 Subject: add :hostmask() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Asbjørn Sloth Tønnesen --- lua/inet/core.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lua/inet/core.lua') diff --git a/lua/inet/core.lua b/lua/inet/core.lua index 0b062e7..f8e17cc 100644 --- a/lua/inet/core.lua +++ b/lua/inet/core.lua @@ -385,6 +385,12 @@ function inet4:netmask() return new_inet4(replace(0xffffffff, 0, 0, hostbits), 32) end +function inet4:hostmask() + local mask = self.mask + local hostbits = 32 - mask + return new_inet4(replace(0xffffffff, 0, hostbits, mask), 32) +end + function inet4:flip() -- find twin by flipping the last network bit local mask = self.mask @@ -716,6 +722,11 @@ function inet6:netmask() return build_inet6_mask(0, mask, 128 - mask) end +function inet6:hostmask() + local mask = self.mask + return build_inet6_mask(mask, 128 - mask, 0) +end + function inet6:flip() -- find twin by flipping the last network bit local mask = self.mask -- cgit v1.2.1