Fix multicastMembershipHelper to not assume addresses are IPv4
Make it iterate the addresses available looking for an IPv4 address, when that's what it needs, instead of just assuming the first entry in the list (when non-empty) is IPv4. Based on a suggestion by Dmitry Pankratov. Task-number: QTBUG-27641 Change-Id: I1920f68ade44a996ea5c2ed691a87ff3e686f35a Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
46730ca610
commit
4c367833b4
@ -679,10 +679,16 @@ static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d,
|
||||
|
||||
if (interface.isValid()) {
|
||||
const QList<QNetworkAddressEntry> addressEntries = interface.addressEntries();
|
||||
if (!addressEntries.isEmpty()) {
|
||||
QHostAddress firstIP = addressEntries.first().ip();
|
||||
mreq4.imr_interface.s_addr = htonl(firstIP.toIPv4Address());
|
||||
} else {
|
||||
bool found = false;
|
||||
for (const QNetworkAddressEntry &entry : addressEntries) {
|
||||
const QHostAddress ip = entry.ip();
|
||||
if (ip.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
mreq4.imr_interface.s_addr = htonl(ip.toIPv4Address());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
d->setError(QAbstractSocket::NetworkError,
|
||||
QNativeSocketEnginePrivate::NetworkUnreachableErrorString);
|
||||
return false;
|
||||
|
@ -959,10 +959,16 @@ static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d,
|
||||
|
||||
if (iface.isValid()) {
|
||||
const QList<QNetworkAddressEntry> addressEntries = iface.addressEntries();
|
||||
if (!addressEntries.isEmpty()) {
|
||||
QHostAddress firstIP = addressEntries.first().ip();
|
||||
mreq4.imr_interface.s_addr = htonl(firstIP.toIPv4Address());
|
||||
} else {
|
||||
bool found = false;
|
||||
for (const QNetworkAddressEntry &entry : addressEntries) {
|
||||
const QHostAddress ip = entry.ip();
|
||||
if (ip.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
mreq4.imr_interface.s_addr = htonl(ip.toIPv4Address());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
d->setError(QAbstractSocket::NetworkError,
|
||||
QNativeSocketEnginePrivate::NetworkUnreachableErrorString);
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user