void ScriptEngine::hostInfo_Ready(const QHostInfo &myInfo)
{
    QScriptValue myVal = myHostLookups.take(myInfo.lookupId());
    if(myVal.isString()) {
        QString info = myInfo.hostName();
        eval("var name = '"+info+"';"+myVal.toString());
    } else {
        if(myVal.isFunction()) {
            QScriptValueList arguments;
            arguments << QString(myInfo.hostName());
            myVal.call(QScriptValue(), arguments);
        }
    }
}
Example #2
0
void DNSHandler::resultsReady(QHostInfo hostInfo)
{
	kdebugf();
//	kdebugm(KDEBUG_WARNING, "resultsReady>>>>>>>>>>%s\n", qPrintable(marker));

	if (hostInfo.hostName().isEmpty())
		emit result(marker, QString::null);
	else
		emit result(marker, hostInfo.hostName());
		

	deleteLater();
	kdebugf2();
}
Example #3
0
  void ExitTunnel::TcpDnsLookupFinished(const QHostInfo &host_info)
  {
    TcpPendingDnsData value = _tcp_pending_dns[host_info.lookupId()];
    _tcp_pending_dns.remove(host_info.lookupId());

    bool okay = (host_info.error() == QHostInfo::NoError) && host_info.addresses().count();

    qDebug() << "SOCKS hostname" << host_info.hostName() << "resolved:" << okay;
    if(okay && _table.ContainsConnection(value.socket)) {
      qDebug() << "SOCKS connecting to hostname" << host_info.hostName();
      value.socket->connectToHost(host_info.addresses()[0], value.port);
    } else {
      qDebug() << "SOCKS aborting failed or closed connection:" << host_info.hostName();
      //CloseSocket(value.socket);
    }
  }
