Changeset 68620 in vbox
- Timestamp:
- Sep 4, 2017 5:30:59 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/win/NetIf-win.cpp
r68026 r68620 1517 1517 static BOOL netIfIsWireless(INetCfgComponent *pAdapter) 1518 1518 { 1519 HRESULT hr; 1520 wchar_t * pswzBindName; 1521 wchar_t FileName[MAX_PATH]; 1522 bool fWireless = false; 1523 1524 hr = pAdapter->GetBindName(&pswzBindName); 1525 wcscpy(FileName, DEVNAME_PREFIX); 1526 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName); 1527 1528 /* open the device */ 1529 HANDLE hDevice = CreateFile(FileName, 1530 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 1531 NULL, 1532 OPEN_EXISTING, 1533 FILE_ATTRIBUTE_NORMAL, 1534 NULL); 1535 1536 if (hDevice != INVALID_HANDLE_VALUE) 1537 { 1538 1539 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */ 1540 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM; 1541 NDIS_PHYSICAL_MEDIUM PhMedium; 1542 DWORD cbResult; 1543 if (DeviceIoControl(hDevice, 1544 IOCTL_NDIS_QUERY_GLOBAL_STATS, 1545 &Oid, 1546 sizeof(Oid), 1547 &PhMedium, 1548 sizeof(PhMedium), 1549 &cbResult, 1550 NULL)) 1551 { 1552 /* that was simple, now examine PhMedium */ 1553 fWireless = PhMedium == NdisPhysicalMediumWirelessWan 1554 || PhMedium == NdisPhysicalMediumWirelessLan 1555 || PhMedium == NdisPhysicalMediumNative802_11 1556 || PhMedium == NdisPhysicalMediumBluetooth; 1557 } 1558 else 1559 { 1560 int winEr = GetLastError(); 1561 LogRel(("netIfIsWireless: DeviceIoControl failed, err (0x%x), ignoring\n", winEr)); 1562 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND); 1563 } 1564 CloseHandle(hDevice); 1519 bool fWireless = false; 1520 1521 /* Construct a device name. */ 1522 LPWSTR pwszBindName = NULL; 1523 HRESULT hrc = pAdapter->GetBindName(&pwszBindName); 1524 if (SUCCEEDED(hrc) && pwszBindName) 1525 { 1526 WCHAR wszFileName[MAX_PATH]; 1527 int vrc = RTUtf16Copy(wszFileName, MAX_PATH, DEVNAME_PREFIX); 1528 if (RT_SUCCESS(vrc)) 1529 vrc = RTUtf16Cat(wszFileName, MAX_PATH, pwszBindName); 1530 if (RT_SUCCESS(vrc)) 1531 { 1532 /* open the device */ 1533 HANDLE hDevice = CreateFileW(wszFileName, 1534 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 1535 NULL, 1536 OPEN_EXISTING, 1537 FILE_ATTRIBUTE_NORMAL, 1538 NULL); 1539 if (hDevice != INVALID_HANDLE_VALUE) 1540 { 1541 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */ 1542 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM; 1543 NDIS_PHYSICAL_MEDIUM PhMedium = NdisPhysicalMediumUnspecified; 1544 DWORD cbResultIgn = 0; 1545 if (DeviceIoControl(hDevice, 1546 IOCTL_NDIS_QUERY_GLOBAL_STATS, 1547 &Oid, 1548 sizeof(Oid), 1549 &PhMedium, 1550 sizeof(PhMedium), 1551 &cbResultIgn, 1552 NULL)) 1553 { 1554 /* that was simple, now examine PhMedium */ 1555 fWireless = PhMedium == NdisPhysicalMediumWirelessWan 1556 || PhMedium == NdisPhysicalMediumWirelessLan 1557 || PhMedium == NdisPhysicalMediumNative802_11 1558 || PhMedium == NdisPhysicalMediumBluetooth; 1559 } 1560 else 1561 { 1562 DWORD rcWin = GetLastError(); 1563 LogRel(("netIfIsWireless: DeviceIoControl to '%ls' failed with rcWin=%u (%#x) - ignoring\n", 1564 wszFileName, rcWin, rcWin)); 1565 Assert(rcWin == ERROR_INVALID_PARAMETER || rcWin == ERROR_NOT_SUPPORTED || rcWin == ERROR_BAD_COMMAND); 1566 } 1567 CloseHandle(hDevice); 1568 } 1569 else 1570 { 1571 DWORD rcWin = GetLastError(); 1572 #if 0 /* bird: Triggers on each VBoxSVC startup so, disabled. Whoever want it, can enable using DEBUG_xxxx. */ 1573 AssertLogRelMsgFailed(("netIfIsWireless: CreateFile on '%ls' failed with rcWin=%u (%#x) - ignoring\n", 1574 wszFileName, rcWin, rcWin)); 1575 #else 1576 LogRel(("netIfIsWireless: CreateFile on '%ls' failed with rcWin=%u (%#x) - ignoring\n", 1577 wszFileName, rcWin, rcWin)); 1578 #endif 1579 } 1580 } 1581 CoTaskMemFree(pwszBindName); 1565 1582 } 1566 1583 else 1567 { 1568 int winEr = GetLastError(); 1569 AssertLogRelMsgFailed(("netIfIsWireless: CreateFile failed, err (0x%x), ignoring\n", winEr)); 1570 } 1571 1572 CoTaskMemFree(pswzBindName); 1584 LogRel(("netIfIsWireless: GetBindName failed hrc=%Rhrc\n", hrc)); 1585 1573 1586 return fWireless; 1574 1587 }
Note:
See TracChangeset
for help on using the changeset viewer.