Files
qt-creator/tests/manual/utils/tcpportsgatherer/main.cpp
Kai Koehne af205ab25d Add TcpPortsGatherer to utils
Can be used to check (non-intrusively) which TCP ports are still available.

Change-Id: I61300f6b7215cb2c0e4a3e6135de305cfd38b5a9
Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
Reviewed-by: hjk <qthjk@ovi.com>
2012-03-02 18:37:39 +01:00

37 lines
1.1 KiB
C++

#include <QCoreApplication>
#include <utils/tcpportsgatherer.h>
#include <QDebug>
#include <QStringList>
using namespace Utils;
int main()
{
qDebug() << "Used TCP Ports (IP4):";
TcpPortsGatherer ip4Ports(TcpPortsGatherer::IPv4Protocol);
qDebug() << ip4Ports.usedPorts().toString();
qDebug() << "Used TCP Ports (IP6):";
TcpPortsGatherer ip6Ports(TcpPortsGatherer::IPv6Protocol);
qDebug() << ip6Ports.usedPorts().toString();
qDebug() << "All Used TCP Ports:";
TcpPortsGatherer ipPorts(TcpPortsGatherer::AnyIPProcol);
qDebug() << ipPorts.usedPorts().toString();
qDebug() << "Getting a few ports ...";
PortList portList = PortList::fromString("10000-10100");
QStringList ports;
for (int i = 0; i < 10; ++i) {
quint16 port = ipPorts.getNextFreePort(&portList);
Q_ASSERT(!ipPorts.usedPorts().contains(port));
Q_ASSERT(port >= 10000);
Q_ASSERT(port < 10100);
QString portStr = QString::number(port);
Q_ASSERT(!ports.contains(portStr));
ports.append(QString::number(port));
}
qDebug() << ports.join(", ");
return 0;
}