Changeset 31905 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Aug 24, 2010 10:16:08 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 65115
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r31867 r31905 41 41 # ifdef RT_OS_SOLARIS 42 42 # include <sys/sockio.h> 43 # include <net/if_arp.h> 43 44 # endif 44 45 # ifdef RT_OS_FREEBSD … … 582 583 583 584 # if defined(RT_OS_SOLARIS) 584 if (ioctl(sd, SIOCGENADDR, &ifrequest[i]) < 0) 585 /* 586 * "ifreq" is obsolete on Solaris. We use the recommended "lifreq". 587 * We might fail if the interface has not been assigned an IP address. 588 * That doesn't matter; as long as it's plumbed we can pick it up. 589 * But, if it has not acquired an IP address we cannot obtain it's MAC 590 * address this way, so we just use all zeros there. 591 */ 592 RTMAC IfMac; 593 RT_ZERO(IfMac); 594 struct lifreq IfReq; 595 RT_ZERO(IfReq); 596 AssertCompile(sizeof(IfReq.lifr_name) >= sizeof(ifrequest[i].ifr_name)); 597 strncpy(IfReq.lifr_name, ifrequest[i].ifr_name, sizeof(ifrequest[i].ifr_name)); 598 if (ioctl(sd, SIOCGLIFADDR, &IfReq) >= 0) 599 { 600 struct arpreq ArpReq; 601 RT_ZERO(ArpReq); 602 memcpy(&ArpReq.arp_pa, &IfReq.lifr_addr, sizeof(struct sockaddr_in)); 603 604 if (ioctl(sd, SIOCGARP, &ArpReq) >= 0) 605 memcpy(&IfMac, ArpReq.arp_ha.sa_data, sizeof(IfMac)); 606 else 607 VBoxServiceError("VMInfo/Network: failed to ioctl(SIOCGARP) on socket: Error %d\n", errno); 608 } 609 else 610 VBoxServiceError("VMInfo/Network: failed to ioctl(SIOCGLIFADDR) on socket: Error %d\n", errno); 585 611 # else 586 612 if (ioctl(sd, SIOCGIFHWADDR, &ifrequest[i]) < 0) 587 # endif 588 {613 { 614 /* @todo don't fail here, handle failure with zero MAC address */ 589 615 VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFHWADDR) on socket: Error %d\n", errno); 590 616 close(sd); 591 617 return RTErrConvertFromErrno(errno); 592 618 } 619 # endif 593 620 594 621 char szMac[32]; 595 622 # if defined(RT_OS_SOLARIS) 596 uint8_t *pu8Mac = (uint8_t*)&ifrequest[i].ifr_enaddr[0];623 uint8_t *pu8Mac = IfMac.au8; 597 624 # else 598 uint8_t *pu8Mac = (uint8_t*)&ifrequest[i].ifr_hwaddr.sa_data[0]; 625 uint8_t *pu8Mac = (uint8_t*)&ifrequest[i].ifr_hwaddr.sa_data[0]; /* @todo see above */ 599 626 # endif 600 627 RTStrPrintf(szMac, sizeof(szMac), "%02X%02X%02X%02X%02X%02X",
Note:
See TracChangeset
for help on using the changeset viewer.