cleanup findInterface() function

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2019-12-30 02:43:40 +00:00
parent 02c313578f
commit a0e21b8fd9

View file

@ -167,7 +167,6 @@ static QSet<QByteArray> interfaceNames(int socket)
static QNetworkInterfacePrivate *findInterface(int socket, QList<QNetworkInterfacePrivate *> &interfaces,
struct ifreq &req)
{
QNetworkInterfacePrivate *iface = 0;
int ifindex = 0;
#ifndef QT_NO_IPV6IFNAME
@ -175,27 +174,24 @@ static QNetworkInterfacePrivate *findInterface(int socket, QList<QNetworkInterfa
ifindex = if_nametoindex(req.ifr_name);
// find the interface data
QList<QNetworkInterfacePrivate *>::Iterator if_it = interfaces.begin();
for ( ; if_it != interfaces.end(); ++if_it)
if ((*if_it)->index == ifindex) {
foreach (QNetworkInterfacePrivate *it, interfaces) {
if (it->index == ifindex) {
// existing interface
iface = *if_it;
break;
return it;
}
}
#else
// Search by name
QList<QNetworkInterfacePrivate *>::Iterator if_it = interfaces.begin();
for ( ; if_it != interfaces.end(); ++if_it)
if ((*if_it)->name == QLatin1String(req.ifr_name)) {
foreach (QNetworkInterfacePrivate *it, interfaces) {
if (it->name == QString::fromLatin1(req.ifr_name)) {
// existing interface
iface = *if_it;
break;
return it;
}
}
#endif
if (!iface) {
// new interface, create data:
iface = new QNetworkInterfacePrivate;
QNetworkInterfacePrivate *iface = new QNetworkInterfacePrivate;
iface->index = ifindex;
interfaces << iface;
@ -226,7 +222,6 @@ static QNetworkInterfacePrivate *findInterface(int socket, QList<QNetworkInterfa
iface->hardwareAddress = iface->makeHwAddress(6, addr);
}
#endif
}
return iface;
}