aboutsummaryrefslogtreecommitdiffstats
path: root/util/ip.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-12-01 04:32:20 +0100
committerKim Alvefur <zash@zash.se>2017-12-01 04:32:20 +0100
commit42e41f583df1697babcede6246b28e69c10dbdc4 (patch)
treec5b16f95023d1a093ac0059044e5c2e1d3d5d73f /util/ip.lua
parente9e827557b7c6c6351a49aa7a1c1e868b1723b62 (diff)
downloadprosody-42e41f583df1697babcede6246b28e69c10dbdc4.tar.gz
prosody-42e41f583df1697babcede6246b28e69c10dbdc4.zip
util.ip: Simplify bitstring method
Diffstat (limited to 'util/ip.lua')
-rw-r--r--util/ip.lua20
1 files changed, 2 insertions, 18 deletions
diff --git a/util/ip.lua b/util/ip.lua
index 5cf612f8..894fe2fb 100644
--- a/util/ip.lua
+++ b/util/ip.lua
@@ -6,6 +6,7 @@
--
local net = require "util.net";
+local hex = require "util.hex";
local ip_methods = {};
@@ -52,24 +53,7 @@ local function new_ip(ipStr, proto)
end
function ip_methods.bits(ip)
- ip = (ip.addr):upper();
- ip:gsub("([^:]*):?", function (c) fields[#fields + 1] = c end);
- if not ip:match(":$") then fields[#fields] = nil; end
- for i, field in ipairs(fields) do
- if field:len() == 0 and i ~= 1 and i ~= #fields then
- for _ = 1, 16 * (9 - #fields) do
- result = result .. "0";
- end
- else
- for _ = 1, 4 - field:len() do
- result = result .. "0000";
- end
- for j = 1, field:len() do
- result = result .. hex2bits[field:sub(j, j)];
- end
- end
- end
- return result;
+ return hex.to(ip.packed):upper():gsub(".", hex2bits);
end
function ip_methods.bits_full(ip)