forked from qt-creator/qt-creator
RemoteLinux: Allow parsing used ports from cat output
We used to run {filePath("sed"), {"-e 's/.*: [[:xdigit:]]*:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' /proc/net/tcp*"} on the device side but doesn't pass quoting on double-remote setups. Chicken out by using a simpler for now command. Change-Id: I7794f803d185bd4b6b717d85c01cc250cc66f1eb Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include "qtcassert.h"
|
||||
#include "stringutils.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include <limits>
|
||||
|
||||
/*! \class Utils::Port
|
||||
@@ -51,6 +53,36 @@ QList<Port> Port::parseFromSedOutput(const QByteArray &output)
|
||||
return ports;
|
||||
}
|
||||
|
||||
QList<Port> Port::parseFromCatOutput(const QByteArray &output)
|
||||
{
|
||||
// Parse something like
|
||||
// sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
|
||||
// : 00000000:2717 00000000:0000 0A 00000000:00000000 00:00000000 00000000 1001 0 3995881 1 0000000000000000 100 0 0 10 0
|
||||
// : 00000000:2716 00000000:0000 0A 00000000:00000000 00:00000000 00000000 1001 0 3594482 1 0000000000000000 100 0 0 10 0
|
||||
const QRegularExpression re(".*: [[:xdigit:]]*:([[:xdigit:]]{4}).*");
|
||||
|
||||
QList<Port> ports;
|
||||
const QStringList lines = QString::fromLocal8Bit(output).split('\n');
|
||||
for (const QString &line : lines) {
|
||||
const QRegularExpressionMatch match = re.match(line);
|
||||
if (!match.hasMatch())
|
||||
continue;
|
||||
const QString portString = match.captured(1);
|
||||
if (portString.size() != 4)
|
||||
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, qPrintable(portString));
|
||||
}
|
||||
}
|
||||
return ports;
|
||||
}
|
||||
|
||||
QList<Port> Port::parseFromNetstatOutput(const QByteArray &output)
|
||||
{
|
||||
QList<Port> ports;
|
||||
|
@@ -25,6 +25,7 @@ public:
|
||||
QString toString() const { return QString::number(m_port); }
|
||||
|
||||
static QList<Port> parseFromSedOutput(const QByteArray &output);
|
||||
static QList<Port> parseFromCatOutput(const QByteArray &output);
|
||||
static QList<Port> parseFromNetstatOutput(const QByteArray &output);
|
||||
|
||||
friend bool operator<(const Port &p1, const Port &p2) { return p1.number() < p2.number(); }
|
||||
|
@@ -1048,13 +1048,17 @@ PortsGatheringMethod LinuxDevice::portsGatheringMethod() const
|
||||
|
||||
Q_UNUSED(protocol)
|
||||
|
||||
// /proc/net/tcp* covers /proc/net/tcp and /proc/net/tcp6
|
||||
return {filePath("sed"),
|
||||
"-e 's/.*: [[:xdigit:]]*:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' /proc/net/tcp*",
|
||||
CommandLine::Raw};
|
||||
// We used to have
|
||||
// // /proc/net/tcp* covers /proc/net/tcp and /proc/net/tcp6
|
||||
// return {filePath("sed"),
|
||||
// "-e 's/.*: [[:xdigit:]]*:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' /proc/net/tcp*",
|
||||
//
|
||||
// here, but that doesn't pass quoting on double-remote setups.
|
||||
// Chicken out by using a simpler command.
|
||||
return {filePath("cat"), {"/proc/net/tcp*"}};
|
||||
},
|
||||
|
||||
&Port::parseFromSedOutput
|
||||
&Port::parseFromCatOutput
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user