aboutsummaryrefslogtreecommitdiffstats
path: root/caputils
diff options
context:
space:
mode:
authorGraham Bloice <graham.bloice@trihedral.com>2018-03-01 00:01:45 +0000
committerGraham Bloice <graham.bloice@trihedral.com>2018-03-01 22:32:04 +0000
commitbf4c2fd82b30d8b088fcb1235263dce9173d4cd7 (patch)
treee1488d70ee99709e6fb89ef80d5ab4aa9c198433 /caputils
parent92bb9ec9da549991f402082794638a4458e77a81 (diff)
Windows: Remove cruft for unsupported versons
Remove all the existing LoadDLL\GetProcAddress combinations that allowed conditional Win32 API usage if supported on the running OS version. All the required functions are present in the versions we support. Change-Id: Ibc43e51cefcd1c7562d4e251784362509f224ed6 Reviewed-on: https://code.wireshark.org/review/26215 Petri-Dish: Graham Bloice <graham.bloice@trihedral.com> Tested-by: Petri Dish Buildbot Reviewed-by: Graham Bloice <graham.bloice@trihedral.com>
Diffstat (limited to 'caputils')
-rw-r--r--caputils/capture_win_ifnames.c115
1 files changed, 24 insertions, 91 deletions
diff --git a/caputils/capture_win_ifnames.c b/caputils/capture_win_ifnames.c
index 2d237daee3..92b22b95d5 100644
--- a/caputils/capture_win_ifnames.c
+++ b/caputils/capture_win_ifnames.c
@@ -218,109 +218,42 @@ gboolean IsWindowsVistaOrLater()
char *
get_interface_friendly_name_from_device_guid(__in GUID *guid)
{
- HMODULE hIPHlpApi;
- HRESULT status;
- WCHAR wName[NDIS_IF_MAX_STRING_SIZE + 1];
HRESULT hr;
- gboolean fallbackToUnpublishedApi=TRUE;
- gboolean haveInterfaceFriendlyName=FALSE;
- int size;
- char *name;
-
- /* Load the ip helper api DLL */
- hIPHlpApi = LoadLibrary(TEXT("iphlpapi.dll"));
- if (hIPHlpApi == NULL) {
- /* Load failed - DLL should always be available in XP+*/
- return NULL;
- }
/* Need to convert an Interface GUID to the interface friendly name (e.g. "Local Area Connection")
* The functions required to do this all reside within iphlpapi.dll
- * - The preferred approach is to use published API functions (Available since Windows Vista)
- * - We do however fallback to trying undocumented API if the published API is not available (Windows XP/2k3 scenario)
*/
- if(IsWindowsVistaOrLater()){
- /* Published API function prototypes (for Windows Vista/Windows Server 2008+) */
- typedef NETIO_STATUS (WINAPI *ProcAddr_CIG2L) (__in CONST GUID *InterfaceGuid, __out PNET_LUID InterfaceLuid);
- typedef NETIO_STATUS (WINAPI *ProcAddr_CIL2A) ( __in CONST NET_LUID *InterfaceLuid,__out_ecount(Length) PWSTR InterfaceAlias, __in SIZE_T Length);
-
- /* Attempt to do the conversion using Published API functions */
- ProcAddr_CIG2L proc_ConvertInterfaceGuidToLuid=(ProcAddr_CIG2L) GetProcAddress(hIPHlpApi, "ConvertInterfaceGuidToLuid");
- if(proc_ConvertInterfaceGuidToLuid!=NULL){
- ProcAddr_CIL2A Proc_ConvertInterfaceLuidToAlias=(ProcAddr_CIL2A) GetProcAddress(hIPHlpApi, "ConvertInterfaceLuidToAlias");
- if(Proc_ConvertInterfaceLuidToAlias!=NULL){
- /* we have our functions ready to go, attempt to convert interface guid->luid->friendlyname */
- NET_LUID InterfaceLuid;
- hr = proc_ConvertInterfaceGuidToLuid(guid, &InterfaceLuid);
- if(hr==NO_ERROR){
- /* guid->luid success */
- hr = Proc_ConvertInterfaceLuidToAlias(&InterfaceLuid, wName, NDIS_IF_MAX_STRING_SIZE+1);
-
- if(hr==NO_ERROR){
- /* luid->friendly name success */
- haveInterfaceFriendlyName=TRUE; /* success */
- }else{
- /* luid->friendly name failed */
- fallbackToUnpublishedApi=FALSE;
+ NET_LUID InterfaceLuid;
+ hr = ConvertInterfaceGuidToLuid(guid, &InterfaceLuid);
+ if(hr == NO_ERROR) {
+ /* guid->luid success */
+ WCHAR wName[NDIS_IF_MAX_STRING_SIZE + 1];
+ hr = ConvertInterfaceLuidToAlias(&InterfaceLuid, wName, NDIS_IF_MAX_STRING_SIZE+1);
+ if(hr == NO_ERROR) {
+ /* luid->friendly name success */
+
+ /* Get the required buffer size, and then convert the string
+ * from UTF-16 to UTF-8. */
+ int size;
+ char *name;
+ size = WideCharToMultiByte(CP_UTF8, 0, wName, -1, NULL, 0, NULL, NULL);
+ if(size != 0) {
+ name = (char *) g_malloc(size);
+ if (name != NULL) {
+ size = WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, size, NULL, NULL);
+ if(size != 0) {
+ return name;
}
- }else{
- fallbackToUnpublishedApi=FALSE;
+ /* Failed, clean up the allocation */
+ g_free(name);
}
-
- }
- }
- }
-
-
- if(fallbackToUnpublishedApi && !haveInterfaceFriendlyName){
- /* Didn't manage to get the friendly name using published api functions
- * (most likely cause wireshark is running on Windows XP/Server 2003)
- * Retry using nhGetInterfaceNameFromGuid (an older unpublished API function) */
- typedef HRESULT (WINAPI *ProcAddr_nhGINFG) (__in GUID *InterfaceGuid, __out PCWSTR InterfaceAlias, __inout DWORD *LengthAddress, wchar_t *a4, wchar_t *a5);
-
- ProcAddr_nhGINFG Proc_nhGetInterfaceNameFromGuid = NULL;
- Proc_nhGetInterfaceNameFromGuid = (ProcAddr_nhGINFG) GetProcAddress(hIPHlpApi, "NhGetInterfaceNameFromGuid");
- if (Proc_nhGetInterfaceNameFromGuid!= NULL) {
- wchar_t *p4=NULL, *p5=NULL;
- DWORD NameSize;
-
- /* testing of nhGetInterfaceNameFromGuid indicates the unpublished API function expects the 3rd parameter
- * to be the available space in bytes (as compared to wchar's) available in the second parameter buffer
- * to receive the friendly name (in unicode format) including the space for the nul termination.*/
- NameSize = sizeof(wName);
-
- /* do the guid->friendlyname lookup */
- status = Proc_nhGetInterfaceNameFromGuid(guid, wName, &NameSize, p4, p5);
-
- if(status==0){
- haveInterfaceFriendlyName=TRUE; /* success */
}
}
}
- /* we have finished with iphlpapi.dll - release it */
- FreeLibrary(hIPHlpApi);
-
- if(!haveInterfaceFriendlyName){
- /* failed to get the friendly name, nothing further to do */
- return NULL;
- }
-
- /* Get the required buffer size, and then convert the string
- * from UTF-16 to UTF-8. */
- size=WideCharToMultiByte(CP_UTF8, 0, wName, -1, NULL, 0, NULL, NULL);
- name=(char *) g_malloc(size);
- if (name == NULL){
- return NULL;
- }
- size=WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, size, NULL, NULL);
- if(size==0){
- /* bytes written == 0, indicating some form of error*/
- g_free(name);
- return NULL;
- }
- return name;
+ /* Failed to get a name */
+ return NULL;
}
/*