Software /
code /
prosody
Comparison
util/ip.lua @ 8433:ca7f8e60410a
util.ip: Add a method returning a normalized IP address
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 01 Dec 2017 04:33:27 +0100 |
parent | 8432:da807f4f706c |
child | 8434:ec8f37baffaa |
comparison
equal
deleted
inserted
replaced
8432:da807f4f706c | 8433:ca7f8e60410a |
---|---|
48 elseif proto ~= "IPv6" and proto ~= "IPv4" then | 48 elseif proto ~= "IPv6" and proto ~= "IPv4" then |
49 return nil, "invalid protocol"; | 49 return nil, "invalid protocol"; |
50 end | 50 end |
51 | 51 |
52 return setmetatable({ addr = ipStr, packed = packed, proto = proto, zone = zone }, ip_mt); | 52 return setmetatable({ addr = ipStr, packed = packed, proto = proto, zone = zone }, ip_mt); |
53 end | |
54 | |
55 function ip_methods:normal() | |
56 return net.ntop(self.packed); | |
53 end | 57 end |
54 | 58 |
55 function ip_methods.bits(ip) | 59 function ip_methods.bits(ip) |
56 return hex.to(ip.packed):upper():gsub(".", hex2bits); | 60 return hex.to(ip.packed):upper():gsub(".", hex2bits); |
57 end | 61 end |