Skip to content

Commit

Permalink
PSTRotator Drv: Only IPv4 addresses are used from DNS query
Browse files Browse the repository at this point in the history
Change LastError to provide more information about the cause of the error
  • Loading branch information
foldynl committed Apr 18, 2024
1 parent 293fdef commit 8dbbe64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
30 changes: 21 additions & 9 deletions rotator/drivers/PSTRotDrv.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <QNetworkDatagram>
#include <QHostInfo>
#include "core/debug.h"
#include "PSTRotDrv.h"

Expand Down Expand Up @@ -62,30 +63,41 @@ bool PSTRotDrv::open()

if ( !rc )
{
lastErrorText = tr("Initialization Error");
lastErrorText = tr("Cannot bind a port") + " " + rotProfile.netport;
qCDebug(runtime) << "Rot is not initialized - cannot bind port address" << rotProfile.netport;
return false;
}

qCDebug(runtime) << "Listening port" << rotProfile.netport + 1;

hostInfo = QHostInfo::fromName(rotProfile.hostname);

const QHostInfo &hostInfo = QHostInfo::fromName(rotProfile.hostname);
if ( hostInfo.error() != QHostInfo::NoError )
{
lastErrorText = tr("Initialization Error");
lastErrorText = tr("Cannot get IP Address for") + " " + rotProfile.hostname;
qCWarning(runtime) << "Cannot get Rotator hostname" << hostInfo.errorString();
return false;
}

if ( hostInfo.addresses().size() < 1 )
const QList<QHostAddress> addresses = hostInfo.addresses();
for ( const QHostAddress &address : addresses )
{
// currently, it seems that PSTRotator supports only IPv4 Addresses
// therefore it is necessary to filter out IPv6 adresses
if ( address.protocol() == QAbstractSocket::IPv4Protocol )
{
rotatorAddress = address;
qCDebug(runtime) << "Found IPv4 address " << address;
}
}

if ( rotatorAddress.isNull() )
{
lastErrorText = tr("Initialization Error");
qCWarning(runtime) << "No IP Address for " << rotProfile.hostname;
lastErrorText = tr("No IPv4 Address for") + " " + rotProfile.hostname;
qCWarning(runtime) << "No IPv4 Address for " << rotProfile.hostname;
return false;
}

qCDebug(runtime) << hostInfo.addresses();
qCDebug(runtime) << rotatorAddress;

connect(&receiveSocket, &QUdpSocket::readyRead,
this, &PSTRotDrv::readPendingDatagrams);
Expand Down Expand Up @@ -183,7 +195,7 @@ void PSTRotDrv::sendCommand(const QString &cmd)
QUdpSocket sendSocket;

sendSocket.writeDatagram(cmd.toUtf8(),
hostInfo.addresses().at(0),
rotatorAddress,
rotProfile.netport);
commandSleep();
}
Expand Down
3 changes: 1 addition & 2 deletions rotator/drivers/PSTRotDrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define ROTATOR_DRIVERS_PSTROTDRV_H

#include <QUdpSocket>
#include <QHostInfo>
#include <QTimer>
#include "GenericRotDrv.h"
#include "rotator/RotCaps.h"
Expand Down Expand Up @@ -39,7 +38,7 @@ private slots:
QTimer timeoutTimer;
QUdpSocket receiveSocket;
QMutex drvLock;
QHostInfo hostInfo;
QHostAddress rotatorAddress;
};

#endif // ROTATOR_DRIVERS_PSTROTDRV_H

0 comments on commit 8dbbe64

Please sign in to comment.