util.ip: Fix protocol detection of IPv6 addresses beginning with : [Backported from...
authorMatthew Wild <mwild1@gmail.com>
Sat, 18 May 2013 20:41:17 +0000 (21:41 +0100)
committerMatthew Wild <mwild1@gmail.com>
Sat, 18 May 2013 20:41:17 +0000 (21:41 +0100)
util/ip.lua

index 226432ccff8887464b7f92b39fe432008ce22b6d..043303eebb311ce6a1d07bcc23b9bdf97db4e620 100644 (file)
@@ -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";