- Timestamp:
- May 27, 2010 9:50:33 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r29764 r29852 22 22 *******************************************************************************/ 23 23 #ifdef RT_OS_WINDOWS 24 #include <winsock2.h> 25 #include <ws2tcpip.h> 26 #include <windows.h> 27 #include <Ntsecapi.h> 24 # include <winsock2.h> 25 # include <iphlpapi.h> 26 # include <ws2tcpip.h> 27 # include <windows.h> 28 # include <Ntsecapi.h> 28 29 #else 29 30 # define __STDC_LIMIT_MACROS … … 242 243 if (r != STATUS_SUCCESS) 243 244 { 244 VBoxServiceError(" LsaEnumerate failed %lu\n", LsaNtStatusToWinError(r));245 VBoxServiceError("VMInfo/Users: LsaEnumerate failed %lu\n", LsaNtStatusToWinError(r)); 245 246 return RTErrConvertFromWin32(LsaNtStatusToWinError(r)); 246 247 } … … 290 291 # endif 291 292 { 292 VBoxServiceError(" Could not set UTMP file! Error: %ld\n", errno);293 VBoxServiceError("VMInfo/Users: Could not set UTMP file! Error: %ld\n", errno); 293 294 } 294 295 setutent(); … … 348 349 349 350 #ifdef RT_OS_WINDOWS 351 IP_ADAPTER_INFO *pAdpInfo = NULL; 352 353 # ifndef TARGET_NT4 354 ULONG cbAdpInfo = sizeof(*pAdpInfo); 355 pAdpInfo = (IP_ADAPTER_INFO*)RTMemAlloc(cbAdpInfo); 356 if (!pAdpInfo) 357 { 358 VBoxServiceError("VMInfo/Network: Failed to allocate IP_ADAPTER_INFO\n"); 359 return VERR_NO_MEMORY; 360 } 361 DWORD dwRet = GetAdaptersInfo(pAdpInfo, &cbAdpInfo); 362 if (dwRet == ERROR_BUFFER_OVERFLOW) 363 { 364 IP_ADAPTER_INFO *pAdpInfoNew = (IP_ADAPTER_INFO*)RTMemRealloc(pAdpInfo, cbAdpInfo); 365 if (pAdpInfoNew) 366 { 367 pAdpInfo = pAdpInfoNew; 368 dwRet = GetAdaptersInfo(pAdpInfo, &cbAdpInfo); 369 } 370 } 371 if (dwRet != ERROR_SUCCESS) 372 { 373 if (pAdpInfo) 374 RTMemFree(pAdpInfo); 375 VBoxServiceError("VMInfo/Network: Failed to get adapter info: Error %d\n", dwRet); 376 return RTErrConvertFromWin32(dwRet); 377 } 378 # endif 379 350 380 SOCKET sd = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0); 351 381 if (sd == SOCKET_ERROR) /* Socket invalid. */ 352 382 { 353 VBoxServiceError("Failed to get a socket: Error %d\n", WSAGetLastError()); 383 VBoxServiceError("VMInfo/Network: Failed to get a socket: Error %d\n", WSAGetLastError()); 384 if (pAdpInfo) 385 RTMemFree(pAdpInfo); 354 386 return RTErrConvertFromWin32(WSAGetLastError()); 355 387 } … … 367 399 0) == SOCKET_ERROR) 368 400 { 369 VBoxServiceError("Failed to WSAIoctl() on socket: Error: %d\n", WSAGetLastError()); 401 VBoxServiceError("VMInfo/Network: Failed to WSAIoctl() on socket: Error: %d\n", WSAGetLastError()); 402 if (pAdpInfo) 403 RTMemFree(pAdpInfo); 370 404 return RTErrConvertFromWin32(WSAGetLastError()); 371 405 } … … 382 416 pAddress = (sockaddr_in *)&(InterfaceList[i].iiAddress); 383 417 Assert(pAddress); 418 char szIp[32]; 419 RTStrPrintf(szIp, sizeof(szIp), "%s", inet_ntoa(pAddress->sin_addr)); 384 420 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/IP", cIfacesReport); 385 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));421 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szIp); 386 422 387 423 pAddress = (sockaddr_in *) & (InterfaceList[i].iiBroadcastAddress); … … 395 431 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/Status", cIfacesReport); 396 432 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, nFlags & IFF_UP ? "Up" : "Down"); 433 434 # ifndef TARGET_NT4 435 IP_ADAPTER_INFO *pAdp; 436 for (pAdp = pAdpInfo; pAdp; pAdp = pAdp->Next) 437 if (!strcmp(pAdp->IpAddressList.IpAddress.String, szIp)) 438 break; 439 440 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/MAC", cIfacesReport); 441 if (pAdp) 442 { 443 char szMac[32]; 444 RTStrPrintf(szMac, sizeof(szMac), "%02X%02X%02X%02X%02X%02X", 445 pAdp->Address[0], pAdp->Address[1], pAdp->Address[2], 446 pAdp->Address[3], pAdp->Address[4], pAdp->Address[5]); 447 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szMac); 448 } 449 else 450 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, NULL); 451 # endif 452 397 453 cIfacesReport++; 398 454 } 455 if (pAdpInfo) 456 RTMemFree(pAdpInfo); 399 457 if (sd >= 0) 400 458 closesocket(sd); 459 401 460 #elif defined(RT_OS_FREEBSD) 402 461 int rc = 0; … … 407 466 if (rc < 0) 408 467 { 409 VBoxServiceError(" Failed to get all interfaces: Error %d\n", errno);468 VBoxServiceError("VMInfo/Network: Failed to get all interfaces: Error %d\n", errno); 410 469 return RTErrConvertFromErrno(errno); 411 470 } … … 475 534 if (sd < 0) 476 535 { 477 VBoxServiceError(" Failed to get a socket: Error %d\n", errno);536 VBoxServiceError("VMInfo/Network: Failed to get a socket: Error %d\n", errno); 478 537 return RTErrConvertFromErrno(errno); 479 538 } … … 485 544 if (ioctl(sd, SIOCGIFCONF, &ifcfg) < 0) 486 545 { 487 VBoxServiceError(" Failed to ioctl(SIOCGIFCONF) on socket: Error %d\n", errno);546 VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFCONF) on socket: Error %d\n", errno); 488 547 return RTErrConvertFromErrno(errno); 489 548 } … … 497 556 if (ioctl(sd, SIOCGIFFLAGS, &ifrequest[i]) < 0) 498 557 { 499 VBoxServiceError(" Failed to ioctl(SIOCGIFFLAGS) on socket: Error %d\n", errno);558 VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFFLAGS) on socket: Error %d\n", errno); 500 559 close(sd); 501 560 return RTErrConvertFromErrno(errno); … … 512 571 if (ioctl(sd, SIOCGIFBRDADDR, &ifrequest[i]) < 0) 513 572 { 514 VBoxServiceError(" Failed to ioctl(SIOCGIFBRDADDR) on socket: Error %d\n", errno);573 VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFBRDADDR) on socket: Error %d\n", errno); 515 574 close(sd); 516 575 return RTErrConvertFromErrno(errno); … … 522 581 if (ioctl(sd, SIOCGIFNETMASK, &ifrequest[i]) < 0) 523 582 { 524 VBoxServiceError(" Failed to ioctl(SIOCGIFBRDADDR) on socket: Error %d\n", errno);583 VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFBRDADDR) on socket: Error %d\n", errno); 525 584 close(sd); 526 585 return RTErrConvertFromErrno(errno); … … 541 600 #endif 542 601 { 543 VBoxServiceError(" Failed to ioctl(SIOCGIFHWADDR) on socket: Error %d\n", errno);602 VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFHWADDR) on socket: Error %d\n", errno); 544 603 close(sd); 545 604 return RTErrConvertFromErrno(errno); … … 596 655 WSADATA wsaData; 597 656 if (WSAStartup(MAKEWORD(2, 2), &wsaData)) 598 VBoxServiceError(" WSAStartup failed! Error: %Rrc\n", RTErrConvertFromWin32(WSAGetLastError()));657 VBoxServiceError("VMInfo: WSAStartup failed! Error: %Rrc\n", RTErrConvertFromWin32(WSAGetLastError())); 599 658 #endif /* RT_OS_WINDOWS */ 600 659 … … 630 689 if (rc2 != VERR_TIMEOUT && RT_FAILURE(rc2)) 631 690 { 632 VBoxServiceError(" RTSemEventMultiWait failed; rc2=%Rrc\n", rc2);691 VBoxServiceError("VMInfo: RTSemEventMultiWait failed; rc2=%Rrc\n", rc2); 633 692 rc = rc2; 634 693 break; … … 679 738 rc = VbglR3GuestPropDisconnect(g_uVMInfoGuestPropSvcClientID); 680 739 if (RT_FAILURE(rc)) 681 VBoxServiceError(" Failed to disconnect from guest property service! Error: %Rrc\n", rc);740 VBoxServiceError("VMInfo: Failed to disconnect from guest property service! Error: %Rrc\n", rc); 682 741 g_uVMInfoGuestPropSvcClientID = 0; 683 742
Note:
See TracChangeset
for help on using the changeset viewer.