Example #4
0
static QScriptValue qhostinfo_fromName(QScriptContext *context, QScriptEngine *engine)
{
    QHostInfo obj;
    QScriptValue scriptlist = engine->newObject();

    if (context->argumentCount() == 1 && context->argument(0).isString()) {
        obj = QHostInfo::fromName(context->argument(0).toString());
        QScriptValue addressList = engine->newObject();
        QList<QHostAddress> qlist = obj.addresses();
        for (int i = 0; i < qlist.size(); i += 1) {
            addressList.setProperty(i, qlist[i].toString());
        }
        scriptlist.setProperty("addresses",   addressList);
        scriptlist.setProperty("error",       obj.error());
        if (obj.error() > 0) {
            scriptlist.setProperty("errorString", obj.errorString());
        }
        else {
            scriptlist.setProperty("errorString", "No Error");
        }
        scriptlist.setProperty("hostName",    obj.hostName());
        scriptlist.setProperty("lookupId",    obj.lookupId());
    }

    return scriptlist;
}
Example #5
0
QString QHostInfoProto::hostName() const
{
    QHostInfo *item = qscriptvalue_cast<QHostInfo*>(thisObject());
    if (item)
        return item->hostName();
    return QString();
}
Example #6
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);
}
void
ControlConnection::setup()
{
    qDebug() << Q_FUNC_INFO << id() << name();

    if ( !m_source.isNull() )
    {
        qDebug() << "This source seems to be online already.";
        Q_ASSERT( false );
        return;
    }

    QString friendlyName;
    if ( Servent::isIPWhitelisted( m_sock->peerAddress() ) )
    {
        // FIXME TODO blocking DNS lookup if LAN, slow/fails on windows?
        QHostInfo i = QHostInfo::fromName( m_sock->peerAddress().toString() );
        if( i.hostName().length() )
            friendlyName = i.hostName();
    }
    else
        friendlyName = name();

    tDebug() << "Detected name:" << name() << friendlyName << m_sock->peerAddress();

    // setup source and remote collection for this peer
    m_source = SourceList::instance()->get( id(), friendlyName );
    m_source->setControlConnection( this );

    // delay setting up collection/etc until source is synced.
    // we need it DB synced so it has an ID + exists in DB.
    connect( m_source.data(), SIGNAL( syncedWithDatabase() ),
                                SLOT( registerSource() ), Qt::QueuedConnection );

    m_source->setOnline();

    m_pingtimer = new QTimer;
    m_pingtimer->setInterval( 5000 );
    connect( m_pingtimer, SIGNAL( timeout() ), SLOT( onPingTimer() ) );
    m_pingtimer->start();
    m_pingtimer_mark.start();
}
void IPNetworkClientWidget::lookupFinished(QHostInfo info)
{
    if (info.error() != QHostInfo::NoError) {
        emit log(info.errorString(), "", Pip3lineConst::LERROR);
    } else { // success populating the combobox, at this point the list shoud not be empty ...
        QList<QHostAddress> list = info.addresses();
        if (list.isEmpty()) {
            qCritical() << "[NetworkClientWidget::lookupFinished] returned adress list is empty T_T";
            return;
        }

        for (int i = 0; i < list.size(); i++) {
            ui->hostResolvComboBox->addItem(list.at(i).toString());
        }
        ui->hostResolvComboBox->setCurrentIndex(0);
        ui->hostResolvComboBox->setDisabled(false);
        listener->setHostAddress(list.at(0));
        listener->setHostname(info.hostName());
        emit newSNI(info.hostName());
    }
}
Example #9
0
void TabbedWebView::setIp(const QHostInfo &info)
{
    if (info.addresses().isEmpty()) {
        return;
    }

    m_currentIp = info.hostName() + " (" + info.addresses().at(0).toString() + ")";

    if (isCurrent()) {
        emit ipChanged(m_currentIp);
    }
}
Example #10
0
void ChatClient::_q_hostInfoFinished(const QHostInfo &hostInfo)
{
    if (hostInfo.addresses().isEmpty()) {
        warning(QString("Could not lookup TURN server %1").arg(hostInfo.hostName()));
        return;
    }

    QXmppCallManager *callManager = findExtension<QXmppCallManager>();
    if (callManager) {
        callManager->setTurnServer(hostInfo.addresses().first(), d->turnPort);
        callManager->setTurnUser(configuration().user());
        callManager->setTurnPassword(configuration().password());
    }
}
Example #11
0
void ConnectPage::hostResponse(const QHostInfo &hostInfo)
{
    if (hostInfo.error() != QHostInfo::NoError)
        return;

    if(hostInfo.addresses().empty())
        return;

    m_currentUrl.setHost(hostInfo.hostName());
    m_valid = true;
    ui->host->setPalette(this->style()->standardPalette());
    emit dnsResolved();
    emit updateButtonState();
}
Example #12
0
  void ExitTunnel::UdpDnsLookupFinished(const QHostInfo &host_info)
  {
    UdpPendingDnsData value = _udp_pending_dns[host_info.lookupId()];
    _udp_pending_dns.remove(host_info.lookupId());

    bool okay = (host_info.error() == QHostInfo::NoError) && host_info.addresses().count();

    qDebug() << "SOCKS UDP hostname" << host_info.hostName() << "resolved:" << okay;
    if(okay && _table.ContainsConnection(value.socket)) {
      qDebug() << "SOCKS Write data" << value.datagram.count();
      value.socket->writeDatagram(value.datagram, host_info.addresses()[0], value.port);
    } else {
      CloseSocket(value.socket);
    }
  }
