Changeset 50565 in vbox
- Timestamp:
- Feb 24, 2014 10:56:52 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r50555 r50565 43 43 # if !defined(RT_OS_OS2) && !defined(RT_OS_FREEBSD) && !defined(RT_OS_HAIKU) 44 44 # include <utmpx.h> /* @todo FreeBSD 9 should have this. */ 45 # endif 46 # ifdef RT_OS_OS2 47 # include <net/if_dl.h> 45 48 # endif 46 49 # ifdef RT_OS_SOLARIS … … 881 884 static int vboxserviceVMInfoWriteNetwork(void) 882 885 { 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]; 886 889 887 890 #ifdef RT_OS_WINDOWS … … 973 976 char szIp[32]; 974 977 RTStrPrintf(szIp, sizeof(szIp), "%s", inet_ntoa(pAddress->sin_addr)); 975 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIf acesReport);978 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfsReported); 976 979 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szIp); 977 980 978 981 pAddress = (sockaddr_in *) & (InterfaceList[i].iiBroadcastAddress); 979 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIf acesReport);982 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfsReported); 980 983 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 981 984 982 985 pAddress = (sockaddr_in *)&(InterfaceList[i].iiNetmask); 983 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIf acesReport);986 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfsReported); 984 987 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 985 988 986 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIf acesReport);989 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfsReported); 987 990 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, nFlags & IFF_UP ? "Up" : "Down"); 988 991 … … 993 996 break; 994 997 995 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIf acesReport);998 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfsReported); 996 999 if (pAdp) 997 1000 { … … 1006 1009 # endif /* !TARGET_NT4 */ 1007 1010 1008 cIf acesReport++;1011 cIfsReported++; 1009 1012 } 1010 1013 if (pAdpInfo) … … 1044 1047 getnameinfo(pIfCurr->ifa_addr, sizeof(struct sockaddr_in), 1045 1048 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 1046 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIf acesReport);1049 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfsReported); 1047 1050 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 1048 1051 … … 1050 1053 getnameinfo(pIfCurr->ifa_broadaddr, sizeof(struct sockaddr_in), 1051 1054 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 1052 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIf acesReport);1055 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfsReported); 1053 1056 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 1054 1057 … … 1056 1059 getnameinfo(pIfCurr->ifa_netmask, sizeof(struct sockaddr_in), 1057 1060 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 1058 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIf acesReport);1061 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfsReported); 1059 1062 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 1060 1063 … … 1073 1076 RTStrPrintf(szMac, sizeof(szMac), "%02X%02X%02X%02X%02X%02X", 1074 1077 pu8Mac[0], pu8Mac[1], pu8Mac[2], pu8Mac[3], pu8Mac[4], pu8Mac[5]); 1075 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIf acesReport);1078 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfsReported); 1076 1079 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szMac); 1077 1080 break; … … 1079 1082 } 1080 1083 1081 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIf acesReport);1084 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfsReported); 1082 1085 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, pIfCurr->ifa_flags & IFF_UP ? "Up" : "Down"); 1083 1086 1084 cIf acesReport++;1087 cIfsReported++; 1085 1088 } 1086 1089 } … … 1090 1093 1091 1094 #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 */ 1092 1101 int sd = socket(AF_INET, SOCK_DGRAM, 0); 1093 1102 if (sd < 0) … … 1098 1107 } 1099 1108 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)) 1105 1145 { 1106 1146 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); 1109 1149 return rc; 1110 1150 } 1111 1151 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; 1122 1231 # 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)); 1180 1234 1181 1235 # 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 } 1203 1263 else 1204 1264 { 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 { 1205 1281 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); 1207 1283 break; 1208 1284 } 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]; 1229 1286 # 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); 1239 1313 close(sd); 1240 1314 if (RT_FAILURE(rc)) 1241 VBoxServiceError("VMInfo/Network: Network enumeration for interface %RU32 failed with error %Rrc\n", cIf acesReport, rc);1315 VBoxServiceError("VMInfo/Network: Network enumeration for interface %RU32 failed with error %Rrc\n", cIfsReported, rc); 1242 1316 1243 1317 #endif /* !RT_OS_WINDOWS */ … … 1250 1324 1251 1325 /* Get former count. */ 1252 uint32_t cIf acesReportOld;1253 rc = VBoxServiceReadPropUInt32(g_uVMInfoGuestPropSvcClientID, g_pszPropCacheValNetCount, &cIf acesReportOld,1326 uint32_t cIfsReportedOld; 1327 rc = VBoxServiceReadPropUInt32(g_uVMInfoGuestPropSvcClientID, g_pszPropCacheValNetCount, &cIfsReportedOld, 1254 1328 0 /* Min */, UINT32_MAX /* Max */); 1255 1329 if ( RT_SUCCESS(rc) 1256 && cIf acesReportOld > cIfacesReport) /* Are some ifaces not around anymore? */1330 && cIfsReportedOld > cIfsReported) /* Are some ifaces not around anymore? */ 1257 1331 { 1258 1332 VBoxServiceVerbose(3, "VMInfo/Network: Stale interface data detected (%RU32 old vs. %RU32 current)\n", 1259 cIf acesReportOld, cIfacesReport);1260 1261 uint32_t uIfaceDeleteIdx = cIf acesReport;1333 cIfsReportedOld, cIfsReported); 1334 1335 uint32_t uIfaceDeleteIdx = cIfsReported; 1262 1336 do 1263 1337 { … … 1279 1353 */ 1280 1354 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValNetCount, "%RU32", 1281 cIf acesReport);1355 cIfsReported); 1282 1356 1283 1357 /* Don't fail here; just report everything we got. */
Note:
See TracChangeset
for help on using the changeset viewer.