当前位置: 首页>>代码示例>>C++>>正文


C++ QNetworkInterface::addressEntries方法代码示例

本文整理汇总了C++中QNetworkInterface::addressEntries方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkInterface::addressEntries方法的具体用法?C++ QNetworkInterface::addressEntries怎么用?C++ QNetworkInterface::addressEntries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QNetworkInterface的用法示例。


在下文中一共展示了QNetworkInterface::addressEntries方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: accessPointChanged

    // Go through all interfaces and add all IPs for interfaces that can
    // broadcast and are not local.
    foreach (QNetworkInterface networkInterface,
             QNetworkInterface::allInterfaces())
    {
        if (!networkInterface.addressEntries().isEmpty()
                && networkInterface.isValid())
        {
            QNetworkInterface::InterfaceFlags interfaceFlags =
                    networkInterface.flags();

            if (interfaceFlags & QNetworkInterface::IsUp
                    && interfaceFlags & QNetworkInterface::IsRunning
                    && interfaceFlags & QNetworkInterface::CanBroadcast
                    && !(interfaceFlags & QNetworkInterface::IsLoopBack))
            {
                qDebug() << "ConnectionManager::handleNetworkSessionOpened():"
                         << "The connection is valid!";

                if (mNetworkSession) {
                    mAccessPoint = mNetworkSession->configuration().name();
                    emit accessPointChanged(mAccessPoint);
                }

                mMyIp.setAddress(networkInterface.addressEntries().at(0).ip().toString());
                emit myIpChanged(mMyIp.toString());

                setState(Connected);
                return;
            }
        }
    }
开发者ID:Alex237,项目名称:tic-tac-toe-qt,代码行数:32,代码来源:connectionmanager.cpp

示例2: QObject

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();
}
开发者ID:JonnyFunFun,项目名称:FilePirate,代码行数:30,代码来源:oceansocket.cpp

示例3: hasInternetConnection

/*
 * Checks if we have internet access!
 */
bool UnixCommand::hasInternetConnection()
{
  QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
  bool result = false;

  for (int i = 0; i < ifaces.count(); i++){
    QNetworkInterface iface = ifaces.at(i);

    if ( iface.flags().testFlag(QNetworkInterface::IsUp)
         && !iface.flags().testFlag(QNetworkInterface::IsLoopBack) ){
      for (int j=0; j<iface.addressEntries().count(); j++){
        /*
         We have an interface that is up, and has an ip address
         therefore the link is present.

         We will only enable this check on first positive,
         all later results are incorrect
        */
        if (result == false)
          result = true;
      }
    }
  }

  //It seems to be alright, but let's make a ping to see the result
  /*if (result == true)
  {
    result = UnixCommand::doInternetPingTest();
  }*/

  return result;
}
开发者ID:aarnt,项目名称:octoxbps,代码行数:35,代码来源:unixcommand.cpp

示例4: getDeviceIP

QString DeviceManager::getDeviceIP()
{
    QNetworkInterface *qni;
    qni = new QNetworkInterface();
    *qni = qni->interfaceFromName(QString("%1").arg("wlan0"));
    return qni->addressEntries().at(0).ip().toString();
}
开发者ID:lijunliang2000,项目名称:taomi,代码行数:7,代码来源:devicemanager.cpp

示例5: getNetworkAddressEntry

