ReactOS 0.4.16-dev-2574-g474348f
tracert.cpp File Reference
#include <stdarg.h>
#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <winuser.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <icmpapi.h>
#include <winsock2.h>
#include <conutils.h>
#include <strsafe.h>
#include "resource.h"
Include dependency graph for tracert.cpp:

Go to the source code of this file.

Classes

struct  TraceInfo
 

Macros

#define SIZEOF_ICMP_ERROR   8
 
#define SIZEOF_IO_STATUS_BLOCK   8
 
#define PACKET_SIZE   32
 
#define MAX_IPADDRESS   32
 
#define NUM_OF_PINGS   3
 
#define MIN_HOP_COUNT   1
 
#define MAX_HOP_COUNT   255
 
#define MIN_MILLISECONDS   1
 
#define MAX_MILLISECONDS   ULONG_MAX
 
#define OutputText(uID, ...)   ConResMsgPrintf(StdOut, 0, (uID), ##__VA_ARGS__)
 

Functions

static VOID Usage ()
 
static bool GetULONG (_In_ PCWSTR String, _Out_ PULONG Value)
 
static bool ResolveTarget ()
 
static bool PrintHopInfo (_In_ PVOID Buffer)
 
static ULONG GetResponseStats (_In_ PVOID ReplyBuffer, _Out_ ULONG &RoundTripTime, _Out_ PVOID &AddressInfo)
 
static bool DecodeResponse (_In_ PVOID ReplyBuffer, _In_ PVOID LastGoodResponse, _In_ bool OutputHopAddress, _Out_ bool &GoodResponse, _Out_ bool &FoundTarget)
 
static bool RunTraceRoute ()
 
static bool GetUlongOptionInRange (_In_ int argc, _In_ wchar_t *argv[], _Inout_ int *i, _Out_ ULONG *Value, _In_ ULONG MinimumValue, _In_ ULONG MaximumValue)
 
static bool ParseCmdline (int argc, wchar_t *argv[])
 
EXTERN_C int wmain (int argc, wchar_t *argv[])
 

Variables

struct TraceInfo Info = { 0 }
 

Macro Definition Documentation

◆ MAX_HOP_COUNT

#define MAX_HOP_COUNT   255

Definition at line 32 of file tracert.cpp.

◆ MAX_IPADDRESS

#define MAX_IPADDRESS   32

Definition at line 29 of file tracert.cpp.

◆ MAX_MILLISECONDS

#define MAX_MILLISECONDS   ULONG_MAX

Definition at line 34 of file tracert.cpp.

◆ MIN_HOP_COUNT

#define MIN_HOP_COUNT   1

Definition at line 31 of file tracert.cpp.

◆ MIN_MILLISECONDS

#define MIN_MILLISECONDS   1

Definition at line 33 of file tracert.cpp.

◆ NUM_OF_PINGS

#define NUM_OF_PINGS   3

Definition at line 30 of file tracert.cpp.

◆ OutputText

