Changeset 29764 in vbox for trunk/src/VBox/Additions
- Timestamp:
- May 24, 2010 6:33:32 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r29594 r29764 41 41 # include <sys/sockio.h> 42 42 # endif 43 # ifdef RT_OS_FREEBSD 44 # include <ifaddrs.h> /* getifaddrs, freeifaddrs */ 45 # include <net/if_dl.h> /* LLADDR */ 46 # include <netdb.h> /* getnameinfo */ 47 # endif 43 48 #endif 44 49 … … 394 399 if (sd >= 0) 395 400 closesocket(sd); 396 #else /* !RT_OS_WINDOWS */ 401 #elif defined(RT_OS_FREEBSD) 402 int rc = 0; 403 struct ifaddrs *pIfHead = NULL; 404 405 /* Get all available interfaces */ 406 rc = getifaddrs(&pIfHead); 407 if (rc < 0) 408 { 409 VBoxServiceError("Failed to get all interfaces: Error %d\n", errno); 410 return RTErrConvertFromErrno(errno); 411 } 412 413 /* Loop through all interfaces and set the data. */ 414 for (struct ifaddrs *pIfCurr = pIfHead; pIfCurr; pIfCurr = pIfCurr->ifa_next) 415 { 416 /* 417 * Only AF_INET and no loopback interfaces 418 * @todo: IPv6 interfaces 419 */ 420 if ( pIfCurr->ifa_addr->sa_family == AF_INET 421 && !(pIfCurr->ifa_flags & IFF_LOOPBACK)) 422 { 423 char szInetAddr[NI_MAXHOST]; 424 425 memset(szInetAddr, 0, NI_MAXHOST); 426 getnameinfo(pIfCurr->ifa_addr, sizeof(struct sockaddr_in), 427 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 428 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/IP", cIfacesReport); 429 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 430 431 memset(szInetAddr, 0, NI_MAXHOST); 432 getnameinfo(pIfCurr->ifa_broadaddr, sizeof(struct sockaddr_in), 433 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 434 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/Broadcast", cIfacesReport); 435 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 436 437 memset(szInetAddr, 0, NI_MAXHOST); 438 getnameinfo(pIfCurr->ifa_netmask, sizeof(struct sockaddr_in), 439 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 440 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/Netmask", cIfacesReport); 441 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 442 443 /* Search for the AF_LINK interface of the current AF_INET one and get the mac. */ 444 for (struct ifaddrs *pIfLinkCurr = pIfHead; pIfLinkCurr; pIfLinkCurr = pIfLinkCurr->ifa_next) 445 { 446 if ( pIfLinkCurr->ifa_addr->sa_family == AF_LINK 447 && !strcmp(pIfCurr->ifa_name, pIfLinkCurr->ifa_name)) 448 { 449 char szMac[32]; 450 uint8_t *pu8Mac = NULL; 451 struct sockaddr_dl *pLinkAddress = (struct sockaddr_dl *)pIfLinkCurr->ifa_addr; 452 453 AssertPtr(pLinkAddress); 454 pu8Mac = (uint8_t *)LLADDR(pLinkAddress); 455 RTStrPrintf(szMac, sizeof(szMac), "%02X%02X%02X%02X%02X%02X", 456 pu8Mac[0], pu8Mac[1], pu8Mac[2], pu8Mac[3], pu8Mac[4], pu8Mac[5]); 457 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/MAC", cIfacesReport); 458 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szMac); 459 break; 460 } 461 } 462 463 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/Status", cIfacesReport); 464 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, pIfCurr->ifa_flags & IFF_UP ? "Up" : "Down"); 465 466 cIfacesReport++; 467 } 468 } 469 470 /* Free allocated resources. */ 471 freeifaddrs(pIfHead); 472 473 #else /* !RT_OS_WINDOWS && !RT_OS_FREEBSD */ 397 474 int sd = socket(AF_INET, SOCK_DGRAM, 0); 398 475 if (sd < 0) … … 449 526 return RTErrConvertFromErrno(errno); 450 527 } 451 #if defined(RT_OS_ FREEBSD) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)528 #if defined(RT_OS_OS2) || defined(RT_OS_SOLARIS) 452 529 pAddress = (sockaddr_in *)&ifrequest[i].ifr_addr; 453 530 #else
Note:
See TracChangeset
for help on using the changeset viewer.