From 01d0b1d6e3fe76d1cd09eeb6474c69e712f37b16 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 8 Apr 2015 14:14:16 -0700 Subject: Merge the multiple implementations of getting the local hostname This commit moves the functionality from QtNetwork's QHostInfo to QtCore. Note that due to Windows ws2_32.dll's quirky behavior of requiring WSAStartup before calling gethostname, this change required moving the initialization to QtCore too. On Linux systems, gethostname() gets the name from uname(), so we bypass the middle man and save one memcpy. Change-Id: I27eaacb532114dd188c4ffff13d32655a6301346 Reviewed-by: Erik Verbruggen Reviewed-by: Oliver Wolff Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/network/kernel/qhostinfo_winrt.cpp | 39 ---------------------------------- 1 file changed, 39 deletions(-) (limited to 'src/network/kernel/qhostinfo_winrt.cpp') diff --git a/src/network/kernel/qhostinfo_winrt.cpp b/src/network/kernel/qhostinfo_winrt.cpp index 1a97fe0e40..3d2344726b 100644 --- a/src/network/kernel/qhostinfo_winrt.cpp +++ b/src/network/kernel/qhostinfo_winrt.cpp @@ -130,45 +130,6 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) return results; } -QString QHostInfo::localHostName() -{ - ComPtr statics; - GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Networking_Connectivity_NetworkInformation).Get(), &statics); - - ComPtr> hostNames; - statics->GetHostNames(&hostNames); - if (!hostNames) - return QString(); - - unsigned int size; - hostNames->get_Size(&size); - if (size == 0) - return QString(); - - for (unsigned int i = 0; i < size; ++i) { - ComPtr hostName; - hostNames->GetAt(i, &hostName); - HostNameType type; - hostName->get_Type(&type); - if (type != HostNameType_DomainName) - continue; - - HString name; - hostName->get_CanonicalName(name.GetAddressOf()); - UINT32 length; - PCWSTR rawString = name.GetRawBuffer(&length); - return QString::fromWCharArray(rawString, length); - } - ComPtr firstHost; - hostNames->GetAt(0, &firstHost); - - HString name; - firstHost->get_CanonicalName(name.GetAddressOf()); - UINT32 length; - PCWSTR rawString = name.GetRawBuffer(&length); - return QString::fromWCharArray(rawString, length); -} - // QString QHostInfo::localDomainName() defined in qnetworkinterface_win.cpp QT_END_NAMESPACE -- cgit v1.2.3