forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -123,27 +123,26 @@ class LinuxPortsGatheringMethod : public PortsGatheringMethod
|
|||||||
{
|
{
|
||||||
QByteArray commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const
|
QByteArray commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const
|
||||||
{
|
{
|
||||||
QString procFilePath;
|
// We might encounter the situation that protocol is given IPv6
|
||||||
int addressLength;
|
// but the consumer of the free port information decides to open
|
||||||
if (protocol == QAbstractSocket::IPv4Protocol) {
|
// an IPv4(only) port. As a result the next IPv6 scan will
|
||||||
procFilePath = QLatin1String("/proc/net/tcp");
|
// report the port again as open (in IPv6 namespace), while the
|
||||||
addressLength = 8;
|
// same port in IPv4 namespace might still be blocked, and
|
||||||
} else {
|
// re-use of this port fails.
|
||||||
procFilePath = QLatin1String("/proc/net/tcp6");
|
// GDBserver behaves exactly like this.
|
||||||
addressLength = 32;
|
|
||||||
}
|
Q_UNUSED(protocol)
|
||||||
return QString::fromLatin1("sed "
|
|
||||||
"'s/.*: [[:xdigit:]]\\{%1\\}:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' %2")
|
// /proc/net/tcp* covers /proc/net/tcp and /proc/net/tcp6
|
||||||
.arg(addressLength).arg(procFilePath).toUtf8();
|
return "sed -e 's/.*: [[:xdigit:]]*:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' /proc/net/tcp*";
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<int> usedPorts(const QByteArray &output) const
|
QList<int> usedPorts(const QByteArray &output) const
|
||||||
{
|
{
|
||||||
QList<int> ports;
|
QList<int> ports;
|
||||||
QList<QByteArray> portStrings = output.split('\n');
|
QList<QByteArray> portStrings = output.split('\n');
|
||||||
portStrings.removeFirst();
|
|
||||||
foreach (const QByteArray &portString, portStrings) {
|
foreach (const QByteArray &portString, portStrings) {
|
||||||
if (portString.isEmpty())
|
if (portString.size() != 4)
|
||||||
continue;
|
continue;
|
||||||
bool ok;
|
bool ok;
|
||||||
const int port = portString.toInt(&ok, 16);
|
const int port = portString.toInt(&ok, 16);
|
||||||
|
Reference in New Issue
Block a user