本文整理汇总了C++中QNetworkAddressEntry::setBroadcast方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkAddressEntry::setBroadcast方法的具体用法?C++ QNetworkAddressEntry::setBroadcast怎么用?C++ QNetworkAddressEntry::setBroadcast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkAddressEntry
的用法示例。
在下文中一共展示了QNetworkAddressEntry::setBroadcast方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: interfaceListing
static QList<QNetworkInterfacePrivate *> interfaceListing()
{
QList<QNetworkInterfacePrivate *> interfaces;
int socket;
if ((socket = qt_safe_socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) == -1)
return interfaces; // error
ifaddrs *interfaceListing;
if (getifaddrs(&interfaceListing) == -1) {
// error
::close(socket);
return interfaces;
}
interfaces = createInterfaces(interfaceListing);
for (ifaddrs *ptr = interfaceListing; ptr; ptr = ptr->ifa_next) {
// Get the interface index
int ifindex = if_nametoindex(ptr->ifa_name);
QNetworkInterfacePrivate *iface = 0;
QList<QNetworkInterfacePrivate *>::Iterator if_it = interfaces.begin();
for ( ; if_it != interfaces.end(); ++if_it)
if ((*if_it)->index == ifindex) {
// found this interface already
iface = *if_it;
break;
}
if (!iface) {
// skip all non-IP interfaces
continue;
}
QNetworkAddressEntry entry;
entry.setIp(addressFromSockaddr(ptr->ifa_addr));
if (entry.ip().isNull())
// could not parse the address
continue;
entry.setNetmask(addressFromSockaddr(ptr->ifa_netmask));
if (iface->flags & QNetworkInterface::CanBroadcast)
entry.setBroadcast(addressFromSockaddr(ptr->ifa_broadaddr));
iface->addressEntries << entry;
}
freeifaddrs(interfaceListing);
::close(socket);
return interfaces;
}
示例3: interfaceListing
static QList<QNetworkInterfacePrivate *> interfaceListing()
{
QList<QNetworkInterfacePrivate *> interfaces;
ifaddrs *interfaceListing;
if (getifaddrs(&interfaceListing) == -1) {
// error
return interfaces;
}
interfaces = createInterfaces(interfaceListing);
for (ifaddrs *ptr = interfaceListing; ptr; ptr = ptr->ifa_next) {
// Get the interface index
QString name = QString::fromLatin1(ptr->ifa_name);
QNetworkInterfacePrivate *iface = 0;
QList<QNetworkInterfacePrivate *>::Iterator if_it = interfaces.begin();
for ( ; if_it != interfaces.end(); ++if_it)
if ((*if_it)->name == name) {
// found this interface already
iface = *if_it;
break;
}
if (!iface) {
// skip all non-IP interfaces
continue;
}
QNetworkAddressEntry entry;
entry.setIp(addressFromSockaddr(ptr->ifa_addr, iface->index, iface->name));
if (entry.ip().isNull())
// could not parse the address
continue;
entry.setNetmask(addressFromSockaddr(ptr->ifa_netmask, iface->index, iface->name));
if (iface->flags & QNetworkInterface::CanBroadcast)
entry.setBroadcast(addressFromSockaddr(ptr->ifa_broadaddr, iface->index, iface->name));
iface->addressEntries << entry;
}
freeifaddrs(interfaceListing);
return interfaces;
}
示例4: err
static QList<QNetworkInterfacePrivate *> interfaceListing()
{
TInt err(KErrNone);
QList<QNetworkInterfacePrivate *> interfaces;
// Connect to Native socket server
RSocketServ socketServ;
err = socketServ.Connect();
if (err)
return interfaces;
// Open dummy socket for interface queries
RSocket socket;
err = socket.Open(socketServ, _L("udp"));
if (err) {
socketServ.Close();
return interfaces;
}
// Ask socket to start enumerating interfaces
err = socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
if (err) {
socket.Close();
socketServ.Close();
return interfaces;
}
int ifindex = 0;
TPckgBuf<TSoInetInterfaceInfo> infoPckg;
TSoInetInterfaceInfo &info = infoPckg();
while (socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, infoPckg) == KErrNone) {
// Do not include IPv6 addresses because netmask and broadcast address cannot be determined correctly
if (info.iName != KNullDesC && info.iAddress.IsV4Mapped()) {
TName address;
QNetworkAddressEntry entry;
QNetworkInterfacePrivate *iface = 0;
iface = new QNetworkInterfacePrivate;
iface->index = ifindex++;
interfaces << iface;
iface->name = qt_TDesC2QString(info.iName);
iface->flags = convertFlags(info);
if (/*info.iFeatures&KIfHasHardwareAddr &&*/ info.iHwAddr.Family() != KAFUnspec) {
for (TInt i = sizeof(SSockAddr); i < sizeof(SSockAddr) + info.iHwAddr.GetUserLen(); i++) {
address.AppendNumFixedWidth(info.iHwAddr[i], EHex, 2);
if ((i + 1) < sizeof(SSockAddr) + info.iHwAddr.GetUserLen())
address.Append(_L(":"));
}
address.UpperCase();
iface->hardwareAddress = qt_TDesC2QString(address);
}
// Get the address of the interface
info.iAddress.Output(address);
entry.setIp(QHostAddress(qt_TDesC2QString(address)));
// Get the interface netmask
// For some reason netmask is always 0.0.0.0
// info.iNetMask.Output(address);
// entry.setNetmask( QHostAddress( qt_TDesC2QString( address ) ) );
// Workaround: Let Symbian determine netmask based on IP address class
// TODO: Works only for IPv4 - Task: 259128 Implement IPv6 support
TInetAddr netmask;
netmask.NetMask(info.iAddress);
netmask.Output(address);
entry.setNetmask(QHostAddress(qt_TDesC2QString(address)));
// Get the interface broadcast address
if (iface->flags & QNetworkInterface::CanBroadcast) {
// For some reason broadcast address is always 0.0.0.0
// info.iBrdAddr.Output(address);
// entry.setBroadcast( QHostAddress( qt_TDesC2QString( address ) ) );
// Workaround: Let Symbian determine broadcast address based on IP address
// TODO: Works only for IPv4 - Task: 259128 Implement IPv6 support
TInetAddr broadcast;
broadcast.NetBroadcast(info.iAddress);
broadcast.Output(address);
entry.setBroadcast(QHostAddress(qt_TDesC2QString(address)));
}
// Add new entry to interface address entries
iface->addressEntries << entry;
#if defined(QNETWORKINTERFACE_DEBUG)
printf("\n Found network interface %s, interface flags:\n\
IsUp = %d, IsRunning = %d, CanBroadcast = %d,\n\
IsLoopBack = %d, IsPointToPoint = %d, CanMulticast = %d, \n\
ip = %s, netmask = %s, broadcast = %s,\n\
hwaddress = %s",
iface->name.toLatin1().constData(),
iface->flags & QNetworkInterface::IsUp, iface->flags & QNetworkInterface::IsRunning, iface->flags & QNetworkInterface::CanBroadcast,
iface->flags & QNetworkInterface::IsLoopBack, iface->flags & QNetworkInterface::IsPointToPoint, iface->flags & QNetworkInterface::CanMulticast,
entry.ip().toString().toLatin1().constData(), entry.netmask().toString().toLatin1().constData(), entry.broadcast().toString().toLatin1().constData(),
iface->hardwareAddress.toLatin1().constData());
#endif
}
}