Software /
code /
prosody
Comparison
util/ip.lua @ 7053:3049137d14b6
util.ip: Fix protocol detection of IPv6 addresses beginning with : [Backported from 0.10]
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 18 May 2013 21:41:17 +0100 |
parent | 7052:306aabf2d57d |
child | 7055:23de70d19e77 |
comparison
equal
deleted
inserted
replaced
7052:306aabf2d57d | 7053:3049137d14b6 |
---|---|
12 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" }; | 12 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" }; |
13 | 13 |
14 local function new_ip(ipStr, proto) | 14 local function new_ip(ipStr, proto) |
15 if not proto then | 15 if not proto then |
16 local sep = ipStr:match("^%x+(.)"); | 16 local sep = ipStr:match("^%x+(.)"); |
17 if sep == ":" then proto = "IPv6" | 17 if sep == ":" or (not(sep) and ipStr:sub(1,1) == ":") then |
18 elseif sep == "." then proto = "IPv4" | 18 proto = "IPv6" |
19 elseif sep == "." then | |
20 proto = "IPv4" | |
19 end | 21 end |
20 if not proto then | 22 if not proto then |
21 return nil, "invalid address"; | 23 return nil, "invalid address"; |
22 end | 24 end |
23 elseif proto ~= "IPv4" and proto ~= "IPv6" then | 25 elseif proto ~= "IPv4" and proto ~= "IPv6" then |