本文整理汇总了C++中QNetworkAddressEntry::prefixLength方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkAddressEntry::prefixLength方法的具体用法?C++ QNetworkAddressEntry::prefixLength怎么用?C++ QNetworkAddressEntry::prefixLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkAddressEntry
的用法示例。
在下文中一共展示了QNetworkAddressEntry::prefixLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSetCheck
void tst_QNetworkAddressEntry::getSetCheck()
{
QNetworkAddressEntry entry;
QVERIFY(entry.ip().isNull());
QVERIFY(entry.netmask().isNull());
QVERIFY(entry.broadcast().isNull());
QCOMPARE(entry.prefixLength(), -1);
entry.setIp(QHostAddress::LocalHost);
QCOMPARE(entry.ip(), QHostAddress(QHostAddress::LocalHost));
entry.setIp(QHostAddress());
QVERIFY(entry.ip().isNull());
entry.setBroadcast(QHostAddress::LocalHost);
QCOMPARE(entry.broadcast(), QHostAddress(QHostAddress::LocalHost));
entry.setBroadcast(QHostAddress());
QVERIFY(entry.broadcast().isNull());
// netmask and prefix length tested in the next test
entry.setIp(QHostAddress::LocalHost);
entry.setBroadcast(QHostAddress::LocalHost);
QNetworkAddressEntry entry2;
QVERIFY(entry != entry2);
QVERIFY(!(entry == entry2));
entry = entry2;
QCOMPARE(entry, entry2);
QVERIFY(entry == entry);
QVERIFY(!(entry != entry2));
}
示例2: contains
static bool contains(QNetworkAddressEntry host, QHostAddress addr)
{
#if !defined(QT_NO_IPV6)
if (addr.protocol() == QAbstractSocket::IPv6Protocol &&
addr.isInSubnet(kLinkLocal6) &&
host.ip().scopeId() != addr.scopeId())
{
return false;
}
#endif
return addr.isInSubnet(host.ip(), host.prefixLength());
}
示例3: prefixAndNetmask
void tst_QNetworkAddressEntry::prefixAndNetmask()
{
QFETCH(QHostAddress, ip);
QFETCH(QHostAddress, netmask);
QFETCH(int, prefix);
QNetworkAddressEntry entry;
// first, without setting the IP, all must be invalid:
entry.setNetmask(netmask);
QVERIFY(entry.netmask().isNull());
entry.setPrefixLength(prefix);
QCOMPARE(entry.prefixLength(), -1);
// set the IP:
entry.setIp(ip);
// set the netmask:
if (!netmask.isNull()) {
entry.setNetmask(netmask);
// was it a valid one?
if (prefix != -1) {
QVERIFY(!entry.netmask().isNull());
QCOMPARE(entry.netmask(), netmask);
QCOMPARE(entry.prefixLength(), prefix);
} else {
// not valid
QVERIFY(entry.netmask().isNull());
QCOMPARE(entry.prefixLength(), -1);
}
}
entry.setNetmask(QHostAddress());
QVERIFY(entry.netmask().isNull());
QCOMPARE(entry.prefixLength(), -1);
// set the prefix
if (prefix != -1) {
entry.setPrefixLength(prefix);
// was it a valid one?
if (!netmask.isNull()) {
QVERIFY(!entry.netmask().isNull());
QCOMPARE(entry.netmask(), netmask);
QCOMPARE(entry.prefixLength(), prefix);
} else {
// not valid
QVERIFY(entry.netmask().isNull());
QCOMPARE(entry.prefixLength(), -1);
}
}
entry.setPrefixLength(-1);
QVERIFY(entry.netmask().isNull());
QCOMPARE(entry.prefixLength(), -1);
}