void PSK_Reporter::dnsLookupResult(QHostInfo info)
{
    if (!info.addresses().isEmpty()) {
        m_pskReporterAddress = info.addresses().at(0);
//        qDebug() << "PSK Reporter IP: " << m_pskReporterAddress;
    }
}
Exemple #2
1
int QHostInfoProto::lookupId() const
{
    QHostInfo *item = qscriptvalue_cast<QHostInfo*>(thisObject());
    if (item)
        return item->lookupId();
    return 0;
}
// the QHostInfoLookupManager will at some point call this via a QThreadPool
void QHostInfoRunnable::run()
{
    QHostInfoLookupManager *manager = theHostInfoLookupManager();
    // check aborted
    if (manager->wasAborted(id)) {
        manager->lookupFinished(this);
        return;
    }

    // check cache
    // FIXME

    // if not in cache: OS lookup
    QHostInfo hostInfo = QHostInfoAgent::fromName(toBeLookedUp);

    // save to cache
    // FIXME

    // check aborted again
    if (manager->wasAborted(id)) {
        manager->lookupFinished(this);
        return;
    }

    // signal emission
    hostInfo.setLookupId(id);
    resultEmitter.emitResultsReady(hostInfo);

    manager->lookupFinished(this);

    // thread goes back to QThreadPool
}
Exemple #4
0
const SipInfo
SipInfo::fromJson( QString json )
{
    SipInfo info;

    QJson::Parser parser;
    bool ok;
    QVariant v = parser.parse( json.toAscii(), &ok );
    if ( !ok  || v.type() != QVariant::Map )
    {
        qDebug() << Q_FUNC_INFO << "Invalid JSON: " << json;
        return info;
    }
    QVariantMap m = v.toMap();

    info.setVisible( m["visible"].toBool() );
    if( m["visible"].toBool() )
    {
        QHostInfo hostInfo;
        hostInfo.setHostName( m["host"].toString() );
        info.setHost( hostInfo );
        info.setPort( m["port"].toInt() );
        info.setUniqname( m["uniqname"].toString() );
        info.setKey( m["key"].toString() );
    }

    return info;
}
Exemple #5
0
QString QHostInfoProto::hostName() const
{
    QHostInfo *item = qscriptvalue_cast<QHostInfo*>(thisObject());
    if (item)
        return item->hostName();
    return QString();
}
Exemple #6
0
QList<QHostAddress> QHostInfoProto::addresses() const
{
    QHostInfo *item = qscriptvalue_cast<QHostInfo*>(thisObject());
    if (item)
        return item->addresses();
    return QList<QHostAddress>();
}
Exemple #7
0
QHostInfo::HostInfoError QHostInfoProto::error() const
{
    QHostInfo *item = qscriptvalue_cast<QHostInfo*>(thisObject());
    if (item)
        return item->error();
    return QHostInfo::NoError;
}
Exemple #8
0
void SlaveInterfacePrivate::slotHostInfo(const QHostInfo &info)
{
    QByteArray data;
    QDataStream stream(&data, QIODevice::WriteOnly);
    stream <<  info.hostName() << info.addresses() << info.error() << info.errorString();
    connection->send(CMD_HOST_INFO, data);
}
/**
 *  \brief connect to host
 *  \return true on success
 */
