Changeset 67414 in vbox for trunk/src/VBox/Runtime/common/net/netaddrstr2.cpp
- Timestamp:
- Jun 15, 2017 1:22:52 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/net/netaddrstr2.cpp
r66445 r67414 511 511 } 512 512 RT_EXPORT_SYMBOL(RTNetStrIsIPv6AddrAny); 513 514 515 RTDECL(int) RTNetMaskToPrefixIPv6(PCRTNETADDRIPV6 pMask, int *piPrefix) 516 { 517 AssertReturn(pMask != NULL, VERR_INVALID_PARAMETER); 518 519 int iPrefix = 0; 520 unsigned int i; 521 522 for (i = 0; i < RT_ELEMENTS(pMask->au8); ++i) 523 { 524 int iBits; 525 switch (pMask->au8[i]) 526 { 527 case 0x00: iBits = 0; break; 528 case 0x80: iBits = 1; break; 529 case 0xc0: iBits = 2; break; 530 case 0xe0: iBits = 3; break; 531 case 0xf0: iBits = 4; break; 532 case 0xf8: iBits = 5; break; 533 case 0xfc: iBits = 6; break; 534 case 0xfe: iBits = 7; break; 535 case 0xff: iBits = 8; break; 536 default: /* non-contiguous mask */ 537 return VERR_INVALID_PARAMETER; 538 } 539 540 iPrefix += iBits; 541 if (iBits != 8) 542 break; 543 } 544 545 for (++i; i < RT_ELEMENTS(pMask->au8); ++i) 546 if (pMask->au8[i] != 0) 547 return VERR_INVALID_PARAMETER; 548 549 if (piPrefix != NULL) 550 *piPrefix = iPrefix; 551 return VINF_SUCCESS; 552 } 553 RT_EXPORT_SYMBOL(RTNetMaskToPrefixIPv6); 554 555 556 RTDECL(int) RTNetPrefixToMaskIPv6(int iPrefix, PRTNETADDRIPV6 pMask) 557 { 558 AssertReturn(pMask != NULL, VERR_INVALID_PARAMETER); 559 560 if (RT_UNLIKELY(iPrefix < 0 || 128 < iPrefix)) 561 return VERR_INVALID_PARAMETER; 562 563 for (unsigned int i = 0; i < RT_ELEMENTS(pMask->au32); ++i) 564 { 565 if (iPrefix == 0) 566 { 567 pMask->au32[i] = 0; 568 } 569 else if (iPrefix >= 32) 570 { 571 pMask->au32[i] = UINT32_C(0xffffffff); 572 iPrefix -= 32; 573 } 574 else 575 { 576 pMask->au32[i] = RT_H2N_U32(UINT32_C(0xffffffff) << (32 - iPrefix)); 577 iPrefix = 0; 578 } 579 } 580 581 return VINF_SUCCESS; 582 } 583 RT_EXPORT_SYMBOL(RTNetPrefixToMaskIPv6);
Note:
See TracChangeset
for help on using the changeset viewer.