mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +08:00
refs #185 , added checks for IPs
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
#include <QtNetwork/QNetworkInterface>
|
#include <QtNetwork/QNetworkInterface>
|
||||||
#include <QtNetwork/QTcpSocket>
|
#include <QtNetwork/QTcpSocket>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QHostAddress>
|
||||||
|
#include <QAbstractSocket>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -82,4 +84,33 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
return CNetworkChecks::canConnect(server.getAddress(), server.getPort(), message, timeoutMs);
|
return CNetworkChecks::canConnect(server.getAddress(), server.getPort(), message, timeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Valid IPv4 address
|
||||||
|
*/
|
||||||
|
bool CNetworkChecks::isValidIPv4Address(const QString &candidate)
|
||||||
|
{
|
||||||
|
QHostAddress address(candidate);
|
||||||
|
return (QAbstractSocket::IPv4Protocol == address.protocol());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Valid IPv6 address
|
||||||
|
*/
|
||||||
|
bool CNetworkChecks::isValidIPv6Address(const QString &candidate)
|
||||||
|
{
|
||||||
|
QHostAddress address(candidate);
|
||||||
|
return (QAbstractSocket::IPv6Protocol == address.protocol());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Valid port?
|
||||||
|
*/
|
||||||
|
bool CNetworkChecks::isValidPort(const QString &port)
|
||||||
|
{
|
||||||
|
bool success;
|
||||||
|
int p = port.toInt(&success);
|
||||||
|
if (!success) return false;
|
||||||
|
return (p >= 1 && p <= 65535);
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -50,6 +50,15 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
static bool canConnect(const BlackMisc::Network::CServer &server, QString &message, int timeoutMs = 1500);
|
static bool canConnect(const BlackMisc::Network::CServer &server, QString &message, int timeoutMs = 1500);
|
||||||
|
|
||||||
|
//! \brief Valid IPv4 address
|
||||||
|
static bool isValidIPv4Address(const QString &candidate);
|
||||||
|
|
||||||
|
//! \brief Valid IPv6 address
|
||||||
|
static bool isValidIPv6Address(const QString &candidate);
|
||||||
|
|
||||||
|
//! \brief Valid port
|
||||||
|
static bool isValidPort(const QString &port);
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user