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 <utils/port.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QRegExp>
|
||||
@@ -59,37 +60,19 @@ class QnxPortsGatheringMethod : public PortsGatheringMethod
|
||||
{
|
||||
Q_UNUSED(protocol);
|
||||
StandardRunnable runnable;
|
||||
// FIXME: Is this extra shell needed?
|
||||
runnable.executable = "/bin/sh";
|
||||
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"
|
||||
"\"";
|
||||
runnable.executable = "netstat";
|
||||
runnable.commandLineArguments = "-na";
|
||||
return runnable;
|
||||
}
|
||||
|
||||
QList<Port> usedPorts(const QByteArray &output) const override
|
||||
{
|
||||
QList<Port> ports;
|
||||
QList<QByteArray> portStrings = output.split('\n');
|
||||
portStrings.removeFirst();
|
||||
foreach (const QByteArray &portString, portStrings) {
|
||||
if (portString.isEmpty())
|
||||
continue;
|
||||
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());
|
||||
}
|
||||
QList<Utils::Port> ports;
|
||||
const QList<QByteArray> lines = output.split('\n');
|
||||
for (const QByteArray &line : lines) {
|
||||
const Port port(Utils::parseUsedPortFromNetstatOutput(line));
|
||||
if (port.isValid() && !ports.contains(port))
|
||||
ports.append(port);
|
||||
}
|
||||
return ports;
|
||||
}
|
||||
|
@@ -243,6 +243,18 @@ void tst_StringUtils::testParseUsedPortFromNetstatOutput_data()
|
||||
QTest::newRow("Mac6") << "tcp6 0 0 *.631 *.* LISTEN" << 631;
|
||||
QTest::newRow("Mac7") << "udp4 0 0 192.168.79.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)
|
||||
|
Reference in New Issue
Block a user