diff options
author | Steven Barth <steven@midlink.org> | 2008-08-08 12:26:45 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-08-08 12:26:45 +0000 |
commit | e080fcebd2396c138d8c916d1cf385a88e0db246 (patch) | |
tree | 9a41e995a438d8ac32c9501f44800bf3d0e7d297 /libs/sys/luasrc | |
parent | f4ec942d1bc3d9a6c822c075017cb2949cd8fff5 (diff) |
libs/core: Cleaned up luci.sys in favor of the new luci.ip module
Diffstat (limited to 'libs/sys/luasrc')
-rw-r--r-- | libs/sys/luasrc/sys.lua | 71 |
1 files changed, 1 insertions, 70 deletions
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index 14a2f294f..b8ec10e0f 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -30,6 +30,7 @@ require("posix") require("luci.bits") require("luci.util") require("luci.fs") +require("luci.ip") --- Invoke the luci-flash executable to write an image to the flash memory. -- @param kpattern Pattern of files to keep over flash process @@ -183,15 +184,6 @@ function net.arptable() return _parse_delimited_table(io.lines("/proc/net/arp"), "%s%s+") end ---- Test whether an IP-Adress belongs to a certain net. --- @param ip IPv4 address to test --- @param ipnet IPv4 network address of the net range to compare against --- @param prefix Network prefix of the net range to compare against --- @return Boolean indicating wheather the ip is within the range -function net.belongs(ip, ipnet, prefix) - return (net.ip4bin(ip):sub(1, prefix) == net.ip4bin(ipnet):sub(1, prefix)) -end - --- Determine the current default route. -- @return Table with the properties of the current default route. -- The following fields are defined: @@ -235,19 +227,6 @@ function net.ip4mac(ip) return mac end ---- Calculate the prefix from a given netmask. --- @param mask IPv4 net mask --- @return Number containing the corresponding numerical prefix -function net.mask4prefix(mask) - local bin = net.ip4bin(mask) - - if not bin then - return nil - end - - return #luci.util.split(bin, "1")-1 -end - --- Returns the current kernel routing table entries. -- @return Table of tables with properties of the corresponding routes. -- The following fields are defined for route entry tables: @@ -257,54 +236,6 @@ function net.routes() return _parse_delimited_table(io.lines("/proc/net/route")) end ---- 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 --- Tests whether the given host responds to ping probes. -- @param host String containing a hostname or IPv4 address |