#include "qgnetworkinterface.h" #include #include #include static QHostAddress qgHostAddress=QHostAddress::LocalHost; static QHostAddress qgBroadcastAddress=QHostAddress::LocalHost; static unsigned int adapter_index; static QHostAddress selectDefaultInterface() { QList hal=QNetworkInterface::allInterfaces(); if (hal.isEmpty()) { qDebug()<<"Network Config: NO HOST ADDRESSES"; return QHostAddress(); } else { foreach(QNetworkInterface nif, hal) { //QList nhal=nif.allAddresses(); QList nhal=nif.addressEntries(); foreach(QNetworkAddressEntry aentry, nhal) { QHostAddress a=aentry.ip(); if (a.toString().startsWith("192.168")) { adapter_index=nif.index(); return aentry.ip(); } } } foreach(QNetworkInterface nif, hal) { //QList nhal=nif.allAddresses(); QList nhal=nif.addressEntries(); foreach(QNetworkAddressEntry aentry, nhal) { QHostAddress a=aentry.ip(); if (a.toString().startsWith("169.254")) { adapter_index=nif.index(); return aentry.ip(); } } } return QHostAddress(); } } void QgNetworkInterface::setNetworkInterface(const QHostAddress& adr) { qgHostAddress=adr; quint32 ip=adr.toIPv4Address(); if (!adr.isLoopback()) ip|=255; qgBroadcastAddress=QHostAddress(ip); qDebug()<<"QgNetworkInterface:"<