VirtualBox

Changeset 31905 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Aug 24, 2010 10:16:08 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
65115
Message:

additions/VBoxService/VBoxServiceVMInfo: fixed obtaining MAC address for Solaris guests. Added some todo's.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp

    r31867 r31905  
    4141# ifdef RT_OS_SOLARIS
    4242#  include <sys/sockio.h>
     43#  include <net/if_arp.h>
    4344# endif
    4445# ifdef RT_OS_FREEBSD
     
    582583
    583584# 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);
    585611# else
    586612        if (ioctl(sd, SIOCGIFHWADDR, &ifrequest[i]) < 0)
    587 # endif
    588         {
     613        {
     614            /* @todo don't fail here, handle failure with zero MAC address */
    589615            VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFHWADDR) on socket: Error %d\n", errno);
    590616            close(sd);
    591617            return RTErrConvertFromErrno(errno);
    592618        }
     619# endif
    593620
    594621        char szMac[32];
    595622# if defined(RT_OS_SOLARIS)
    596         uint8_t *pu8Mac = (uint8_t*)&ifrequest[i].ifr_enaddr[0];
     623        uint8_t *pu8Mac = IfMac.au8;
    597624# 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 */
    599626# endif
    600627        RTStrPrintf(szMac, sizeof(szMac), "%02X%02X%02X%02X%02X%02X",
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette