本文整理汇总了C++中QNetworkInterface::index方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkInterface::index方法的具体用法?C++ QNetworkInterface::index怎么用?C++ QNetworkInterface::index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkInterface
的用法示例。
在下文中一共展示了QNetworkInterface::index方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: throw
void Inet6AddressHolder::init(QByteArray addr, QNetworkInterface nif)
throw (UnknownHostException)
{
setAddr(addr);
if (nif.isValid()) {
this->scope_id = nif.index();//deriveNumericScope(ipaddress, nif);
this->scope_id_set = true;
this->scope_ifname = nif;
this->scope_ifname_set = true;
}
}
示例3: multicastMembershipHelper
static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d,
int how6,
int how4,
const QHostAddress &groupAddress,
const QNetworkInterface &iface)
{
int level = 0;
int sockOpt = 0;
char *sockArg;
int sockArgSize;
struct ip_mreq mreq4;
#ifndef QT_NO_IPV6
struct ipv6_mreq mreq6;
if (groupAddress.protocol() == QAbstractSocket::IPv6Protocol) {
level = IPPROTO_IPV6;
sockOpt = how6;
sockArg = reinterpret_cast<char *>(&mreq6);
sockArgSize = sizeof(mreq6);
memset(&mreq6, 0, sizeof(mreq6));
Q_IPV6ADDR ip6 = groupAddress.toIPv6Address();
memcpy(&mreq6.ipv6mr_multiaddr, &ip6, sizeof(ip6));
mreq6.ipv6mr_interface = iface.index();
} else
#endif
if (groupAddress.protocol() == QAbstractSocket::IPv4Protocol) {
level = IPPROTO_IP;
sockOpt = how4;
sockArg = reinterpret_cast<char *>(&mreq4);
sockArgSize = sizeof(mreq4);
memset(&mreq4, 0, sizeof(mreq4));
mreq4.imr_multiaddr.s_addr = htonl(groupAddress.toIPv4Address());
if (iface.isValid()) {
QList<QNetworkAddressEntry> addressEntries = iface.addressEntries();
if (!addressEntries.isEmpty()) {
QHostAddress firstIP = addressEntries.first().ip();
mreq4.imr_interface.s_addr = htonl(firstIP.toIPv4Address());
} else {
d->setError(QAbstractSocket::NetworkError,
QNativeSocketEnginePrivate::NetworkUnreachableErrorString);
return false;
}
} else {
mreq4.imr_interface.s_addr = INADDR_ANY;
}
} else {
// unreachable
d->setError(QAbstractSocket::UnsupportedSocketOperationError,
QNativeSocketEnginePrivate::ProtocolUnsupportedErrorString);
return false;
}
int res = setsockopt(d->socketDescriptor, level, sockOpt, sockArg, sockArgSize);
if (res == -1) {
d->setError(QAbstractSocket::UnsupportedSocketOperationError,
QNativeSocketEnginePrivate::OperationUnsupportedErrorString);
return false;
}
return true;
}
示例4: doRequestUpdate
void QGenericEngine::doRequestUpdate()
{
#ifndef QT_NO_NETWORKINTERFACE
QMutexLocker locker(&mutex);
// Immediately after connecting with a wireless access point
// QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a
// second time results in a non-empty list. If we loose interfaces we will end up removing
// network configurations which will break current sessions.
QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
if (interfaces.isEmpty())
interfaces = QNetworkInterface::allInterfaces();
QStringList previous = accessPointConfigurations.keys();
// create configuration for each interface
while (!interfaces.isEmpty()) {
QNetworkInterface interface = interfaces.takeFirst();
if (!interface.isValid())
continue;
// ignore loopback interface
if (interface.flags() & QNetworkInterface::IsLoopBack)
continue;
// ignore WLAN interface handled in separate engine
if (qGetInterfaceType(interface.name()) == QNetworkConfiguration::BearerWLAN)
continue;
uint identifier;
if (interface.index())
identifier = qHash(QLatin1String("generic:") + QString::number(interface.index()));
else
identifier = qHash(QLatin1String("generic:") + interface.hardwareAddress());
const QString id = QString::number(identifier);
previous.removeAll(id);
QString name = interface.humanReadableName();
if (name.isEmpty())
name = interface.name();
QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined;
if((interface.flags() & QNetworkInterface::IsUp) && !interface.addressEntries().isEmpty())
state |= QNetworkConfiguration::Active;
if (accessPointConfigurations.contains(id)) {
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
bool changed = false;
ptr->mutex.lock();
if (!ptr->isValid) {
ptr->isValid = true;
changed = true;
}
if (ptr->name != name) {
ptr->name = name;
changed = true;
}
if (ptr->id != id) {
ptr->id = id;
changed = true;
}
if (ptr->state != state) {
ptr->state = state;
changed = true;
}
ptr->mutex.unlock();
if (changed) {
locker.unlock();
emit configurationChanged(ptr);
locker.relock();
}
} else {
QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);
ptr->name = name;
ptr->isValid = true;
ptr->id = id;
ptr->state = state;
ptr->type = QNetworkConfiguration::InternetAccessPoint;
ptr->bearerType = qGetInterfaceType(interface.name());
accessPointConfigurations.insert(id, ptr);
configurationInterface.insert(id, interface.name());
locker.unlock();
emit configurationAdded(ptr);
locker.relock();
}
}
//.........这里部分代码省略.........