Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.8.x, 5.7.0
-
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
- is duplicated by
-
QTBUG-61888 UDP Multicast on Specific Network Interface
- Closed
- replaces
-
QTBUG-30949 QUdpSocket join to group error
- Closed
-
QTBUG-53127 Windows: Trying to join to a multicast group as a receiver with specific interface always uses default interface
- Closed