Merge remote-tracking branch 'origin/fix-network-detector-ipv6'

This commit is contained in:
Jenkins 2018-03-14 17:00:49 +01:00
commit b2a20c4530
3 changed files with 11 additions and 7 deletions

View File

@ -14,6 +14,7 @@ DeviceMonitor::DeviceMonitor(const QString &macAddress, const QString &ipAddress
connect(m_arpLookupProcess, SIGNAL(finished(int)), this, SLOT(arpLookupFinished(int))); connect(m_arpLookupProcess, SIGNAL(finished(int)), this, SLOT(arpLookupFinished(int)));
m_pingProcess = new QProcess(this); m_pingProcess = new QProcess(this);
m_pingProcess->setReadChannelMode(QProcess::MergedChannels);
connect(m_pingProcess, SIGNAL(finished(int)), this, SLOT(pingFinished(int))); connect(m_pingProcess, SIGNAL(finished(int)), this, SLOT(pingFinished(int)));
} }
@ -29,11 +30,12 @@ void DeviceMonitor::update()
void DeviceMonitor::lookupArpCache() void DeviceMonitor::lookupArpCache()
{ {
m_arpLookupProcess->start("ip", {"-s", "neighbor", "list"}); m_arpLookupProcess->start("ip", {"-4", "-s", "neighbor", "list"});
} }
void DeviceMonitor::ping() void DeviceMonitor::ping()
{ {
// qCDebug(dcNetworkDetector()) << "Running:" << "ping" << "-c" << "1" << m_host->address();
m_pingProcess->start("ping", {"-c", "1", m_host->address()}); m_pingProcess->start("ping", {"-c", "1", m_host->address()});
} }
@ -66,14 +68,14 @@ void DeviceMonitor::arpLookupFinished(int exitCode)
} }
} else { } else {
// ARP claims the device to be stale... try to ping it. // 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..."; 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(); ping();
} }
break; break;
} }
} }
if (!found) { if (!found) {
qCDebug(dcNetworkDetector()) << "Device" << m_host->macAddress() << "not found in ARP cache. Trying to ping it..."; qCDebug(dcNetworkDetector()) << "Device" << m_host->macAddress() << "not found in ARP cache. Trying to ping it on" << m_host->address();
ping(); ping();
} }

View File

@ -141,9 +141,9 @@ void DevicePluginNetworkDetector::deviceReachableChanged(bool reachable)
{ {
DeviceMonitor *monitor = static_cast<DeviceMonitor*>(sender()); DeviceMonitor *monitor = static_cast<DeviceMonitor*>(sender());
Device *device = m_monitors.value(monitor); Device *device = m_monitors.value(monitor);
if (device->stateValue(networkDeviceInRangeStateTypeId).toBool() != reachable) { if (device->stateValue(networkDeviceConnectedStateTypeId).toBool() != reachable) {
qCDebug(dcNetworkDetector()) << "Device" << device->paramValue(networkDeviceMacAddressParamTypeId).toString() << "reachable changed" << reachable; qCDebug(dcNetworkDetector()) << "Device" << device->paramValue(networkDeviceMacAddressParamTypeId).toString() << "reachable changed" << reachable;
device->setStateValue(networkDeviceInRangeStateTypeId, reachable); device->setStateValue(networkDeviceConnectedStateTypeId, reachable);
} }
} }

View File

@ -17,6 +17,7 @@
"Device", "Device",
"Sensor" "Sensor"
], ],
"interfaces": ["connectable"],
"primaryStateTypeId": "cb43e1b5-4f61-4538-bfa2-c33055c542cf", "primaryStateTypeId": "cb43e1b5-4f61-4538-bfa2-c33055c542cf",
"createMethods": ["user", "discovery"], "createMethods": ["user", "discovery"],
"paramTypes": [ "paramTypes": [
@ -38,11 +39,12 @@
"stateTypes": [ "stateTypes": [
{ {
"id": "cb43e1b5-4f61-4538-bfa2-c33055c542cf", "id": "cb43e1b5-4f61-4538-bfa2-c33055c542cf",
"name": "inRange", "name": "connected",
"displayName": "Device in network", "displayName": "Device in network",
"displayNameEvent": "Device in network changed", "displayNameEvent": "Device in network changed",
"type": "bool", "type": "bool",
"defaultValue": false "defaultValue": false,
"cached": false
} }
] ]
} }