aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2023-03-14 18:23:33 +0000
committerMatthew Wild <mwild1@gmail.com>2023-03-14 18:23:33 +0000
commit3eedf79c8bd6555ebe601c67942af07aff3782a1 (patch)
tree67955602d364fb405b73930060563c109366747d
parent9c8b2f50990d4ab9f25e16a9adf211af236f3d75 (diff)
downloadprosody-3eedf79c8bd6555ebe601c67942af07aff3782a1.tar.gz
prosody-3eedf79c8bd6555ebe601c67942af07aff3782a1.zip
util.ip: Add is_ip() helper method to detect if an object is an ip object
-rw-r--r--util/ip.lua5
1 files changed, 5 insertions, 0 deletions
diff --git a/util/ip.lua b/util/ip.lua
index 4b450934..5e20febe 100644
--- a/util/ip.lua
+++ b/util/ip.lua
@@ -241,9 +241,14 @@ function match(ipA, ipB, bits)
return ipA.bits:sub(1, bits) == ipB.bits:sub(1, bits);
end
+local function is_ip(obj)
+ return getmetatable(obj) == ip_mt;
+end
+
return {
new_ip = new_ip,
commonPrefixLength = commonPrefixLength,
parse_cidr = parse_cidr,
match = match,
+ is_ip = is_ip;
};