Ejemplo n.º 1
0
QNetworkInterface QNativeSocketEnginePrivate::nativeMulticastInterface() const
{
#ifndef QT_NO_IPV6
    if (socketProtocol == QAbstractSocket::IPv6Protocol) {
        uint v;
        QT_SOCKOPTLEN_T sizeofv = sizeof(v);
        if (::getsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF, (char *) &v, &sizeofv) == -1)
            return QNetworkInterface();
        return QNetworkInterface::interfaceFromIndex(v);
    }
#endif

    struct in_addr v;
    v.s_addr = 0;
    QT_SOCKOPTLEN_T sizeofv = sizeof(v);
    if (::getsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (char *) &v, &sizeofv) == -1)
        return QNetworkInterface();
    if (v.s_addr != 0 && sizeofv >= QT_SOCKOPTLEN_T(sizeof(v))) {
        QHostAddress ipv4(ntohl(v.s_addr));
        QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
        for (int i = 0; i < ifaces.count(); ++i) {
            const QNetworkInterface &iface = ifaces.at(i);
            if (!(iface.flags() & QNetworkInterface::CanMulticast))
                continue;
            QList<QNetworkAddressEntry> entries = iface.addressEntries();
            for (int j = 0; j < entries.count(); ++j) {
                const QNetworkAddressEntry &entry = entries.at(j);
                if (entry.ip() == ipv4)
                    return iface;
            }
        }
    }
    return QNetworkInterface();
}
Ejemplo n.º 2
0
QNetworkInterface QNetworkSessionPrivate::currentInterface() const
{
    if (!publicConfig.isValid() || !engine || state != QNetworkSession::Connected)
        return QNetworkInterface();

    QString interface = engine->getInterfaceFromId(activeConfig.identifier());

    if (interface.isEmpty())
        return QNetworkInterface();
    return QNetworkInterface::interfaceFromName(interface);
}
Ejemplo n.º 3
0
/*! \since 4.8 */
QNetworkInterface QNativeSocketEngine::multicastInterface() const
{
    Q_D(const QNativeSocketEngine);
    Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::multicastInterface(), QNetworkInterface());
    Q_CHECK_TYPE(QNativeSocketEngine::multicastInterface(), QAbstractSocket::UdpSocket, QNetworkInterface());
    return d->nativeMulticastInterface();
}
Ejemplo n.º 4
0
// ----------------------------------------------------------------------------
// getNetworkInterface (static)
// ----------------------------------------------------------------------------
QNetworkInterface NetworkTools::getNetworkInterface(const QString &in_name)
{
    if (in_name.isEmpty()) return QNetworkInterface();

    QNetworkInterface net_if;
    QList<QNetworkInterface> net_if_list = QNetworkInterface::allInterfaces();
    foreach(QNetworkInterface temp, net_if_list)
    {
        if (temp.humanReadableName().compare(in_name, Qt::CaseInsensitive) != 0) continue;
        net_if = temp; break;
    }
    return net_if;
}
Ejemplo n.º 5
0
/**
 * Creates object of TcpNetwork and UdpNetwork, connect their signals with respective slots.
 * Initializes all variables.
 */
wavrNetwork::wavrNetwork(void) {
    pUdpNetwork = new wavrUdpNetwork();
    pTcpNetwork = new wavrTcpNetwork();

    connect(pUdpNetwork, SIGNAL(broadcastReceived(DatagramHeader*,QString*)),
            this, SLOT(udp_receiveBroadcast(DatagramHeader*,QString*)));
    connect(pTcpNetwork, SIGNAL(newConnection(QString*,QString*)),
            this, SLOT(tcp_newConnection(QString*,QString*)));
    connect(pTcpNetwork, SIGNAL(connectionLost(QString*)),
            this, SLOT(tcp_connectionLost(QString*)));
    connect(pTcpNetwork, SIGNAL(messageReceived(DatagramHeader*,QString*)),
            this, SLOT(tcp_receiveMessage(DatagramHeader*,QString*)));
    connect(pTcpNetwork, SIGNAL(progressReceived(QString*, QString*)),
        this, SLOT(tcp_receiveProgress(QString*, QString*)));

    pTimer = NULL;
    ipAddress = QString::null;
    subnetMask = QString::null;
    networkInterface = QNetworkInterface();
    interfaceName = QString::null;
    isConnected = false;
    canReceive = false;
}
Ejemplo n.º 6
0
QNetworkInterface QNetworkInfoPrivate::interfaceForMode(QNetworkInfo::NetworkMode mode, int interface)
{
    switch (mode) {
    case QNetworkInfo::WlanMode: {
        QStringList dirs = QDir(*NETWORK_SYSFS_PATH()).entryList(*WLAN_MASK());
        if (interface < dirs.size()) {
            QNetworkInterface networkInterface = QNetworkInterface::interfaceFromName(dirs.at(interface));
            if (networkInterface.isValid())
                return networkInterface;
        }
        break;
    }

    case QNetworkInfo::EthernetMode: {
        QStringList dirs = QDir(*NETWORK_SYSFS_PATH()).entryList(*ETHERNET_MASK());
        if (interface < dirs.size()) {
            QNetworkInterface networkInterface = QNetworkInterface::interfaceFromName(dirs.at(interface));
            if (networkInterface.isValid())
                return networkInterface;
        }
        break;
    }

//    case QNetworkInfo::BluetoothMode:
//    case QNetworkInfo::GsmMode:
//    case QNetworkInfo::CdmaMode:
//    case QNetworkInfo::WcdmaMode:
//    case QNetworkInfo::WimaxMode:
//    case QNetworkInfo::LteMode:
//    case QNetworkInfo::TdscdmaMode:
    default:
        break;
    };

    return QNetworkInterface();
}
QNetworkInterface QHttpSocketEngine::multicastInterface() const
{
    return QNetworkInterface();
}
Ejemplo n.º 8
0
QNetworkInterface TorcNetwork::GetInterface(void)
{
    QMutexLocker locker(gNetworkLock);

    return gNetwork ? gNetwork->Interface() : QNetworkInterface();
}
Ejemplo n.º 9
0
 Inet6Address::Inet6Address(QString hostName, QByteArray addr) {
     holder6 = new Inet6AddressHolder();
     try {
         initif (hostName, addr, QNetworkInterface());
     } catch (UnknownHostException e) {} /* cant happen if ifname is null */
 }
Ejemplo n.º 10
0
bool MulticastSocket::joinMulticastGroup(const QHostAddress &groupAddress)
{
    return joinMulticastGroup(groupAddress, QNetworkInterface());
}