2012-02-28 12:13:04 +01:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <utils/tcpportsgatherer.h>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "Used TCP Ports (IP4):";
|
|
|
|
|
|
2013-03-20 12:48:11 +01:00
|
|
|
TcpPortsGatherer portsGatherer;
|
|
|
|
|
portsGatherer.update(QAbstractSocket::IPv4Protocol);
|
|
|
|
|
qDebug() << portsGatherer.usedPorts();
|
2012-02-28 12:13:04 +01:00
|
|
|
|
|
|
|
|
qDebug() << "Used TCP Ports (IP6):";
|
2013-03-20 12:48:11 +01:00
|
|
|
portsGatherer.update(QAbstractSocket::IPv6Protocol);
|
|
|
|
|
qDebug() << portsGatherer.usedPorts();
|
2012-02-28 12:13:04 +01:00
|
|
|
|
|
|
|
|
qDebug() << "All Used TCP Ports:";
|
2013-03-20 12:48:11 +01:00
|
|
|
portsGatherer.update(QAbstractSocket::UnknownNetworkLayerProtocol);
|
|
|
|
|
qDebug() << portsGatherer.usedPorts();
|
2012-02-28 12:13:04 +01:00
|
|
|
|
|
|
|
|
qDebug() << "Getting a few ports ...";
|
2013-02-25 19:10:16 +01:00
|
|
|
PortList portList = PortList::fromString(QLatin1String("10000-10100"));
|
2012-02-28 12:13:04 +01:00
|
|
|
QStringList ports;
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
2013-03-20 12:48:11 +01:00
|
|
|
quint16 port = portsGatherer.getNextFreePort(&portList);
|
|
|
|
|
Q_ASSERT(!portsGatherer.usedPorts().contains(port));
|
2012-02-28 12:13:04 +01:00
|
|
|
Q_ASSERT(port >= 10000);
|
|
|
|
|
Q_ASSERT(port < 10100);
|
|
|
|
|
QString portStr = QString::number(port);
|
|
|
|
|
Q_ASSERT(!ports.contains(portStr));
|
|
|
|
|
ports.append(QString::number(port));
|
|
|
|
|
}
|
2013-02-25 19:10:16 +01:00
|
|
|
qDebug() << ports.join(QLatin1String(", "));
|
2012-02-28 12:13:04 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|