mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
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
This commit is contained in:
parent
acec4be2e4
commit
1883e277ac
1 changed files with 37 additions and 17 deletions
|
@ -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;
|
||||
|
||||
if (GetAdaptersInfo(adapter, &buflen) == ERROR_BUFFER_OVERFLOW) {
|
||||
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) == NO_ERROR) {
|
||||
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;
|
||||
}
|
||||
|
||||
exit:
|
||||
HeapFree(GetProcessHeap(), 0, adapter);
|
||||
return status;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue