diff --git a/libnymea-core/hardware/network/networkdevicediscoveryreplyimpl.cpp b/libnymea-core/hardware/network/networkdevicediscoveryreplyimpl.cpp index 38102b95..c7e28e85 100644 --- a/libnymea-core/hardware/network/networkdevicediscoveryreplyimpl.cpp +++ b/libnymea-core/hardware/network/networkdevicediscoveryreplyimpl.cpp @@ -33,9 +33,9 @@ #include -namespace nymeaserver { +Q_DECLARE_LOGGING_CATEGORY(dcNetworkDeviceDiscovery) -NYMEA_LOGGING_CATEGORY(dcNetworkDeviceDiscovery, "NetworkDeviceDiscovery") +namespace nymeaserver { NetworkDeviceDiscoveryReplyImpl::NetworkDeviceDiscoveryReplyImpl(QObject *parent) : NetworkDeviceDiscoveryReply(parent) diff --git a/libnymea/network/arpsocket.cpp b/libnymea/network/arpsocket.cpp index ab92223b..4247e05e 100644 --- a/libnymea/network/arpsocket.cpp +++ b/libnymea/network/arpsocket.cpp @@ -71,9 +71,6 @@ bool ArpSocket::sendRequest() if (!m_isOpen) return false; - // Initially load the arp cache before we start to broadcast - //loadArpCache(); - // Send the ARP request trough each network interface qCDebug(dcArpSocket()) << "Sending ARP request to all local network interfaces..."; foreach (const QNetworkInterface &networkInterface, QNetworkInterface::allInterfaces()) { @@ -88,9 +85,8 @@ bool ArpSocket::sendRequest(const QString &interfaceName) if (!m_isOpen) return false; - // Get the interface - qCDebug(dcArpSocket()) << "Sending ARP request to all network interfaces" << interfaceName << "..."; + qCDebug(dcArpSocket()) << "Sending ARP request to network interface" << interfaceName << "..."; QNetworkInterface networkInterface = QNetworkInterface::interfaceFromName(interfaceName); if (!networkInterface.isValid()) { qCWarning(dcArpSocket()) << "Failed to send the ARP request to network interface" << interfaceName << "because the interface is not valid."; @@ -109,7 +105,7 @@ bool ArpSocket::sendRequest(const QNetworkInterface &networkInterface) if (networkInterface.flags().testFlag(QNetworkInterface::IsLoopBack)) return false; - // If have no interface indes, we cannot use this network + // If the interface index is unknown, we cannot use this network if (networkInterface.index() == 0) { qCDebug(dcArpSocket()) << "Failed to send the ARP request to network interface" << networkInterface.name() << "because the system interface index is unknown."; return false; diff --git a/libnymea/network/ping.cpp b/libnymea/network/ping.cpp index 674ee96c..e5eaae11 100644 --- a/libnymea/network/ping.cpp +++ b/libnymea/network/ping.cpp @@ -135,7 +135,7 @@ void Ping::sendNextReply() PingReply *reply = m_replyQueue.dequeue(); //qCDebug(dcPing()) << "Send next reply," << m_replyQueue.count() << "left in queue"; m_queueTimer->start(); - QTimer::singleShot(0, this, [=]() { performPing(reply); }); + QTimer::singleShot(0, reply, [=]() { performPing(reply); }); } void Ping::performPing(PingReply *reply) @@ -146,6 +146,13 @@ void Ping::performPing(PingReply *reply) return; } + if (reply->targetHostAddress().isNull()) { + m_error = PingReply::ErrorInvalidHostAddress; + qCWarning(dcPing()) << "Cannot send ping request" << m_error; + finishReply(reply, m_error); + return; + } + // Get host ip address struct hostent *hostname = gethostbyname(reply->targetHostAddress().toString().toLocal8Bit().constData()); struct sockaddr_in pingAddress; diff --git a/libnymea/network/pingreply.h b/libnymea/network/pingreply.h index 60837181..8bf8ca19 100644 --- a/libnymea/network/pingreply.h +++ b/libnymea/network/pingreply.h @@ -57,7 +57,8 @@ public: ErrorPermissionDenied, ErrorSocketError, ErrorTimeout, - ErrorHostUnreachable + ErrorHostUnreachable, + ErrorInvalidHostAddress }; Q_ENUM(Error)