Example #13
0
void ReverseResolution::hostResolved(const QHostInfo &host)
{
    const QString ip = m_lookups.take(host.lookupId());
    Q_ASSERT(!ip.isNull());

    if (host.error() != QHostInfo::NoError) {
        qDebug() << "DNS Reverse resolution error: " << host.errorString();
        return;
    }

    const QString hostname = host.hostName();

    qDebug() << Q_FUNC_INFO << ip << QString("->") << hostname;
    m_cache.insert(ip, new QString(hostname));
    if (isUsefulHostName(hostname, ip))
        emit ipResolved(ip, hostname);
}
Example #14
0
void HifiSockAddr::handleLookupResult(const QHostInfo& hostInfo) {
    if (hostInfo.error() != QHostInfo::NoError) {
        qCDebug(networking) << "Lookup failed for" << hostInfo.lookupId() << ":" << hostInfo.errorString();
        emit lookupFailed();
    }

    foreach(const QHostAddress& address, hostInfo.addresses()) {
        // just take the first IPv4 address
        if (address.protocol() == QAbstractSocket::IPv4Protocol) {
            _address = address;
            qCDebug(networking) << "QHostInfo lookup result for"
                << hostInfo.hostName() << "with lookup ID" << hostInfo.lookupId() << "is" << address.toString();
            emit lookupCompleted();
            break;
        }
    }
}
Example #15
0
void cTelnet::handle_socket_signal_hostFound(QHostInfo hostInfo)
{
    if(!hostInfo.addresses().isEmpty())
    {
        mHostAddress = hostInfo.addresses().first();
        QString msg = "[ INFO ]  -  The IP address of "+hostName+" has been found. It is: "+mHostAddress.toString()+"\n";
        postMessage( msg );
        msg = "[ INFO ]  -  trying to connect to "+mHostAddress.toString()+":"+QString::number(hostPort)+" ...\n";
        postMessage( msg );
        socket.connectToHost(mHostAddress, hostPort);
    }
    else
    {
        socket.connectToHost(hostInfo.hostName(), hostPort);
        QString msg = "[ ERROR ] Host name lookup Failure! Connection cannot be established. The server name is not correct, not working properly, or your nameservers are not working properly.\n";
        postMessage( msg );
        return;
    }
}
Example #16
0
QHostInfo QHostInfoAgent::fromName(const QString &hostName)
{
    QHostInfo results;

#if defined(QHOSTINFO_DEBUG)
    qDebug("QHostInfoAgent::fromName(%s) looking up...",
           hostName.toLatin1().constData());
#endif

    // Load res_init on demand.
    static volatile bool triedResolve = false;
    if (!triedResolve) {
        QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_init));
        if (!triedResolve) {
            resolveLibrary();
            triedResolve = true;
        }
    }

    // If res_init is available, poll it.
    if (local_res_init)
        local_res_init();

    QHostAddress address;
    if (address.setAddress(hostName)) {
        // Reverse lookup
// Reverse lookups using getnameinfo are broken on darwin, use gethostbyaddr instead.
#if !defined (QT_NO_GETADDRINFO) && !defined (Q_OS_DARWIN)
        sockaddr_in sa4;
#ifndef QT_NO_IPV6
        sockaddr_in6 sa6;
#endif
        sockaddr *sa = 0;
        QT_SOCKLEN_T saSize = 0;
        if (address.protocol() == QAbstractSocket::IPv4Protocol) {
            sa = (sockaddr *)&sa4;
            saSize = sizeof(sa4);
            memset(&sa4, 0, sizeof(sa4));
            sa4.sin_family = AF_INET;
            sa4.sin_addr.s_addr = htonl(address.toIPv4Address());
        }
#ifndef QT_NO_IPV6
        else {
            sa = (sockaddr *)&sa6;
            saSize = sizeof(sa6);
            memset(&sa6, 0, sizeof(sa6));
            sa6.sin6_family = AF_INET6;
            memcpy(sa6.sin6_addr.s6_addr, address.toIPv6Address().c, sizeof(sa6.sin6_addr.s6_addr));
        }
#endif

        char hbuf[NI_MAXHOST];
        if (sa && getnameinfo(sa, saSize, hbuf, sizeof(hbuf), 0, 0, 0) == 0)
            results.setHostName(QString::fromLatin1(hbuf));
#else
        in_addr_t inetaddr = qt_safe_inet_addr(hostName.toLatin1().constData());
        struct hostent *ent = gethostbyaddr((const char *)&inetaddr, sizeof(inetaddr), AF_INET);
        if (ent)
            results.setHostName(QString::fromLatin1(ent->h_name));
#endif

        if (results.hostName().isEmpty())
            results.setHostName(address.toString());
        results.setAddresses(QList<QHostAddress>() << address);
        return results;
    }

    // IDN support
    QByteArray aceHostname = QUrl::toAce(hostName);
    results.setHostName(hostName);
    if (aceHostname.isEmpty()) {
        results.setError(QHostInfo::HostNotFound);
        results.setErrorString(hostName.isEmpty() ?
                               QCoreApplication::translate("QHostInfoAgent", "No host name given") :
                               QCoreApplication::translate("QHostInfoAgent", "Invalid hostname"));
        return results;
    }

