- Fix sending malformed ICMP packets because we read the wrong length from the wrong...
[reactos.git] / reactos / base / applications / network / tracert / tracert.c
index 0377d80..97bc8b8 100644 (file)
@@ -260,10 +260,10 @@ PreparePacket(PAPPINFO pInfo,
     pInfo->SendPacket->icmpheader.code     = 0;
     pInfo->SendPacket->icmpheader.checksum = 0;
     pInfo->SendPacket->icmpheader.id       = (USHORT)GetCurrentProcessId();
-    pInfo->SendPacket->icmpheader.seq      = iSeqNum;
+    pInfo->SendPacket->icmpheader.seq      = htons((USHORT)iSeqNum);
 
     /* calculate checksum of packet */
-    pInfo->SendPacket->icmpheader.checksum  = CheckSum((PUSHORT)&pInfo->SendPacket,
+    pInfo->SendPacket->icmpheader.checksum  = CheckSum((PUSHORT)&pInfo->SendPacket->icmpheader,
                                                        sizeof(ICMP_HEADER) + PACKET_SIZE);
 }
 
@@ -279,8 +279,8 @@ SendPacket(PAPPINFO pInfo)
     pInfo->lTimeStart = GetTime(pInfo);
 
     iSockRet = sendto(pInfo->icmpSock,              //socket
-                      (char *)pInfo->SendPacket,   //buffer
-                      PACKET_SIZE,                  //size of buffer
+                      (char *)&pInfo->SendPacket->icmpheader,//buffer
+                      sizeof(ICMP_HEADER) + PACKET_SIZE,//size of buffer
                       0,                            //flags
                       (SOCKADDR *)&pInfo->dest,     //destination
                       sizeof(pInfo->dest));         //address length
@@ -396,11 +396,7 @@ DecodeResponse(PAPPINFO pInfo)
                     DebugPrint(_T("Rouge packet: header id,  process id  %d"), TTLExceedHdr->OrigIcmpHeader.id, GetCurrentProcessId());
                     return -1;
                 }
-#ifndef _WIN64
-                _tprintf(_T("%3lld ms"), (pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart);
-#else
-                _tprintf(_T("%3I64d ms"), (pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart);
-#endif
+                _tprintf(_T("%3ld ms"), (ULONG)((pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart));
                 return 0;
 
            case ECHO_REPLY :
@@ -411,11 +407,7 @@ DecodeResponse(PAPPINFO pInfo)
                     DebugPrint(_T("Rouge packet: header id %d, process id  %d"), IcmpHdr->icmpheader.id, GetCurrentProcessId());
                     return -1;
                 }
-#ifndef _WIN64
-                _tprintf(_T("%3lld ms"), (pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart);
-#else
-                _tprintf(_T("%3I64d ms"), (pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart);
-#endif
+                _tprintf(_T("%3ld ms"), (ULONG)((pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart));
                 return 1;
 
            case DEST_UNREACHABLE :
@@ -606,7 +598,7 @@ Cleanup(PAPPINFO pInfo)
                  0,
                  pInfo->SendPacket);
 
-    if (pInfo->SendPacket)
+    if (pInfo->RecvPacket)
         HeapFree(GetProcessHeap(),
                  0,
                  pInfo->RecvPacket);