VirtualBox

Changeset 50554 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 24, 2014 11:38:25 AM (11 years ago)
Author:
vboxsync
Message:

VBoxServiceVMInfo.cpp: Fixed interface IP address on OS/2 (probably applicable everywhere) and implemented getting the MAC address on OS/2.

File:
1 edited

Legend:

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

    r50448 r50554  
    10341034        /*
    10351035         * Only AF_INET and no loopback interfaces
    1036          * @todo: IPv6 interfaces
    10371036         */
     1037        /** @todo: IPv6 interfaces */
    10381038        if (   pIfCurr->ifa_addr->sa_family == AF_INET
    10391039            && !(pIfCurr->ifa_flags & IFF_LOOPBACK))
     
    11101110    }
    11111111
    1112     ifreq* ifrequest = ifcfg.ifc_req;
     1112    ifreq *ifrequest = ifcfg.ifc_req;
    11131113    int cIfacesSystem = ifcfg.ifc_len / sizeof(ifreq);
    11141114
     1115# ifdef RT_OS_OS2 /* Get the physical addresses. */
     1116    struct ifmib IfStats;
     1117    if (ioctl(sd, SIOSTATIF, &IfStats) < 0)
     1118    {
     1119        VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOSTATIF): errno=%d\n", errno);
     1120        RT_ZERO(IfStats);
     1121    }
     1122# endif
     1123
    11151124    for (int i = 0; i < cIfacesSystem; ++i)
    11161125    {
    1117         sockaddr_in *pAddress;
     1126# ifdef RT_OS_OS2
     1127        ifreq IfReqCopy = ifrequest[i];
     1128# endif
     1129        /* Get the interface flags. */
    11181130        if (ioctl(sd, SIOCGIFFLAGS, &ifrequest[i]) < 0)
    11191131        {
     1132# ifdef RT_OS_OS2 /* Ignore errors when querying flags for non-existing interfaces. */
     1133            if (errno == ENXIO)
     1134                continue;
     1135# endif
    11201136            rc = RTErrConvertFromErrno(errno);
    1121             VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFFLAGS) on socket: Error %Rrc\n", rc);
     1137            VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFFLAGS,#%u) on socket: Error %Rrc\n", i, rc);
    11221138            break;
    11231139        }
     
    11251141            continue;
    11261142
    1127         bool fIfUp = !!(ifrequest[i].ifr_flags & IFF_UP);
    1128         pAddress = ((sockaddr_in *)&ifrequest[i].ifr_addr);
    1129         Assert(pAddress);
     1143        bool const fIfUp = !!(ifrequest[i].ifr_flags & IFF_UP);
     1144
     1145# ifdef RT_OS_OS2 /* I think this should be done everywhere. */
     1146        /* Get the address. */
     1147        ifrequest[i] = IfReqCopy;
     1148        if (ioctl(sd, SIOCGIFADDR, &ifrequest[i]) < 0)
     1149        {
     1150            rc = RTErrConvertFromErrno(errno);
     1151            VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFADDR) on socket: Error %Rrc\n", rc);
     1152            break;
     1153        }
     1154# endif
     1155        sockaddr_in *pAddress = ((sockaddr_in *)&ifrequest[i].ifr_addr);
    11301156        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfacesReport);
    11311157        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    11321158
     1159        /* Get the broadcast address. */
    11331160        if (ioctl(sd, SIOCGIFBRDADDR, &ifrequest[i]) < 0)
    11341161        {
     
    11411168        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    11421169
     1170        /* Get the net mask. */
    11431171        if (ioctl(sd, SIOCGIFNETMASK, &ifrequest[i]) < 0)
    11441172        {
     
    11521180        pAddress = (sockaddr_in *)&ifrequest[i].ifr_netmask;
    11531181# endif
    1154 
    11551182        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfacesReport);
    11561183        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
     
    11641191         * address this way, so we just use all zeros there.
    11651192         */
    1166         RTMAC IfMac;
     1193        RTMAC   IfMac;
    11671194        RT_ZERO(IfMac);
    11681195        struct lifreq IfReq;
     
    11901217            continue;
    11911218        }
    1192 # else
    1193 #  ifndef RT_OS_OS2 /** @todo port this to OS/2 */
     1219# elif defined(RT_OS_OS2)
     1220        RTMAC   IfMac;
     1221        uint32_t iIfStat = RT_MIN((unsigned)IfStats.ifNumber, IFMIB_ENTRIES); /* paranoia */
     1222        while (iIfStat-- > 0) /** @todo test this code with more than one interface. */
     1223            if (IfStats.iftable[iIfStat].iftIndex == i)
     1224                memcpy(&IfMac, IfStats.iftable[iIfStat].iftPhysAddr, sizeof(IfMac));
     1225#else
    11941226        if (ioctl(sd, SIOCGIFHWADDR, &ifrequest[i]) < 0)
    11951227        {
     
    11981230            break;
    11991231        }
    1200 #  endif
     1232        RTMAC IfMac = *(PRTMAC)&ifrequest[i].ifr_hwaddr.sa_data[0];
    12011233# endif
    1202 
    1203 # ifndef RT_OS_OS2 /** @todo port this to OS/2 */
    1204         char szMac[32];
    1205 #  if defined(RT_OS_SOLARIS)
    1206         uint8_t *pu8Mac = IfMac.au8;
    1207 #  else
    1208         uint8_t *pu8Mac = (uint8_t*)&ifrequest[i].ifr_hwaddr.sa_data[0];        /* @todo see above */
    1209 #  endif
    1210         RTStrPrintf(szMac, sizeof(szMac), "%02X%02X%02X%02X%02X%02X",
    1211                     pu8Mac[0], pu8Mac[1], pu8Mac[2], pu8Mac[3],  pu8Mac[4], pu8Mac[5]);
    12121234        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfacesReport);
    1213         VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szMac);
    1214 # endif /* !OS/2*/
     1235        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%02X%02X%02X%02X%02X%02X",
     1236                                   IfMac.au8[0], IfMac.au8[1], IfMac.au8[2], IfMac.au8[3], IfMac.au8[4], IfMac.au8[5]);
    12151237
    12161238        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfacesReport);
Note: See TracChangeset for help on using the changeset viewer.

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