#if !defined (QT_NO_GETADDRINFO)
    // Call getaddrinfo, and place all IPv4 addresses at the start and
    // the IPv6 addresses at the end of the address list in results.
    addrinfo *res = 0;
    struct addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = PF_UNSPEC;
#ifdef Q_ADDRCONFIG
    hints.ai_flags = Q_ADDRCONFIG;
#endif

    int result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
# ifdef Q_ADDRCONFIG
    if (result == EAI_BADFLAGS) {
        // if the lookup failed with AI_ADDRCONFIG set, try again without it
        hints.ai_flags = 0;
        result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
    }
# endif

    if (result == 0) {
        addrinfo *node = res;
        QList<QHostAddress> addresses;
        while (node) {
#ifdef QHOSTINFO_DEBUG
                qDebug() << "getaddrinfo node: flags:" << node->ai_flags << "family:" << node->ai_family << "ai_socktype:" << node->ai_socktype << "ai_protocol:" << node->ai_protocol << "ai_addrlen:" << node->ai_addrlen;
#endif
            if (node->ai_family == AF_INET) {
                QHostAddress addr;
                addr.setAddress(ntohl(((sockaddr_in *) node->ai_addr)->sin_addr.s_addr));
                if (!addresses.contains(addr))
                    addresses.append(addr);
            }
#ifndef QT_NO_IPV6
            else if (node->ai_family == AF_INET6) {
                QHostAddress addr;
                sockaddr_in6 *sa6 = (sockaddr_in6 *) node->ai_addr;
                addr.setAddress(sa6->sin6_addr.s6_addr);
                if (sa6->sin6_scope_id)
                    addr.setScopeId(QString::number(sa6->sin6_scope_id));
                if (!addresses.contains(addr))
                    addresses.append(addr);
            }
#endif
            node = node->ai_next;
        }
        if (addresses.isEmpty() && node == 0) {
            // Reached the end of the list, but no addresses were found; this
            // means the list contains one or more unknown address types.
            results.setError(QHostInfo::UnknownError);
            results.setErrorString(tr("Unknown address type"));
        }

        results.setAddresses(addresses);
        freeaddrinfo(res);
    } else if (result == EAI_NONAME
               || result ==  EAI_FAIL
#ifdef EAI_NODATA
	       // EAI_NODATA is deprecated in RFC 3493
	       || result == EAI_NODATA
#endif
	       ) {
        results.setError(QHostInfo::HostNotFound);
        results.setErrorString(tr("Host not found"));
    } else {
        results.setError(QHostInfo::UnknownError);
        results.setErrorString(QString::fromLocal8Bit(gai_strerror(result)));
    }

