Mercurial > prosody-hg
comparison util/ip.lua @ 5599:34e9f237b915
Merge 0.9->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 18 May 2013 13:20:46 +0200 |
| parents | 8c1a3243d16f 6fe09707c73b |
| children | e07f4f02e4f9 |
comparison
equal
deleted
inserted
replaced
| 5595:b9c836dc8f2a | 5599:34e9f237b915 |
|---|---|
| 20 if not proto then | 20 if not proto then |
| 21 return nil, "invalid address"; | 21 return nil, "invalid address"; |
| 22 end | 22 end |
| 23 elseif proto ~= "IPv4" and proto ~= "IPv6" then | 23 elseif proto ~= "IPv4" and proto ~= "IPv6" then |
| 24 return nil, "invalid protocol"; | 24 return nil, "invalid protocol"; |
| 25 end | |
| 26 if proto == "IPv6" and ipStr:find('.', 1, true) then | |
| 27 local changed; | |
| 28 ipStr, changed = ipStr:gsub(":(%d+)%.(%d+)%.(%d+)%.(%d+)$", function(a,b,c,d) | |
| 29 return (":%04X:%04X"):format(a*256+b,c*256+d); | |
| 30 end); | |
| 31 if changed ~= 1 then return nil, "invalid-address"; end | |
| 25 end | 32 end |
| 26 | 33 |
| 27 return setmetatable({ addr = ipStr, proto = proto }, ip_mt); | 34 return setmetatable({ addr = ipStr, proto = proto }, ip_mt); |
| 28 end | 35 end |
| 29 | 36 |
