Added network utils
This commit is contained in:
22
DbNetworkLib.pro
Normal file
22
DbNetworkLib.pro
Normal file
@ -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)
|
9
dbnetworklib_global.h
Normal file
9
dbnetworklib_global.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#if defined(DBNETWORKLIB_LIBRARY)
|
||||||
|
# define DBNETWORKLIB_EXPORT Q_DECL_EXPORT
|
||||||
|
#else
|
||||||
|
# define DBNETWORKLIB_EXPORT Q_DECL_IMPORT
|
||||||
|
#endif
|
20
utils/netutils.cpp
Normal file
20
utils/netutils.cpp
Normal 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
utils/netutils.h
Normal file
7
utils/netutils.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "dbnetworklib_global.h"
|
||||||
|
|
||||||
|
#include <QHostAddress>
|
||||||
|
|
||||||
|
QHostAddress DBNETWORKLIB_EXPORT parseHostAddress(const QString &hostAddress);
|
Reference in New Issue
Block a user