bool MythSocket::ConnectToHost(const QString &host, quint16 port)
{
    QHostAddress hadr;

    // attempt direct assignment
    if (!hadr.setAddress(host))
    {
        // attempt internal lookup through MythCoreContext
        if (!gCoreContext ||
            !hadr.setAddress(gCoreContext->GetBackendServerIP(host)))
        {
            // attempt external lookup from hosts/DNS
            QHostInfo info = QHostInfo::fromName(host);
            if (!info.addresses().isEmpty())
            {
                hadr = info.addresses().first();
            }
            else
            {
                LOG(VB_GENERAL, LOG_ERR, LOC + QString("Unable to lookup: %1")
                        .arg(host));
                return false;
            }
        }
    }

    return MythSocket::ConnectToHost(hadr, port);
}
Exemple #10
0
void Dialog::createHost() {
    createHostDialog = new QDialog();
    createHostDialog->setWindowTitle("正在等待客户端加入");
    createHostDialog->setFixedSize(300, 200);
    
    QString localHostName = QHostInfo::localHostName();
    QHostInfo info = QHostInfo::fromName(localHostName);
    foreach(QHostAddress address, info.addresses())
        if(address.protocol() == QAbstractSocket::IPv4Protocol) {
            qDebug() << address.toString();
            QStringList list = address.toString().split(".");
            if (list[0] == "127")// || list[0] == "10")
                continue;
            myIP = address.toString();
            break;
        }
    QLabel *IPLabel = new QLabel("Host IP: ", createHostDialog);
    IPEdit = new QLineEdit(myIP, createHostDialog);
    cancelWaitButton = new QPushButton("取消", createHostDialog);
    OKWaitButton = new QPushButton("连接", createHostDialog);
    QVBoxLayout *vt = new QVBoxLayout(createHostDialog);
    QHBoxLayout *ht = new QHBoxLayout();
    QHBoxLayout *ht2 = new QHBoxLayout();
    vt->addLayout(ht);
    vt->addLayout(ht2);
    ht->addWidget(IPLabel, 0, Qt::AlignHCenter);
    ht->addWidget(IPEdit, 0, Qt::AlignHCenter);
    ht2->addWidget(OKWaitButton, 0, Qt::AlignHCenter);
    ht2->addWidget(cancelWaitButton, 0, Qt::AlignHCenter);
    createHostDialog->show();
    
    connect(OKWaitButton, SIGNAL(clicked(bool)), this, SLOT(waitForConnect()));
    connect(cancelWaitButton, SIGNAL(clicked(bool)), this, SLOT(cancelCreateHost()));

}
QString ConnectionTester::Private::localIpAddress() const
{
    QHostInfo hostInfo = QHostInfo::fromName(QHostInfo::localHostName());
    QList<QHostAddress> hostNameLookupAddressList = hostInfo.addresses();
    QList<QHostAddress> interfaceAddressList = QNetworkInterface::allAddresses();

    //qDebug()<<__FUNCTION__<<"hostName lookup addresses:"<<hostNameLookupAddressList;
    //qDebug()<<__FUNCTION__<<"interface addresses:"<<interfaceAddressList;

    QHostAddress hostIp;
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)

    foreach (QHostAddress addr, hostNameLookupAddressList)
    {
        if (addr.protocol() == QAbstractSocket::IPv4Protocol && interfaceAddressList.contains(addr))
        {
            if (NetworkHelper::isLocalIpAddress(addr))
            {
                //qDebug() << __FUNCTION__ << addr << " is local ip";
                hostIp = addr;
                break;
            }
            else if (NetworkHelper::isLinkLocalAddress(addr))
            {
                //qDebug() << __FUNCTION__ << addr << " is Link Local Address";
                hostIp = addr;
            }
            else
            {
                //qDebug() << __FUNCTION__ << addr << "is some different address";
            }
        }
    }

#else

    foreach (const QHostAddress &addr, interfaceAddressList)
    {
        if (addr.protocol() != QAbstractSocket::IPv4Protocol)
        {
            interfaceAddressList.removeAll(addr);
        }

        if (addr.toString().startsWith("127."))
        {
            interfaceAddressList.removeAll(addr);
        }
    }

    if (!interfaceAddressList.empty())
    {
        hostIp = interfaceAddressList.first();
    }

    //qDebug() << "Hope" << hostIp << "is a local ip";

