Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-27641

Multicast joining fails on multiple interfaces

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.9.0 Beta 2
    • 4.8.x, 5.7.0
    • Network: Sockets
    • None
    • Windows, Linux
    • 4c367833b4c1776f01eff3d51472a9889c85e1c5

    Description

      When trying to use QUdpSocket::joinMulticastGroup with multiple interfaces it often fails under certain conditions.

      After looking into the source code of qnativesocketengine_*.cpp I found the following code that is actually incorrect:

                  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;
                  }
      

      This code takes the first address from the list and assumes it is an IPv4 address (which might not be true).
      The proper approach would be to iterate through the list and check for IPv4 protocol:

      	QList<QNetworkAddressEntry> addressEntries = iface.addressEntries();
      		for (int i = 0; i < addressEntries.length(); i++) {
      			if (addressEntries[i].ip().protocol() == QAbstractSocket::IPv4Protocol) {
      				...
      				break;
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Eddy Edward Welbourne
              dremon Dmitry Pankratov
              Votes:
              5 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes