Pool Video Switch v2
Software video switch for distributed remote display in a lecture environment
network.cpp
Go to the documentation of this file.
1 /*
2  * network.cpp
3  *
4  * Created on: 28.01.2013
5  * Author: sr
6  */
7 
8 #include "network.h"
9 #include <QNetworkInterface>
10 #include <QHostAddress>
11 #include <QList>
12 
13 namespace Network
14 {
15 
16 
23 {
24  QList<QHostAddress> list(QNetworkInterface::allAddresses());
25  return interfaceAddressesToString(list);
26 }
27 
28 QString interfaceAddressesToString(const QList<QHostAddress>& list)
29 {
30  QString ret;
31  ret.reserve(500);
32  for (QList<QHostAddress>::const_iterator it(list.begin()); it != list.end(); ++it) {
33  if (*it == QHostAddress::LocalHost || *it == QHostAddress::LocalHostIPv6)
34  continue; // TODO: Filter other addresses/ranges?
35  ret.append("|");
36  ret.append(it->toString());
37  }
38  ret.append("|");
39  return ret;
40 }
41 
42 bool isAddressInList(const QString& list, const QString& address)
43 {
44  static const QString find("|%1|");
45  return list.contains(find.arg(address), Qt::CaseSensitive);
46 }
47 
48 
49 }
bool isAddressInList(const QString &list, const QString &address)
Definition: network.cpp:42
QString interfaceAddressesToString()
Returns list of all addresses assigned to the interfaces of this machine.
Definition: network.cpp:22