#else
    // Fall back to gethostbyname for platforms that don't define
    // getaddrinfo. gethostbyname does not support IPv6, and it's not
    // reentrant on all platforms. For now this is okay since we only
    // use one QHostInfoAgent, but if more agents are introduced, locking
    // must be provided.
    QMutexLocker locker(::getHostByNameMutex());
    hostent *result = gethostbyname(aceHostname.constData());
    if (result) {
        if (result->h_addrtype == AF_INET) {
            QList<QHostAddress> addresses;
            for (char **p = result->h_addr_list; *p != 0; p++) {
                QHostAddress addr;
                addr.setAddress(ntohl(*((quint32 *)*p)));
                if (!addresses.contains(addr))
                    addresses.prepend(addr);
            }
            results.setAddresses(addresses);
        } else {
            results.setError(QHostInfo::UnknownError);
            results.setErrorString(tr("Unknown address type"));
        }
#if !defined(Q_OS_VXWORKS)
    } else if (h_errno == HOST_NOT_FOUND || h_errno == NO_DATA
               || h_errno == NO_ADDRESS) {
        results.setError(QHostInfo::HostNotFound);
        results.setErrorString(tr("Host not found"));
#endif
    } else {
        results.setError(QHostInfo::UnknownError);
        results.setErrorString(tr("Unknown error"));
    }
#endif //  !defined (QT_NO_GETADDRINFO)

#if defined(QHOSTINFO_DEBUG)
    if (results.error() != QHostInfo::NoError) {
        qDebug("QHostInfoAgent::fromName(): error #%d %s",
               h_errno, results.errorString().toLatin1().constData());
    } else {
        QString tmp;
        QList<QHostAddress> addresses = results.addresses();
        for (int i = 0; i < addresses.count(); ++i) {
            if (i != 0) tmp += ", ";
            tmp += addresses.at(i).toString();
        }
        qDebug("QHostInfoAgent::fromName(): found %i entries for \"%s\": {%s}",
               addresses.count(), hostName.toLatin1().constData(),
               tmp.toLatin1().constData());
    }
