Tuesday, May 31, 2016

New method QHostAddress::isMulticast() in Qt 5.6

Among new features of Qt 5.6 new method was added for QHostAddress:


This bool method returns true if IPv4 or IPv6 address is multicast.

From wikipedia a multicast address is a logical identifier for a group of hosts in a network available to process datagrams or frames intended to be multicast for a network service.

Here is the test program which shows the output for different IPv4 addresses:

#include <QCoreApplication> 
#include <QDebug>
#include <QHostAddress>

int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);

    QHostAddress ipv4false("");
    qDebug() << ipv4false.isMulticast(); // false
    // The All Hosts multicast group addresses all 
    // hosts on the same network segment.
    QHostAddress ipv4true("");
    qDebug() << ipv4true.isMulticast(); // true

    return a.exec();

It works the same way for IPv6 addresses.

No comments:

Post a Comment