Exemplo n.º 1
0
void ImageProcessing::checkNetwork()
{
	bool running = false;
	QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();

	qWarning() << __FUNCTION__ << ": Running the network check";
	if (pNextImage->isActive()) {
		qWarning() << __FUNCTION__ << ": Turning off image display timer";
		pNextImage->stop();
	}
	for (int i = 0; i < interfaces.size(); i++) {
		QNetworkInterface ni = interfaces[i];
		if (ni.name() != "wlan0")
			continue;

		qWarning() << __FUNCTION__ << ": Checking interface" << ni.name() << " with flags" << ni.flags();

		if (ni.flags().testFlag(QNetworkInterface::IsUp) && ni.flags().testFlag(QNetworkInterface::IsRunning)) {
			running = true;
			getContentList();
		}
	}
	if (!running) {
		qWarning() << __FUNCTION__ << ": Network check didn't find an available interface";
		showLocalImage();
	}
}
Exemplo n.º 2
0
/**
 * @brief wavrNetwork::getNetworkAddressEntry
 * @param pAddressEntry Gets the address entries from network interface and fills in this variable.
 * @return Returns true opon success.
 *  Gets the address entries from network interface whether IPV4 or IPV6 and fills the data in pAddressEntry.
 */
bool wavrNetwork::getNetworkAddressEntry(QNetworkAddressEntry* pAddressEntry) {
    //	get the first active network interface
    QNetworkInterface networkInterface;

    if(getNetworkInterface(&networkInterface)) {
        wavrTrace::write("Querying IP address from network interface...");

        //	get a list of all associated ip addresses of the interface
        QList<QNetworkAddressEntry> addressEntries = networkInterface.addressEntries();
        //	return the first address which is an ipv4 address
        for(int index = 0; index < addressEntries.count(); index++) {
            if(addressEntries[index].ip().protocol() == QAbstractSocket::IPv4Protocol) {
                *pAddressEntry = addressEntries[index];
                this->networkInterface = networkInterface;
                this->interfaceName = networkInterface.name();
                wavrTrace::write("IPv4 address found for network interface.");
                return true;
            }
        }
        // if ipv4 address is not present, check for ipv6 address
        for(int index = 0; index < addressEntries.count(); index++) {
            if(addressEntries[index].ip().protocol() == QAbstractSocket::IPv6Protocol) {
                *pAddressEntry = addressEntries[index];
                this->networkInterface = networkInterface;
                this->interfaceName = networkInterface.name();
                wavrTrace::write("IPv6 address found for network interface.");
                return true;
            }
        }

        wavrTrace::write("Warning: No IP address found for network interface.");
    }

    return false;
}
Exemplo n.º 3
0
OceanSocket::OceanSocket(QObject *parent) :
    QObject(parent)
{
    // setup the heartbeat timer
    heartbeat = new QTimer(this);
    connect(heartbeat, SIGNAL(timeout()), this, SLOT(heartbeatTimer()));

    // setup our ocean sockets
    groupAddress = QHostAddress(MULTICAST_ADDRESS);

    QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
    for (int i = 0; i < ifaces.count(); i++) {
        QNetworkInterface iface = ifaces.at(i);
        if (iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack) && iface.flags().testFlag(QNetworkInterface::CanMulticast)) {
            for (int j = 0; j < iface.addressEntries().count(); j++) {
                if (iface.addressEntries().at(j).ip().protocol() != QAbstractSocket::IPv4Protocol) continue;
                qDebug() << "Ocean bind to iface: " << iface.name() << endl << "IP: " << iface.addressEntries().at(j).ip().toString() << endl;
                QUdpSocket* socket = new QUdpSocket(this);
                socket->bind(QHostAddress::AnyIPv4, 8047, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
                socket->joinMulticastGroup(groupAddress, iface);
                connect(socket, SIGNAL(readyRead()), this, SLOT(processIncomingWaves()));
                boundAddresses.append(iface.addressEntries().at(j).ip());
                multicastSockets.append(socket);
            }
        }
    }

    sendSocket = new QUdpSocket(this);
    sendSocket->bind();
}
Exemplo n.º 4
0
   // Set up bind address combobox
 foreach (const QNetworkInterface &netif, QNetworkInterface::allInterfaces())
 {
   const QString &hname = netif.name();
   foreach (const QNetworkAddressEntry &netaddr, netif.addressEntries())
   {
     const QHostAddress &addr = netaddr.ip();
     if (addr.protocol() == QAbstractSocket::IPv4Protocol)
     {
       QString item_text(addr.toString() + " (" + hname + ")");
       settings_dialog.bind_address->addItem(item_text, addr.toString());
     }
   }
 }
