Changeset 11684 in vbox
- Timestamp:
- Aug 26, 2008 6:12:07 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/testcase/tstIntNet-1.cpp
r11470 r11684 50 50 static uint32_t g_DhcpXID = 0; 51 51 static bool g_fDhcpReply = false; 52 static bool g_fPingReply = false; 52 53 static uint32_t g_cOtherPkts = 0; 53 54 static uint32_t g_cArpPkts = 0; … … 417 418 418 419 doXmitFrame(hIf, pSession, pBuf, &abFrame[0], (uint8_t *)(pDhcpMsg + 1) - (uint8_t *)&abFrame[0], pFileRaw, pFileText); 420 } 421 422 423 static uint16_t icmpChecksum(PRTNETICMPV4HDR pHdr, int cbHdr) 424 { 425 int cbLeft = cbHdr; 426 uint16_t *pbSrc = (uint16_t *)pHdr; 427 uint16_t oddByte = 0; 428 int cSum = 0; 429 430 while (cbLeft > 1) 431 { 432 cSum += *pbSrc++; 433 cbLeft -= 2; 434 } 435 436 if (cbLeft == 1) 437 { 438 *(uint16_t *)(&oddByte) = *(uint16_t *)pbSrc; 439 cSum += oddByte; 440 } 441 442 cSum = (cSum >> 16) + (cSum & 0xffff); 443 cSum += (cSum >> 16); 444 uint16_t Result = ~cSum; 445 return Result; 446 } 447 448 449 /** 450 * Does the rudimentary ping test with fixed destination and source IPs. 451 * 452 * @param hIf The interface handle. 453 * @param pSession The session. 454 * @param pBuf The shared interface buffer. 455 * @param pSrcMac The mac address to use as source. 456 * @param pFileRaw The file to write the raw data to (optional). 457 * @param pFileText The file to write a textual packet summary to (optional). 458 */ 459 static void doPingTest(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, PINTNETBUF pBuf, PCRTMAC pSrcMac, PRTSTREAM pFileRaw, PRTSTREAM pFileText) 460 { 461 uint8_t abFrame[4096]; 462 PRTNETETHERHDR pEthHdr = (PRTNETETHERHDR)&abFrame[0]; 463 PRTNETIPV4 pIpHdr = (PRTNETIPV4) (pEthHdr + 1); 464 PRTNETICMPV4ECHO pIcmpEcho = (PRTNETICMPV4ECHO) (pIpHdr + 1); 465 466 /* 467 * Create a simple ping request. 468 */ 469 memset(&abFrame, 0, sizeof(abFrame)); 470 471 pIcmpEcho->Hdr.icmp_type = RTNETICMPV4_TYPE_ECHO_REQUEST; 472 pIcmpEcho->Hdr.icmp_code = 0; 473 pIcmpEcho->icmp_id = 0x06; 474 pIcmpEcho->icmp_seq = 0x05; 475 size_t cbPad = 56; 476 memset(&pIcmpEcho->icmp_data, '\0', cbPad); 477 pIcmpEcho->Hdr.icmp_cksum = icmpChecksum(&pIcmpEcho->Hdr, cbPad + 8); 478 479 /* IP */ 480 pIpHdr->ip_v = 4; 481 pIpHdr->ip_hl = sizeof(*pIpHdr) / sizeof(uint32_t); 482 pIpHdr->ip_tos = 0; 483 pIpHdr->ip_len = RT_H2BE_U16(sizeof(*pIcmpEcho) + cbPad + sizeof(*pIpHdr)); 484 pIpHdr->ip_id = (uint16_t)RTRandU32(); 485 pIpHdr->ip_off = 0; 486 pIpHdr->ip_ttl = 255; 487 pIpHdr->ip_p = 0x01; /*ICMP */ 488 pIpHdr->ip_sum = 0; 489 pIpHdr->ip_src.u = UINT32_C(0x9701A8C0); /* 192.168.1.151 */ 490 pIpHdr->ip_dst.u = UINT32_C(0xF9A344D0); /* 208.68.163.249 */ 491 pIpHdr->ip_sum = RTNetIPv4HdrChecksum(pIpHdr); 492 493 /* Ethernet */ 494 memset(&pEthHdr->DstMac, 0xff, sizeof(pEthHdr->DstMac)); /* broadcast */ 495 496 pEthHdr->SrcMac = *pSrcMac; 497 #if 0 /* Enable with host's real Mac address for testing of the testcase. */ 498 pEthHdr->SrcMac.au8[0] = 0x00; 499 pEthHdr->SrcMac.au8[1] = 0x1b; 500 pEthHdr->SrcMac.au8[2] = 0x24; 501 pEthHdr->SrcMac.au8[3] = 0xa0; 502 pEthHdr->SrcMac.au8[4] = 0x2f; 503 pEthHdr->SrcMac.au8[5] = 0xce; 504 #endif 505 506 pEthHdr->EtherType = RT_H2BE_U16(RTNET_ETHERTYPE_IPV4); /* IP */ 507 508 doXmitFrame(hIf, pSession, pBuf, &abFrame[0], (uint8_t *)(pIcmpEcho + 1) + cbPad - (uint8_t *)&abFrame[0], pFileRaw, pFileText); 419 509 } 420 510 … … 510 600 } 511 601 } 602 else if (pIpHdr->ip_p == 0x01) /* ICMP */ 603 { 604 PRTNETICMPV4HDR pIcmpHdr = (PRTNETICMPV4HDR)(pIpHdr + 1); 605 PRTNETICMPV4ECHO pIcmpEcho = (PRTNETICMPV4ECHO)(pIpHdr + 1); 606 if ( pIcmpHdr->icmp_type == RTNETICMPV4_TYPE_ECHO_REPLY 607 && pIcmpEcho->icmp_seq == 0x05 608 && pIpHdr->ip_dst.u == UINT32_C(0x9701A8C0) 609 #if 0 610 /** Enable with the host's real Mac address for testing of the testcase.*/ 611 && pEthHdr->DstMac.au8[0] == 0x00 612 && pEthHdr->DstMac.au8[1] == 0x1b 613 && pEthHdr->DstMac.au8[2] == 0x24 614 && pEthHdr->DstMac.au8[3] == 0xa0 615 && pEthHdr->DstMac.au8[4] == 0x2f 616 && pEthHdr->DstMac.au8[5] == 0xce 617 #else 618 && pEthHdr->DstMac.au16[0] == pSrcMac->au16[0] 619 && pEthHdr->DstMac.au16[1] == pSrcMac->au16[1] 620 && pEthHdr->DstMac.au16[2] == pSrcMac->au16[2] 621 #endif 622 ) 623 { 624 g_fPingReply = true; 625 RTPrintf("tstIntNet-1: Ping reply! From %d.%d.%d.%d\n", 626 pIpHdr->ip_src.au8[0], 627 pIpHdr->ip_src.au8[1], 628 pIpHdr->ip_src.au8[2], 629 pIpHdr->ip_src.au8[3]); 630 } 631 else 632 RTPrintf("type=%d seq=%d dstmac=%.6Rhxs ip=%d.%d.%d.%d\n", pIcmpHdr->icmp_type, pIcmpEcho->icmp_seq, 633 &pEthHdr->DstMac, pIpHdr->ip_dst.au8[0], pIpHdr->ip_dst.au8[1], pIpHdr->ip_dst.au8[2], pIpHdr->ip_dst.au8[3]); 634 } 512 635 } 513 636 } … … 560 683 { "--text-file", 't', RTGETOPT_REQ_STRING }, 561 684 { "--xmit-test", 'x', RTGETOPT_REQ_NOTHING }, 685 { "--ping-test", 'P', RTGETOPT_REQ_NOTHING }, 562 686 { "--help", 'h', RTGETOPT_REQ_NOTHING }, 563 687 { "--?", '?', RTGETOPT_REQ_NOTHING }, … … 583 707 PRTSTREAM pFileText = g_pStdOut; 584 708 bool fXmitTest = false; 709 bool fPingTest = false; 585 710 RTMAC SrcMac; 586 711 SrcMac.au8[0] = 0x08; … … 672 797 case 'x': 673 798 fXmitTest = true; 799 break; 800 801 case 'P': 802 fPingTest = true; 674 803 break; 675 804 … … 807 936 doXmitTest(OpenReq.hIf, pSession, pBuf, &SrcMac, pFileRaw, pFileText); 808 937 938 if (fPingTest) 939 doPingTest(OpenReq.hIf, pSession, pBuf, &SrcMac, pFileRaw, pFileText); 940 809 941 /* 810 942 * Either enter sniffing mode or do a timeout thing. … … 813 945 { 814 946 doPacketSniffing(OpenReq.hIf, pSession, pBuf, cMillies, pFileRaw, pFileText, &SrcMac); 815 if (fXmitTest != g_fDhcpReply) 947 if ( fXmitTest 948 && !g_fDhcpReply) 816 949 { 817 950 RTPrintf("tstIntNet-1: Error! The DHCP server didn't reply... (Perhaps you don't have one?)\n", rc); 951 g_cErrors++; 952 } 953 954 if ( fPingTest 955 && !g_fPingReply) 956 { 957 RTPrintf("tstIntNet-1: Error! No reply for ping request...\n", rc); 818 958 g_cErrors++; 819 959 }
Note:
See TracChangeset
for help on using the changeset viewer.