diff options
author | Kim Alvefur <zash@zash.se> | 2016-01-04 17:47:40 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2016-01-04 17:47:40 +0100 |
commit | fe0303fe45e4265d0c72c0c55da2dbab90d2c2d3 (patch) | |
tree | da70d51c4f2940b127d7eb1d1f7ac5c5ef38d4bb | |
parent | 8a6298f134d7c880e5d38a46e6a43400bfb7787a (diff) | |
download | prosody-fe0303fe45e4265d0c72c0c55da2dbab90d2c2d3.tar.gz prosody-fe0303fe45e4265d0c72c0c55da2dbab90d2c2d3.zip |
util.ip: Support zone id syntax in IPv6 addresses
-rw-r--r-- | util/ip.lua | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/util/ip.lua b/util/ip.lua index 043303ee..acfd7f24 100644 --- a/util/ip.lua +++ b/util/ip.lua @@ -25,6 +25,10 @@ local function new_ip(ipStr, proto) elseif proto ~= "IPv4" and proto ~= "IPv6" then return nil, "invalid protocol"; end + local zone; + if proto == "IPv6" and ipStr:find('%', 1, true) then + ipStr, zone = ipStr:match("^(.-)%%(.*)"); + end if proto == "IPv6" and ipStr:find('.', 1, true) then local changed; ipStr, changed = ipStr:gsub(":(%d+)%.(%d+)%.(%d+)%.(%d+)$", function(a,b,c,d) @@ -33,7 +37,7 @@ local function new_ip(ipStr, proto) if changed ~= 1 then return nil, "invalid-address"; end end - return setmetatable({ addr = ipStr, proto = proto }, ip_mt); + return setmetatable({ addr = ipStr, proto = proto, zone = zone }, ip_mt); end local function toBits(ip) |