void PSK_Reporter::dnsLookupResult(QHostInfo info)
{
    if (!info.addresses().isEmpty()) {
        m_pskReporterAddress = info.addresses().at(0);
//        qDebug() << "PSK Reporter IP: " << m_pskReporterAddress;
    }
}
Example #2
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;
        }
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  ;
                }
            }
        }
Example #4
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;
}
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();
        }
    }
}
Example #6
0
/**
 *  \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);
}
Example #7
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));
    }
Example #8
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();
}
Example #9
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();
}
Example #10
0
void Host::setAddress (const QHostInfo &hostInfo)
{
    if (!hostInfo.addresses().isEmpty())
    {
        _address = hostInfo.addresses().first();
        foreach (Service *s, servicesList())
            s->update();
    }
}
Example #11
0
void xmppClient::slotHostInfoFinished(const QHostInfo &hostInfo)
{
    if (!hostInfo.addresses().isEmpty()) {
        info(QString("Found TURN server %1 port %2 for domain %3").arg(hostInfo.addresses().first().toString(), QString::number(m_turnPort), configuration().domain()));
        callManager->setTurnServer(hostInfo.addresses().first(), m_turnPort);
        callManager->setTurnUser(configuration().user());
        callManager->setTurnPassword(configuration().password());
    }
    m_turnFinished = true;
    startCall();
}
Example #12
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 #13
0
bool CTcpFetcher::bind(int targetPort){
    if (m_pTcpSocket->bind(targetPort)){
        QHostInfo hInfo = QHostInfo::fromName(m_targetHost);
        if (!hInfo.addresses().isEmpty()){
            foreach (QHostAddress addr, hInfo.addresses())
                qDebug() << " ADDRESS FOUND FOR HOST " << m_targetHost << " / " << addr.toString();
            qDebug () << " Will send to " << hInfo.addresses().first();
            m_pTcpSocket->connectToHost(hInfo.addresses().first(), targetPort);
            return connect(m_pTcpSocket, SIGNAL(readyRead()), this, SLOT(readyRead()) );
        }
    }else qDebug() << "Error in UDP DGram bind : " << m_pTcpSocket->errorString();
    return false;
}
Example #14
0
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;

}
Example #15
0
void GameSpyServer::query()
{
    QHostInfo ns = QHostInfo::fromName(m_sHost);
    if(!ns.addresses().isEmpty())
    {
        if(m_pUdpSocket->writeDatagram("\\basic\\\\info\\", 13,
            ns.addresses().first(), m_iPort) == -1)
        {
            emit errorEncountered(m_pUdpSocket->errorString());
        }
    }
    else
        emit errorEncountered(ns.errorString());
}
void slm_machine::L_addBuddyButtonPressed()
{
	//check if the alias and hostname or ip address is entered
	if(ui_addBuddyScreen->L_buddyAliasLine->text().isEmpty())
	{
		QMessageBox::warning(this,QString("No Alias!"),QString("Please Enter an Alias For The Buddy!"));

	}
	else if(ui_addBuddyScreen->L_buddyIPAddressLine->text().isEmpty() && ui_addBuddyScreen->L_buddyHostNameLine->text().isEmpty())
	{
		QMessageBox::warning(this,QString("No Host Name or IP Address!"),QString("Please Enter a Host Name or IP Address For The Buddy!"));
	}
	else if(!ui_addBuddyScreen->L_buddyIPAddressLine->text().isEmpty())
	{
		//validate the IP address
		if(!(this->IPAddressValidator(ui_addBuddyScreen->L_buddyIPAddressLine->text())))
		{
			QMessageBox::warning(this,QString("Wrong IP Address!"),QString("IP Address is not Valid!"));
		}
		else
		{
			buddies->AliasBuddyList.append(ui_addBuddyScreen->L_buddyAliasLine->text());
			buddyModel->setStringList(buddies->AliasBuddyList);
			ui->buddyList->setModel(buddyModel);

			buddies->IPBuddyList.append(ui_addBuddyScreen->L_buddyIPAddressLine->text());

                        addBuddyScreenDialog->close();
		}
	}
	else if(ui_addBuddyScreen->L_buddyIPAddressLine->text().isEmpty() && !ui_addBuddyScreen->L_buddyHostNameLine->text().isEmpty())
	{
		QHostInfo info = QHostInfo::fromName(ui_addBuddyScreen->L_buddyHostNameLine->text());

                //check if a valid host name is found
                if(info.addresses().isEmpty())
                {
                    QMessageBox::warning(this,QString("Host Error!"),QString("Host name cannot be found, you may try to enter buddy IP instead!"));
                }
                else
                {
                    buddies->AliasBuddyList.append(ui_addBuddyScreen->L_buddyAliasLine->text());
                    buddyModel->setStringList(buddies->AliasBuddyList);
                    ui->buddyList->setModel(buddyModel);

                    buddies->IPBuddyList.append(info.addresses().first().toString());
                    addBuddyScreenDialog->close();
                }
	}
}
Example #17
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 #18
0
void HostipRunner::slotLookupFinished(const QHostInfo &info)
{
    if ( !info.addresses().isEmpty() ) {
        m_hostInfo = info;
        QString hostAddress = info.addresses().first().toString();
        QString query = QString( "http://api.hostip.info/get_html.php?ip=%1&position=true" ).arg( hostAddress );
        m_request.setUrl( QUrl( query ) );

        // @todo FIXME Must currently be done in the main thread, see bug 257376
        QTimer::singleShot( 0, this, SLOT(get()) );
    }
    else
      slotNoResults();
}
Example #19
0
void InternalCoreConnection::adressResolved(QHostInfo hostInfo)
{
   this->currentHostLookupID = -1;

   if (hostInfo.addresses().isEmpty())
   {
      emit connectingError(ICoreConnection::ERROR_HOST_UNKOWN);
      return;
   }

   this->addressesToTry = hostInfo.addresses();

   this->tryToConnectToTheNextAddress();
}
Example #20
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);
    }
  }
void connection::dnsResults(QHostInfo info)
{
	if (info.addresses().count() > 0)
	{
		currentProxy.setHostName(info.addresses().at(0).toString());
	
		socket->setProxy(currentProxy);
                //QSettings settings(QSettings::defaultFormat(), QSettings::UserScope, "qutim/qutim."+m_profile_name, "icqsettings");
                QSettings settings(QSettings::defaultFormat(), QSettings::UserScope, "qutim/qutim."+m_profile_name+"/ICQ."+icqUin, "accountsettings");
		QString host = settings.value("connection/host", "login.icq.com").toString();
		quint16 port = settings.value("connection/port", 5190).toInt();
		connectedToBos = false;
		socket->connectToHost(host,port);
	}
}
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();
	}
}
Example #23
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 #24
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);
}
Example #25
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()));

}
Example #26
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);
}
Example #27
0
QList<QHostAddress> QHostInfoProto::addresses() const
{
    QHostInfo *item = qscriptvalue_cast<QHostInfo*>(thisObject());
    if (item)
        return item->addresses();
    return QList<QHostAddress>();
}
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;
}
Example #29
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 #30
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;
}