X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fip.lua;h=043303eebb311ce6a1d07bcc23b9bdf97db4e620;hb=533fc1fa57ce10fc0821f8edaeb247f2710a543c;hp=856bf03498261860db5796afccac66258c33beae;hpb=62a9a111a30cec7df60fab5df8452ea49ce06da7;p=prosody.git diff --git a/util/ip.lua b/util/ip.lua index 856bf034..043303ee 100644 --- a/util/ip.lua +++ b/util/ip.lua @@ -12,7 +12,17 @@ local ip_mt = { __index = function (ip, key) return (ip_methods[key])(ip); end, local hex2bits = { ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011", ["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111", ["8"] = "1000", ["9"] = "1001", ["A"] = "1010", ["B"] = "1011", ["C"] = "1100", ["D"] = "1101", ["E"] = "1110", ["F"] = "1111" }; local function new_ip(ipStr, proto) - if proto ~= "IPv4" and proto ~= "IPv6" then + if not proto then + local sep = ipStr:match("^%x+(.)"); + if sep == ":" or (not(sep) and ipStr:sub(1,1) == ":") then + proto = "IPv6" + elseif sep == "." then + proto = "IPv4" + end + if not proto then + return nil, "invalid address"; + end + elseif proto ~= "IPv4" and proto ~= "IPv6" then return nil, "invalid protocol"; end if proto == "IPv6" and ipStr:find('.', 1, true) then