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; }
QHostInfo::HostInfoError QHostInfoProto::error() const { QHostInfo *item = qscriptvalue_cast<QHostInfo*>(thisObject()); if (item) return item->error(); return QHostInfo::NoError; }
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; }
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); }
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 ; } } }
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); }
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; }
// ---------------------------------------------------------------------------- // 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); } }
void Network::lookedUp(const QHostInfo &host) { if (host.error() != QHostInfo::NoError) { qDebug() << "Lookup failed:" << host.errorString(); return; } _serverAddr = host.addresses().at(0); }
void Connection::onServerAddressLookedUp(const QHostInfo &host) { if (host.error() == QHostInfo::NoError) { testAddressLatency(host.addresses().first()); } else { onLatencyAvailable(SQProfile::LATENCY_ERROR); } }
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); }
void Address::onLookUpFinished(const QHostInfo &host) { if (host.error() != QHostInfo::NoError) { emit lookedUp(false, host.errorString()); } else { ipAddrList = host.addresses(); emit lookedUp(true, QString()); } }
void ServerInfo::reverselookUp(const QHostInfo &host) { qDebug() << __PRETTY_FUNCTION__ << " called ..."; if (host.error() != QHostInfo::NoError) { qDebug() << "Lookup failed:" << host.errorString(); return; } }
void In2SaiControl::lookedUp(const QHostInfo & host){ if (host.error() != QHostInfo::NoError) { qDebug() << "Lookup failed:" << host.errorString(); return; } foreach (const QHostAddress &address, host.addresses()) qDebug() << "Found address:" << address.toString(); }
void WeatherWorker::networkLookedUp(const QHostInfo &host) { if(host.error() != QHostInfo::NoError) { //qDebug() << "test network failed, errorCode:" << host.error(); emit this->nofityNetworkStatus(host.errorString()); } else { //qDebug() << "test network success, the server's ip:" << host.addresses().first().toString(); emit this->nofityNetworkStatus("OK"); } }
void MainWindow::finishedLookup(QHostInfo info) { if(info.error()) { serverView->append(info.errorString()); } else { serverView->append("Connecting..."); sock.connectToHost(info.addresses().first(), ui->portEdit->text().toInt()); } }
void NtpApp::sltLookupReceived(QHostInfo host) { if (host.error() != QHostInfo::NoError) { qDebug() << "Lookup failed:" << host.errorString(); return; } foreach (const QHostAddress &address, host.addresses()) qDebug() << "Found address:" << address.toString(); HostInfo = host; }
void servers_widget::lookedUP(const QHostInfo& hi) { gbxNS->setEnabled(true); if (hi.error() == QHostInfo::NoError && !hi.addresses().empty()) { m_smodel->addServer(last_server_name, libed2k::net_identifier(hi.addresses().at(0).toIPv4Address(), last_server_port)); } last_server_name.clear(); last_server_port = 0; }
void CertWizard::lookedUp(QHostInfo info) { bPendingDns = false; if (info.error() == QHostInfo::NoError) { bValidDomain = true; qlError->setText(QString()); qwpNew->setComplete(true); next(); } else { bValidDomain = false; qlError->setText(tr("Unable to resolve domain.")); qwpNew->setComplete(false); } }
void QHostInfoCache::put(const QString &name, const QHostInfo &info) { // if the lookup failed, don't cache if (info.error() != QHostInfo::NoError) return; QHostInfoCacheElement* element = new QHostInfoCacheElement(); element->info = info; element->age = QElapsedTimer(); element->age.start(); QMutexLocker locker(&this->mutex); cache.insert(name, element); // cache will take ownership }
void BonjourServiceResolver::finishConnect( const QHostInfo& hostInfo ) { if(hostInfo.error() == QHostInfo::NoError) { Q_EMIT bonjourRecordResolved(hostInfo, d->bonjourPort); } else { Q_EMIT error(3); } cleanupResolve(); Q_EMIT bonjourResolverReady(); }
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(); }
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); } }
void QamUdpSocket::lookupHost(const QHostInfo& hostInfo ) { if ( hostInfo.error() != QHostInfo::NoError ) { emit sockInfo( QString("host not found!") ) ; return ; } QList<QHostAddress> addresses = hostInfo.addresses() ; if ( addresses.first().toString() == "::1" ) // loopback IPv6 setAddress(addresses.at(1) ) ; // 127.0.0.1 else setAddress(addresses.first() ) ; m_hostResolved = true ; }
void MainWindow::PrintConnectionInfo(const QHostInfo &hostInfo, int port) { const QList<QHostAddress> &addresses = hostInfo.addresses(); if (hostInfo.error() != QHostInfo::NoError) { qWarning("Lookup failed: %s", hostInfo.errorString().toAscii().constData()); return; } if (!addresses.isEmpty()) { QHostAddress address = addresses.first(); qDebug() << "Connect: " << address.toString() << " Port: " << port << endl; } }
void AutorizationWindows::on_server_editingFinished() { QHostInfo hostInfo = QHostInfo::fromName(ui->server->text()); QPalette palette; if (hostInfo.error() != QHostInfo::NoError) { palette.setColor(QPalette::Text,Qt::red); ui->server->setPalette(palette); isServer = false; ui->connect->setEnabled(false); } if(hostInfo.error() == QHostInfo::NoError) { palette.setColor(QPalette::Text,Qt::black); ui->server->setPalette(palette); server = hostInfo.addresses().first(); ui->server->setPlaceholderText(server.toString()); qDebug()<<server.toString(); isServer = true; if(port>100) ui->connect->setEnabled(true); } }
QScriptValue NetworkAutomaticProxy::dnsResolve(QScriptContext *context, QScriptEngine *engine) { if (context->argumentCount() != 1) { return context->throwError(QLatin1String("Function dnsResolve takes only one argument!")); } const QHostInfo host = QHostInfo::fromName(context->argument(0).toString()); if (host.error() == QHostInfo::NoError) { return host.addresses().first().toString(); } return engine->undefinedValue(); }
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); } }
void WebView::load(const LoadRequest &request) { const QUrl reqUrl = request.url(); if (reqUrl.isEmpty()) return; if (reqUrl.scheme() == QL1S("javascript")) { const QString scriptSource = reqUrl.toString().mid(11); // Is the javascript source percent encoded or not? // Looking for % character in source should work in most cases if (scriptSource.contains(QL1C('%'))) page()->runJavaScript(QUrl::fromPercentEncoding(scriptSource.toUtf8())); else page()->runJavaScript(scriptSource); return; } if (isUrlValid(reqUrl)) { loadRequest(request); return; } // Make sure to correctly load hosts like localhost (eg. without the dot) if (!reqUrl.isEmpty() && reqUrl.scheme().isEmpty() && !QzTools::containsSpace(reqUrl.path()) && // See #1622 !reqUrl.path().contains(QL1C('.')) ) { QUrl u(QSL("http://") + reqUrl.path()); if (u.isValid()) { // This is blocking... QHostInfo info = QHostInfo::fromName(u.path()); if (info.error() == QHostInfo::NoError) { LoadRequest req = request; req.setUrl(u); loadRequest(req); return; } } } if (qzSettings->searchFromAddressBar) { const LoadRequest searchRequest = mApp->searchEnginesManager()->searchResult(request.urlString()); loadRequest(searchRequest); } }