From 1883e277accd46f3407af7dba9f82d50069ab254 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Thu, 26 May 2005 13:45:08 +0000 Subject: [PATCH] Dynamically load and detect iphlpapi. Makes rpcrt4 work on systems without the DLL and also does not force every app on the system to load the network libraries like before svn path=/trunk/; revision=15513 --- reactos/lib/rpcrt4/rpcrt4_main.c | 54 ++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/reactos/lib/rpcrt4/rpcrt4_main.c b/reactos/lib/rpcrt4/rpcrt4_main.c index bdab2e87036..4f8d66a6ba6 100644 --- a/reactos/lib/rpcrt4/rpcrt4_main.c +++ b/reactos/lib/rpcrt4/rpcrt4_main.c @@ -319,6 +319,8 @@ static void RPC_UuidGetSystemTime(ULONGLONG *time) *time += TICKS_15_OCT_1582_TO_1601; } +typedef DWORD WINAPI (*LPGETADAPTERSINFO)(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen); + /* Assume that a hardware address is at least 6 bytes long */ #define ADDRESS_BYTES_NEEDED 6 @@ -329,28 +331,46 @@ static RPC_STATUS RPC_UuidGetNodeAddress(BYTE *address) ULONG buflen = sizeof(IP_ADAPTER_INFO); PIP_ADAPTER_INFO adapter = HeapAlloc(GetProcessHeap(), 0, buflen); + HANDLE hIpHlpApi; + LPGETADAPTERSINFO pGetAdaptersInfo; + + hIpHlpApi = LoadLibrary("iphlpapi.dll"); + if (hIpHlpApi) + { + pGetAdaptersInfo = (LPGETADAPTERSINFO)GetProcAddress(hIpHlpApi, "GetAdaptersInfo"); + if (pGetAdaptersInfo) + { + if (pGetAdaptersInfo(adapter, &buflen) == ERROR_BUFFER_OVERFLOW) { + HeapFree(GetProcessHeap(), 0, adapter); + adapter = HeapAlloc(GetProcessHeap(), 0, buflen); + } - if (GetAdaptersInfo(adapter, &buflen) == ERROR_BUFFER_OVERFLOW) { - HeapFree(GetProcessHeap(), 0, adapter); - adapter = HeapAlloc(GetProcessHeap(), 0, buflen); - } - - if (GetAdaptersInfo(adapter, &buflen) == NO_ERROR) { - for (i = 0; i < ADDRESS_BYTES_NEEDED; i++) { - address[i] = adapter->Address[i]; + if (pGetAdaptersInfo(adapter, &buflen) == NO_ERROR) { + for (i = 0; i < ADDRESS_BYTES_NEEDED; i++) { + address[i] = adapter->Address[i]; + } + } + else + { + goto local; + } } + + /* Free the Library */ + FreeLibrary(hIpHlpApi); + goto exit; } + +local: /* We can't get a hardware address, just use random numbers. - Set the multicast bit to prevent conflicts with real cards. */ - else { - for (i = 0; i < ADDRESS_BYTES_NEEDED; i++) { - address[i] = rand() & 0xff; - } - - address[0] |= 0x01; - status = RPC_S_UUID_LOCAL_ONLY; + Set the multicast bit to prevent conflicts with real cards. */ + for (i = 0; i < ADDRESS_BYTES_NEEDED; i++) { + address[i] = rand() & 0xff; } - + address[0] |= 0x01; + status = RPC_S_UUID_LOCAL_ONLY; + +exit: HeapFree(GetProcessHeap(), 0, adapter); return status; }