Software /
code /
prosody
Changeset
5597:6fe09707c73b
util.ip: Convert IPv4 mapped addresses to hex.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 18 May 2013 13:14:19 +0200 (2013-05-18) |
parents | 5596:73fea1a87afd |
children | 5598:3bb8aefd8ce0 |
files | util/ip.lua |
diffstat | 1 files changed, 7 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/util/ip.lua Sat May 18 13:11:44 2013 +0200 +++ b/util/ip.lua Sat May 18 13:14:19 2013 +0200 @@ -15,6 +15,13 @@ if proto ~= "IPv4" and proto ~= "IPv6" then return nil, "invalid protocol"; 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) + return (":%04X:%04X"):format(a*256+b,c*256+d); + end); + if changed ~= 1 then return nil, "invalid-address"; end + end return setmetatable({ addr = ipStr, proto = proto }, ip_mt); end