#endif
    return results;
}
Example #17
0
void KviDnsResolver::slotHostLookupTerminated(const QHostInfo &oHostInfo)
{
	if(oHostInfo.error() != QHostInfo::NoError)
	{
		m_pPrivateData->eState = Failure;

		switch(oHostInfo.error())
		{
			case QHostInfo::HostNotFound:
				m_pPrivateData->eError = KviError::HostNotFound;
			break;
			default:
				m_pPrivateData->eError = KviError::DNSQueryFailed;
			break;
		}

		m_pPrivateData->szError = oHostInfo.errorString();

		emit lookupDone(this);

		return;
	}

	m_pPrivateData->szHostName = oHostInfo.hostName();

	QList<QHostAddress> lAddresses = oHostInfo.addresses();

	m_pPrivateData->pAddressList->clear();

	m_pPrivateData->eError = KviError::Success;
	m_pPrivateData->szError = QString();
	m_pPrivateData->eState = Success;

	foreach(QHostAddress oAddress,lAddresses)
	{
		switch(m_pPrivateData->eQueryType)
		{
			case IPv4:
				if(oAddress.protocol() == QAbstractSocket::IPv4Protocol)
					m_pPrivateData->pAddressList->append(new QString(oAddress.toString()));
			break;
			case IPv6:
				if(oAddress.protocol() == QAbstractSocket::IPv6Protocol)
					m_pPrivateData->pAddressList->append(new QString(oAddress.toString()));
			break;
			case Any:
				m_pPrivateData->pAddressList->append(new QString(oAddress.toString()));
			break;
			default:
				KVI_ASSERT_MSG(false,"Invalid DNS query type!");
				m_pPrivateData->eState = Failure;
				m_pPrivateData->eError = KviError::InternalError;
				m_pPrivateData->szError = __tr2qs("Internal error: unhandled DNS query type");
				emit lookupDone(this);
				return;
			break;
		}
	}

	if(m_pPrivateData->pAddressList->isEmpty())
	{
		m_pPrivateData->eState = Failure;
		m_pPrivateData->eError = KviError::ValidNameButNoIpAddress;
		m_pPrivateData->szError = __tr2qs("DNS query returned no IP address results of the requested type");
	}

	emit lookupDone(this);

}
Example #18
0
/*! Handles the response of an asynchronous DNS lookup on the user's IP address.
*/
void QwsClientSocket::handleHostLookupResult(QHostInfo hostInfo)
{
    qDebug() << "Received host lookup response:" << hostInfo.hostName();
    user.setClientHostName(hostInfo.hostName());
}
Example #19
0
void MainWindow::processDatagrams()
{

    const hdr_t  *request;

    do {
        qint64 sz = _udpSocket.pendingDatagramSize();
        Q_ASSERT(sz >= (qint64) sizeof(hdr_t));
        QByteArray      datagram(sz,0);
        QByteArray      rdatagram;
        QHostAddress    host;
        quint16         port;
        bool            res;

        Q_ASSERT(sz == _udpSocket.readDatagram(datagram.data(), datagram.size(), &host, &port));

        request = (hdr_t*) datagram.constData();
        Q_ASSERT(datagram.size() == request->pdusz);

        // _log << "Req:" << *request << endl;

        // skip respons messages
        if(request->cmdid >= RDSK_Response)
        {
           // _log << ", skip" << endl;
            continue;
        }

        QHostInfo hi = QHostInfo::fromName(host.toString());
        QString   hn(hi.hostName());
        QVariant var;
        CPMClient* client;
        QList<QTreeWidgetItem*> clientitem = ui->treeWidget->findItems(hn,Qt::MatchFixedString);


        if(clientitem.isEmpty())
        {
            client = new CPMClient(hn);
            connect(client,SIGNAL(adddrive(CPMClient*,CPMDrive*)),this,SLOT(adddrive(CPMClient*,CPMDrive*)));
            var.setValue(client);
            QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(hn));
            item->setData(0,Qt::UserRole, var);
            ui->treeWidget->addTopLevelItem(item);
        }
        else
        {
            var = clientitem.first()->data(0,Qt::UserRole);
        }

        client = qobject_cast<CPMClient*>(qvariant_cast<QObject*>(var));
        Q_ASSERT(client);

        res = client->req(*request, rdatagram);
        hdr_t  *response = (hdr_t*)rdatagram.data();


        if(!res)
            _log << "ERR:" << *response << endl;

        sz = _udpSocket.writeDatagram((const char*)response, (qint64)response->pdusz, host, port);
        if(_clientwidget)
            _clientwidget->update();
        Q_ASSERT( sz == response->pdusz);

    }while(_udpSocket.hasPendingDatagrams());
