---- Convert hexadecimal 32 bit value to IPv4 address.
--- @param hex String containing the hexadecimal value
--- @param be Boolean indicating wheather the given value is big endian
--- @return String containing the corresponding IP4 address
-function net.hexip4(hex, be)
- if #hex ~= 8 then
- return nil
- end
-
- be = be or luci.util.bigendian()
-
- local hexdec = luci.bits.Hex2Dec
-
- local ip = ""
- if be then
- ip = ip .. tostring(hexdec(hex:sub(1,2))) .. "."
- ip = ip .. tostring(hexdec(hex:sub(3,4))) .. "."
- ip = ip .. tostring(hexdec(hex:sub(5,6))) .. "."
- ip = ip .. tostring(hexdec(hex:sub(7,8)))
- else
- ip = ip .. tostring(hexdec(hex:sub(7,8))) .. "."
- ip = ip .. tostring(hexdec(hex:sub(5,6))) .. "."
- ip = ip .. tostring(hexdec(hex:sub(3,4))) .. "."
- ip = ip .. tostring(hexdec(hex:sub(1,2)))
- end
-
- return ip
-end
-
---- Convert given IPv4 address to binary value.
--- @param ip String containing a IPv4 address
--- @return String containing corresponding binary value
-function net.ip4bin(ip)
- local parts = luci.util.split(ip, '.')
- if #parts ~= 4 then
- return nil
- end
-
- local decbin = luci.bits.Dec2Bin
-
- local bin = ""
- bin = bin .. decbin(parts[1], 8)
- bin = bin .. decbin(parts[2], 8)
- bin = bin .. decbin(parts[3], 8)
- bin = bin .. decbin(parts[4], 8)
-
- return bin
-end