Exemplo n.º 5
0
int PortControler::findNameInPcap(QNetworkInterface &network)
{
    QString networkName = network.name();
    int i = 0;
    for ( currDev = allDevs; currDev != nullptr; currDev = currDev->next )
    {
        QString intName = currDev->name;
        if ( intName.contains( networkName ) )
        {
           return i;
        }
        ++i;
    }
    return -1;
}
Exemplo n.º 6
0
void QGenericEngine::doRequestUpdate()
{
#ifndef QT_NO_NETWORKINTERFACE
    QMutexLocker locker(&mutex);

    // Immediately after connecting with a wireless access point
    // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a
    // second time results in a non-empty list. If we loose interfaces we will end up removing
    // network configurations which will break current sessions.
    QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
    if (interfaces.isEmpty())
        interfaces = QNetworkInterface::allInterfaces();

    QStringList previous = accessPointConfigurations.keys();

    // create configuration for each interface
    while (!interfaces.isEmpty()) {
        QNetworkInterface interface = interfaces.takeFirst();

        if (!interface.isValid())
            continue;

        // ignore loopback interface
        if (interface.flags() & QNetworkInterface::IsLoopBack)
            continue;

        // ignore WLAN interface handled in separate engine
        if (qGetInterfaceType(interface.name()) == QNetworkConfiguration::BearerWLAN)
            continue;

        uint identifier;
        if (interface.index())
            identifier = qHash(QLatin1String("generic:") + QString::number(interface.index()));
        else
            identifier = qHash(QLatin1String("generic:") + interface.hardwareAddress());

        const QString id = QString::number(identifier);

        previous.removeAll(id);

        QString name = interface.humanReadableName();
        if (name.isEmpty())
            name = interface.name();

        QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined;
        if((interface.flags() & QNetworkInterface::IsUp) && !interface.addressEntries().isEmpty())
            state |= QNetworkConfiguration::Active;

        if (accessPointConfigurations.contains(id)) {
            QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);

            bool changed = false;

            ptr->mutex.lock();

            if (!ptr->isValid) {
                ptr->isValid = true;
                changed = true;
            }

            if (ptr->name != name) {
                ptr->name = name;
                changed = true;
            }

            if (ptr->id != id) {
                ptr->id = id;
                changed = true;
            }

            if (ptr->state != state) {
                ptr->state = state;
                changed = true;
            }

            ptr->mutex.unlock();

            if (changed) {
                locker.unlock();
                emit configurationChanged(ptr);
                locker.relock();
            }
        } else {
            QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);

            ptr->name = name;
            ptr->isValid = true;
            ptr->id = id;
            ptr->state = state;
            ptr->type = QNetworkConfiguration::InternetAccessPoint;
            ptr->bearerType = qGetInterfaceType(interface.name());

            accessPointConfigurations.insert(id, ptr);
            configurationInterface.insert(id, interface.name());

            locker.unlock();
            emit configurationAdded(ptr);
            locker.relock();
        }
    }

    while (!previous.isEmpty()) {
        QNetworkConfigurationPrivatePointer ptr =
            accessPointConfigurations.take(previous.takeFirst());

        configurationInterface.remove(ptr->id);

        locker.unlock();
        emit configurationRemoved(ptr);
        locker.relock();
    }

    locker.unlock();
