Mercurial > prosody-hg
comparison util/ip.lua @ 5602:e8a0e545ee05
Merge
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 18 May 2013 15:29:31 +0100 |
| parents | 34e9f237b915 |
| children | e07f4f02e4f9 |
comparison
equal
deleted
inserted
replaced
| 5601:f55ab5fa939f | 5602:e8a0e545ee05 |
|---|---|
| 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 |
