diff options
author | hjk <hjk@theqtcompany.com> | 2016-04-15 12:23:23 +0200 |
---|---|---|
committer | hjk <hjk@theqtcompany.com> | 2016-04-18 09:57:33 +0000 |
commit | b7fabb290bdae023bb0a26e07e3ddba1c2d9d6d5 (patch) | |
tree | e63cae1663b181fb71d49ee62fc04f1fe0e3074a | |
parent | a24ce30425d78a68247c5f79d75f45535e7952f0 (diff) |
RemoteLinux: Relax port gathering
We might encounter the situation that protocol is given as IPv6
but the consumer of the free port information decides to open
an IPv4(only) port. As a result the next IPv6 scan will
report the port again as open (in IPv6 namespace), while the
same port in IPv4 namespace might still be blocked, and
re-use of this port fails.
Err on the safe side, and consider ports taken in either space
as blocked.
Change-Id: I2e4be40ab4df5398e26e197c12408efe905b1a2f
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
-rw-r--r-- | src/plugins/remotelinux/linuxdevice.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 6f960c0786..6675a2aeb4 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -123,27 +123,26 @@ class LinuxPortsGatheringMethod : public PortsGatheringMethod { QByteArray commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const { - QString procFilePath; - int addressLength; - if (protocol == QAbstractSocket::IPv4Protocol) { - procFilePath = QLatin1String("/proc/net/tcp"); - addressLength = 8; - } else { - procFilePath = QLatin1String("/proc/net/tcp6"); - addressLength = 32; - } - return QString::fromLatin1("sed " - "'s/.*: [[:xdigit:]]\\{%1\\}:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' %2") - .arg(addressLength).arg(procFilePath).toUtf8(); + // We might encounter the situation that protocol is given IPv6 + // but the consumer of the free port information decides to open + // an IPv4(only) port. As a result the next IPv6 scan will + // report the port again as open (in IPv6 namespace), while the + // same port in IPv4 namespace might still be blocked, and + // re-use of this port fails. + // GDBserver behaves exactly like this. + + Q_UNUSED(protocol) + + // /proc/net/tcp* covers /proc/net/tcp and /proc/net/tcp6 + return "sed -e 's/.*: [[:xdigit:]]*:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' /proc/net/tcp*"; } QList<int> usedPorts(const QByteArray &output) const { QList<int> ports; QList<QByteArray> portStrings = output.split('\n'); - portStrings.removeFirst(); foreach (const QByteArray &portString, portStrings) { - if (portString.isEmpty()) + if (portString.size() != 4) continue; bool ok; const int port = portString.toInt(&ok, 16); |