Fix network detection for Windows OS (#94)
* Fix Warnings
Fix some of the compile warnings on invalid castings
* Improve parallels detection
Parallels Desktop (MAC) is now properly detected and identified (not as Other)
* Fix network detection for Windows OS
- Proper usage of GetAdaptersInfo
Co-authored-by: Gabriele Contini <gcontini@users.noreply.github.com>
| | |
| | | # Cmake generated files |
| | | build/* |
| | | !build/.gitkeep |
| | | install/* |
| | | |
| | | #eclipse files |
| | | .cproject |
| | |
| | | int license_version; // license file version |
| | | } LicenseInfo; |
| | | |
| | | typedef enum { BARE_TO_METAL, VMWARE, VIRTUALBOX, V_XEN, KVM, HV, V_OTHER } LCC_API_VIRTUALIZATION_DETAIL; |
| | | typedef enum { BARE_TO_METAL, VMWARE, VIRTUALBOX, V_XEN, KVM, HV, PARALLELS, V_OTHER } LCC_API_VIRTUALIZATION_DETAIL; |
| | | |
| | | typedef enum { |
| | | PROV_UNKNOWN = 0, |
| | |
| | | {V_XEN, "XEN"}, |
| | | {KVM, "KVM"}, |
| | | {HV, "Microsoft Hypervisor"}, |
| | | {PARALLELS, "Parallels Desktop"}, |
| | | {V_OTHER, "Other type of vm"}}; |
| | | |
| | | const unordered_map<int, string> descByVirt = {{LCC_API_VIRTUALIZATION_SUMMARY::NONE, "No virtualization"}, |
| | |
| | | const unsigned char* bin = (const unsigned char*)binaryData;
|
| | |
|
| | | int rc = 0; // result counter
|
| | | int byteNo; // I need this after the loop
|
| | | unsigned int byteNo; // I need this after the loop
|
| | |
|
| | | int modulusLen = len % 3;
|
| | | int pad = ((modulusLen & 1) << 1) + ((modulusLen & 2) >> 1); // 2 gives 1 and 1 gives 2, but 0 gives 0.
|
| | |
| | | const unsigned char* safeAsciiPtr = (const unsigned char*)tmp_str.c_str();
|
| | | std::vector<uint8_t> bin;
|
| | | int cb = 0;
|
| | | int charNo;
|
| | | unsigned int charNo;
|
| | | int pad = 0;
|
| | | size_t len = tmp_str.size();
|
| | |
|
| | |
| | | ifstream in(filename, std::ios::binary); |
| | | if (in) { |
| | | string contents; |
| | | size_t index = in.seekg(0, ios::end).tellg(); |
| | | size_t index = (size_t)in.seekg(0, ios::end).tellg(); |
| | | size_t limited_size = min(index, max_size); |
| | | contents.resize(limited_size); |
| | | in.seekg(0, ios::beg); |
| | |
| | | result = strategy->validate_identifier(pc_id); |
| | | } catch (logic_error& e) { |
| | | LOG_ERROR("Error validating identifier %s: %s", str_code.c_str(), e.what()); |
| | | ((void)(e)); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | |
| | | const unordered_map<string, LCC_API_VIRTUALIZATION_DETAIL> virtual_cpu_names{ |
| | | {"bhyve bhyve ", V_OTHER}, {"KVM", KVM}, {"MICROSOFT", HV}, {" lrpepyh vr", HV}, |
| | | {"prl hyperv ", V_OTHER}, {"VMWARE", VMWARE}, {"XenVMMXenVMM", V_XEN}, {"ACRNACRNACRN", V_OTHER}, |
| | | {"prl hyperv ", PARALLELS}, {"VMWARE", VMWARE}, {"XenVMMXenVMM", V_XEN}, {"ACRNACRNACRN", V_OTHER}, |
| | | {"VBOX", VIRTUALBOX}}; |
| | | |
| | | const unordered_map<string, LCC_API_VIRTUALIZATION_DETAIL> vm_vendors{{"VMWARE", VMWARE}, |
| | | {"MICROSOFT", HV}, |
| | | {"PARALLELS", PARALLELS}, |
| | | {"VITRUAL MACHINE", V_OTHER}, |
| | | {"INNOTEK GMBH", VIRTUALBOX}, |
| | | {"POWERVM", V_OTHER}, |
| | |
| | | #include <iphlpapi.h> |
| | | #include <unordered_map> |
| | | #include <stdio.h> |
| | | //#pragma comment(lib, "IPHLPAPI.lib") |
| | | #pragma comment(lib, "IPHLPAPI.lib") |
| | | |
| | | #include "../../base/string_utils.h" |
| | | #include "../../base/logger.h" |
| | |
| | | unordered_map<string, OsAdapterInfo> adapterByName; |
| | | FUNCTION_RETURN f_return = FUNC_RET_OK; |
| | | DWORD dwStatus; |
| | | int adapter_info_size; |
| | | PIP_ADAPTER_INFO pAdapterInfo; |
| | | DWORD dwBufLen = sizeof(IP_ADAPTER_INFO); |
| | | |
| | | unsigned int i = 3; |
| | | do { |
| | | // Make an initial call to GetAdaptersInfo to get the necessary size into the ulOutBufLen variable |
| | | pAdapterInfo = (PIP_ADAPTER_INFO)malloc(dwBufLen); |
| | | if (pAdapterInfo == nullptr) { |
| | | return FUNC_RET_ERROR; |
| | | } |
| | | |
| | | dwStatus = GetAdaptersInfo( // Call GetAdapterInfo |
| | | pAdapterInfo, // [out] buffer to receive data |
| | | &dwBufLen // [in] size of receive data buffer |
| | | ); |
| | | if (dwStatus != NO_ERROR && pAdapterInfo != nullptr) { |
| | | free(pAdapterInfo); |
| | | pAdapterInfo = nullptr; |
| | | } |
| | | } while (dwStatus == ERROR_BUFFER_OVERFLOW && i-- > 0); |
| | | |
| | | // Incase the buffer was too small, reallocate with the returned dwBufLen |
| | | if (dwStatus == ERROR_BUFFER_OVERFLOW) { |
| | | free(pAdapterInfo); |
| | | pAdapterInfo = (PIP_ADAPTER_INFO)malloc(dwBufLen); |
| | | |
| | | // Will only fail if buffer cannot be allocated (out of memory) |
| | | if (pAdapterInfo == nullptr) { |
| | | return FUNC_RET_BUFFER_TOO_SMALL; |
| | | } |
| | | |
| | | dwStatus = GetAdaptersInfo( // Call GetAdapterInfo |
| | | pAdapterInfo, // [out] buffer to receive data |
| | | &dwBufLen // [in] size of receive data buffer |
| | | ); |
| | | |
| | | switch (dwStatus) { |
| | | case NO_ERROR: |
| | | break; |
| | | |
| | | case ERROR_BUFFER_OVERFLOW: |
| | | free(pAdapterInfo); |
| | | return FUNC_RET_BUFFER_TOO_SMALL; |
| | | |
| | | default: |
| | | free(pAdapterInfo); |
| | | return FUNC_RET_ERROR; |
| | | } |
| | | |
| | | adapter_info_size = dwBufLen / sizeof(IP_ADAPTER_INFO); |
| | | if (adapter_info_size == 0) { |
| | | return FUNC_RET_NOT_AVAIL; |
| | | } |
| | | |
| | | PIP_ADAPTER_INFO pAdapter = pAdapterInfo; |
| | | i = 0; |
| | | FUNCTION_RETURN result = FUNC_RET_OK; |
| | | while (pAdapter) { |
| | | OsAdapterInfo ai = {}; |
| | |
| | | memcpy(ai.mac_address, pAdapter->Address, 8); |
| | | translate(pAdapter->IpAddressList.IpAddress.String, ai.ipv4_address); |
| | | ai.type = IFACE_TYPE_ETHERNET; |
| | | i++; |
| | | pAdapter = pAdapter->Next; |
| | | if (i == adapter_info_size) { |
| | | result = FUNC_RET_BUFFER_TOO_SMALL; |
| | | break; |
| | | } |
| | | adapterByName[string(ai.description)] = ai; |
| | | } |
| | | free(pAdapterInfo); |
| | |
| | | cout << (len & 0x80) << endl; |
| | | if ((len & 0x80) > 0) { |
| | | size_t blen = len & 0x7F; |
| | | for (int i = 0; i < blen; i++) { |
| | | for (size_t i = 0; i < blen; i++) { |
| | | result += (*(ptr++) << (i * 8)); |
| | | } |
| | | } else { |
| | |
| | | if (expected_length < length) { |
| | | return FUNC_RET_ERROR; |
| | | } |
| | | for (int i = 0; i < length; i++) { |
| | | for (size_t i = 0; i < length; i++) { |
| | | location[i] = *(ptr++); |
| | | } |
| | | return FUNC_RET_OK; |
| | |
| | | ss << " --" PARAM_LICENSE_OUTPUT " " << license_fname_s; |
| | | ss << " --" PARAM_PROJECT_FOLDER " " << LCC_TEST_LICENSES_PROJECT; |
| | | |
| | | for (int i = 0; i < other_args.size(); i++) { |
| | | for (size_t i = 0; i < other_args.size(); i++) { |
| | | ss << " " << other_args[i]; |
| | | } |
| | | cout << "executing :" << ss.str() << endl; |