#define OutputText (   uID,
  ... 
)    ConResMsgPrintf(StdOut, 0, (uID), ##__VA_ARGS__)

Definition at line 68 of file tracert.cpp.

◆ PACKET_SIZE

#define PACKET_SIZE   32

Definition at line 28 of file tracert.cpp.

◆ SIZEOF_ICMP_ERROR

#define SIZEOF_ICMP_ERROR   8

Definition at line 26 of file tracert.cpp.

◆ SIZEOF_IO_STATUS_BLOCK

#define SIZEOF_IO_STATUS_BLOCK   8

Definition at line 27 of file tracert.cpp.

Function Documentation

◆ DecodeResponse()

static bool DecodeResponse ( _In_ PVOID  ReplyBuffer,
_In_ PVOID  LastGoodResponse,
_In_ bool  OutputHopAddress,
_Out_ bool GoodResponse,
_Out_ bool FoundTarget 
)
static

Definition at line 230 of file tracert.cpp.

237{
238 ULONG RoundTripTime;
239 PVOID AddressInfo;
240 ULONG Status = GetResponseStats(ReplyBuffer, RoundTripTime, AddressInfo);
241
242 switch (Status)
243 {
244 case IP_SUCCESS:
246 if (RoundTripTime)
247 {
248 OutputText(IDS_HOP_TIME, RoundTripTime);
249 }
250 else
251 {
253 }
254 GoodResponse = true;
255 break;
256
259 FoundTarget = true;
260 PrintHopInfo(AddressInfo);
263 {
265 }
267 {
269 }
270 return true;
271
272 case IP_REQ_TIMED_OUT:
274 break;
275
278 return false;
279
280 default:
282 return false;
283 }
284
285 if (OutputHopAddress)
286 {
287 if (Status == IP_REQ_TIMED_OUT && LastGoodResponse)
288 {
289 Status = GetResponseStats(LastGoodResponse, RoundTripTime, AddressInfo);
290 }
291 if (Status == IP_SUCCESS)
292 {
293 FoundTarget = true;
294 }
296 {
297 PrintHopInfo(AddressInfo);
299 }
300 else if (Status == IP_REQ_TIMED_OUT)
301 {
303 }
304 }
305
306 return true;
307}
#define IDS_DEST_HOST_UNREACHABLE
Definition: resource.h:24
#define IDS_TRANSMIT_FAILED
Definition: resource.h:28
#define IDS_DEST_NET_UNREACHABLE
Definition: resource.h:25
#define IDS_TIMEOUT
Definition: resource.h:14
#define IDS_HOP_TIME
Definition: resource.h:12
#define IDS_HOP_ZERO
Definition: resource.h:13
#define IDS_REQ_TIMED_OUT
Definition: resource.h:17
#define IDS_LINEBREAK
Definition: resource.h:18
#define IDS_HOP_RESPONSE
Definition: resource.h:19
#define IDS_GEN_FAILURE
Definition: resource.h:8
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG _Out_writes_bytes_opt_ ReplyLength PVOID ReplyBuffer
Definition: fltkernel.h:1902
Status
Definition: gdiplustypes.h:25
#define IP_DEST_NET_UNREACHABLE
Definition: ipexport.h:115
#define IP_DEST_HOST_UNREACHABLE
Definition: ipexport.h:116
#define IP_GENERAL_FAILURE
Definition: ipexport.h:138
#define IP_REQ_TIMED_OUT
Definition: ipexport.h:123
#define IP_TTL_EXPIRED_TRANSIT
Definition: ipexport.h:126
#define IP_SUCCESS
Definition: ipexport.h:113
static bool PrintHopInfo(_In_ PVOID Buffer)
Definition: tracert.cpp:128
static ULONG GetResponseStats(_In_ PVOID ReplyBuffer, _Out_ ULONG &RoundTripTime, _Out_ PVOID &AddressInfo)
Definition: tracert.cpp:196
#define OutputText(uID,...)
Definition: tracert.cpp:68
uint32_t ULONG
Definition: typedefs.h:59

Referenced by RunTraceRoute().

◆ GetResponseStats()

static ULONG GetResponseStats ( _In_ PVOID  ReplyBuffer,
_Out_ ULONG RoundTripTime,
_Out_ PVOID AddressInfo 
)
static

Definition at line 196 of file tracert.cpp.

201{
203
204 if (Info.Family == AF_INET6)
205 {
206 PICMPV6_ECHO_REPLY EchoReplyV6;
207 EchoReplyV6 = (PICMPV6_ECHO_REPLY)ReplyBuffer;
208 Status = EchoReplyV6->Status;
209 RoundTripTime = EchoReplyV6->RoundTripTime;
210 AddressInfo = &EchoReplyV6->Address;
211 }
212 else
213 {
214#ifdef _WIN64
215 PICMP_ECHO_REPLY32 EchoReplyV4;
216 EchoReplyV4 = (PICMP_ECHO_REPLY32)ReplyBuffer;
217#else
218 PICMP_ECHO_REPLY EchoReplyV4;
219 EchoReplyV4 = (PICMP_ECHO_REPLY)ReplyBuffer;
220#endif
221 Status = EchoReplyV4->Status;
222 RoundTripTime = EchoReplyV4->RoundTripTime;
223 AddressInfo = &EchoReplyV4->Address;
224 }
225
226 return Status;
227}
struct icmp_echo_reply * PICMP_ECHO_REPLY
ICMPV6_ECHO_REPLY_LH * PICMPV6_ECHO_REPLY
Definition: ipexport.h:195
IPV6_ADDRESS_EX Address
Definition: ipexport.h:189
unsigned int RoundTripTime
Definition: ipexport.h:191
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
#define AF_INET6
Definition: winsock.h:363

Referenced by DecodeResponse().

◆ GetULONG()

static bool GetULONG ( _In_ PCWSTR  String,
_Out_ PULONG  Value 
)
static

Definition at line 79 of file tracert.cpp.

82{
83 PWSTR StopString;
84
85 // Check input arguments
86 if (*String == UNICODE_NULL)
87 return false;
88
89 // Clear errno so we can use its value after
90 // the call to wcstoul to check for errors.
91 errno = 0;
92
93 // Try to convert String to ULONG
94 *Value = wcstoul(String, &StopString, 10);
95 if ((errno != ERANGE) && (errno != 0 || *StopString != UNICODE_NULL))
96 return false;
97 // The conversion was successful
98 return true;
99}
_ACRTIMP __msvcrt_ulong __cdecl wcstoul(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2912
#define ERANGE
Definition: errno.h:55
#define errno
Definition: errno.h:120
#define UNICODE_NULL
uint16_t * PWSTR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2439
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by GetUlongOptionInRange().

◆ GetUlongOptionInRange()

static bool GetUlongOptionInRange ( _In_ int  argc,
_In_ wchar_t argv[],
_Inout_ int i,
_Out_ ULONG Value,
_In_ ULONG  MinimumValue,
_In_ ULONG  MaximumValue 
)
static

Definition at line 480 of file tracert.cpp.

487{
488 ULONG ParsedValue = 0;
489
490 // Check if we have enough values
491 if ((*i + 1) > (argc - 1))
492 {
494 return false;
495 }
496
497 (*i)++;
498
499 // Try to parse and convert the value as ULONG.
500 // Check if ParsedValue is within the specified range.
501 if (!GetULONG(argv[*i], &ParsedValue) ||
502 ((ParsedValue < MinimumValue) || (ParsedValue > MaximumValue)))
503 {
504 (*i)--;
506 return false;
507 }
508
509 *Value = ParsedValue;
510 return true;
511}
#define IDS_BAD_OPTION_VALUE
Definition: resource.h:22
#define IDS_MISSING_OPTION_VALUE
Definition: resource.h:23
MonoAssembly int argc
Definition: metahost.c:107
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define argv
Definition: mplay32.c:18
static bool GetULONG(_In_ PCWSTR String, _Out_ PULONG Value)
Definition: tracert.cpp:79

Referenced by ParseCmdline().

◆ ParseCmdline()

static bool ParseCmdline ( int  argc,
wchar_t argv[] 
)
static

Definition at line 514 of file tracert.cpp.

515{
516 if (argc < 2)
517 {
518 Usage();
519 return false;
520 }
521
522 for (int i = 1; i < argc; i++)
523 {
524 if (argv[i][0] == '-' || argv[i][0] == '/')
525 {
526 switch (argv[i][1])
527 {
528 case 'd':
529 Info.ResolveAddresses = false;
530 break;
531
532 case 'h':
534 argv,
535 &i,
536 &Info.MaxHops,
539 {
540 return false;
541 }
542 break;
543
544 case 'j':
545 printf("-j is not yet implemented.\n");
546 return false;
547
548 case 'w':
550 argv,
551 &i,
552 &Info.Timeout,
555 {
556 return false;
557 }
558 break;
559
560 case '4':
561 Info.Family = AF_INET;
562 break;
563
564 case '6':
565 Info.Family = AF_INET6;
566 break;
567
568 default:
569 {
571 Usage();
572 return false;
573 }
574 }
575 }
576 else
577 {
578 // The host must be the last argument
579 if (i != (argc - 1))
580 {
581 Usage();
582 return false;
583 }
584
585 StringCchCopyW(Info.HostName, NI_MAXHOST, argv[i]);
586 break;
587 }
588 }
589
590 // Check for missing host
591 if (Info.HostName[0] == UNICODE_NULL)
592 {
594 Usage();
595 return false;
596 }
597 return true;
598}
#define IDS_INVALID_OPTION
Definition: resource.h:7
#define IDS_MISSING_TARGET
Definition: resource.h:24
#define AF_INET
Definition: tcpip.h:117
#define printf
Definition: freeldr.h:104
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
#define MAX_HOP_COUNT
Definition: tracert.cpp:32
static bool GetUlongOptionInRange(_In_ int argc, _In_ wchar_t *argv[], _Inout_ int *i, _Out_ ULONG *Value, _In_ ULONG MinimumValue, _In_ ULONG MaximumValue)
Definition: tracert.cpp:480
#define MIN_HOP_COUNT
Definition: tracert.cpp:31
#define MAX_MILLISECONDS
Definition: tracert.cpp:34
#define MIN_MILLISECONDS
Definition: tracert.cpp:33
static VOID Usage()
Definition: tracert.cpp:73
#define NI_MAXHOST
Definition: ws2def.h:365

Referenced by wmain().

◆ PrintHopInfo()

static bool PrintHopInfo ( _In_ PVOID  Buffer)
static

Definition at line 128 of file tracert.cpp.

129{
130 SOCKADDR_IN6 SockAddrIn6 = { 0 };
131 SOCKADDR_IN SockAddrIn = { 0 };
132 PSOCKADDR SockAddr;
134
135 if (Info.Family == AF_INET6)
136 {
138 SockAddrIn6.sin6_family = AF_INET6;
139 CopyMemory(SockAddrIn6.sin6_addr.u.Word, Ipv6Addr->sin6_addr, sizeof(SockAddrIn6.sin6_addr));
140 //SockAddrIn6.sin6_addr = Ipv6Addr->sin6_addr;
141 SockAddr = (PSOCKADDR)&SockAddrIn6;
142 Size = sizeof(SockAddrIn6);
143
144 }
145 else
146 {
148 SockAddrIn.sin_family = AF_INET;
149 SockAddrIn.sin_addr.S_un.S_addr = *Address;
150 SockAddr = (PSOCKADDR)&SockAddrIn;
151 Size = sizeof(SockAddrIn);
152 }
153
154 INT Status;
155 bool Resolved = false;
156 WCHAR HostName[NI_MAXHOST];
157 if (Info.ResolveAddresses)
158 {
159 Status = GetNameInfoW(SockAddr,
160 Size,
161 HostName,
163 NULL,
164 0,
166 if (Status == 0)
167 {
168 Resolved = true;
169 }
170 }
171
172 WCHAR IpAddress[MAX_IPADDRESS];
173 Status = GetNameInfoW(SockAddr,
174 Size,
175 IpAddress,
177 NULL,
178 0,
180 if (Status == 0)
181 {
182 if (Resolved)
183 {
184 OutputText(IDS_HOP_RES_INFO, HostName, IpAddress);
185 }
186 else
187 {
188 OutputText(IDS_HOP_IP_INFO, IpAddress);
189 }
190 }
191
192 return (Status == 0);
193}
INT WSAAPI GetNameInfoW(IN CONST SOCKADDR *pSockaddr, IN socklen_t SockaddrLength, OUT PWCHAR pNodeBuffer, IN DWORD NodeBufferSize, OUT PWCHAR pServiceBuffer, IN DWORD ServiceBufferSize, IN INT Flags)
Definition: addrinfo.c:873
#define IDS_HOP_RES_INFO
Definition: resource.h:15
#define IDS_HOP_IP_INFO
Definition: resource.h:16
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
struct _IPV6_ADDRESS_EX * PIPV6_ADDRESS_EX
#define CopyMemory
Definition: minwinbase.h:29
int socklen_t
Definition: tcp.c:35
short WCHAR
Definition: pedump.c:58
ULONG IPAddr
Definition: pfhook.h:35
static WCHAR Address[46]
Definition: ping.c:68
USHORT sin6_addr[8]
Definition: ipexport.h:173
union in6_addr::@3218 u
USHORT Word[8]
Definition: in6addr.h:6
ADDRESS_FAMILY sin6_family
Definition: ws2ipdef.h:179
IN6_ADDR sin6_addr
Definition: ws2ipdef.h:182
struct in_addr sin_addr
Definition: winsock.h:506
short sin_family
Definition: winsock.h:504
#define MAX_IPADDRESS
Definition: tracert.cpp:29
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
struct sockaddr * PSOCKADDR
Definition: winsock.h:479
#define NI_NAMEREQD
Definition: ws2def.h:361
#define NI_NUMERICHOST
Definition: ws2def.h:360

Referenced by DecodeResponse().

◆ ResolveTarget()

static bool ResolveTarget ( )
static

Definition at line 102 of file tracert.cpp.

103{
104 ADDRINFOW Hints;
105 ZeroMemory(&Hints, sizeof(Hints));
106 Hints.ai_family = Info.Family;
107 Hints.ai_flags = AI_CANONNAME;
108
109 int Status;
110 Status = GetAddrInfoW(Info.HostName,
111 NULL,
112 &Hints,
113 &Info.Target);
114 if (Status != 0)
115 return false;
116
117 Status = GetNameInfoW(Info.Target->ai_addr,
118 (socklen_t)Info.Target->ai_addrlen,
119 Info.TargetIP,
121 NULL,
122 0,
124 return (Status == 0);
125}
INT WSAAPI GetAddrInfoW(IN PCWSTR pszNodeName, IN PCWSTR pszServiceName, IN const ADDRINFOW *ptHints, OUT PADDRINFOW *pptResult)
Definition: addrinfo.c:509
#define ZeroMemory
Definition: minwinbase.h:31
int ai_flags
Definition: ws2def.h:682
int ai_family
Definition: ws2def.h:683
#define AI_CANONNAME
Definition: ws2def.h:294

Referenced by RunTraceRoute(), and wmain().

◆ RunTraceRoute()

static bool RunTraceRoute ( )
static

Definition at line 310 of file tracert.cpp.

311{
312 bool Success = false;
313 PVOID ReplyBuffer = NULL, LastGoodResponse = NULL;
314 DWORD ReplySize;
315
317 bool Quit = false;
318 ULONG HopCount = 1;
319 bool FoundTarget = false;
320
322 if (!Success)
323 {
325 goto Cleanup;
326 }
327
329 if (Info.Family == AF_INET6)
330 {
331 ReplySize += sizeof(ICMPV6_ECHO_REPLY);
332 }
333 else
334 {
335#ifdef _WIN64
336 ReplySize += sizeof(ICMP_ECHO_REPLY32);
337#else
338 ReplySize += sizeof(ICMP_ECHO_REPLY);
339#endif
340 }
341
343 if (ReplyBuffer == NULL)
344 {
345 Success = false;
346 goto Cleanup;
347 }
348
349 if (Info.Family == AF_INET6)
350 {
351 Info.hIcmpFile = Icmp6CreateFile();
352 }
353 else
354 {
355 Info.hIcmpFile = IcmpCreateFile();
356 }
357 if (Info.hIcmpFile == INVALID_HANDLE_VALUE)
358 {
359 Success = false;
360 goto Cleanup;
361 }
362
363 OutputText(IDS_TRACE_INFO, Info.HostName, Info.TargetIP, Info.MaxHops);
364
365 IP_OPTION_INFORMATION IpOptionInfo;
366 ZeroMemory(&IpOptionInfo, sizeof(IpOptionInfo));
367
368 while ((HopCount <= Info.MaxHops) && (FoundTarget == false) && (Quit == false))
369 {
370 OutputText(IDS_HOP_COUNT, HopCount);
371
372 if (LastGoodResponse)
373 {
374 HeapFree(heap, 0, LastGoodResponse);
375 LastGoodResponse = NULL;
376 }
377
378 for (int Ping = 1; Ping <= NUM_OF_PINGS; Ping++)
379 {
380 BYTE SendBuffer[PACKET_SIZE];
381 bool GoodResponse = false;
382
383 IpOptionInfo.Ttl = static_cast<UCHAR>(HopCount);
384
385 if (Info.Family == AF_INET6)
386 {
387 struct sockaddr_in6 Source;
388
389 ZeroMemory(&Source, sizeof(Source));
390 Source.sin6_family = AF_INET6;
391
392 (void)Icmp6SendEcho2(Info.hIcmpFile,
393 NULL,
394 NULL,
395 NULL,
396 &Source,
397 (struct sockaddr_in6 *)Info.Target->ai_addr,
398 SendBuffer,
400 &IpOptionInfo,
402 ReplySize,
403 Info.Timeout);
404 }
405 else
406 {
407 (void)IcmpSendEcho2(Info.hIcmpFile,
408 NULL,
409 NULL,
410 NULL,
411 ((PSOCKADDR_IN)Info.Target->ai_addr)->sin_addr.s_addr,
412 SendBuffer,
414 &IpOptionInfo,
416 ReplySize,
417 Info.Timeout);
418 }
419
421 LastGoodResponse,
422 (Ping == NUM_OF_PINGS),
423 GoodResponse,
424 FoundTarget) == false)
425 {
426 Quit = true;
427 break;
428 }
429
430 if (FoundTarget)
431 {
432 Success = true;
433 break;
434 }
435
436 if (GoodResponse)
437 {
438 if (LastGoodResponse)
439 {
440 HeapFree(heap, 0, LastGoodResponse);
441 }
442 LastGoodResponse = HeapAlloc(heap, HEAP_ZERO_MEMORY, ReplySize);
443 if (LastGoodResponse == NULL)
444 {
445 Success = false;
446 goto Cleanup;
447 }
448 CopyMemory(LastGoodResponse, ReplyBuffer, ReplySize);
449 }
450 }
451
452 HopCount++;
453 Sleep(100);
454 }
455
457
458Cleanup:
459 if (ReplyBuffer)
460 {
462 }
463 if (LastGoodResponse)
464 {
465 HeapFree(heap, 0, LastGoodResponse);
466 }
467 if (Info.Target)
468 {
469 FreeAddrInfoW(Info.Target);
470 }
471 if (Info.hIcmpFile)
472 {
473 IcmpCloseHandle(Info.hIcmpFile);
474 }
475
476 return Success;
477}
#define FreeAddrInfoW(a)
Definition: addrinfo.c:21
#define IDS_UNABLE_RESOLVE
Definition: resource.h:7
#define IDS_TRACE_COMPLETE
Definition: resource.h:6
#define IDS_HOP_COUNT
Definition: resource.h:11
#define IDS_TRACE_INFO
Definition: resource.h:5
#define GetProcessHeap()
Definition: compat.h:736
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
BOOL WINAPI IcmpCloseHandle(_In_ HANDLE IcmpHandle)
Definition: icmp.c:202
DWORD WINAPI IcmpSendEcho2(_In_ HANDLE IcmpHandle, _In_opt_ HANDLE Event, _In_opt_ PIO_APC_ROUTINE ApcRoutine, _In_opt_ PVOID ApcContext, _In_ IPAddr DestinationAddress, _In_ LPVOID RequestData, _In_ WORD RequestSize, _In_opt_ PIP_OPTION_INFORMATION RequestOptions, _Out_ LPVOID ReplyBuffer, _In_ DWORD ReplySize, _In_ DWORD Timeout)
Definition: icmp.c:285
HANDLE WINAPI Icmp6CreateFile(void)
Definition: icmp.c:15
HANDLE WINAPI IcmpCreateFile(void)
Definition: icmp.c:219
DWORD WINAPI Icmp6SendEcho2(_In_ HANDLE IcmpHandle, _In_opt_ HANDLE Event, _In_opt_ PIO_APC_ROUTINE ApcRoutine, _In_opt_ PVOID ApcContext, _In_ struct sockaddr_in6 *SourceAddress, _In_ struct sockaddr_in6 *DestinationAddress, _In_ LPVOID RequestData, _In_ WORD RequestSize, _In_ PIP_OPTION_INFORMATION RequestOptions, _Out_ LPVOID ReplyBuffer, _In_ DWORD ReplySize, _In_ DWORD Timeout)
Definition: icmp.c:77
static const WCHAR Cleanup[]
Definition: register.c:80
@ Success
Definition: eventcreate.c:712
unsigned long DWORD
Definition: ntddk_ex.h:95
ICMPV6_ECHO_REPLY_LH ICMPV6_ECHO_REPLY
Definition: ipexport.h:194
struct icmp_echo_reply ICMP_ECHO_REPLY
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
unsigned short USHORT
Definition: pedump.c:61
static void Ping(void)
Definition: ping.c:419
Definition: heap.c:86
unsigned char Ttl
Definition: ipexport.h:33
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:726
#define NUM_OF_PINGS
Definition: tracert.cpp:30
#define SIZEOF_ICMP_ERROR
Definition: tracert.cpp:26
static bool DecodeResponse(_In_ PVOID ReplyBuffer, _In_ PVOID LastGoodResponse, _In_ bool OutputHopAddress, _Out_ bool &GoodResponse, _Out_ bool &FoundTarget)
Definition: tracert.cpp:230
#define SIZEOF_IO_STATUS_BLOCK
Definition: tracert.cpp:27
static bool ResolveTarget()
Definition: tracert.cpp:102
#define PACKET_SIZE
Definition: tracert.cpp:28
unsigned char UCHAR
Definition: typedefs.h:53
unsigned char BYTE
Definition: xxhash.c:193

Referenced by wmain().

◆ Usage()

static VOID Usage ( void  )
static

Definition at line 73 of file tracert.cpp.

74{
76}
#define IDS_USAGE
Definition: resource.h:3

Referenced by ParseCmdline().

◆ wmain()

EXTERN_C int wmain ( int  argc,
wchar_t argv[] 
)

Definition at line 601 of file tracert.cpp.

602{
603 /* Initialize the Console Standard Streams */
605
606 Info.ResolveAddresses = true;
607 Info.MaxHops = 30;
608 Info.Timeout = 4000;
609 Info.Family = AF_UNSPEC;
610
611 if (!ParseCmdline(argc, argv))
612 {
613 return 1;
614 }
615
616 WSADATA WsaData;
617 if (WSAStartup(MAKEWORD(2, 2), &WsaData))
618 {
619 return 1;
620 }
621
622 bool Success;
624
625 WSACleanup();
626
627 return Success ? 0 : 1;
628}
#define ConInitStdStreams()
Definition: conutils_noros.h:5
static bool RunTraceRoute()
Definition: tracert.cpp:310
static bool ParseCmdline(int argc, wchar_t *argv[])
Definition: tracert.cpp:514
#define MAKEWORD(a, b)
Definition: typedefs.h:248
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
#define AF_UNSPEC
Definition: winsock.h:338

Variable Documentation

◆ Info