libs/core: Cleaned up luci.sys in favor of the new luci.ip module
[project/luci.git] / libs / core / luasrc / ip.lua
index 15730db..68ac384 100644 (file)
@@ -211,6 +211,8 @@ function Hex( hex, prefix, family, swap )
 
        if swap and LITTLE_ENDIAN then
                for i = #hex, 1, -2 do tmp = tmp .. hex:sub( i - 1, i ) end
+       else
+               tmp = tmp .. hex
        end
 
        hex = tmp
@@ -358,8 +360,9 @@ function cidr.mask( self, bits )
 end
 
 function cidr.contains( self, addr )
-       local mask1 = self:mask()
-       local mask2 = addr:mask()
+       assert( self[1] == addr[1], "Can't compare IPv4 and IPv6 addresses" )
+       local mask1 = self:prefix()
+       local mask2 = addr:prefix()
        if mask1 <= mask2 then
                return self:mask(addr:prefix()) == mask2
        end