#endif

    return hostIp.toString();
}
Exemple #12
0
bool ProviderUdp::init(const QJsonObject &deviceConfig, std::string defaultHost)
{
	LedDevice::init(deviceConfig);

	QString host = deviceConfig["host"].toString(QString::fromStdString(defaultHost));
	
	if (_address.setAddress(host) )
	{
		Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].toString().toStdString().c_str());
	}
	else
	{
		Debug( _log, "Failed to parse %s as an ip address.", deviceConfig["host"].toString().toStdString().c_str());
		QHostInfo info = QHostInfo::fromName(host);
		if (info.addresses().isEmpty())
		{
			Debug( _log, "Failed to parse %s as a hostname.", deviceConfig["host"].toString().toStdString().c_str());
			throw std::runtime_error("invalid target address");
		}
		Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].toString().toStdString().c_str());
		_address = info.addresses().first();
	}

	_port = deviceConfig["port"].toInt(_port);
	if ( _port<=0 || _port > 65535)
	{
		throw std::runtime_error("invalid target port");
	}
	
	Debug( _log, "UDP using %s:%d", _address.toString().toStdString().c_str() , _port );
	
	_LatchTime_ns = deviceConfig["latchtime"].toInt(_LatchTime_ns);

	return true;
}
Exemple #13
0
        QString DccCommon::getOwnIp( Server* server )
        {
            QString ownIp;
            int methodId = Preferences::self()->dccMethodToGetOwnIp();

            if ( methodId == 1 && server )
            {
                // by the WELCOME message or the USERHOST message from the server
                ownIp = server->getOwnIpByServerMessage();
            }
            else if ( methodId == 2 && !Preferences::self()->dccSpecificOwnIp().isEmpty() )
            {
                // manual
                QHostInfo res = QHostInfo::fromName(Preferences::self()->dccSpecificOwnIp());
                if(res.error() == QHostInfo::NoError && !res.addresses().isEmpty())
                {
                    ownIp = res.addresses().first().toString();
                }
            }

            // fallback or methodId == 0 (network interface)
            if ( ownIp.isEmpty() && server )
            {
                ownIp = server->getOwnIpByNetworkInterface();
            }

            kDebug() << ownIp;
            return ownIp;
        }
