forked from qt-creator/qt-creator
Qnx: Use simpler portsgatherer command
As indicated by the removed comment, the original version was way too complicated. Change-Id: Ie5d8d8fbe7bd8e44e0538117cd2aaa73958f7d8c Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include <ssh/sshconnection.h>
|
#include <ssh/sshconnection.h>
|
||||||
#include <utils/port.h>
|
#include <utils/port.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
@@ -59,37 +60,19 @@ class QnxPortsGatheringMethod : public PortsGatheringMethod
|
|||||||
{
|
{
|
||||||
Q_UNUSED(protocol);
|
Q_UNUSED(protocol);
|
||||||
StandardRunnable runnable;
|
StandardRunnable runnable;
|
||||||
// FIXME: Is this extra shell needed?
|
runnable.executable = "netstat";
|
||||||
runnable.executable = "/bin/sh";
|
runnable.commandLineArguments = "-na";
|
||||||
runnable.commandLineArguments = "-c \""
|
|
||||||
"netstat -na "
|
|
||||||
"| sed 's/[a-z]\\+\\s\\+[0-9]\\+\\s\\+[0-9]\\+\\s\\+\\(\\*\\|[0-9\\.]\\+\\)\\.\\([0-9]\\+\\).*/\\2/g' "
|
|
||||||
"| while read line; do "
|
|
||||||
"if [[ $line != udp* ]] && [[ $line != Active* ]]; then "
|
|
||||||
"printf '%x\n' $line; "
|
|
||||||
"fi; "
|
|
||||||
"done"
|
|
||||||
"\"";
|
|
||||||
return runnable;
|
return runnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Port> usedPorts(const QByteArray &output) const override
|
QList<Port> usedPorts(const QByteArray &output) const override
|
||||||
{
|
{
|
||||||
QList<Port> ports;
|
QList<Utils::Port> ports;
|
||||||
QList<QByteArray> portStrings = output.split('\n');
|
const QList<QByteArray> lines = output.split('\n');
|
||||||
portStrings.removeFirst();
|
for (const QByteArray &line : lines) {
|
||||||
foreach (const QByteArray &portString, portStrings) {
|
const Port port(Utils::parseUsedPortFromNetstatOutput(line));
|
||||||
if (portString.isEmpty())
|
if (port.isValid() && !ports.contains(port))
|
||||||
continue;
|
ports.append(port);
|
||||||
bool ok;
|
|
||||||
const Port port(portString.toInt(&ok, 16));
|
|
||||||
if (ok) {
|
|
||||||
if (!ports.contains(port))
|
|
||||||
ports << port;
|
|
||||||
} else {
|
|
||||||
qWarning("%s: Unexpected string '%s' is not a port.",
|
|
||||||
Q_FUNC_INFO, portString.data());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ports;
|
return ports;
|
||||||
}
|
}
|
||||||
|
@@ -243,6 +243,18 @@ void tst_StringUtils::testParseUsedPortFromNetstatOutput_data()
|
|||||||
QTest::newRow("Mac6") << "tcp6 0 0 *.631 *.* LISTEN" << 631;
|
QTest::newRow("Mac6") << "tcp6 0 0 *.631 *.* LISTEN" << 631;
|
||||||
QTest::newRow("Mac7") << "udp4 0 0 192.168.79.1.123 *.*" << 123;
|
QTest::newRow("Mac7") << "udp4 0 0 192.168.79.1.123 *.*" << 123;
|
||||||
QTest::newRow("Mac9") << "udp4 0 0 192.168.8.1.123 *.*" << 123;
|
QTest::newRow("Mac9") << "udp4 0 0 192.168.8.1.123 *.*" << 123;
|
||||||
|
|
||||||
|
// QNX
|
||||||
|
QTest::newRow("Qnx1") << "Active Internet connections (including servers)" << -1;
|
||||||
|
QTest::newRow("Qnx2") << "Proto Recv-Q Send-Q Local Address Foreign Address State " << -1;
|
||||||
|
QTest::newRow("Qnx3") << "tcp 0 0 10.9.7.5.22 10.9.7.4.46592 ESTABLISHED" << 22;
|
||||||
|
QTest::newRow("Qnx4") << "tcp 0 0 *.8000 *.* LISTEN " << 8000;
|
||||||
|
QTest::newRow("Qnx5") << "tcp 0 0 *.22 *.* LISTEN " << 22;
|
||||||
|
QTest::newRow("Qnx6") << "udp 0 0 *.* *.* " << -1;
|
||||||
|
QTest::newRow("Qnx7") << "udp 0 0 *.* *.* " << -1;
|
||||||
|
QTest::newRow("Qnx8") << "Active Internet6 connections (including servers)" << -1;
|
||||||
|
QTest::newRow("Qnx9") << "Proto Recv-Q Send-Q Local Address Foreign Address (state) " << -1;
|
||||||
|
QTest::newRow("QnxA") << "tcp6 0 0 *.22 *.* LISTEN " << 22;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_StringUtils)
|
QTEST_MAIN(tst_StringUtils)
|
||||||
|
Reference in New Issue
Block a user