#endif

    emit updateCompleted();
}
Exemplo n.º 7
0
void QAndroidBearerEngine::updateConfigurations()
{
#ifndef QT_NO_NETWORKINTERFACE
    if (m_connectivityManager == 0)
        return;

    {
        QMutexLocker locker(&mutex);
        QStringList oldKeys = accessPointConfigurations.keys();

        QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
        if (interfaces.isEmpty())
            interfaces = QNetworkInterface::allInterfaces();

        // Create a configuration for each of the main types (WiFi, Mobile, Bluetooth, WiMax, Ethernet)
        foreach (const AndroidNetworkInfo &netInfo, m_connectivityManager->getAllNetworkInfo()) {

            if (!netInfo.isValid())
                continue;

            const QString name = networkConfType(netInfo);
            if (name.isEmpty())
                continue;

            QNetworkConfiguration::BearerType bearerType = getBearerType(netInfo);

            QString interfaceName;
            QNetworkConfiguration::StateFlag state = QNetworkConfiguration::Defined;
            if (netInfo.isAvailable()) {
                if (netInfo.isConnected()) {
                    // Attempt to map an interface to this configuration
                    while (!interfaces.isEmpty()) {
                        QNetworkInterface interface = interfaces.takeFirst();
                        // ignore loopback interface
                        if (!interface.isValid())
                            continue;

                        if (interface.flags() & QNetworkInterface::IsLoopBack)
                            continue;
                        // There is no way to get the interface from the NetworkInfo, so
                        // look for an active interface...
                        if (interface.flags() & QNetworkInterface::IsRunning
                                && !interface.addressEntries().isEmpty()) {
                            state = QNetworkConfiguration::Active;
                            interfaceName = interface.name();
                            break;
                        }
                    }
                }
            }

            const QString key = QString(QLatin1String("android:%1:%2")).arg(name).arg(interfaceName);
            const QString id = QString::number(qHash(key));
            m_configurationInterface[id] = interfaceName;

            oldKeys.removeAll(id);
            if (accessPointConfigurations.contains(id)) {
                QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
                bool changed = false;
                {
                    const QMutexLocker confLocker(&ptr->mutex);

                    if (!ptr->isValid) {
                        ptr->isValid = true;
                        changed = true;
                    }

                    // Don't reset the bearer type to 'Unknown'
                    if (ptr->bearerType != QNetworkConfiguration::BearerUnknown
                            && ptr->bearerType != bearerType) {
                        ptr->bearerType = bearerType;
                        changed = true;
                    }

                    if (ptr->name != name) {
                        ptr->name = name;
                        changed = true;
                    }

                    if (ptr->id != id) {
                        ptr->id = id;
                        changed = true;
                    }

                    if (ptr->state != state) {
                        ptr->state = state;
                        changed = true;
                    }
                } // Unlock configuration

                if (changed) {
                    locker.unlock();
                    Q_EMIT configurationChanged(ptr);
                    locker.relock();
                }
            } else {
                QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);
                ptr->name = name;
                ptr->isValid = true;
                ptr->id = id;
                ptr->state = state;
                ptr->type = QNetworkConfiguration::InternetAccessPoint;
                ptr->bearerType = bearerType;
                accessPointConfigurations.insert(id, ptr);
                locker.unlock();
                Q_EMIT configurationAdded(ptr);
                locker.relock();
            }
        }

        while (!oldKeys.isEmpty()) {
            QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(oldKeys.takeFirst());
            m_configurationInterface.remove(ptr->id);
            locker.unlock();
            Q_EMIT configurationRemoved(ptr);
            locker.relock();
        }

    } // Unlock engine

#endif // QT_NO_NETWORKINTERFACE

    Q_EMIT updateCompleted();
}