Handle duplicate stale arp cache entries better
This commit is contained in:
parent
81b1ce65b9
commit
6076fd0db2
@ -41,7 +41,7 @@ void DeviceMonitor::lookupArpCache()
|
|||||||
|
|
||||||
void DeviceMonitor::ping()
|
void DeviceMonitor::ping()
|
||||||
{
|
{
|
||||||
// qCDebug(dcNetworkDetector()) << "Running:" << "ping" << "-c" << "1" << m_host->address();
|
qCDebug(dcNetworkDetector()) << "Sending ARP Ping to" << m_host->hostName() << m_host->macAddress() << m_host->address();
|
||||||
QNetworkInterface targetInterface;
|
QNetworkInterface targetInterface;
|
||||||
foreach (const QNetworkInterface &interface, QNetworkInterface::allInterfaces()) {
|
foreach (const QNetworkInterface &interface, QNetworkInterface::allInterfaces()) {
|
||||||
foreach (const QNetworkAddressEntry &addressEntry, interface.addressEntries()) {
|
foreach (const QNetworkAddressEntry &addressEntry, interface.addressEntries()) {
|
||||||
@ -73,35 +73,39 @@ void DeviceMonitor::arpLookupFinished(int exitCode)
|
|||||||
|
|
||||||
QString data = QString::fromLatin1(m_arpLookupProcess->readAll());
|
QString data = QString::fromLatin1(m_arpLookupProcess->readAll());
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
bool needsPing = true;
|
||||||
foreach (QString line, data.split('\n')) {
|
foreach (QString line, data.split('\n')) {
|
||||||
line.replace(QRegExp("[ ]{1,}"), " ");
|
line.replace(QRegExp("[ ]{1,}"), " ");
|
||||||
QStringList parts = line.split(" ");
|
QStringList parts = line.split(" ");
|
||||||
int lladdrIndex = parts.indexOf("lladdr");
|
int lladdrIndex = parts.indexOf("lladdr");
|
||||||
if (lladdrIndex >= 0 && parts.count() > lladdrIndex && parts.at(lladdrIndex+1).toLower() == m_host->macAddress().toLower()) {
|
if (lladdrIndex >= 0 && parts.count() > lladdrIndex && parts.at(lladdrIndex+1).toLower() == m_host->macAddress().toLower()) {
|
||||||
found = true;
|
found = true;
|
||||||
|
if (parts.last() == "REACHABLE") {
|
||||||
|
qCDebug(dcNetworkDetector()) << "Device" << m_host->macAddress() << "found in ARP cache and claims to be REACHABLE";
|
||||||
|
if (!m_host->reachable()) {
|
||||||
|
m_host->setReachable(true);
|
||||||
|
emit reachableChanged(true);
|
||||||
|
}
|
||||||
|
m_host->seen();
|
||||||
|
emit seen();
|
||||||
// Verify if IP address is still the same
|
// Verify if IP address is still the same
|
||||||
if (parts.first() != m_host->address()) {
|
if (parts.first() != m_host->address()) {
|
||||||
m_host->setAddress(parts.first());
|
m_host->setAddress(parts.first());
|
||||||
emit addressChanged(parts.first());
|
emit addressChanged(parts.first());
|
||||||
}
|
}
|
||||||
if (parts.last() == "REACHABLE") {
|
// If we have a reachable entry, stop processing here
|
||||||
qCDebug(dcNetworkDetector()) << "Device" << m_host->macAddress() << "found in ARP cache and claims to be REACHABLE";
|
needsPing = false;
|
||||||
m_host->seen();
|
|
||||||
if (!m_host->reachable()) {
|
|
||||||
m_host->setReachable(true);
|
|
||||||
emit reachableChanged(true);
|
|
||||||
}
|
|
||||||
emit seen();
|
|
||||||
} else {
|
|
||||||
// ARP claims the device to be stale... try to ping it.
|
|
||||||
qCDebug(dcNetworkDetector()) << "Device" << m_host->macAddress() << "found in ARP cache but is marked as" << parts.last() << ". Trying to ping it on" << m_host->address();
|
|
||||||
ping();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
// ARP claims the device to be stale... Flagging device to require a ping.
|
||||||
|
qCDebug(dcNetworkDetector()) << "Device" << m_host->macAddress() << "found in ARP cache but is marked as" << parts.last();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
qCDebug(dcNetworkDetector()) << "Device" << m_host->macAddress() << "not found in ARP cache. Trying to ping it on" << m_host->address();
|
qCDebug(dcNetworkDetector()) << "Device" << m_host->macAddress() << "not found in ARP cache.";
|
||||||
|
ping();
|
||||||
|
} else if (needsPing) {
|
||||||
ping();
|
ping();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user