- Timestamp:
- Mar 5, 2009 2:49:41 PM (16 years ago)
- Location:
- trunk/src/VBox/NetworkServices
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp
r17374 r17403 201 201 int run(void); 202 202 203 static const char *dhcpMsgName(uint8_t MsgType);204 205 203 protected: 206 int addConfig(VBoxNetDhcpCfg *pCfg); 207 bool handleDhcpMsg(uint8_t uMsgType, PCRTNETBOOTP pDhcpMsg, size_t cb); 208 209 inline void debugPrint( int32_t iMinLevel, bool fMsg, const char *pszFmt, ...) const; 210 void debugPrintV(int32_t iMinLevel, bool fMsg, const char *pszFmt, va_list va) const; 204 int addConfig(VBoxNetDhcpCfg *pCfg); 205 bool handleDhcpMsg(uint8_t uMsgType, PCRTNETBOOTP pDhcpMsg, size_t cb); 206 207 inline void debugPrint( int32_t iMinLevel, bool fMsg, const char *pszFmt, ...) const; 208 void debugPrintV(int32_t iMinLevel, bool fMsg, const char *pszFmt, va_list va) const; 209 static const char *debugDhcpName(uint8_t uMsgType); 211 210 212 211 protected: … … 217 216 RTMAC m_MacAddress; 218 217 RTNETADDRIPV4 m_IpAddress; 219 int32_t m_cVerbosity;220 218 /** @} */ 221 219 … … 235 233 /** @} */ 236 234 237 /** @name The current packet (for debugPrint)235 /** @name Debug stuff 238 236 * @{ */ 237 int32_t m_cVerbosity; 239 238 uint8_t m_uCurMsgType; 240 239 uint16_t m_cbCurMsg; … … 274 273 m_pIfBuf = NULL; 275 274 275 m_cVerbosity = 0; 276 276 m_uCurMsgType = UINT8_MAX; 277 277 m_cbCurMsg = 0; 278 278 m_pCurMsg = NULL; 279 279 memset(&m_CurHdrs, '\0', sizeof(m_CurHdrs)); 280 281 280 282 281 #if 1 /* while hacking. */ … … 376 375 RTGETOPTSTATE State; 377 376 int rc = RTGetOptInit(&State, argc, argv, &s_aOptionDefs[0], RT_ELEMENTS(s_aOptionDefs), 0, 0); 378 AssertR eturn(rc, 49);377 AssertRCReturn(rc, 49); 379 378 380 379 VBoxNetDhcpCfg *pCurCfg = NULL; … … 494 493 { 495 494 m_pSession = NULL; 496 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: SUPR3Init -> %Rrc \n", rc);495 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: SUPR3Init -> %Rrc", rc); 497 496 return 1; 498 497 } … … 502 501 if (RT_FAILURE(rc)) 503 502 { 504 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: RTPathProgram -> %Rrc \n", rc);503 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: RTPathProgram -> %Rrc", rc); 505 504 return 1; 506 505 } … … 509 508 if (RT_FAILURE(rc)) 510 509 { 511 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: SUPLoadVMM(\"%s\") -> %Rrc \n", szPath, rc);510 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: SUPLoadVMM(\"%s\") -> %Rrc", szPath, rc); 512 511 return 1; 513 512 } … … 531 530 * Issue the request. 532 531 */ 533 if (m_cVerbosity >= 2) 534 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: attempting to open/create network \"%s\"...\n", OpenReq.szNetwork); 532 debugPrint(2, false, "attempting to open/create network \"%s\"...", OpenReq.szNetwork); 535 533 rc = SUPCallVMMR0Ex(NIL_RTR0PTR, VMMR0_DO_INTNET_OPEN, 0, &OpenReq.Hdr); 536 534 if (RT_SUCCESS(rc)) 537 535 { 538 536 m_hIf = OpenReq.hIf; 539 if (m_cVerbosity >= 1) 540 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: successfully opened/created \"%s\" - hIf=%#x\n", 541 OpenReq.szNetwork, m_hIf); 537 debugPrint(1, false, "successfully opened/created \"%s\" - hIf=%#x", OpenReq.szNetwork, m_hIf); 542 538 543 539 /* … … 554 550 { 555 551 PINTNETBUF pBuf = GetRing3BufferReq.pRing3Buf; 556 if (m_cVerbosity >= 1) 557 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: pBuf=%p cbBuf=%d cbSend=%d cbRecv=%d\n", 558 pBuf, pBuf->cbBuf, pBuf->cbSend, pBuf->cbRecv); 552 debugPrint(1, false, "pBuf=%p cbBuf=%d cbSend=%d cbRecv=%d", 553 pBuf, pBuf->cbBuf, pBuf->cbSend, pBuf->cbRecv); 559 554 m_pIfBuf = pBuf; 560 555 … … 607 602 WaitReq.pSession = m_pSession; 608 603 WaitReq.hIf = m_hIf; 609 WaitReq.cMillies = RT_INDEFINITE_WAIT;604 WaitReq.cMillies = 2000; /* 2 secs - the sleep is for some reason uninterruptible... */ /** @todo fix interruptability in SrvIntNet! */ 610 605 int rc = SUPCallVMMR0Ex(NIL_RTR0PTR, VMMR0_DO_INTNET_IF_WAIT, 0, &WaitReq.Hdr); 611 606 if (RT_FAILURE(rc)) 612 607 { 608 if (rc == VERR_TIMEOUT) 609 continue; 613 610 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: VMMR0_DO_INTNET_IF_WAIT returned %Rrc\n", rc); 614 611 return 1; … … 620 617 while (INTNETRingGetReadable(pRingBuf) > 0) 621 618 { 622 size_t 623 void 624 625 626 619 size_t cb; 620 void *pv = VBoxNetUDPMatch(m_pIfBuf, 67 /* bootps */, &m_MacAddress, 621 VBOXNETUDP_MATCH_UNICAST | VBOXNETUDP_MATCH_BROADCAST | VBOXNETUDP_MATCH_CHECKSUM 622 | (m_cVerbosity > 2 ? VBOXNETUDP_MATCH_PRINT_STDERR : 0), 623 &m_CurHdrs, &cb); 627 624 if (pv && cb) 628 625 { … … 638 635 m_uCurMsgType = UINT8_MAX; 639 636 } 640 else if (m_cVerbosity >= 1)641 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: Skipping invalid DHCP packet.\n");637 else 638 debugPrint(1, true, "VBoxNetDHCP: Skipping invalid DHCP packet.\n"); 642 639 643 640 m_pCurMsg = NULL; … … 664 661 bool VBoxNetDhcp::handleDhcpMsg(uint8_t uMsgType, PCRTNETBOOTP pDhcpMsg, size_t cb) 665 662 { 663 debugPrint(0, true, "todo"); 666 664 return false; 667 665 } … … 678 676 inline void VBoxNetDhcp::debugPrint(int32_t iMinLevel, bool fMsg, const char *pszFmt, ...) const 679 677 { 680 if (iMinLevel >= m_cVerbosity)678 if (iMinLevel <= m_cVerbosity) 681 679 { 682 680 va_list va; … … 698 696 void VBoxNetDhcp::debugPrintV(int iMinLevel, bool fMsg, const char *pszFmt, va_list va) const 699 697 { 700 if (iMinLevel >= m_cVerbosity)698 if (iMinLevel <= m_cVerbosity) 701 699 { 702 700 va_list vaCopy; /* This dude is *very* special, thus the copy. */ … … 709 707 && m_pCurMsg) 710 708 { 711 if (m_uCurMsgType != UINT8_MAX) 712 { 713 // const char *pszMsg = dhcpMsgName(m_uCurMsgType); 714 // RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: debug: \n", 715 // //m_pCurMsg->bp_chaddr 716 } 717 else 718 { 719 } 709 const char *pszMsg = m_uCurMsgType != UINT8_MAX ? debugDhcpName(m_uCurMsgType) : ""; 710 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: debug: %8s chaddr=%.6Rhxs ciaddr=%d.%d.%d.%d yiaddr=%d.%d.%d.%d siaddr=%d.%d.%d.%d\n", 711 pszMsg, 712 &m_pCurMsg->bp_chaddr, 713 m_pCurMsg->bp_ciaddr.au8[0], m_pCurMsg->bp_ciaddr.au8[1], m_pCurMsg->bp_ciaddr.au8[2], m_pCurMsg->bp_ciaddr.au8[3], 714 m_pCurMsg->bp_yiaddr.au8[0], m_pCurMsg->bp_yiaddr.au8[1], m_pCurMsg->bp_yiaddr.au8[2], m_pCurMsg->bp_yiaddr.au8[3], 715 m_pCurMsg->bp_siaddr.au8[0], m_pCurMsg->bp_siaddr.au8[1], m_pCurMsg->bp_siaddr.au8[2], m_pCurMsg->bp_siaddr.au8[3]); 720 716 } 717 } 718 } 719 720 721 /** 722 * Gets the name of given DHCP message type. 723 * 724 * @returns Readonly name. 725 * @param uMsgType The message number. 726 */ 727 /* static */ const char *VBoxNetDhcp::debugDhcpName(uint8_t uMsgType) 728 { 729 switch (uMsgType) 730 { 731 case 0: return "MT_00"; 732 case RTNET_DHCP_MT_DISCOVER: return "DISCOVER"; 733 case RTNET_DHCP_MT_OFFER: return "OFFER"; 734 case RTNET_DHCP_MT_REQUEST: return "REQUEST"; 735 case RTNET_DHCP_MT_DECLINE: return "DECLINE"; 736 case RTNET_DHCP_MT_ACK: return "ACK"; 737 case RTNET_DHCP_MT_NAC: return "NAC"; 738 case RTNET_DHCP_MT_RELEASE: return "RELEASE"; 739 case RTNET_DHCP_MT_INFORM: return "INFORM"; 740 case 9: return "MT_09"; 741 case 10: return "MT_0a"; 742 case 11: return "MT_0b"; 743 case 12: return "MT_0c"; 744 case 13: return "MT_0d"; 745 case 14: return "MT_0e"; 746 case 15: return "MT_0f"; 747 case 16: return "MT_10"; 748 case 17: return "MT_11"; 749 case 18: return "MT_12"; 750 case 19: return "MT_13"; 751 case UINT8_MAX: return "MT_ff"; 752 default: return "UNKNOWN"; 721 753 } 722 754 } -
trunk/src/VBox/NetworkServices/UDPLib/VBoxNetUDP.cpp
r17374 r17403 114 114 /* Valid IPv4 header? */ 115 115 size_t const offIpHdr = (uintptr_t)pIpHdr - (uintptr_t)pEthHdr; 116 if (!RTNetIPv4IsHdrValid(pIpHdr, cbFrame , cbFrame - offIpHdr))116 if (!RTNetIPv4IsHdrValid(pIpHdr, cbFrame - offIpHdr, cbFrame - offIpHdr)) 117 117 return NULL; 118 118
Note:
See TracChangeset
for help on using the changeset viewer.