summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2015-08-11 19:24:51 -0700
committerThiago Macieira <thiago.macieira@intel.com>2015-09-13 18:54:15 +0000
commit181c8d80d19f975ccf943fa79107f1e839e33e68 (patch)
tree3f12cc480ea640422cb6fada0e67d33d8159f872 /src/network
parent7bd64776825f0e025cc2597e6c1909efbb1233f7 (diff)
QNetworkInterface: get a friendlier (but not too friendly) name
Since Windows Vista, the OS keeps an extra set of names for each interface, which are identifier-like and more friendly than previously, but not the user-description. For example: previous name: "{2B09D370-A032-4478-8444-495AD9301D67}" new name: "wireless_6" friendly name: "Local Area Connection* 12" Change-Id: I7de033f80b0e4431b7f1ffff13f995f983689f06 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/kernel/kernel.pri2
-rw-r--r--src/network/kernel/qnetworkinterface_win.cpp19
2 files changed, 20 insertions, 1 deletions
diff --git a/src/network/kernel/kernel.pri b/src/network/kernel/kernel.pri
index 671b57ed11..435bfd6c27 100644
--- a/src/network/kernel/kernel.pri
+++ b/src/network/kernel/kernel.pri
@@ -38,6 +38,8 @@ win32: {
kernel/qhostinfo_win.cpp \
kernel/qnetworkinterface_win.cpp
LIBS_PRIVATE += -ldnsapi -liphlpapi
+ DEFINES += WINVER=0x0600 _WIN32_WINNT=0x0600
+
} else {
SOURCES += kernel/qdnslookup_winrt.cpp \
kernel/qhostinfo_winrt.cpp \
diff --git a/src/network/kernel/qnetworkinterface_win.cpp b/src/network/kernel/qnetworkinterface_win.cpp
index d73d3ecdc9..907638f73e 100644
--- a/src/network/kernel/qnetworkinterface_win.cpp
+++ b/src/network/kernel/qnetworkinterface_win.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2015 Intel Corporation.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtNetwork module of the Qt Toolkit.
@@ -56,6 +57,9 @@
QT_BEGIN_NAMESPACE
+typedef NETIO_STATUS (WINAPI *PtrConvertInterfaceLuidToName)(const NET_LUID *, PWSTR, SIZE_T);
+static PtrConvertInterfaceLuidToName ptrConvertInterfaceLuidToName = 0;
+
static void resolveLibs()
{
// try to find the functions we need from Iphlpapi.dll
@@ -66,7 +70,11 @@ static void resolveLibs()
Q_ASSERT(iphlpapiHnd);
#if defined(Q_OS_WINCE)
+ // since Windows Embedded Compact 7
+ ptrConvertInterfaceLuidToName = (PtrConvertInterfaceLuidToName)GetProcAddress(iphlpapiHnd, L"ConvertInterfaceLuidToNameW");
#else
+ // since Windows Vista
+ ptrConvertInterfaceLuidToName = (PtrConvertInterfaceLuidToName)GetProcAddress(iphlpapiHnd, "ConvertInterfaceLuidToNameW");
#endif
done = true;
}
@@ -176,7 +184,16 @@ static QList<QNetworkInterfacePrivate *> interfaceListingWinXP()
if (ptr->IfType == IF_TYPE_PPP)
iface->flags |= QNetworkInterface::IsPointToPoint;
- iface->name = QString::fromLocal8Bit(ptr->AdapterName);
+ if (ptrConvertInterfaceLuidToName && ptr->Length >= offsetof(IP_ADAPTER_ADDRESSES, Luid)) {
+ // use ConvertInterfaceLuidToName because that returns a friendlier name, though not
+ // as friendly as FriendlyName below
+ WCHAR buf[IF_MAX_STRING_SIZE + 1];
+ if (ptrConvertInterfaceLuidToName(&ptr->Luid, buf, sizeof(buf)/sizeof(buf[0])) == NO_ERROR)
+ iface->name = QString::fromWCharArray(buf);
+ }
+ if (iface->name.isEmpty())
+ iface->name = QString::fromLocal8Bit(ptr->AdapterName);
+
iface->friendlyName = QString::fromWCharArray(ptr->FriendlyName);
if (ptr->PhysicalAddressLength)
iface->hardwareAddress = iface->makeHwAddress(ptr->PhysicalAddressLength,