Changeset 50554 in vbox for trunk/src/VBox
- Timestamp:
- Feb 24, 2014 11:38:25 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r50448 r50554 1034 1034 /* 1035 1035 * Only AF_INET and no loopback interfaces 1036 * @todo: IPv6 interfaces1037 1036 */ 1037 /** @todo: IPv6 interfaces */ 1038 1038 if ( pIfCurr->ifa_addr->sa_family == AF_INET 1039 1039 && !(pIfCurr->ifa_flags & IFF_LOOPBACK)) … … 1110 1110 } 1111 1111 1112 ifreq *ifrequest = ifcfg.ifc_req;1112 ifreq *ifrequest = ifcfg.ifc_req; 1113 1113 int cIfacesSystem = ifcfg.ifc_len / sizeof(ifreq); 1114 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 } 1122 # endif 1123 1115 1124 for (int i = 0; i < cIfacesSystem; ++i) 1116 1125 { 1117 sockaddr_in *pAddress; 1126 # ifdef RT_OS_OS2 1127 ifreq IfReqCopy = ifrequest[i]; 1128 # endif 1129 /* Get the interface flags. */ 1118 1130 if (ioctl(sd, SIOCGIFFLAGS, &ifrequest[i]) < 0) 1119 1131 { 1132 # ifdef RT_OS_OS2 /* Ignore errors when querying flags for non-existing interfaces. */ 1133 if (errno == ENXIO) 1134 continue; 1135 # endif 1120 1136 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); 1122 1138 break; 1123 1139 } … … 1125 1141 continue; 1126 1142 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); 1130 1156 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfacesReport); 1131 1157 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 1132 1158 1159 /* Get the broadcast address. */ 1133 1160 if (ioctl(sd, SIOCGIFBRDADDR, &ifrequest[i]) < 0) 1134 1161 { … … 1141 1168 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 1142 1169 1170 /* Get the net mask. */ 1143 1171 if (ioctl(sd, SIOCGIFNETMASK, &ifrequest[i]) < 0) 1144 1172 { … … 1152 1180 pAddress = (sockaddr_in *)&ifrequest[i].ifr_netmask; 1153 1181 # endif 1154 1155 1182 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfacesReport); 1156 1183 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); … … 1164 1191 * address this way, so we just use all zeros there. 1165 1192 */ 1166 RTMAC IfMac;1193 RTMAC IfMac; 1167 1194 RT_ZERO(IfMac); 1168 1195 struct lifreq IfReq; … … 1190 1217 continue; 1191 1218 } 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 1194 1226 if (ioctl(sd, SIOCGIFHWADDR, &ifrequest[i]) < 0) 1195 1227 { … … 1198 1230 break; 1199 1231 } 1200 # endif 1232 RTMAC IfMac = *(PRTMAC)&ifrequest[i].ifr_hwaddr.sa_data[0]; 1201 1233 # 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 # else1208 uint8_t *pu8Mac = (uint8_t*)&ifrequest[i].ifr_hwaddr.sa_data[0]; /* @todo see above */1209 # endif1210 RTStrPrintf(szMac, sizeof(szMac), "%02X%02X%02X%02X%02X%02X",1211 pu8Mac[0], pu8Mac[1], pu8Mac[2], pu8Mac[3], pu8Mac[4], pu8Mac[5]);1212 1234 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]); 1215 1237 1216 1238 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfacesReport);
Note:
See TracChangeset
for help on using the changeset viewer.