Changeset 17981 in vbox for trunk/src/VBox/Main
- Timestamp:
- Mar 16, 2009 9:37:19 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 44566
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostNetworkInterfaceImpl.cpp
r17890 r17981 215 215 CheckComRCReturnRC (autoCaller.rc()); 216 216 217 if (m.IPAddress == 0) 218 { 219 Bstr("").detachTo(aIPAddress); 220 return S_OK; 221 } 222 217 223 in_addr tmp; 218 224 #if defined(RT_OS_WINDOWS) … … 243 249 AutoCaller autoCaller (this); 244 250 CheckComRCReturnRC (autoCaller.rc()); 251 252 if (m.IPAddress == 0 || m.networkMask == 0) 253 { 254 Bstr("").detachTo(aNetworkMask); 255 return S_OK; 256 } 245 257 246 258 in_addr tmp; … … 409 421 if(mask != INADDR_NONE) 410 422 { 411 int rc = NetIfEnableStaticIpConfig(mVBox, this, ip, mask);423 int rc = NetIfEnableStaticIpConfig(mVBox, this, m.IPAddress, ip, mask); 412 424 if (RT_SUCCESS(rc)) 413 425 { … … 439 451 CheckComRCReturnRC (autoCaller.rc()); 440 452 441 int rc = NetIfEnableStaticIpConfigV6(mVBox, this, aIPV6Address, aIPV6MaskPrefixLength);453 int rc = NetIfEnableStaticIpConfigV6(mVBox, this, m.IPV6Address, aIPV6Address, aIPV6MaskPrefixLength); 442 454 if (RT_FAILURE(rc)) 443 455 { -
trunk/src/VBox/Main/darwin/NetIfList-darwin.cpp
r17814 r17981 162 162 void extractAddresses(int iAddrMask, caddr_t cp, caddr_t cplim, PNETIFINFO pInfo) 163 163 { 164 struct sockaddr *sa; 165 struct sockaddr_in *pIPAddr, *pIPNetMask; 166 struct sockaddr_in6 *pIPv6Addr, *pIPv6NetMask; 164 struct sockaddr *sa, *addresses[RTAX_MAX]; 167 165 168 166 for (int i = 0; i < RTAX_MAX && cp < cplim; i++) { … … 172 170 sa = (struct sockaddr *)cp; 173 171 174 switch (i) 175 { 176 case RTAX_IFA: 177 switch (sa->sa_family) 178 { 179 case AF_INET: 180 pIPAddr = (struct sockaddr_in *)sa; 181 Assert(sizeof(pInfo->IPAddress) == sizeof(pIPAddr->sin_addr)); 182 if (!pInfo->IPAddress.u) 183 pInfo->IPAddress.u = pIPAddr->sin_addr.s_addr; 184 break; 185 case AF_INET6: 186 pIPv6Addr = (struct sockaddr_in6 *)sa; 187 Assert(sizeof(pInfo->IPv6Address) == sizeof(pIPv6Addr->sin6_addr)); 188 if (!(pInfo->IPv6Address.s.Lo || pInfo->IPv6Address.s.Hi)) 189 memcpy(pInfo->IPv6Address.au8, 190 pIPv6Addr->sin6_addr.__u6_addr.__u6_addr8, 191 sizeof(pInfo->IPv6Address)); 192 break; 193 default: 194 Log(("NetIfList: Unsupported address family: %u\n", sa->sa_family)); 195 break; 196 } 197 break; 198 case RTAX_NETMASK: 199 switch (sa->sa_family) 200 { 201 case AF_INET: 202 pIPAddr = (struct sockaddr_in *)sa; 203 if (!pInfo->IPNetMask.u) 204 pInfo->IPNetMask.u = pIPAddr->sin_addr.s_addr; 205 break; 206 case AF_INET6: 207 pIPv6Addr = (struct sockaddr_in6 *)sa; 208 if (!(pInfo->IPv6NetMask.s.Lo || pInfo->IPv6NetMask.s.Hi)) 209 memcpy(pInfo->IPv6NetMask.au8, 210 pIPv6Addr->sin6_addr.__u6_addr.__u6_addr8, 211 sizeof(pInfo->IPv6NetMask)); 212 break; 213 default: 214 Log(("NetIfList: Unsupported address family: %u\n", sa->sa_family)); 215 break; 216 } 217 break; 218 } 172 addresses[i] = sa; 173 219 174 ADVANCE(cp, sa); 175 } 176 177 switch (addresses[RTAX_IFA]->sa_family) 178 { 179 case AF_INET: 180 if (!pInfo->IPAddress.u) 181 { 182 pInfo->IPAddress.u = ((struct sockaddr_in *)addresses[RTAX_IFA])->sin_addr.s_addr; 183 pInfo->IPNetMask.u = ((struct sockaddr_in *)addresses[RTAX_NETMASK])->sin_addr.s_addr; 184 } 185 break; 186 case AF_INET6: 187 if (!pInfo->IPv6Address.s.Lo && !pInfo->IPv6Address.s.Hi) 188 { 189 memcpy(pInfo->IPv6Address.au8, 190 ((struct sockaddr_in6 *)addresses[RTAX_IFA])->sin6_addr.__u6_addr.__u6_addr8, 191 sizeof(pInfo->IPv6Address)); 192 memcpy(pInfo->IPv6NetMask.au8, 193 ((struct sockaddr_in6 *)addresses[RTAX_NETMASK])->sin6_addr.__u6_addr.__u6_addr8, 194 sizeof(pInfo->IPv6NetMask)); 195 } 196 break; 197 default: 198 Log(("NetIfList: Unsupported address family: %u\n", sa->sa_family)); 199 break; 220 200 } 221 201 } -
trunk/src/VBox/Main/generic/NetIf-generic.cpp
r17929 r17981 32 32 #define VBOXNETADPCTL_NAME "VBoxNetAdpCtl" 33 33 34 static int NetIfAdpCtl(HostNetworkInterface * pIf, char *pszAddr, char *psz Mask)34 static int NetIfAdpCtl(HostNetworkInterface * pIf, char *pszAddr, char *pszOption, char *pszMask) 35 35 { 36 const char *args[] = { NULL, NULL, pszAddr, NULL, NULL, NULL }; 37 if (pszMask) 38 { 39 args[3] = "netmask"; 40 args[4] = pszMask; 41 } 36 const char *args[] = { NULL, NULL, pszAddr, pszOption, pszMask, NULL }; 42 37 43 38 char szAdpCtl[RTPATH_MAX]; … … 78 73 } 79 74 80 int NetIfEnableStaticIpConfig(VirtualBox * /* vBox */, HostNetworkInterface * pIf, ULONG ip, ULONG mask)75 int NetIfEnableStaticIpConfig(VirtualBox * /* vBox */, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask) 81 76 { 77 char *pszOption, *pszMask; 82 78 char szAddress[16]; /* 4*3 + 3*1 + 1 */ 83 79 char szNetMask[16]; /* 4*3 + 3*1 + 1 */ 84 uint8_t *pu8Addr = (uint8_t *)&ip; 85 uint8_t *pu8Mask = (uint8_t *)&mask; 80 uint8_t *pu8Addr = (uint8_t *)&aNewIp; 81 uint8_t *pu8Mask = (uint8_t *)&aMask; 82 if (aNewIp == 0) 83 { 84 pu8Addr = (uint8_t *)&aOldIp; 85 pszOption = "remove"; 86 pszMask = NULL; 87 } 88 else 89 { 90 pszOption = "netmask"; 91 pszMask = szNetMask; 92 RTStrPrintf(szNetMask, sizeof(szNetMask), "%d.%d.%d.%d", 93 pu8Mask[0], pu8Mask[1], pu8Mask[2], pu8Mask[3]); 94 } 86 95 RTStrPrintf(szAddress, sizeof(szAddress), "%d.%d.%d.%d", 87 96 pu8Addr[0], pu8Addr[1], pu8Addr[2], pu8Addr[3]); 88 RTStrPrintf(szNetMask, sizeof(szNetMask), "%d.%d.%d.%d", 89 pu8Mask[0], pu8Mask[1], pu8Mask[2], pu8Mask[3]); 90 return NetIfAdpCtl(pIf, szAddress, szNetMask); 97 return NetIfAdpCtl(pIf, szAddress, pszOption, pszMask); 91 98 } 92 99 93 int NetIfEnableStaticIpConfigV6(VirtualBox * /* vBox */, HostNetworkInterface * pIf, IN_BSTR a IPV6Address, ULONG aIPV6MaskPrefixLength)100 int NetIfEnableStaticIpConfigV6(VirtualBox * /* vBox */, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength) 94 101 { 95 102 char szAddress[5*8 + 1 + 5 + 1]; 96 RTStrPrintf(szAddress, sizeof(szAddress), "%ls/%d", 97 aIPV6Address, aIPV6MaskPrefixLength); 98 return NetIfAdpCtl(pIf, szAddress, NULL); 103 if (Bstr(aIPV6Address).length()) 104 { 105 RTStrPrintf(szAddress, sizeof(szAddress), "%ls/%d", 106 aIPV6Address, aIPV6MaskPrefixLength); 107 return NetIfAdpCtl(pIf, szAddress, NULL, NULL); 108 } 109 else 110 { 111 RTStrPrintf(szAddress, sizeof(szAddress), "%ls", 112 aOldIPV6Address); 113 return NetIfAdpCtl(pIf, szAddress, "remove", NULL); 114 } 99 115 } 100 116 -
trunk/src/VBox/Main/include/netif.h
r17856 r17981 78 78 79 79 int NetIfList(std::list <ComObjPtr <HostNetworkInterface> > &list); 80 int NetIfEnableStaticIpConfig(VirtualBox *pVbox, HostNetworkInterface * pIf, ULONG ip, ULONG mask);81 int NetIfEnableStaticIpConfigV6(VirtualBox *pVbox, HostNetworkInterface * pIf, IN_BSTR a IPV6Address, ULONG aIPV6MaskPrefixLength);80 int NetIfEnableStaticIpConfig(VirtualBox *pVbox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask); 81 int NetIfEnableStaticIpConfigV6(VirtualBox *pVbox, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength); 82 82 int NetIfEnableDynamicIpConfig(VirtualBox *pVbox, HostNetworkInterface * pIf); 83 83 int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVbox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress);
Note:
See TracChangeset
for help on using the changeset viewer.