Changeset 32257 in vbox
- Timestamp:
- Sep 6, 2010 8:27:05 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/checksum/ipv4.cpp
r28800 r32257 299 299 DECLINLINE(uint32_t) rtNetIPv4AddDataChecksum(void const *pvData, size_t cbData, uint32_t u32Sum, bool *pfOdd) 300 300 { 301 uint16_t const *pw = (uint16_t const *)pvData; 301 302 if (*pfOdd) 302 303 { … … 316 317 317 318 /* iterate the data. */ 318 uint16_t const *pw = (uint16_t const *)pvData;319 319 while (cbData > 1) 320 320 { … … 398 398 RTDECL(uint16_t) RTNetUDPChecksum(uint32_t u32Sum, PCRTNETUDP pUdpHdr) 399 399 { 400 bool fOdd; 400 401 u32Sum = rtNetIPv4AddUDPChecksum(pUdpHdr, u32Sum); 401 boolfOdd = false;402 fOdd = false; 402 403 u32Sum = rtNetIPv4AddDataChecksum(pUdpHdr + 1, RT_BE2H_U16(pUdpHdr->uh_ulen) - sizeof(*pUdpHdr), u32Sum, &fOdd); 403 404 return rtNetIPv4FinalizeChecksum(u32Sum); … … 419 420 RTDECL(uint16_t) RTNetIPv4UDPChecksum(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, void const *pvData) 420 421 { 422 bool fOdd; 421 423 uint32_t u32Sum = rtNetIPv4PseudoChecksum(pIpHdr); 422 424 u32Sum = rtNetIPv4AddUDPChecksum(pUdpHdr, u32Sum); 423 boolfOdd = false;425 fOdd = false; 424 426 u32Sum = rtNetIPv4AddDataChecksum(pvData, RT_BE2H_U16(pUdpHdr->uh_ulen) - sizeof(*pUdpHdr), u32Sum, &fOdd); 425 427 return rtNetIPv4FinalizeChecksum(u32Sum); … … 442 444 * Size validation. 443 445 */ 446 size_t cb; 444 447 if (RT_UNLIKELY(cbPktMax < RTNETUDP_MIN_LEN)) 445 448 return false; 446 size_tcb = RT_BE2H_U16(pUdpHdr->uh_ulen);449 cb = RT_BE2H_U16(pUdpHdr->uh_ulen); 447 450 if (RT_UNLIKELY(cb > cbPktMax)) 448 451 return false; … … 510 513 RTDECL(uint16_t) RTNetIPv4TCPChecksum(PCRTNETIPV4 pIpHdr, PCRTNETTCP pTcpHdr, void const *pvData) 511 514 { 515 bool fOdd; 516 size_t cbData; 512 517 uint32_t u32Sum = rtNetIPv4PseudoChecksum(pIpHdr); 513 518 u32Sum = rtNetIPv4AddTCPChecksum(pTcpHdr, u32Sum); 514 boolfOdd = false;515 size_tcbData = RT_BE2H_U16(pIpHdr->ip_len) - pIpHdr->ip_hl * 4 - pTcpHdr->th_off * 4;519 fOdd = false; 520 cbData = RT_BE2H_U16(pIpHdr->ip_len) - pIpHdr->ip_hl * 4 - pTcpHdr->th_off * 4; 516 521 u32Sum = rtNetIPv4AddDataChecksum(pvData ? pvData : (uint8_t const *)pTcpHdr + pTcpHdr->th_off * 4, 517 522 cbData, u32Sum, &fOdd); … … 536 541 RTDECL(uint16_t) RTNetTCPChecksum(uint32_t u32Sum, PCRTNETTCP pTcpHdr, void const *pvData, size_t cbData) 537 542 { 543 bool fOdd; 538 544 u32Sum = rtNetIPv4AddTCPChecksum(pTcpHdr, u32Sum); 539 boolfOdd = false;545 fOdd = false; 540 546 u32Sum = rtNetIPv4AddDataChecksum(pvData, cbData, u32Sum, &fOdd); 541 547 return rtNetIPv4FinalizeChecksum(u32Sum); … … 556 562 DECLINLINE(bool) rtNetIPv4IsTCPSizeValid(PCRTNETIPV4 pIpHdr, PCRTNETTCP pTcpHdr, size_t cbHdrMax, size_t cbPktMax) 557 563 { 564 size_t cbTcpHdr; 565 size_t cbTcp; 566 558 567 Assert(cbPktMax >= cbHdrMax); 559 568 … … 563 572 if (RT_UNLIKELY(cbPktMax < RTNETTCP_MIN_LEN)) 564 573 return false; 565 size_tcbTcpHdr = pTcpHdr->th_off * 4;574 cbTcpHdr = pTcpHdr->th_off * 4; 566 575 if (RT_UNLIKELY(cbTcpHdr > cbHdrMax)) 567 576 return false; 568 size_tcbTcp = RT_BE2H_U16(pIpHdr->ip_len) - pIpHdr->ip_hl * 4;577 cbTcp = RT_BE2H_U16(pIpHdr->ip_len) - pIpHdr->ip_hl * 4; 569 578 if (RT_UNLIKELY(cbTcp > cbPktMax)) 570 579 return false; … … 642 651 RTDECL(bool) RTNetIPv4IsDHCPValid(PCRTNETUDP pUdpHdr, PCRTNETBOOTP pDhcp, size_t cbDhcp, uint8_t *pMsgType) 643 652 { 653 ssize_t cbLeft; 654 uint8_t MsgType; 655 PCRTNETDHCPOPT pOpt; 656 644 657 AssertPtrNull(pMsgType); 645 658 if (pMsgType) … … 674 687 * (because that seems to be indicating that it's BOOTP and not DHCP). 675 688 */ 676 ssize_tcbLeft = (ssize_t)cbDhcp - RT_OFFSETOF(RTNETBOOTP, bp_vend.Dhcp.dhcp_cookie) + sizeof(pDhcp->bp_vend.Dhcp.dhcp_cookie);689 cbLeft = (ssize_t)cbDhcp - RT_OFFSETOF(RTNETBOOTP, bp_vend.Dhcp.dhcp_cookie) + sizeof(pDhcp->bp_vend.Dhcp.dhcp_cookie); 677 690 if (cbLeft < 0) 678 691 return true; … … 681 694 if (cbLeft < 1) 682 695 return true; 683 PCRTNETDHCPOPTpOpt = (PCRTNETDHCPOPT)&pDhcp->bp_vend.Dhcp.dhcp_opts[0];696 pOpt = (PCRTNETDHCPOPT)&pDhcp->bp_vend.Dhcp.dhcp_opts[0]; 684 697 if (pOpt->dhcp_opt == RTNET_DHCP_OPT_END) 685 698 return false; … … 691 704 * we don't accept END without MSG_TYPE. 692 705 */ 693 uint8_tMsgType = 0;706 MsgType = 0; 694 707 while (cbLeft > 0) 695 708 {
Note:
See TracChangeset
for help on using the changeset viewer.