Added network utils

This commit is contained in:
Daniel Brunner
2018-09-17 20:25:41 +02:00
parent 5ff56978fb
commit ad8a80ac9b
4 changed files with 58 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
#include "netutils.h"
QHostAddress parseHostAddress(const QString &hostAddress)
{
static const QMap<QString, QHostAddress> specialHostAddresses {
{ QStringLiteral("QHostAddress::Null"), QHostAddress::Null },
{ QStringLiteral("QHostAddress::Broadcast"), QHostAddress::Broadcast },
{ QStringLiteral("QHostAddress::LocalHost"), QHostAddress::LocalHost },
{ QStringLiteral("QHostAddress::LocalHostIPv6"), QHostAddress::LocalHostIPv6 },
{ QStringLiteral("QHostAddress::Any"), QHostAddress::Any },
{ QStringLiteral("QHostAddress::AnyIPv6"), QHostAddress::AnyIPv6 },
{ QStringLiteral("QHostAddress::AnyIPv4"), QHostAddress::AnyIPv4 }
};
const auto iter = specialHostAddresses.find(hostAddress);
if(iter != specialHostAddresses.constEnd())
return *iter;
return QHostAddress(hostAddress);
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#include "dbnetworklib_global.h"
#include <QHostAddress>
QHostAddress DBNETWORKLIB_EXPORT parseHostAddress(const QString &hostAddress);