From 1bf9cb44e24ba2d795e3c242276d07acb0e46322 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 11 Aug 2015 15:21:30 -0700 Subject: [PATCH] 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 --- src/network/kernel/qnetworkinterface_unix.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp index 04e1ce7edd..38cddd8f7a 100644 --- a/src/network/kernel/qnetworkinterface_unix.cpp +++ b/src/network/kernel/qnetworkinterface_unix.cpp @@ -185,9 +185,14 @@ static QNetworkInterfacePrivate *findInterface(int socket, QList= 0) + ifindex = req.ifr_ifindex; +# else ifindex = if_nametoindex(req.ifr_name); +# endif // find the interface data QList::Iterator if_it = interfaces.begin();