From 97c8781f404ae2020facfa7b82a522f71ec655a6 Mon Sep 17 00:00:00 2001 From: Andreas Holzammer Date: Mon, 12 Mar 2012 10:48:40 +0100 Subject: [PATCH] Dynamical get function GetTcp6Table Windows XP does not support IPV6; if we directly link against Iphlpapi.lib, Creator fails to load. To bypass this issue, lookup IPV6 function dynamically. Change-Id: Idd49b977b924458cc8cd6fbe646f5c05e853060b Reviewed-by: Kai Koehne --- src/libs/utils/tcpportsgatherer.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/libs/utils/tcpportsgatherer.cpp b/src/libs/utils/tcpportsgatherer.cpp index 2a89f17ef2b..9b130c86f6d 100644 --- a/src/libs/utils/tcpportsgatherer.cpp +++ b/src/libs/utils/tcpportsgatherer.cpp @@ -37,6 +37,7 @@ #include #ifdef Q_OS_WIN +#include #include #include #include @@ -60,8 +61,8 @@ public: }; #ifdef Q_OS_WIN -template -QSet usedTcpPorts() +template +QSet usedTcpPorts(ULONG (__stdcall *Func)(Table*, PULONG, BOOL)) { Table *table = static_cast(malloc(sizeof(Table))); DWORD dwSize = sizeof(Table); @@ -97,9 +98,19 @@ void TcpPortsGathererPrivate::updateWin(TcpPortsGatherer::ProtocolFlags protocol QSet ports; if (protocolFlags & TcpPortsGatherer::IPv4Protocol) - ports.unite(usedTcpPorts()); - if (protocolFlags & TcpPortsGatherer::IPv6Protocol) - ports.unite(usedTcpPorts()); + ports.unite(usedTcpPorts(GetTcpTable)); + + //Dynamically load symbol for GetTcp6Table for systems that dont have support for IPV6, + //eg Windows XP + typedef ULONG (__stdcall *GetTcp6TablePtr)(PMIB_TCP6TABLE, PULONG, BOOL); + static GetTcp6TablePtr getTcp6TablePtr = 0; + + if (!getTcp6TablePtr) + getTcp6TablePtr = (GetTcp6TablePtr)QLibrary::resolve(QLatin1String("Iphlpapi.dll"), + "GetTcp6Table"); + + if (getTcp6TablePtr && (protocolFlags & TcpPortsGatherer::IPv6Protocol)) + ports.unite(usedTcpPorts(getTcp6TablePtr)); foreach (int port, ports) { if (!usedPorts.contains(port))