Changeset 87360 in vbox
- Timestamp:
- Jan 21, 2021 8:19:42 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/NATNetworkImpl.cpp
r87323 r87360 261 261 HRESULT NATNetwork::setNetwork(const com::Utf8Str &aIPv4NetworkCidr) 262 262 { 263 { 264 263 RTNETADDRIPV4 Addr, Mask; 264 int iPrefix; 265 int rc; 266 267 rc = RTNetStrToIPv4Cidr(aIPv4NetworkCidr.c_str(), &Addr, &iPrefix); 268 if (RT_FAILURE(rc)) 269 return setError(E_FAIL, "%s is not a valid IPv4 CIDR notation", 270 aIPv4NetworkCidr.c_str()); 271 272 /* 273 * /32 is a single address, not a network, /31 is the degenerate 274 * point-to-point case, so reject these. Larger values and 275 * non-positive values are already treated as errors by the 276 * conversion. 277 */ 278 if (iPrefix > 30) 279 return setError(E_FAIL, "%s network is too small", aIPv4NetworkCidr.c_str()); 280 281 rc = RTNetPrefixToMaskIPv4(iPrefix, &Mask); 282 AssertRCReturn(rc, setError(E_FAIL, 283 "%s: internal error: failed to convert prefix %d to netmask: %Rrc", 284 aIPv4NetworkCidr.c_str(), iPrefix, rc)); 285 286 if ((Addr.u & ~Mask.u) != 0) 287 return setError(E_FAIL, 288 "%s: the specified address is longer than the specified prefix", 289 aIPv4NetworkCidr.c_str()); 290 291 /* normalized CIDR notation */ 292 com::Utf8StrFmt strCidr("%RTnaipv4/%d", Addr.u, iPrefix); 293 294 { 265 295 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 266 296 267 if ( aIPv4NetworkCidr == m->s.strIPv4NetworkCidr)297 if (m->s.strIPv4NetworkCidr == strCidr) 268 298 return S_OK; 269 299 … … 278 308 279 309 280 m->s.strIPv4NetworkCidr = aIPv4NetworkCidr;310 m->s.strIPv4NetworkCidr = strCidr; 281 311 i_recalculateIpv4AddressAssignments(); 282 312 } 283 313 284 314 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS); 285 HRESULT rc = m->pVirtualBox->i_saveSettings();286 ComAssertComRCRetRC( rc);315 HRESULT hrc = m->pVirtualBox->i_saveSettings(); 316 ComAssertComRCRetRC(hrc); 287 317 return S_OK; 288 318 }
Note:
See TracChangeset
for help on using the changeset viewer.