QNetworkInterface: prefer SIOCGIFINDEX over if_nametoindex
On Linux (on a bad system without getifaddrs), the ioctl for SIOCGIFINDEX should be faster than if_nametoindex. The ioctl on the already open socket will require one syscall, while if_nametoindex will require at least one more (to open the socket), probably more. Change-Id: I7de033f80b0e4431b7f1ffff13f9888bf2044105 Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
parent
3bfba054cb
commit
1bf9cb44e2
@ -185,9 +185,14 @@ static QNetworkInterfacePrivate *findInterface(int socket, QList<QNetworkInterfa
|
|||||||
QNetworkInterfacePrivate *iface = 0;
|
QNetworkInterfacePrivate *iface = 0;
|
||||||
int ifindex = 0;
|
int ifindex = 0;
|
||||||
|
|
||||||
#ifndef QT_NO_IPV6IFNAME
|
#if !defined(QT_NO_IPV6IFNAME) || defined(SIOCGIFINDEX)
|
||||||
// Get the interface index
|
// Get the interface index
|
||||||
|
# ifdef SIOCGIFINDEX
|
||||||
|
if (qt_safe_ioctl(socket, SIOCGIFINDEX, &req) >= 0)
|
||||||
|
ifindex = req.ifr_ifindex;
|
||||||
|
# else
|
||||||
ifindex = if_nametoindex(req.ifr_name);
|
ifindex = if_nametoindex(req.ifr_name);
|
||||||
|
# endif
|
||||||
|
|
||||||
// find the interface data
|
// find the interface data
|
||||||
QList<QNetworkInterfacePrivate *>::Iterator if_it = interfaces.begin();
|
QList<QNetworkInterfacePrivate *>::Iterator if_it = interfaces.begin();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user