diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-03-11 18:16:24 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-03-11 18:26:31 +0100 |
commit | 62630fbf880058aa1c7ae10ecf5ae5cb6e4af5bb (patch) | |
tree | 17b0770f9acadb2cbdb3294956158e827d4e99af /modules/luci-base/luasrc/sys.lua | |
parent | bf04031171b3a64d7a018902123422be70da63bd (diff) |
luci-base: fix parsing of ethers(5)
The /etc/ethers file may contain any number of white space characters
between the mac address and the IP/hostname field, so extend the pattern
to allow for that.
Man ethers(5) also states that the IP field may be a symbolic hostname,
so test whether the name is an IP address or hostname before adding it
to the hints structure.
Fixes #1674.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/luasrc/sys.lua')
-rw-r--r-- | modules/luci-base/luasrc/sys.lua | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/luci-base/luasrc/sys.lua b/modules/luci-base/luasrc/sys.lua index 84c747f2b..b00feda5a 100644 --- a/modules/luci-base/luasrc/sys.lua +++ b/modules/luci-base/luasrc/sys.lua @@ -146,9 +146,13 @@ local function _nethints(what, callback) if fs.access("/etc/ethers") then for e in io.lines("/etc/ethers") do - mac, ip = e:match("^([a-f0-9]%S+) (%S+)") - if mac and ip then - _add(what, mac:upper(), ip, nil, nil) + mac, name = e:match("^([a-fA-F0-9:]+)%s+(%S+)") + if mac and name then + if luci.ip.IPv4(name) then + _add(what, mac:upper(), name, nil, nil) + else + _add(what, mac:upper(), nil, nil, name) + end end end end |