Example #20
0
QHostInfo QHostInfoAgent::fromName(const QString &hostName)
{
    QHostInfo results;

#if defined(QHOSTINFO_DEBUG)
    qDebug("QHostInfoAgent::fromName(%s) looking up...",
           hostName.toLatin1().constData());
#endif

    // Load res_init on demand.
    resolveLibrary();

    // If res_init is available, poll it.
    if (local_res_init)
        local_res_init();

    QHostAddress address;
    if (address.setAddress(hostName)) {
        // Reverse lookup
        sockaddr_in sa4;
        sockaddr_in6 sa6;
        sockaddr *sa = 0;
        QT_SOCKLEN_T saSize = 0;
        if (address.protocol() == QAbstractSocket::IPv4Protocol) {
            sa = (sockaddr *)&sa4;
            saSize = sizeof(sa4);
            memset(&sa4, 0, sizeof(sa4));
            sa4.sin_family = AF_INET;
            sa4.sin_addr.s_addr = htonl(address.toIPv4Address());
        }
        else {
            sa = (sockaddr *)&sa6;
            saSize = sizeof(sa6);
            memset(&sa6, 0, sizeof(sa6));
            sa6.sin6_family = AF_INET6;
            memcpy(sa6.sin6_addr.s6_addr, address.toIPv6Address().c, sizeof(sa6.sin6_addr.s6_addr));
        }

        char hbuf[NI_MAXHOST];
        if (sa && getnameinfo(sa, saSize, hbuf, sizeof(hbuf), 0, 0, 0) == 0)
            results.setHostName(QString::fromLatin1(hbuf));

        if (results.hostName().isEmpty())
            results.setHostName(address.toString());
        results.setAddresses(QList<QHostAddress>() << address);
        return results;
    }

    // IDN support
    QByteArray aceHostname = QUrl::toAce(hostName);
    results.setHostName(hostName);
    if (aceHostname.isEmpty()) {
        results.setError(QHostInfo::HostNotFound);
        results.setErrorString(hostName.isEmpty() ?
                               QCoreApplication::translate("QHostInfoAgent", "No host name given") :
                               QCoreApplication::translate("QHostInfoAgent", "Invalid hostname"));
        return results;
    }

    // Call getaddrinfo, and place all IPv4 addresses at the start and
    // the IPv6 addresses at the end of the address list in results.
    addrinfo *res = 0;
    struct addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = PF_UNSPEC;
#ifdef Q_ADDRCONFIG
    hints.ai_flags = Q_ADDRCONFIG;
#endif

    int result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
# ifdef Q_ADDRCONFIG
    if (result == EAI_BADFLAGS) {
        // if the lookup failed with AI_ADDRCONFIG set, try again without it
        hints.ai_flags = 0;
        result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
    }
# endif

    if (result == 0) {
        addrinfo *node = res;
        QList<QHostAddress> addresses;
        while (node) {
#ifdef QHOSTINFO_DEBUG
                qDebug() << "getaddrinfo node: flags:" << node->ai_flags << "family:" << node->ai_family << "ai_socktype:" << node->ai_socktype << "ai_protocol:" << node->ai_protocol << "ai_addrlen:" << node->ai_addrlen;
#endif
            if (node->ai_family == AF_INET) {
                QHostAddress addr;
                addr.setAddress(ntohl(((sockaddr_in *) node->ai_addr)->sin_addr.s_addr));
                if (!addresses.contains(addr))
                    addresses.append(addr);
            }
            else if (node->ai_family == AF_INET6) {
                QHostAddress addr;
                sockaddr_in6 *sa6 = (sockaddr_in6 *) node->ai_addr;
                addr.setAddress(sa6->sin6_addr.s6_addr);
                if (sa6->sin6_scope_id)
                    addr.setScopeId(QString::number(sa6->sin6_scope_id));
                if (!addresses.contains(addr))
                    addresses.append(addr);
            }
            node = node->ai_next;
        }
        if (addresses.isEmpty() && node == 0) {
            // Reached the end of the list, but no addresses were found; this
            // means the list contains one or more unknown address types.
            results.setError(QHostInfo::UnknownError);
            results.setErrorString(tr("Unknown address type"));
        }

        results.setAddresses(addresses);
        freeaddrinfo(res);
    } else if (result == EAI_NONAME
               || result ==  EAI_FAIL
#ifdef EAI_NODATA
               // EAI_NODATA is deprecated in RFC 3493
               || result == EAI_NODATA
#endif
               ) {
        results.setError(QHostInfo::HostNotFound);
        results.setErrorString(tr("Host not found"));
    } else {
        results.setError(QHostInfo::UnknownError);
        results.setErrorString(QString::fromLocal8Bit(gai_strerror(result)));
    }


#if defined(QHOSTINFO_DEBUG)
    if (results.error() != QHostInfo::NoError) {
        qDebug("QHostInfoAgent::fromName(): error #%d %s",
               h_errno, results.errorString().toLatin1().constData());
    } else {
        QString tmp;
        QList<QHostAddress> addresses = results.addresses();
        for (int i = 0; i < addresses.count(); ++i) {
            if (i != 0) tmp += ", ";
            tmp += addresses.at(i).toString();
        }
        qDebug("QHostInfoAgent::fromName(): found %i entries for \"%s\": {%s}",
               addresses.count(), hostName.toLatin1().constData(),
               tmp.toLatin1().constData());
    }
#endif
    return results;
}