Make sure we only pass a single IP to ping

For some mysterious reason, I have a duplicate default gateway on my
Forma, one with no metrics, and a proper one.
This ensures we pick the proper one.

I'm fairly sure this is temporary insanity on the part of my device,
but, still, it can't hurt.

route -n:
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
0.0.0.0         192.168.0.1     0.0.0.0         UG    208    0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     208    0        0 eth0

ip r:
default via 192.168.0.1 dev eth0
default via 192.168.0.1 dev eth0  metric 208
192.168.0.0/24 dev eth0  src 192.168.0.49  metric 208
pull/5103/head
NiLuJe 5 years ago
parent c7400821f1
commit 2ab3e48286

@ -314,9 +314,9 @@ function Device:retrieveNetworkInfo()
-- NOTE: No -w flag available in the old busybox build used on Legacy Kindles...
local pingok
if self:isKindle() and self:hasKeyboard() then
pingok = os.execute("ping -q -c 2 `ip r | grep default | cut -d ' ' -f 3` > /dev/null")
pingok = os.execute("ping -q -c 2 `ip r | grep default | tail -n 1 | cut -d ' ' -f 3` > /dev/null")
else
pingok = os.execute("ping -q -w 3 -c 2 `ip r | grep default | cut -d ' ' -f 3` > /dev/null")
pingok = os.execute("ping -q -w 3 -c 2 `ip r | grep default | tail -n 1 | cut -d ' ' -f 3` > /dev/null")
end
if pingok == 0 then
result = result .. "Gateway ping successful"

@ -104,9 +104,9 @@ function NetworkMgr:isConnected()
-- `-c1` try only once; `-w2` wait 2 seconds
-- NOTE: No -w flag available in the old busybox build used on Legacy Kindles...
if Device:isKindle() and Device:hasKeyboard() then
return 0 == os.execute([[ping -c1 $(/sbin/route -n | awk '$4 == "UG" {print $2}')]])
return 0 == os.execute([[ping -c1 $(/sbin/route -n | awk '$4 == "UG" {print $2}' | tail -n 1)]])
else
return 0 == os.execute([[ping -c1 -w2 $(/sbin/route -n | awk '$4 == "UG" {print $2}')]])
return 0 == os.execute([[ping -c1 -w2 $(/sbin/route -n | awk '$4 == "UG" {print $2}' | tail -n 1)]])
end
end
end

Loading…
Cancel
Save