Exemple #14
0
void NetClient::connectToServer(const QString &hostName, qint16 port,
                                HostIdentifierType identType)
{
    QHostAddress address;
    if (identType == HostName)
    {
        QHostInfo host = QHostInfo::fromName(hostName);
        if (host.error() != QHostInfo::NoError)
        {
            qDebug() << host.errorString();
            return;
        }
        else
        {
            address = host.addresses().first();
        }
    }
    else
    {
        if (!address.setAddress(hostName))
        {
            qDebug() << "Setting address failed" << endl;
            return;
        }
    }

    tcpSocket->connectToHost(address, port);
}
Exemple #15
0
void MainWidget::hostLookuped(QHostInfo hostInfo)
{
    m_v4Addr.clear();
    m_v6Addr.clear();

    qDebug() << "ipV6 addresses:";
    for( auto address: hostInfo.addresses()){
        if( address.protocol() == QAbstractSocket::IPv6Protocol ){
            qDebug() << "  " << address;
            m_v6Addr = address;
            break;
        }
    }
    qDebug() << "ipV4 addresses:";
    for( auto address: hostInfo.addresses()){
        if( address.protocol() == QAbstractSocket::IPv4Protocol ){
            qDebug() << "  " << address;
            m_v4Addr = address;
            break;
        }
    }

    if(! m_v6Addr.isNull()){
        QUrl url;
        url.setScheme("http");
        url.setHost(m_v6Addr.toString());
        qDebug() << "request to " << url;

        connect(m_naman,SIGNAL(finished(QNetworkReply*)),
                this,SLOT(replyFinishedV6(QNetworkReply*)));
        m_naman->get(QNetworkRequest(url));
    }
ControlConnection::ControlConnection( Servent* parent, const QString &ha )
    : Connection( parent )
    , m_dbsyncconn( 0 )
    , m_registered( false )
    , m_pingtimer( 0 )
{
    qDebug() << "CTOR controlconnection";
    setId("ControlConnection()");

    // auto delete when connection closes:
    connect( this, SIGNAL( finished() ), SLOT( deleteLater() ) );

    this->setMsgProcessorModeIn( MsgProcessor::UNCOMPRESS_ALL | MsgProcessor::PARSE_JSON );
    this->setMsgProcessorModeOut( MsgProcessor::COMPRESS_IF_LARGE );

    if ( !ha.isEmpty() )
    {
        QHostAddress qha( ha );
        if ( !qha.isNull() )
            m_peerIpAddress = qha;
        else
        {
            QHostInfo qhi = QHostInfo::fromName( ha );
            if ( !qhi.addresses().isEmpty() )
                m_peerIpAddress = qhi.addresses().first();
        }
    }
}
Exemple #17
0
QString Funcoes::IP_LocalHost()
{

    QHostInfo info = QHostInfo::fromName( QHostInfo::localHostName() );
    QString retorno, IPs;
    QList<QHostAddress> l = info.addresses();
    int qtd = l.count();

    for(int i = 0; i < qtd; ++i)
    {
        QString tempIp = l[i].toString();
        if(tempIp != "127.0.0.1" && tempIp != "127.0.1.1")
        {
            IPs+= tempIp;
            break;
        }
    }
//    QNetworkAddressEntry endereco;
//    QHostAddress ip;
//    QNetworkInterface iface;
//    //iface = QNetworkInterface::interfaceFromName(  iface.name() );
//            QList<QNetworkAddressEntry> entries = iface.addressEntries();
//            if (!entries.isEmpty())
//            {
//                    QNetworkAddressEntry entry = entries.first();
//                    ip = entry.ip();
//            }

    retorno = IPs;
    return retorno;
}
void RemoteControlDialog::updateIPlabel(bool running)
{
	if (running)
	{
		QString localHostName=QHostInfo::localHostName();
		QHostInfo hostInfo = QHostInfo::fromName(localHostName);
		QString ipString("");
		for (auto a : hostInfo.addresses())
		{
			if ((a.protocol() == QAbstractSocket::IPv4Protocol) && a != QHostAddress(QHostAddress::LocalHost))
			{
				ipString += a.toString() + " ";
				continue;
			}
		}
		ui->label_RemoteRunningState->setText(q_("Listening on %1, IP: ").arg(localHostName) + ipString);
		ui->label_RemoteRunningState->show();
	}
	else
	{
		ui->label_RemoteRunningState->setText(q_("Not active."));
		// Maybe even hide the label?
		ui->label_RemoteRunningState->hide();
	}
}
Exemple #19
0
/*!
    Looks up the IP address(es) associated with host name \a name, and
    returns an ID for the lookup. When the result of the lookup is
    ready, the slot or signal \a member in \a receiver is called with
    a QHostInfo argument. The QHostInfo object can then be inspected
    to get the results of the lookup.

    The lookup is performed by a single function call, for example:

    \snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 2

    The implementation of the slot prints basic information about the
    addresses returned by the lookup, or reports an error if it failed:

    \snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 3

    If you pass a literal IP address to \a name instead of a host name,
    QHostInfo will search for the domain name for the IP (i.e., QHostInfo will
    perform a \e reverse lookup). On success, the resulting QHostInfo will
    contain both the resolved domain name and IP addresses for the host
    name. Example:

    \snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 4

    \note There is no guarantee on the order the signals will be emitted
    if you start multiple requests with lookupHost().

    \sa abortHostLookup(), addresses(), error(), fromName()
*/
int QHostInfo::lookupHost(const QString &name, QObject *receiver,
                          const char *member)
{
#if defined QHOSTINFO_DEBUG
    qDebug("QHostInfo::lookupHost(\"%s\", %p, %s)",
           name.toLatin1().constData(), receiver, member ? member + 1 : 0);
#endif

    if (!QAbstractEventDispatcher::instance(QThread::currentThread())) {
        qWarning("QHostInfo::lookupHost() called with no event dispatcher");
        return -1;
    }

    qRegisterMetaType<QHostInfo>("QHostInfo");

    int id = theIdCounter.fetchAndAddRelaxed(1); // generate unique ID

    if (name.isEmpty()) {
        if (!receiver)
            return -1;

        QHostInfo hostInfo(id);
        hostInfo.setError(QHostInfo::HostNotFound);
        hostInfo.setErrorString(QCoreApplication::translate("QHostInfo", "No host name given"));
        QScopedPointer<QHostInfoResult> result(new QHostInfoResult);
        QObject::connect(result.data(), SIGNAL(resultsReady(QHostInfo)),
                         receiver, member, Qt::QueuedConnection);
        result.data()->emitResultsReady(hostInfo);
        return id;
    }

    QHostInfoLookupManager *manager = theHostInfoLookupManager();

    if (manager) {
        // the application is still alive
        if (manager->cache.isEnabled()) {
            // check cache first
            bool valid = false;
            QHostInfo info = manager->cache.get(name, &valid);
            if (valid) {
                if (!receiver)
                    return -1;

                info.setLookupId(id);
                QHostInfoResult result;
                QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection);
                result.emitResultsReady(info);
                return id;
            }
        }

        // cache is not enabled or it was not in the cache, do normal lookup
        QHostInfoRunnable* runnable = new QHostInfoRunnable(name, id);
        if (receiver)
            QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection);
        manager->scheduleLookup(runnable);
    }

    return id;
}
bool NetworkConnectorEngine::performDNSLookup(QHostAddress* aAddressToBeSet,
        const QString& aFromDnsName,
        bool aDoWeHaveIpv6 ) {
    bool isAddressSet = false ;
    QHostInfo info = QHostInfo::fromName(aFromDnsName) ;
    if ( info.error() == QHostInfo::NoError ) {
        bool isAddressSet ( false ) ;
        // check for ipv6 addr if we have one
        if ( aDoWeHaveIpv6 ) {
            foreach ( const QHostAddress& result,
                      info.addresses() ) {
                if ( result.protocol() == QAbstractSocket::IPv6Protocol ) {
                    isAddressSet = true ;
                    aAddressToBeSet->setAddress(result.toIPv6Address()) ;
                    break  ;
                }
            }
        }
        if ( isAddressSet == false ) {
            foreach ( const QHostAddress& result,
                      info.addresses() ) {
                if ( result.protocol() == QAbstractSocket::IPv4Protocol ) {
                    isAddressSet = true ;
                    aAddressToBeSet->setAddress(result.toIPv4Address()) ;
                    break  ;
                }
            }
        }
QList<QHostAddress> LimitedSocket::performResolve(QString host, bool bPreferIPv6)
{
	QHostInfo info = QHostInfo::fromName(host);
	QList<QHostAddress> addresses, ip4, ip6;
	
	addresses = info.addresses();
	
	if(info.error() != QHostInfo::NoError)
		throw info.errorString();
	
	foreach(QHostAddress addr, addresses)
	{
		if(addr.protocol() == QAbstractSocket::IPv6Protocol)
			ip6 << addr;
		else if(addr.protocol() == QAbstractSocket::IPv4Protocol)
			ip4 << addr;
	}
	
	addresses.clear();
	
	if(bPreferIPv6)
		addresses << ip6 << ip4;
	else
		addresses << ip4 << ip6;
	
	return addresses;
}
Exemple #22
0
// Отправка измененных данных в главное окно
void serverEdit::on_save_clicked() {
    qInfo() << "serverEdit::on_save_clicked: Send start";

    // Создаем экземпляр класса favServer
    favServer server;
    // Заполняем его информацией из виджетов..
    //..параметров сервера
    server.serverName = ui->serverName->text();
    server.serverIP = ui->serverIP->text();
    server.serverPort = ui->serverPort->text();
    server.serverPass = ui->serverPassword->text();
    server.check_name = ui->name_check->isChecked();
    server.name = ui->name->currentText();

    //..Конвертируем Url в IP
    //..проверяем, IP ли это
    bool isIP = true;
    int pointCount = 0;
    int numberCount = 0;
    for(int i = 0; i< server.serverIP.size();i++) {
        if(server.serverIP[i].isNumber()) {
            isIP = true;
            numberCount++;
        } else if (server.serverIP[i] == '.') {
            isIP = true;
            pointCount++;
        } else {
            isIP = false;
            break;
        }
    }
    // Если это IP - проверяем его корректность
    if(isIP) { //127.0.0.1
        if(pointCount < 3 || numberCount <4 || numberCount > 12) {
            QMessageBox::warning(this,tr("Внимание!"), tr("Некорректный IP адресс сервера.\nВведите правильный IP сервера или его Url.\nПример: \"127.0.0.1\", \"example.server.com\"\nТип ошибки: IP Adress INCORRECT"), QMessageBox::Ok);
            qInfo() << "serverEdit::on_save_clicked: IP Adress INCORRECT";
            return;
        }
    // Если это Url - конвертируем в IP
    } else {
        QHostInfo info = QHostInfo::fromName(server.serverIP);
        if(info.errorString() == "Unknown error") {
            server.serverIP = info.addresses()[0].toString();
        } else {
            QMessageBox::warning(this,tr("Внимание!"), tr("Некорректный адресс сервера.\nВведите правильный IP сервера или его Url.\nПример: \"127.0.0.1\", \"example.server.com\"\nТип ошибки: ")+info.errorString(), QMessageBox::Ok);
            qInfo() << "serverEdit::on_save_clicked: " << info.errorString();
            return;
        }
    }

    //..активированных аддонов
    for(int i = 0;i<ui->addonTree->topLevelItemCount();i++)
        if(ui->addonTree->topLevelItem(i)->checkState(0) == Qt::Checked)
            server.serverAddons.append(ui->addonTree->topLevelItem(i)->text(2) + "/" +ui->addonTree->topLevelItem(i)->text(1));

    // Передаем экземпляр в сигнал
    emit sendData(server, newServ);
    this->close();
}
void MusicNetworkThread::networkStateChanged()
{
    bool block = M_SETTING->value(MusicSettingManager::CloseNetWorkChoiced).toBool();
    QHostInfo info = QHostInfo::fromName(NETWORK_REQUEST_ADDRESS);
    m_networkState = !info.addresses().isEmpty();
    m_networkState = block ? false : m_networkState;
    emit networkConnectionStateChanged(m_networkState);
}
Exemple #24
0
void Connection::onServerAddressLookedUp(const QHostInfo &host)
{
    if (host.error() == QHostInfo::NoError) {
        testAddressLatency(host.addresses().first());
    } else {
        onLatencyAvailable(SQProfile::LATENCY_ERROR);
    }
}
Exemple #25
0
void Network::lookedUp(const QHostInfo &host)
{
    if (host.error() != QHostInfo::NoError) {
        qDebug() << "Lookup failed:" << host.errorString();
        return;
    }
    _serverAddr = host.addresses().at(0);
}
Exemple #26
0
// ----------------------------------------------------------------------------
// getHostAddress (static)
// ----------------------------------------------------------------------------
QHostAddress NetworkTools::getHostAddress(const QHostInfo &in_host_info)
{
    if (in_host_info.lookupId() == -1) return QHostAddress();
    if (in_host_info.error() != QHostInfo::NoError) return QHostAddress();
    if (in_host_info.addresses().isEmpty()) return QHostAddress();

    return in_host_info.addresses().first();
}
void Connection::onServerAddressLookedUp(const QHostInfo &host)
{
    if (host.error() == QHostInfo::NoError) {
        testAddressLatency(host.addresses().first());
    } else {
        onLatencyTestFinished(-2);
    }
}
Exemple #28
0
// the QHostInfoLookupManager will at some point call this via a QThreadPool
void QHostInfoRunnable::run()
{
    QHostInfoLookupManager *manager = theHostInfoLookupManager();
    // check aborted
    if (manager->wasAborted(id)) {
        manager->lookupFinished(this);
        return;
    }

    QHostInfo hostInfo;

    // QHostInfo::lookupHost already checks the cache. However we need to check
    // it here too because it might have been cache saved by another QHostInfoRunnable
    // in the meanwhile while this QHostInfoRunnable was scheduled but not running
    if (manager->cache.isEnabled()) {
        // check the cache first
        bool valid = false;
        hostInfo = manager->cache.get(toBeLookedUp, &valid);
        if (!valid) {
            // not in cache, we need to do the lookup and store the result in the cache
            hostInfo = QHostInfoAgent::fromName(toBeLookedUp);
            manager->cache.put(toBeLookedUp, hostInfo);
        }
    } else {
        // cache is not enabled, just do the lookup and continue
        hostInfo = QHostInfoAgent::fromName(toBeLookedUp);
    }

    // check aborted again
    if (manager->wasAborted(id)) {
        manager->lookupFinished(this);
        return;
    }

    // signal emission
    hostInfo.setLookupId(id);
    resultEmitter.emitResultsReady(hostInfo);

    // now also iterate through the postponed ones
    {
        QMutexLocker locker(&manager->mutex);
        QMutableListIterator<QHostInfoRunnable*> iterator(manager->postponedLookups);
        while (iterator.hasNext()) {
            QHostInfoRunnable* postponed = iterator.next();
            if (toBeLookedUp == postponed->toBeLookedUp) {
                // we can now emit
                iterator.remove();
                hostInfo.setLookupId(postponed->id);
                postponed->resultEmitter.emitResultsReady(hostInfo);
                delete postponed;
            }
        }
    }

    manager->lookupFinished(this);

    // thread goes back to QThreadPool
}
Exemple #29
0
QString Server::addressLookup( const QString& address )
{
    QHostInfo info = QHostInfo::fromName( address );

    if( !info.addresses().isEmpty() )
        return info.addresses().first().toString(); // there should be only one address
    else
        return QString();
}
Exemple #30
0
 Q_SLOT void lookupResult(const QHostInfo & host) {
    m_timer.stop();
    if (host.error() != QHostInfo::NoError)
       return hasResult(Error);
    for (auto ifAddr : QNetworkInterface::allAddresses())
       if (host.addresses().contains(ifAddr))
          return hasResult(Local);
    return hasResult(NonLocal);
 }