diff --git a/indra/cmake/Linking.cmake b/indra/cmake/Linking.cmake index 4028a3f7a6288f86f10dd56c6e6abb749eb7968f..df1753ded8d9cfa10dcb19509c8d9f4f9f83d53c 100644 --- a/indra/cmake/Linking.cmake +++ b/indra/cmake/Linking.cmake @@ -65,7 +65,6 @@ if (WINDOWS) mswsock psapi winmm - netapi32 wldap32 gdi32 user32 diff --git a/indra/cmake/PluginAPI.cmake b/indra/cmake/PluginAPI.cmake index d1649e824868ee702d07f0510fe927aae9cf7692..879c8536e4a6591519ffeb674e908becd454087f 100644 --- a/indra/cmake/PluginAPI.cmake +++ b/indra/cmake/PluginAPI.cmake @@ -5,7 +5,6 @@ if (WINDOWS) wsock32 ws2_32 psapi - netapi32 advapi32 user32 ) diff --git a/indra/llcommon/lluuid.cpp b/indra/llcommon/lluuid.cpp index c6c1e73fbcd24977ca148ddf6cffe1abaa7763f2..e924421ff2a8100e8da21680b709f2f1fc757e68 100644 --- a/indra/llcommon/lluuid.cpp +++ b/indra/llcommon/lluuid.cpp @@ -27,7 +27,7 @@ // We can't use WIN32_LEAN_AND_MEAN here, needs lots of includes. #if LL_WINDOWS -#include "llwin32headers.h" +#include "llwin32headerslean.h" // ugh, this is ugly. We need to straighten out our linking for this library #pragma comment(lib, "IPHLPAPI.lib") #include <iphlpapi.h> @@ -456,51 +456,88 @@ static void get_random_bytes(void *buf, int nbytes) #if LL_WINDOWS -typedef struct _ASTAT_ -{ - ADAPTER_STATUS adapt; - NAME_BUFFER NameBuff [30]; -}ASTAT, * PASTAT; - // static S32 LLUUID::getNodeID(unsigned char *node_id) { - ASTAT Adapter; - NCB Ncb; - UCHAR uRetCode; - LANA_ENUM lenum; - int i; - int retval = 0; + static bool got_node_id = false; + static unsigned char local_node_id[6]; + if (got_node_id) + { + memcpy(node_id, local_node_id, sizeof(local_node_id)); + return 1; + } - memset( &Ncb, 0, sizeof(Ncb) ); - Ncb.ncb_command = NCBENUM; - Ncb.ncb_buffer = (UCHAR *)&lenum; - Ncb.ncb_length = sizeof(lenum); - uRetCode = Netbios( &Ncb ); + S32 retval = 0; + PIP_ADAPTER_ADDRESSES pAddresses = nullptr; + ULONG outBufLen = 0U; + DWORD dwRetVal = 0U; - for(i=0; i < lenum.length ;i++) - { - memset( &Ncb, 0, sizeof(Ncb) ); - Ncb.ncb_command = NCBRESET; - Ncb.ncb_lana_num = lenum.lana[i]; + ULONG family = AF_INET; + ULONG flags = GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_INCLUDE_GATEWAYS; - uRetCode = Netbios( &Ncb ); + GetAdaptersAddresses( + AF_INET, + flags, + nullptr, + nullptr, + &outBufLen); - memset( &Ncb, 0, sizeof (Ncb) ); - Ncb.ncb_command = NCBASTAT; - Ncb.ncb_lana_num = lenum.lana[i]; + constexpr U32 MAX_TRIES = 3U; + U32 iteration = 0U; + do { - strcpy( (char *)Ncb.ncb_callname, "* " ); /* Flawfinder: ignore */ - Ncb.ncb_buffer = (unsigned char *)&Adapter; - Ncb.ncb_length = sizeof(Adapter); + pAddresses = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(malloc(outBufLen)); + if (pAddresses == nullptr) { + return 0; + } - uRetCode = Netbios( &Ncb ); - if ( uRetCode == 0 ) - { - memcpy(node_id,Adapter.adapt.adapter_address,6); /* Flawfinder: ignore */ - retval = 1; + dwRetVal = + GetAdaptersAddresses(family, flags, nullptr, pAddresses, &outBufLen); + + if (dwRetVal == ERROR_BUFFER_OVERFLOW) { + free(pAddresses); + pAddresses = nullptr; } + else { + break; + } + + ++iteration; + + } while ((dwRetVal == ERROR_BUFFER_OVERFLOW) && (iteration < MAX_TRIES)); + + if (dwRetVal == NO_ERROR) + { + PIP_ADAPTER_ADDRESSES pCurrAddresses = pAddresses; + PIP_ADAPTER_GATEWAY_ADDRESS pFirstGateway = nullptr; + do { + pFirstGateway = pCurrAddresses->FirstGatewayAddress; + if (pFirstGateway) + { + if ((pCurrAddresses->IfType == IF_TYPE_ETHERNET_CSMACD || pCurrAddresses->IfType == IF_TYPE_IEEE80211) && pCurrAddresses->ConnectionType == NET_IF_CONNECTION_DEDICATED + && pCurrAddresses->OperStatus == IfOperStatusUp) + { + if (pCurrAddresses->PhysicalAddressLength == 6) + { + for (size_t i = 0; i < 5; ++i) + { + node_id[i] = pCurrAddresses->PhysicalAddress[i]; + local_node_id[i] = pCurrAddresses->PhysicalAddress[i]; + } + retval = 1; + got_node_id = true; + break; + } + } + } + pCurrAddresses = pCurrAddresses->Next; + } while (pCurrAddresses); // Terminate if last adapter } + + if(pAddresses) + free(pAddresses); + pAddresses = nullptr; + return retval; } @@ -892,7 +929,9 @@ U32 LLUUID::getRandomSeed() md5_seed.finalize(); md5_seed.raw_digest(seed); - return(*(U32 *)seed); + U32 out; + memcpy(&out, seed, sizeof(out)); + return out; } BOOL LLUUID::parseUUID(const std::string& buf, LLUUID* value)