/**
 * @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;
}
开发者ID:parikshitag,项目名称:wavr,代码行数:41,代码来源:network.cpp

示例6: settings

bool
Utilities::isOnline(QNetworkAccessManager *manager)
{
    bool ret = false;
    QSettings settings("Entomologist");
    if (settings.value("work-offline", false).toBool())
        return(false);

#if QT_VERSION >= 0x040700
    if (manager->networkAccessible() != QNetworkAccessManager::NotAccessible)
        ret = true;
    else
        ret = false;
#else
    QNetworkInterface iface;
    QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();

    for (int i = 0; i < ifaces.count(); ++i)
    {
        iface = ifaces.at(i);
        if (iface.flags().testFlag(QNetworkInterface::IsUp)
            && !iface.flags().testFlag(QNetworkInterface::IsLoopBack) )
        {
            if (iface.addressEntries().count() >= 1)
            {
                ret = true;
                break;
            }
        }
    }
#endif

    return(ret);
}
开发者ID:Entomologist,项目名称:entomologist,代码行数:34,代码来源:Utilities.cpp

示例7: isConnectedToNetwork2

bool isConnectedToNetwork2()
{
    QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
    bool result = false;

    for (int i = 0; i < ifaces.count(); i++)
    {
        QNetworkInterface iface = ifaces.at(i);
        if ( iface.flags().testFlag(QNetworkInterface::IsUp)
             && !iface.flags().testFlag(QNetworkInterface::IsLoopBack) )
        {


            // this loop is important
            for (int j=0; j<iface.addressEntries().count(); j++)
            {

                // we have an interface that is up, and has an ip address
                // therefore the link is present

                // we will only enable this check on first positive,
                // all later results are incorrect

                if (result == false)
                    result = true;
            }
        }

    }

    return result;
}
开发者ID:albo1962,项目名称:adbFire,代码行数:32,代码来源:preferencesdialog.cpp

示例8: interfaceBoxIndexChanged

//someone selected another interface
void ApplicationWindow::interfaceBoxIndexChanged(int boxIndex)
{
    //get the right index data
    int interfaceIndex=interfaceBox->itemData(boxIndex).toInt();
    QNetworkInterface tmpInterface = QNetworkInterface::interfaceFromIndex (interfaceIndex);

    macLine->setText(tmpInterface.hardwareAddress());
   // indexLine->setText(QString("%1").arg(interfaceIndex));

    QList<QNetworkAddressEntry> interfaceAdresses;
    interfaceAdresses=tmpInterface.addressEntries();

    if (interfaceAdresses.size()>0)
    {
        ipLine->setText(interfaceAdresses[0].ip().toString());
        maskLine->setText(interfaceAdresses[0].netmask().toString());
    }
    else
    {
        ipLine->setText("");
        maskLine->setText("");
    }
        writeLog(createHeaderText());

}
开发者ID:eastcoastkiter,项目名称:info,代码行数:26,代码来源:application.cpp

示例9: nativeSetMulticastInterface

bool QNativeSocketEnginePrivate::nativeSetMulticastInterface(const QNetworkInterface &iface)
{
#ifndef QT_NO_IPV6
    if (socketProtocol == QAbstractSocket::IPv6Protocol) {
        uint v = iface.isValid() ? iface.index() : 0;
        return (::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF, (char *) &v, sizeof(v)) != -1);
    }
#endif

    struct in_addr v;
    if (iface.isValid()) {
        QList<QNetworkAddressEntry> entries = iface.addressEntries();
        for (int i = 0; i < entries.count(); ++i) {
            const QNetworkAddressEntry &entry = entries.at(i);
            const QHostAddress &ip = entry.ip();
            if (ip.protocol() == QAbstractSocket::IPv4Protocol) {
                v.s_addr = htonl(ip.toIPv4Address());
                int r = ::setsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (char *) &v, sizeof(v));
                if (r != -1)
                    return true;
            }
        }
        return false;
    }

    v.s_addr = INADDR_ANY;
    return (::setsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (char *) &v, sizeof(v)) != -1);
}
开发者ID:13W,项目名称:phantomjs,代码行数:28,代码来源:qnativesocketengine_win.cpp

示例10: getHostAddress

// ----------------------------------------------------------------------------
// getHostAddress (static)
// ----------------------------------------------------------------------------
QHostAddress NetworkTools::getHostAddress(const QNetworkInterface &in_interface)
{
    if (in_interface.isValid() == false) return QHostAddress();

    QList<QNetworkAddressEntry> addr_entry_list = in_interface.addressEntries();
    if (addr_entry_list.isEmpty()) return QHostAddress();

    return addr_entry_list.first().ip();
}
开发者ID:ttuna,项目名称:public,代码行数:12,代码来源:util_network.cpp

示例11: sendMessage

bool OceanSocket::sendMessage(const char message_type, QString data)
{
    QByteArray pulse = QString(message_type+data).toUtf8();
    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)) {
            bool isIp4 = false;
            for (int j = 0; j < iface.addressEntries().count(); j++) {
                if (iface.addressEntries().at(j).ip().scopeId() == "")
                    isIp4 = true;
            }
            if (isIp4) {
                sendSocket->setMulticastInterface(iface);
                sendSocket->writeDatagram(pulse.data(), pulse.size(), groupAddress, 8047);
            }
        }
    }

    return true;
}
开发者ID:JonnyFunFun,项目名称:FilePirate,代码行数:21,代码来源:oceansocket.cpp

示例12: item_text

   // 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());
     }
   }
 }
开发者ID:dg9oaa,项目名称:svxlink,代码行数:14,代码来源:Settings.cpp

示例13: scan

void PJobRunnerNetworkScanner::scan(const QNetworkInterface& interface){
    foreach(const QNetworkAddressEntry& address_entry, interface.addressEntries()){
        if(m_want_stop) break;
        quint32 netmask = address_entry.netmask().toIPv4Address();
        quint32 local_ip = address_entry.ip().toIPv4Address();
        quint32 address_to_try = (local_ip & netmask) + 1;
        //quint32 inv_netmask = ~netmask;

        if(interface.humanReadableName() == "lo"){
            std::cout << "Skipping interface \"lo\"." << std::endl;
            continue;
        }

        if(!interface.isValid()){
            std::cout << "Skipping interface \"" << interface.humanReadableName().toStdString() << "\"." << std::endl;
            continue;
        }

        if(address_entry.ip().protocol() != QAbstractSocket::IPv4Protocol){
            std::cout << "Skipping non-IPv4 interface." << std::endl;
            continue;
        }

        if(address_entry.ip() == QHostAddress::LocalHost){
            std::cout << "Skipping loopback interface." << std::endl;
            continue;
        }

        if(address_entry.ip().isNull()){
            continue;
        }

        std::cout << "Probing interface " << interface.humanReadableName().toStdString() << std::endl;
        std::cout << "Local address is " << interface.hardwareAddress().toStdString() << std::endl;
        std::cout << "Netmask: " << address_entry.netmask().toString().toStdString() << std::endl;
        std::cout << "Searching local network..." << std::endl;
        while((address_to_try & netmask) == (local_ip & netmask)){
            if(m_want_stop) break;
            std::cout << "\r" << QHostAddress(address_to_try).toString().toStdString();
            std::cout.flush();
            emit probing_host(QHostAddress(address_to_try));
            PJobRunnerSessionWrapper* session = new PJobRunnerSessionWrapper(QHostAddress(address_to_try), 50);
            if(session->is_valid()) found(session);
            else delete session;
            address_to_try++;
        }
    }
    emit finished_scanning();
    m_want_stop = false;
}
开发者ID:lucksus,项目名称:PJob,代码行数:50,代码来源:pjobrunnernetworkscanner.cpp

示例14: joinMulticastGroup

bool MulticastSocket::joinMulticastGroup(const QHostAddress& groupAddress, const QNetworkInterface& iface)
{
    bool success = false;

    foreach (const QNetworkAddressEntry& addressEntry, iface.addressEntries()) {
        const QHostAddress interfaceAddress = addressEntry.ip();

        if (interfaceAddress.protocol() == IPv4Protocol) {
            ip_mreq mreq;
            mreq.imr_multiaddr.s_addr = htonl(groupAddress.toIPv4Address());
            mreq.imr_interface.s_addr = htonl(interfaceAddress.toIPv4Address());

            const bool error = setsockopt(socketDescriptor(), IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char*) &mreq, sizeof(mreq)) == -1;
            if (error)
                setErrorString(strerror(errno));
            else
                success = true;
        }
    }

    return success;
}
开发者ID:RoboCup-SSL,项目名称:ssl-logtools,代码行数:22,代码来源:multicastsocket.cpp

示例15: updateInterfaceAddressCombo

void AdvancedSettings::updateInterfaceAddressCombo()
{
    // Try to get the currently selected interface name
    const QString ifaceName = comboBoxInterface.itemData(comboBoxInterface.currentIndex()).toString(); // Empty string for the first element
    const QString currentAddress = BitTorrent::Session::instance()->networkInterfaceAddress();

    // Clear all items and reinsert them, default to all
    comboBoxInterfaceAddress.clear();
    comboBoxInterfaceAddress.addItem(tr("All addresses"));
    comboBoxInterfaceAddress.setCurrentIndex(0);

    auto populateCombo = [this, &currentAddress](const QString &ip, const QAbstractSocket::NetworkLayerProtocol &protocol)
    {
        Q_ASSERT((protocol == QAbstractSocket::IPv4Protocol) || (protocol == QAbstractSocket::IPv6Protocol));
        // Only take ipv4 for now?
        if ((protocol != QAbstractSocket::IPv4Protocol) && (protocol != QAbstractSocket::IPv6Protocol))
            return;
        comboBoxInterfaceAddress.addItem(ip);
        //Try to select the last added one
        if (ip == currentAddress)
            comboBoxInterfaceAddress.setCurrentIndex(comboBoxInterfaceAddress.count() - 1);
    };

    if (ifaceName.isEmpty()) {
        for (const QHostAddress &ip : asConst(QNetworkInterface::allAddresses()))
            populateCombo(ip.toString(), ip.protocol());
    }
    else {
        const QNetworkInterface iface = QNetworkInterface::interfaceFromName(ifaceName);
        const QList<QNetworkAddressEntry> addresses = iface.addressEntries();
        for (const QNetworkAddressEntry &entry : addresses) {
            const QHostAddress ip = entry.ip();
            populateCombo(ip.toString(), ip.protocol());
        }
    }
}
开发者ID:paolo-sz,项目名称:qBittorrent,代码行数:36,代码来源:advancedsettings.cpp


注:本文中的QNetworkInterface::addressEntries方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。