Files
qt-creator/tests/manual/utils/tcpportsgatherer/main.cpp

37 lines
1.1 KiB
C++
Raw Normal View History

#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;
}