diff options
author | sr | 2013-02-04 19:50:31 +0100 |
---|---|---|
committer | sr | 2013-02-04 19:50:31 +0100 |
commit | 1a5709501f94014d41987b956338bb6424b9f90c (patch) | |
tree | d3b93fe8dc406bca56aff147ef5cc4cbf9ed6be0 /src/shared/network.cpp | |
parent | Test (diff) | |
download | pvs2-1a5709501f94014d41987b956338bb6424b9f90c.tar.gz pvs2-1a5709501f94014d41987b956338bb6424b9f90c.tar.xz pvs2-1a5709501f94014d41987b956338bb6424b9f90c.zip |
Initial commit
Diffstat (limited to 'src/shared/network.cpp')
-rw-r--r-- | src/shared/network.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/shared/network.cpp b/src/shared/network.cpp new file mode 100644 index 0000000..6dd6a73 --- /dev/null +++ b/src/shared/network.cpp @@ -0,0 +1,50 @@ +/* + * network.cpp + * + * Created on: 28.01.2013 + * Author: sr + */ + +#include "network.h" +#include <QNetworkInterface> +#include <QHostAddress> +#include <QList> + +namespace Network +{ + + +/** + * Returns list of all addresses assigned to the interfaces of this machine. + * Every address is surrounded by '|', eg: + * |1.2.3.4|3.66.77.88|123:34::1| + */ +QString interfaceAddressesToString() +{ + QList<QHostAddress> list(QNetworkInterface::allAddresses()); + return interfaceAddressesToString(list); +} + +QString interfaceAddressesToString(const QList<QHostAddress>& list) +{ + QString ret; + ret.reserve(500); + for (QList<QHostAddress>::const_iterator it(list.begin()); it != list.end(); ++it) + { + if (*it == QHostAddress::LocalHost || *it == QHostAddress::LocalHostIPv6) + continue; // TODO: Filter other addresses/ranges? + ret.append("|"); + ret.append(it->toString()); + } + ret.append("|"); + return ret; +} + +bool isAddressInList(const QString& list, const QString& address) +{ + static const QString find("|%1|"); + return list.contains(find.arg(address), Qt::CaseSensitive); +} + + +} |