/* * network.cpp * * Created on: 28.01.2013 * Author: sr */ #include "network.h" #include #include #include 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 list(QNetworkInterface::allAddresses()); return interfaceAddressesToString(list); } QString interfaceAddressesToString(const QList& list) { QString ret; ret.reserve(500); for (QList::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); } }