VirtualBox

Changeset 50565 in vbox


Ignore:
Timestamp:
Feb 24, 2014 10:56:52 PM (11 years ago)
Author:
vboxsync
Message:

VBoxServiceVMInfo.cpp: Turns out there isn't anything wrong with SIOCGIFCONF on OS/2, we just got some bad code that didn't really understand the interface. For really good code and understanding, see Stevens' get_ifi_info(). Made our stuff a bit more flexible and reduced the OS/2 pollution a little. The code could still benefit seriously from some functions. Exposed the interface name on solaris, linux and OS/2 (because we can).

File:
1 edited

Legend:

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

    r50555 r50565  
    4343# if !defined(RT_OS_OS2) && !defined(RT_OS_FREEBSD) && !defined(RT_OS_HAIKU)
    4444#  include <utmpx.h> /* @todo FreeBSD 9 should have this. */
     45# endif
     46# ifdef RT_OS_OS2
     47#  include <net/if_dl.h>
    4548# endif
    4649# ifdef RT_OS_SOLARIS
     
    881884static int vboxserviceVMInfoWriteNetwork(void)
    882885{
    883     int rc = VINF_SUCCESS;
    884     uint32_t  cIfacesReport = 0;
    885     char szPropPath[256];
     886    int         rc = VINF_SUCCESS;
     887    uint32_t    cIfsReported = 0;
     888    char        szPropPath[256];
    886889
    887890#ifdef RT_OS_WINDOWS
     
    973976        char szIp[32];
    974977        RTStrPrintf(szIp, sizeof(szIp), "%s", inet_ntoa(pAddress->sin_addr));
    975         RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfacesReport);
     978        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfsReported);
    976979        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szIp);
    977980
    978981        pAddress = (sockaddr_in *) & (InterfaceList[i].iiBroadcastAddress);
    979         RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfacesReport);
     982        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfsReported);
    980983        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    981984
    982985        pAddress = (sockaddr_in *)&(InterfaceList[i].iiNetmask);
    983         RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfacesReport);
     986        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfsReported);
    984987        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    985988
    986         RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfacesReport);
     989        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfsReported);
    987990        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, nFlags & IFF_UP ? "Up" : "Down");
    988991
     
    993996                break;
    994997
    995         RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfacesReport);
     998        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfsReported);
    996999        if (pAdp)
    9971000        {
     
    10061009# endif /* !TARGET_NT4 */
    10071010
    1008         cIfacesReport++;
     1011        cIfsReported++;
    10091012    }
    10101013    if (pAdpInfo)
     
    10441047            getnameinfo(pIfCurr->ifa_addr, sizeof(struct sockaddr_in),
    10451048                        szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
    1046             RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfacesReport);
     1049            RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfsReported);
    10471050            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr);
    10481051
     
    10501053            getnameinfo(pIfCurr->ifa_broadaddr, sizeof(struct sockaddr_in),
    10511054                        szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
    1052             RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfacesReport);
     1055            RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfsReported);
    10531056            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr);
    10541057
     
    10561059            getnameinfo(pIfCurr->ifa_netmask, sizeof(struct sockaddr_in),
    10571060                        szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
    1058             RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfacesReport);
     1061            RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfsReported);
    10591062            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr);
    10601063
     
    10731076                    RTStrPrintf(szMac, sizeof(szMac), "%02X%02X%02X%02X%02X%02X",
    10741077                                pu8Mac[0], pu8Mac[1], pu8Mac[2], pu8Mac[3],  pu8Mac[4], pu8Mac[5]);
    1075                     RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfacesReport);
     1078                    RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfsReported);
    10761079                    VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szMac);
    10771080                    break;
     
    10791082            }
    10801083
    1081             RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfacesReport);
     1084            RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfsReported);
    10821085            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, pIfCurr->ifa_flags & IFF_UP ? "Up" : "Down");
    10831086
    1084             cIfacesReport++;
     1087            cIfsReported++;
    10851088        }
    10861089    }
     
    10901093
    10911094#else /* !RT_OS_WINDOWS && !RT_OS_FREEBSD */
     1095    /*
     1096     * Use SIOCGIFCONF to get a list of interface/protocol configurations.
     1097     *
     1098     * See "UNIX Network Programming Volume 1" by W. R. Stevens, section 17.6
     1099     * for details on this ioctl.
     1100     */
    10921101    int sd = socket(AF_INET, SOCK_DGRAM, 0);
    10931102    if (sd < 0)
     
    10981107    }
    10991108
    1100     ifconf ifcfg;
    1101     char buffer[1024] = {0};
    1102     ifcfg.ifc_len = sizeof(buffer);
    1103     ifcfg.ifc_buf = buffer;
    1104     if (ioctl(sd, SIOCGIFCONF, &ifcfg) < 0)
     1109    /* Call SIOCGIFCONF with the right sized buffer (remember the size). */
     1110    static int      s_cbBuf = 256; // 1024
     1111    int             cbBuf   = s_cbBuf;
     1112    char           *pchBuf;
     1113    struct ifconf   IfConf;
     1114    rc = VINF_SUCCESS;
     1115    for (;;)
     1116    {
     1117        pchBuf = (char *)RTMemTmpAllocZ(cbBuf);
     1118        if (!pchBuf)
     1119        {
     1120            rc = VERR_NO_TMP_MEMORY;
     1121            break;
     1122        }
     1123
     1124        IfConf.ifc_len = cbBuf;
     1125        IfConf.ifc_buf = pchBuf;
     1126        if (ioctl(sd, SIOCGIFCONF, &IfConf) >= 0)
     1127        {
     1128            /* Hard to anticipate how space an address might possibly take, so
     1129               making some generous assumptions here to avoid performing the
     1130               query twice with different buffer sizes. */
     1131            if (IfConf.ifc_len + 128 < cbBuf)
     1132                break;
     1133        }
     1134        else if (errno != EOVERFLOW)
     1135        {
     1136            rc = RTErrConvertFromErrno(errno);
     1137            break;
     1138        }
     1139
     1140        /* grow the buffer */
     1141        s_cbBuf = cbBuf *= 2;
     1142        RTMemFree(pchBuf);
     1143    }
     1144    if (RT_FAILURE(rc))
    11051145    {
    11061146        close(sd);
    1107         rc = RTErrConvertFromErrno(errno);
    1108         VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFCONF) on socket: Error %Rrc\n", rc);
     1147        RTMemTmpFree(pchBuf);
     1148        VBoxServiceError("VMInfo/Network: Error doing SIOCGIFCONF (cbBuf=%d): %Rrc\n", cbBuf, rc);
    11091149        return rc;
    11101150    }
    11111151
    1112     ifreq *ifrequest = ifcfg.ifc_req;
    1113     int cIfacesSystem = ifcfg.ifc_len / sizeof(ifreq);
    1114 
    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     }
     1152    /*
     1153     * Iterate the interface/protocol configurations.
     1154     *
     1155     * Note! The current code naively assumes one IPv4 address per interface.
     1156     *       This means that guest assigning more than one address to an
     1157     *       interface will get multiple entries for one physical interface.
     1158     */
     1159#ifdef RT_OS_OS2
     1160    struct ifreq   *pPrevLinkAddr = NULL;
     1161#endif
     1162    struct ifreq   *pCur   = IfConf.ifc_req;
     1163    size_t          cbLeft = IfConf.ifc_len;
     1164    while (cbLeft >= sizeof(*pCur))
     1165    {
     1166        /* Figure the size of the current request. */
     1167        size_t const cbCur = RT_OFFSETOF(struct ifreq, ifr_addr)
     1168                           + RT_MAX(sizeof(struct sockaddr), pCur->ifr_addr.sa_len);
     1169        AssertBreak(cbCur <= cbLeft);
     1170
     1171#ifdef RT_OS_OS2
     1172        /* On OS/2 we get the MAC address in the AF_LINK that the BSD 4.4 stack
     1173           emits.  We boldly ASSUME these always comes first. */
     1174        if (   pCur->ifr_addr.sa_family == AF_LINK
     1175            && ((struct sockaddr_dl *)&pCur->ifr_addr)->sdl_alen == 6)
     1176            pPrevLinkAddr = pCur;
     1177#endif
     1178
     1179        /* Skip it if it's not the kind of address we're looking for. */
     1180        struct ifreq IfReqTmp;
     1181        bool         fIfUp = false;
     1182        bool         fSkip = false;
     1183        if (pCur->ifr_addr.sa_family != AF_INET)
     1184            fSkip = true;
     1185        else
     1186        {
     1187            /* Get the interface flags so we can detect loopback and check if it's up. */
     1188            IfReqTmp = *pCur;
     1189            if (ioctl(sd, SIOCGIFFLAGS, &IfReqTmp) < 0)
     1190            {
     1191                rc = RTErrConvertFromErrno(errno);
     1192                VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFFLAGS,%s) on socket: Error %Rrc\n", pCur->ifr_name, rc);
     1193                break;
     1194            }
     1195            fIfUp = !!(IfReqTmp.ifr_flags & IFF_UP);
     1196            if (IfReqTmp.ifr_flags & IFF_LOOPBACK) /* Skip the loopback device. */
     1197                fSkip = true;
     1198        }
     1199        if (!fSkip)
     1200        {
     1201            size_t offSubProp = RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32", cIfsReported);
     1202
     1203            sockaddr_in *pAddress = (sockaddr_in *)&pCur->ifr_addr;
     1204            strcpy(&szPropPath[offSubProp], "/V4/IP");
     1205            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
     1206
     1207            /* Get the broadcast address. */
     1208            IfReqTmp = *pCur;
     1209            if (ioctl(sd, SIOCGIFBRDADDR, &IfReqTmp) < 0)
     1210            {
     1211                rc = RTErrConvertFromErrno(errno);
     1212                VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFBRDADDR) on socket: Error %Rrc\n", rc);
     1213                break;
     1214            }
     1215            pAddress = (sockaddr_in *)&IfReqTmp.ifr_broadaddr;
     1216            strcpy(&szPropPath[offSubProp], "/V4/Broadcast");
     1217            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
     1218
     1219            /* Get the net mask. */
     1220            IfReqTmp = *pCur;
     1221            if (ioctl(sd, SIOCGIFNETMASK, &IfReqTmp) < 0)
     1222            {
     1223                rc = RTErrConvertFromErrno(errno);
     1224                VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFNETMASK) on socket: Error %Rrc\n", rc);
     1225                break;
     1226            }
     1227# if defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
     1228            pAddress = (sockaddr_in *)&IfReqTmp.ifr_addr;
     1229# else
     1230            pAddress = (sockaddr_in *)&IfReqTmp.ifr_netmask;
    11221231# endif
    1123 
    1124     for (int i = 0; i < cIfacesSystem; ++i)
    1125     {
    1126         /* Get the interface flags - ASSUMES the address isn't really overwritten (ugly). */
    1127         if (ioctl(sd, SIOCGIFFLAGS, &ifrequest[i]) < 0)
    1128         {
    1129 # ifdef RT_OS_OS2 /* Ignore errors when querying flags for non-existing interfaces. */
    1130             if (errno == ENXIO)
    1131                 continue;
    1132 # endif
    1133             rc = RTErrConvertFromErrno(errno);
    1134             VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFFLAGS,#%u) on socket: Error %Rrc\n", i, rc);
    1135             break;
    1136         }
    1137         if (ifrequest[i].ifr_flags & IFF_LOOPBACK) /* Skip the loopback device. */
    1138             continue;
    1139 
    1140         bool const fIfUp = !!(ifrequest[i].ifr_flags & IFF_UP);
    1141 
    1142 # ifdef RT_OS_OS2
    1143         /* Don't know what OS/2 returns in SIOCGIFCONF, but it isn't the address.  Get it. */
    1144         if (ioctl(sd, SIOCGIFADDR, &ifrequest[i]) < 0)
    1145         {
    1146             rc = RTErrConvertFromErrno(errno);
    1147             VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFADDR) on socket: Error %Rrc\n", rc);
    1148             break;
    1149         }
    1150 # endif
    1151         sockaddr_in *pAddress = ((sockaddr_in *)&ifrequest[i].ifr_addr);
    1152         RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfacesReport);
    1153         VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    1154 
    1155         /* Get the broadcast address. */
    1156         if (ioctl(sd, SIOCGIFBRDADDR, &ifrequest[i]) < 0)
    1157         {
    1158             rc = RTErrConvertFromErrno(errno);
    1159             VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFBRDADDR) on socket: Error %Rrc\n", rc);
    1160             break;
    1161         }
    1162         pAddress = (sockaddr_in *)&ifrequest[i].ifr_broadaddr;
    1163         RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfacesReport);
    1164         VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    1165 
    1166         /* Get the net mask. */
    1167         if (ioctl(sd, SIOCGIFNETMASK, &ifrequest[i]) < 0)
    1168         {
    1169             rc = RTErrConvertFromErrno(errno);
    1170             VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFNETMASK) on socket: Error %Rrc\n", rc);
    1171             break;
    1172         }
    1173 # if defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
    1174         pAddress = (sockaddr_in *)&ifrequest[i].ifr_addr;
    1175 # else
    1176         pAddress = (sockaddr_in *)&ifrequest[i].ifr_netmask;
    1177 # endif
    1178         RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfacesReport);
    1179         VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
     1232            strcpy(&szPropPath[offSubProp], "/V4/Netmask");
     1233            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    11801234
    11811235# if defined(RT_OS_SOLARIS)
    1182         /*
    1183          * "ifreq" is obsolete on Solaris. We use the recommended "lifreq".
    1184          * We might fail if the interface has not been assigned an IP address.
    1185          * That doesn't matter; as long as it's plumbed we can pick it up.
    1186          * But, if it has not acquired an IP address we cannot obtain it's MAC
    1187          * address this way, so we just use all zeros there.
    1188          */
    1189         RTMAC   IfMac;
    1190         RT_ZERO(IfMac);
    1191         struct lifreq IfReq;
    1192         RT_ZERO(IfReq);
    1193         AssertCompile(sizeof(IfReq.lifr_name) >= sizeof(ifrequest[i].ifr_name));
    1194         strncpy(IfReq.lifr_name, ifrequest[i].ifr_name, sizeof(ifrequest[i].ifr_name));
    1195         if (ioctl(sd, SIOCGLIFADDR, &IfReq) >= 0)
    1196         {
    1197             struct arpreq ArpReq;
    1198             RT_ZERO(ArpReq);
    1199             memcpy(&ArpReq.arp_pa, &IfReq.lifr_addr, sizeof(struct sockaddr_in));
    1200 
    1201             if (ioctl(sd, SIOCGARP, &ArpReq) >= 0)
    1202                 memcpy(&IfMac, ArpReq.arp_ha.sa_data, sizeof(IfMac));
     1236            /*
     1237             * "ifreq" is obsolete on Solaris. We use the recommended "lifreq".
     1238             * We might fail if the interface has not been assigned an IP address.
     1239             * That doesn't matter; as long as it's plumbed we can pick it up.
     1240             * But, if it has not acquired an IP address we cannot obtain it's MAC
     1241             * address this way, so we just use all zeros there.
     1242             */
     1243            RTMAC           IfMac;
     1244            struct lifreq   IfReq;
     1245            RT_ZERO(IfReq);
     1246            AssertCompile(sizeof(IfReq.lifr_name) >= sizeof(pCur->ifr_name));
     1247            strncpy(IfReq.lifr_name, pCur->ifr_name, sizeof(pCur->ifr_name));
     1248            if (ioctl(sd, SIOCGLIFADDR, &IfReq) >= 0)
     1249            {
     1250                struct arpreq ArpReq;
     1251                RT_ZERO(ArpReq);
     1252                memcpy(&ArpReq.arp_pa, &IfReq.lifr_addr, sizeof(struct sockaddr_in));
     1253
     1254                if (ioctl(sd, SIOCGARP, &ArpReq) >= 0)
     1255                    memcpy(&IfMac, ArpReq.arp_ha.sa_data, sizeof(IfMac));
     1256                else
     1257                {
     1258                    rc = RTErrConvertFromErrno(errno);
     1259                    VBoxServiceError("VMInfo/Network: failed to ioctl(SIOCGARP) on socket: Error %Rrc\n", rc);
     1260                    break;
     1261                }
     1262            }
    12031263            else
    12041264            {
     1265                VBoxServiceVerbose(2, "VMInfo/Network: Interface %d has no assigned IP address, skipping ...\n", i);
     1266                continue;
     1267            }
     1268# elif defined(RT_OS_OS2)
     1269            RTMAC   IfMac;
     1270            if (   pPrevLinkAddr
     1271                && strncmp(pCur->ifr_name, pPrevLinkAddr->ifr_name, sizeof(pCur->ifr_name)) == 0)
     1272            {
     1273                struct sockaddr_dl *pDlAddr = (struct sockaddr_dl *)&pPrevLinkAddr->ifr_addr;
     1274                IfMac = *(PRTMAC)&pDlAddr->sdl_data[pDlAddr->sdl_nlen];
     1275            }
     1276            else
     1277                RT_ZERO(IfMac);
     1278#else
     1279            if (ioctl(sd, SIOCGIFHWADDR, &IfReqTmp) < 0)
     1280            {
    12051281                rc = RTErrConvertFromErrno(errno);
    1206                 VBoxServiceError("VMInfo/Network: failed to ioctl(SIOCGARP) on socket: Error %Rrc\n", rc);
     1282                VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFHWADDR) on socket: Error %Rrc\n", rc);
    12071283                break;
    12081284            }
    1209         }
    1210         else
    1211         {
    1212             VBoxServiceVerbose(2, "VMInfo/Network: Interface %d has no assigned IP address, skipping ...\n", i);
    1213             continue;
    1214         }
    1215 # elif defined(RT_OS_OS2)
    1216         RTMAC   IfMac;
    1217         uint32_t iIfStat = RT_MIN((unsigned)IfStats.ifNumber, IFMIB_ENTRIES); /* paranoia */
    1218         while (iIfStat-- > 0) /** @todo test this code with more than one interface. */
    1219             if (IfStats.iftable[iIfStat].iftIndex == i)
    1220                 memcpy(&IfMac, IfStats.iftable[iIfStat].iftPhysAddr, sizeof(IfMac));
    1221 #else
    1222         if (ioctl(sd, SIOCGIFHWADDR, &ifrequest[i]) < 0)
    1223         {
    1224             rc = RTErrConvertFromErrno(errno);
    1225             VBoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFHWADDR) on socket: Error %Rrc\n", rc);
    1226             break;
    1227         }
    1228         RTMAC IfMac = *(PRTMAC)&ifrequest[i].ifr_hwaddr.sa_data[0];
     1285            RTMAC IfMac = *(PRTMAC)&IfReqTmp.ifr_hwaddr.sa_data[0];
    12291286# endif
    1230         RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfacesReport);
    1231         VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%02X%02X%02X%02X%02X%02X",
    1232                                    IfMac.au8[0], IfMac.au8[1], IfMac.au8[2], IfMac.au8[3], IfMac.au8[4], IfMac.au8[5]);
    1233 
    1234         RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfacesReport);
    1235         VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, fIfUp ? "Up" : "Down");
    1236         cIfacesReport++;
    1237     } /* For all interfaces */
    1238 
     1287            strcpy(&szPropPath[offSubProp], "/MAC");
     1288            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%02X%02X%02X%02X%02X%02X",
     1289                                       IfMac.au8[0], IfMac.au8[1], IfMac.au8[2], IfMac.au8[3], IfMac.au8[4], IfMac.au8[5]);
     1290
     1291            strcpy(&szPropPath[offSubProp], "/Status");
     1292            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, fIfUp ? "Up" : "Down");
     1293
     1294            /* The name. */
     1295            int rc2 = RTStrValidateEncodingEx(pCur->ifr_name, sizeof(pCur->ifr_name), 0);
     1296            if (RT_SUCCESS(rc2))
     1297            {
     1298                strcpy(&szPropPath[offSubProp], "/Name");
     1299                VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%.*s", sizeof(pCur->ifr_name), pCur->ifr_name);
     1300            }
     1301
     1302            cIfsReported++;
     1303        }
     1304
     1305        /*
     1306         * Next interface/protocol configuration.
     1307         */
     1308        pCur = (struct ifreq *)((uintptr_t)pCur + cbCur);
     1309        cbLeft -= cbCur;
     1310    }
     1311
     1312    RTMemTmpFree(pchBuf);
    12391313    close(sd);
    12401314    if (RT_FAILURE(rc))
    1241         VBoxServiceError("VMInfo/Network: Network enumeration for interface %RU32 failed with error %Rrc\n", cIfacesReport, rc);
     1315        VBoxServiceError("VMInfo/Network: Network enumeration for interface %RU32 failed with error %Rrc\n", cIfsReported, rc);
    12421316
    12431317#endif /* !RT_OS_WINDOWS */
     
    12501324
    12511325    /* Get former count. */
    1252     uint32_t cIfacesReportOld;
    1253     rc = VBoxServiceReadPropUInt32(g_uVMInfoGuestPropSvcClientID, g_pszPropCacheValNetCount, &cIfacesReportOld,
     1326    uint32_t cIfsReportedOld;
     1327    rc = VBoxServiceReadPropUInt32(g_uVMInfoGuestPropSvcClientID, g_pszPropCacheValNetCount, &cIfsReportedOld,
    12541328                                   0 /* Min */, UINT32_MAX /* Max */);
    12551329    if (   RT_SUCCESS(rc)
    1256         && cIfacesReportOld > cIfacesReport) /* Are some ifaces not around anymore? */
     1330        && cIfsReportedOld > cIfsReported) /* Are some ifaces not around anymore? */
    12571331    {
    12581332        VBoxServiceVerbose(3, "VMInfo/Network: Stale interface data detected (%RU32 old vs. %RU32 current)\n",
    1259                            cIfacesReportOld, cIfacesReport);
    1260 
    1261         uint32_t uIfaceDeleteIdx = cIfacesReport;
     1333                           cIfsReportedOld, cIfsReported);
     1334
     1335        uint32_t uIfaceDeleteIdx = cIfsReported;
    12621336        do
    12631337        {
     
    12791353     */
    12801354    VBoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValNetCount, "%RU32",
    1281                                cIfacesReport);
     1355                               cIfsReported);
    12821356
    12831357    /* Don't fail here; just report everything we got. */
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