diff --git a/DbNetworkLib.pro b/DbNetworkLib.pro new file mode 100644 index 0000000..dba492e --- /dev/null +++ b/DbNetworkLib.pro @@ -0,0 +1,22 @@ +QT += core network +QT -= gui widgets + +PROJECT_ROOT = ../.. + +TARGET = dbnetwork + +DEFINES += DBNETWORKLIB_LIBRARY + +SOURCES += \ + utils/netutils.cpp + +HEADERS += dbnetworklib_global.h \ + utils/netutils.h + +FORMS += + +RESOURCES += + +TRANSLATIONS += + +include($${PROJECT_ROOT}/lib.pri) diff --git a/dbnetworklib_global.h b/dbnetworklib_global.h new file mode 100644 index 0000000..6b93f85 --- /dev/null +++ b/dbnetworklib_global.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +#if defined(DBNETWORKLIB_LIBRARY) +# define DBNETWORKLIB_EXPORT Q_DECL_EXPORT +#else +# define DBNETWORKLIB_EXPORT Q_DECL_IMPORT +#endif diff --git a/utils/netutils.cpp b/utils/netutils.cpp new file mode 100644 index 0000000..555e4bd --- /dev/null +++ b/utils/netutils.cpp @@ -0,0 +1,20 @@ +#include "netutils.h" + +QHostAddress parseHostAddress(const QString &hostAddress) +{ + static const QMap 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); +} diff --git a/utils/netutils.h b/utils/netutils.h new file mode 100644 index 0000000..280f131 --- /dev/null +++ b/utils/netutils.h @@ -0,0 +1,7 @@ +#pragma once + +#include "dbnetworklib_global.h" + +#include + +QHostAddress DBNETWORKLIB_EXPORT parseHostAddress(const QString &hostAddress);