util.ip: Fix protocol detection of IPv6 addresses beginning with :

vault/0.11
Matthew Wild 13 years ago
parent cb3fc989da
commit e6d86ed80b
  1. 6
      util/ip.lua

@ -14,8 +14,10 @@ local hex2bits = { ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011
local function new_ip(ipStr, proto)
if not proto then
local sep = ipStr:match("^%x+(.)");
if sep == ":" then proto = "IPv6"
elseif sep == "." then proto = "IPv4"
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";

Loading…
Cancel
Save