Index: ping.rc =================================================================== --- ping.rc (revision 47984) +++ ping.rc (working copy) @@ -1,7 +1,13 @@ /* $Id$ */ +#include +#include "resource.h" #define REACTOS_STR_FILE_DESCRIPTION "ReactOS TCP/IPv4 Win32 Ping\0" #define REACTOS_STR_INTERNAL_NAME "ping\0" #define REACTOS_STR_ORIGINAL_FILENAME "ping.exe\0" #define REACTOS_STR_ORIGINAL_COPYRIGHT "Casper S. Hornstrup (chorns@users.sourceforge.net)\0" #include + +#include "lang/en-US.rc" + + Index: lang/en-US.rc =================================================================== --- lang/en-US.rc (revision 0) +++ lang/en-US.rc (revision 0) @@ -0,0 +1,48 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +STRINGTABLE DISCARDABLE +BEGIN + IDS_USAGE "\nUsage: ping [-t] [-n count] [-l size] [-w timeout] destination-host\n\n" \ + "Options:\n" \ + " -t Ping the specified host until stopped.\n" \ + " To stop - type Control-C.\n" \ + " -n count Number of echo requests to send.\n" \ + " -l size Send buffer size.\n" \ + " -w timeout Timeout in milliseconds to wait for each reply.\n\n\0" + + IDS_PING_WITH_BYTES "\nPinging %s [%s] with %d bytes of data:\n\n\0" + IDS_PING_STATISTICS "\nPing statistics for %s:\n\0" + IDS_PACKETS_SENT_RECEIVED_LOST " Packets: Sent = %d, Received = %d, Lost = %d (%d%% loss),\n\0" + IDS_APPROXIMATE_ROUND_TRIP "Approximate round trip times in milli-seconds:\n\0" + IDS_MIN_MAX_AVERAGE " Minimum = %s, Maximum = %s, Average = %s\n\0" + IDS_NOT_ENOUGH_RESOURCES "Not enough free resources available.\n\0" + IDS_UNKNOWN_HOST "Unknown host %s.\n\0" + IDS_SETSOCKOPT_FAILED "setsockopt failed (%d).\n\0" + IDS_COULD_NOT_CREATE_SOCKET "Could not create socket (#%d).\n\0" + IDS_COULD_NOT_INIT_WINSOCK "Could not initialize winsock dll.\n\0" + IDS_DEST_MUST_BE_SPECIFIED "Name or IP address of destination host must be specified.\n\0" + IDS_BAD_PARAMETER "Bad parameter %s.\n\0" + IDS_BAD_OPTION_FORMAT "Bad option format %s.\n\0" + IDS_BAD_OPTION "Bad option %s.\n\0" + IDS_BAD_VALUE_OPTION_L "Bad value for option -l, valid range is from 0 to %d.\n\0" + IDS_REPLY_FROM "Reply from %s: bytes=%d time%s%s TTL=%d\n\0" + IDS_DEST_UNREACHABLE "Destination host unreachable.\n\0" + IDS_COULD_NOT_TRANSMIT "Could not transmit data (%d).\n\0" + IDS_COULD_NOT_RECV "Could not receive data (%d).\n\0" + IDS_REQUEST_TIMEOUT "Request timed out.\n\0" + IDS_MS "ms\0" + IDS_1MS "1ms\0" + +#ifndef NDEBUG + IDS_DBG_BUFF_SIZE "Buffer (0x%p) Size (0x%lX).\n\0" + IDS_DBG_NEXT_LINE "\n\0" + IDS_DBG_HEX_CHAR "%02X \0" + IDS_DBG_BAD_SIZE "Bad size (0x%X < 0x%X)\n\0" + IDS_DBG_BAD_ICMP_TYPE "Bad ICMP type (0x%X should be 0x%X)\n\0" + IDS_DBG_BAD_ICMP_ID "Bad ICMP id (0x%X should be 0x%X)\n\0" + IDS_DBG_BAD_SOURCE "Bad source address (%s should be %s)\n\0" + IDS_DBG_SEND "Sending packet\n\0" + IDS_DBG_RECV "Received packet\n\0" +#endif +END + Index: ping.rbuild =================================================================== --- ping.rbuild (revision 47984) +++ ping.rbuild (working copy) @@ -1,9 +1,10 @@ - + . ws2_32 + user32 ping.c ping.rc Index: resource.h =================================================================== --- resource.h (revision 0) +++ resource.h (revision 0) @@ -0,0 +1,35 @@ +#define IDS_USAGE 100 +#define IDS_PING_WITH_BYTES 101 +#define IDS_PING_STATISTICS 102 +#define IDS_PACKETS_SENT_RECEIVED_LOST 103 +#define IDS_APPROXIMATE_ROUND_TRIP 104 +#define IDS_MIN_MAX_AVERAGE 105 +#define IDS_NOT_ENOUGH_RESOURCES 106 +#define IDS_UNKNOWN_HOST 107 +#define IDS_SETSOCKOPT_FAILED 108 +#define IDS_COULD_NOT_CREATE_SOCKET 109 +#define IDS_COULD_NOT_INIT_WINSOCK 110 +#define IDS_DEST_MUST_BE_SPECIFIED 111 +#define IDS_BAD_PARAMETER 112 +#define IDS_BAD_OPTION_FORMAT 113 +#define IDS_BAD_OPTION 114 +#define IDS_BAD_VALUE_OPTION_L 115 +#define IDS_REPLY_FROM 116 +#define IDS_DEST_UNREACHABLE 117 +#define IDS_COULD_NOT_TRANSMIT 118 +#define IDS_COULD_NOT_RECV 119 +#define IDS_REQUEST_TIMEOUT 120 +#define IDS_MS 121 +#define IDS_1MS 122 + +#ifndef NDEBUG +#define IDS_DBG_BUFF_SIZE 200 +#define IDS_DBG_NEXT_LINE 201 +#define IDS_DBG_HEX_CHAR 202 +#define IDS_DBG_BAD_SIZE 203 +#define IDS_DBG_BAD_ICMP_TYPE 204 +#define IDS_DBG_BAD_ICMP_ID 205 +#define IDS_DBG_BAD_SOURCE 206 +#define IDS_DBG_SEND 207 +#define IDS_DBG_RECV 208 +#endif Property changes on: resource.h ___________________________________________________________________ Added: svn:eol-style + native Index: ping.c =================================================================== --- ping.c (revision 47984) +++ ping.c (working copy) @@ -12,9 +12,13 @@ #include #include #include +#include "resource.h" #define NDEBUG +#define NUNICODE_RESOLVE +// Unset this, if functions GetAddrInfoW and FreeAddrInfoW avaible + /* General ICMP constants */ #define ICMP_MINSIZE 8 /* Minimum ICMP packet size */ #define ICMP_MAXSIZE 65535 /* Maximum ICMP packet size */ @@ -67,10 +71,11 @@ ULONG TTLValue; ULONG TOSValue; ULONG Timeout; -CHAR TargetName[256]; +WCHAR TargetName[256]; SOCKET IcmpSock; SOCKADDR_IN Target; -LPSTR TargetIP; +LPWSTR TargetIP; +WCHAR TargetIPBuff[16]; FD_SET Fds; TIMEVAL Timeval; UINT CurrentSeqNum; @@ -85,7 +90,10 @@ LARGE_INTEGER TicksPerUs; /* Ticks per microsecond */ LARGE_INTEGER SentTime; BOOL UsePerformanceCounter; +HANDLE hStdOutput; +void FormatOutput(UINT, ...); + #ifndef NDEBUG /* Display the contents of a buffer */ static VOID DisplayBuffer( @@ -93,30 +101,67 @@ DWORD Size) { UINT i; - PCHAR p; + PWCHAR p; - printf("Buffer (0x%p) Size (0x%lX).\n", Buffer, Size); + FormatOutput(IDS_DBG_BUFF_SIZE, Buffer, Size); - p = (PCHAR)Buffer; + p = (PWCHAR)Buffer; for (i = 0; i < Size; i++) { if (i % 16 == 0) - printf("\n"); - printf("%02X ", (p[i]) & 0xFF); + FormatOutput(IDS_DBG_NEXT_LINE); + FormatOutput(IDS_DBG_HEX_CHAR, (p[i]) & 0xFF); } } #endif /* !NDEBUG */ +void FormatOutput(UINT uID, ...) +{ + va_list valist; + + WCHAR Buf[1024]; + LPWSTR Format; + static size_t BufSizeData; + static LPWSTR BufData; + DWORD written; + UINT DataLength; + HANDLE hHeap = GetProcessHeap(); + + va_start(valist, uID); + + if(!BufData) + { + BufData = Buf; + BufSizeData = sizeof(Buf); + } + + if(!LoadString(NULL, uID, (LPWSTR)&Format, 0)) + return; + + while( (BufSizeData / sizeof(WCHAR) - 1) <= (DataLength = _vsnwprintf(BufData, BufSizeData / sizeof(WCHAR), Format, valist)) ) + { + if(BufData != Buf) + HeapFree(hHeap, 0, BufData); + + BufSizeData = BufSizeData*2; + BufData = HeapAlloc(hHeap, 0, BufSizeData*2); + + if(!BufData) + { + if(!(BufSizeData = LoadString(NULL, IDS_NOT_ENOUGH_RESOURCES, (LPWSTR)&Format, 0))) + return; + WriteConsole(hStdOutput, Format, BufSizeData, &written, NULL); + return; + } + } + + WriteConsole(hStdOutput, BufData, DataLength, &written, NULL); +} + /* Display usage information on screen */ static VOID Usage(VOID) { - printf("\nUsage: ping [-t] [-n count] [-l size] [-w timeout] destination-host\n\n"); - printf("Options:\n"); - printf(" -t Ping the specified host until stopped.\n"); - printf(" To stop - type Control-C.\n"); - printf(" -n count Number of echo requests to send.\n"); - printf(" -l size Send buffer size.\n"); - printf(" -w timeout Timeout in milliseconds to wait for each reply.\n\n"); + FormatOutput(IDS_USAGE); } /* Reset configuration to default values */ @@ -157,26 +202,26 @@ } /* Return ULONG in a string */ -static ULONG GetULONG(LPSTR String) +static ULONG GetULONG(LPWSTR String) { UINT i, Length; ULONG Value; - LPSTR StopString; + LPWSTR StopString; i = 0; - Length = (UINT)_tcslen(String); - while ((i < Length) && ((String[i] < '0') || (String[i] > '9'))) i++; - if ((i >= Length) || ((String[i] < '0') || (String[i] > '9'))) + Length = (UINT)lstrlen(String); + while ((i < Length) && ((String[i] < L'0') || (String[i] > L'9'))) i++; + if ((i >= Length) || ((String[i] < L'0') || (String[i] > L'9'))) { InvalidOption = TRUE; return 0; } - Value = strtoul(&String[i], &StopString, 10); + Value = wcstoul(&String[i], &StopString, 10); return Value; } /* Return ULONG in a string. Try next paramter if not successful */ -static ULONG GetULONG2(LPSTR String1, LPSTR String2, PINT i) +static ULONG GetULONG2(LPWSTR String1, LPWSTR String2, PINT i) { ULONG Value; @@ -184,7 +229,7 @@ if (InvalidOption) { InvalidOption = FALSE; - if (String2[0] != '-') + if (String2[0] != L'-') { Value = GetULONG(String2); if (!InvalidOption) @@ -196,7 +241,7 @@ } /* Parse command line parameters */ -static BOOL ParseCmdline(int argc, char* argv[]) +static BOOL ParseCmdline(int argc, LPWSTR argv[]) { INT i; BOOL ShowUsage; @@ -210,34 +255,34 @@ for (i = 1; i < argc; i++) { - if (argv[i][0] == '-') + if (argv[i][0] == L'-') { switch (argv[i][1]) { - case 't': NeverStop = TRUE; break; - case 'a': ResolveAddresses = TRUE; break; - case 'n': PingCount = GetULONG2(&argv[i][2], argv[i + 1], &i); break; - case 'l': + case L't': NeverStop = TRUE; break; + case L'a': ResolveAddresses = TRUE; break; + case L'n': PingCount = GetULONG2(&argv[i][2], argv[i + 1], &i); break; + case L'l': DataSize = GetULONG2(&argv[i][2], argv[i + 1], &i); if (DataSize > ICMP_MAXSIZE - sizeof(ICMP_ECHO_PACKET) - sizeof(IPv4_HEADER)) { - printf("Bad value for option -l, valid range is from 0 to %d.\n", + FormatOutput(IDS_BAD_VALUE_OPTION_L, ICMP_MAXSIZE - (int)sizeof(ICMP_ECHO_PACKET) - (int)sizeof(IPv4_HEADER)); return FALSE; } break; - case 'f': DontFragment = TRUE; break; - case 'i': TTLValue = GetULONG2(&argv[i][2], argv[i + 1], &i); break; - case 'v': TOSValue = GetULONG2(&argv[i][2], argv[i + 1], &i); break; - case 'w': Timeout = GetULONG2(&argv[i][2], argv[i + 1], &i); break; + case L'f': DontFragment = TRUE; break; + case L'i': TTLValue = GetULONG2(&argv[i][2], argv[i + 1], &i); break; + case L'v': TOSValue = GetULONG2(&argv[i][2], argv[i + 1], &i); break; + case L'w': Timeout = GetULONG2(&argv[i][2], argv[i + 1], &i); break; default: - printf("Bad option %s.\n", argv[i]); + FormatOutput(IDS_BAD_OPTION, argv[i]); Usage(); return FALSE; } if (InvalidOption) { - printf("Bad option format %s.\n", argv[i]); + FormatOutput(IDS_BAD_OPTION_FORMAT, argv[i]); return FALSE; } } @@ -245,7 +290,7 @@ { if (FoundTarget) { - printf("Bad parameter %s.\n", argv[i]); + FormatOutput(IDS_BAD_PARAMETER, argv[i]); return FALSE; } else @@ -258,7 +303,7 @@ if ((!ShowUsage) && (!FoundTarget)) { - printf("Name or IP address of destination host must be specified.\n"); + FormatOutput(IDS_DEST_MUST_BE_SPECIFIED); return FALSE; } @@ -296,22 +341,26 @@ WORD wVersionRequested; WSADATA WsaData; INT Status; - ULONG Addr; - PHOSTENT phe; + ADDRINFOW Hints = {0}, *Addrs; + IN_ADDR Addr; + int ValidAddr; +#ifdef NUNICODE_RESOLVE + char aTargetName[256]; +#endif wVersionRequested = MAKEWORD(2, 2); Status = WSAStartup(wVersionRequested, &WsaData); if (Status != 0) { - printf("Could not initialize winsock dll.\n"); + FormatOutput(IDS_COULD_NOT_INIT_WINSOCK); return FALSE; } IcmpSock = WSASocket(AF_INET, SOCK_RAW, IPPROTO_ICMP, NULL, 0, 0); if (IcmpSock == INVALID_SOCKET) { - printf("Could not create socket (#%d).\n", WSAGetLastError()); + FormatOutput(IDS_COULD_NOT_CREATE_SOCKET, WSAGetLastError()); return FALSE; } @@ -321,7 +370,7 @@ (const char *)&DontFragment, sizeof(DontFragment)) == SOCKET_ERROR) { - printf("setsockopt failed (%d).\n", WSAGetLastError()); + FormatOutput(IDS_SETSOCKOPT_FAILED, WSAGetLastError()); return FALSE; } @@ -331,35 +380,51 @@ (const char *)&TTLValue, sizeof(TTLValue)) == SOCKET_ERROR) { - printf("setsockopt failed (%d).\n", WSAGetLastError()); + FormatOutput(IDS_SETSOCKOPT_FAILED, WSAGetLastError()); return FALSE; } ZeroMemory(&Target, sizeof(Target)); - phe = NULL; - Addr = inet_addr(TargetName); - if (Addr == INADDR_NONE) + + Hints.ai_family = AF_INET; + Hints.ai_flags = AI_NUMERICHOST; +#ifdef NUNICODE_RESOLVE + WideCharToMultiByte(CP_ACP, 0, TargetName, -1, aTargetName, + sizeof(aTargetName), "-", NULL); + + if ((ValidAddr = getaddrinfo(aTargetName, NULL, (ADDRINFOA*)&Hints, (struct addrinfo **)&Addrs))) { - phe = gethostbyname(TargetName); - if (phe == NULL) - { - printf("Unknown host %s.\n", TargetName); - return FALSE; - } + Hints.ai_flags = 0; + ValidAddr = getaddrinfo(aTargetName, NULL, (ADDRINFOA*)&Hints, (struct addrinfo **)&Addrs); } - - if (phe != NULL) - CopyMemory(&Target.sin_addr, phe->h_addr, phe->h_length); +#else /* NUNICODE_RESOLVE */ + if ((ValidAddr = GetAddrInfo(TargetName, NULL, (ADDRINFOW*)&Hints, &Addrs))) + { + Hints.ai_flags = 0; + ValidAddr = GetAddrInfo(TargetName, NULL, (ADDRINFOW*)&Hints, &Addrs); + } +#endif /* NUNICODE_RESOLVE */ + + if (ValidAddr) + { + FormatOutput(IDS_UNKNOWN_HOST, TargetName); + return FALSE; + } else - Target.sin_addr.s_addr = Addr; + { + CopyMemory((void*)&Target, (void*)Addrs->ai_addr, sizeof(SOCKADDR_IN)); +#ifdef NUNICODE_RESOLVE + freeaddrinfo((PADDRINFOA)Addrs); +#else + FreeAddrInfo(Addrs); +#endif + } - if (phe != NULL) - Target.sin_family = phe->h_addrtype; - else - Target.sin_family = AF_INET; - - TargetIP = inet_ntoa(Target.sin_addr); + TargetIP = TargetIPBuff; + Addr = Target.sin_addr; + swprintf(TargetIP, L"%d.%d.%d.%d", Addr.S_un.S_un_b.s_b1, Addr.S_un.S_un_b.s_b2, + Addr.S_un.S_un_b.s_b3, Addr.S_un.S_un_b.s_b4); CurrentSeqNum = 1; SentCount = 0; LostCount = 0; @@ -405,16 +470,19 @@ } } -static VOID TimeToMsString(LPSTR String, LARGE_INTEGER Time) + +static VOID TimeToMsString(LPWSTR String, LARGE_INTEGER Time) { - CHAR Convstr[40]; + WCHAR Convstr[40]; LARGE_INTEGER LargeTime; + LPWSTR ms; LargeTime.QuadPart = Time.QuadPart / TicksPerMs.QuadPart; - _i64toa(LargeTime.QuadPart, Convstr, 10); - strcpy(String, Convstr); - strcat(String, "ms"); + _i64tow(LargeTime.QuadPart, Convstr, 10); + lstrcpy(String, Convstr); + LoadString(NULL, IDS_MS, (LPWSTR)&ms, 0); + lstrcat(String, ms); } /* Locate the ICMP data and print it. Returns TRUE if the packet was good, @@ -424,10 +492,11 @@ PIPv4_HEADER IpHeader; PICMP_ECHO_PACKET Icmp; UINT IphLength; - CHAR Time[100]; + WCHAR Time[100]; LARGE_INTEGER RelativeTime; LARGE_INTEGER LargeTime; - CHAR Sign[2]; + WCHAR Sign[2]; + WCHAR szReplyIP[16]; IpHeader = (PIPv4_HEADER)buffer; @@ -436,7 +505,7 @@ if (size < IphLength + ICMP_MINSIZE) { #ifndef NDEBUG - printf("Bad size (0x%X < 0x%X)\n", size, IphLength + ICMP_MINSIZE); + FormatOutput(IDS_DBG_BAD_SIZE, size, IphLength + ICMP_MINSIZE); #endif /* !NDEBUG */ return FALSE; } @@ -446,7 +515,7 @@ if (Icmp->Icmp.Type != ICMPMSG_ECHOREPLY) { #ifndef NDEBUG - printf("Bad ICMP type (0x%X should be 0x%X)\n", Icmp->Icmp.Type, ICMPMSG_ECHOREPLY); + FormatOutput(IDS_DBG_BAD_ICMP_TYPE, Icmp->Icmp.Type, ICMPMSG_ECHOREPLY); #endif /* !NDEBUG */ return FALSE; } @@ -454,7 +523,7 @@ if (Icmp->Icmp.Id != (USHORT)GetCurrentProcessId()) { #ifndef NDEBUG - printf("Bad ICMP id (0x%X should be 0x%X)\n", Icmp->Icmp.Id, (USHORT)GetCurrentProcessId()); + FormatOutput(IDS_DBG_BAD_ICMP_ID, Icmp->Icmp.Id, (USHORT)GetCurrentProcessId()); #endif /* !NDEBUG */ return FALSE; } @@ -462,7 +531,7 @@ if (from->sin_addr.s_addr != Target.sin_addr.s_addr) { #ifndef NDEBUG - printf("Bad source address (%s should be %s)\n", inet_ntoa(from->sin_addr), inet_ntoa(Target.sin_addr)); + FormatOutput(IDS_DBG_BAD_SOURCE, inet_ntoa(from->sin_addr), inet_ntoa(Target.sin_addr)); #endif /* !NDEBUG */ return FALSE; } @@ -473,17 +542,23 @@ if ((RelativeTime.QuadPart / TicksPerMs.QuadPart) < 1) { - strcpy(Sign, "<"); - strcpy(Time, "1ms"); + LPWSTR ms1; + wcscpy(Sign, L"<"); + LoadString(NULL, IDS_1MS, (LPWSTR)&ms1, 0); + wcscpy(Time, ms1); } else { - strcpy(Sign, "="); + wcscpy(Sign, L"="); TimeToMsString(Time, RelativeTime); } - printf("Reply from %s: bytes=%d time%s%s TTL=%d\n", inet_ntoa(from->sin_addr), + swprintf(szReplyIP, L"%d.%d.%d.%d", from->sin_addr.S_un.S_un_b.s_b1, + from->sin_addr.S_un.S_un_b.s_b2, + from->sin_addr.S_un.S_un_b.s_b3, + from->sin_addr.S_un.S_un_b.s_b4); + FormatOutput(IDS_REPLY_FROM, szReplyIP, size - IphLength - (int)sizeof(ICMP_ECHO_PACKET), Sign, Time, IpHeader->TTL); if (RelativeTime.QuadPart < MinRTT.QuadPart || !MinRTTSet) { @@ -513,7 +588,7 @@ Buffer = GlobalAlloc(0, Size); if (!Buffer) { - printf("Not enough free resources available.\n"); + FormatOutput(IDS_NOT_ENOUGH_RESOURCES); return FALSE; } @@ -543,9 +618,9 @@ { #ifndef NDEBUG - printf("Sending packet\n"); + FormatOutput(IDS_DBG_SEND); DisplayBuffer(Buffer, sizeof(ICMP_ECHO_PACKET) + DataSize); - printf("\n"); + FormatOutput(IDS_DBG_NEXT_LINE); #endif /* !NDEBUG */ Status = sendto(IcmpSock, Buffer, sizeof(ICMP_ECHO_PACKET) + DataSize, @@ -557,9 +632,9 @@ { LostCount++; if (WSAGetLastError() == WSAEHOSTUNREACH) - printf("Destination host unreachable.\n"); + FormatOutput(IDS_DEST_UNREACHABLE); else - printf("Could not transmit data (%d).\n", WSAGetLastError()); + FormatOutput(IDS_COULD_NOT_TRANSMIT, WSAGetLastError()); GlobalFree(Buffer); return FALSE; } @@ -578,9 +653,9 @@ Status = recvfrom(IcmpSock, Buffer, Size, 0, &From, &Length); #ifndef NDEBUG - printf("Received packet\n"); + FormatOutput(IDS_DBG_RECV); DisplayBuffer(Buffer, Status); - printf("\n"); + FormatOutput(IDS_DBG_NEXT_LINE); #endif /* !NDEBUG */ } else @@ -589,7 +664,7 @@ { if (WSAGetLastError() != WSAETIMEDOUT) { - printf("Could not receive data (%d).\n", WSAGetLastError()); + FormatOutput(IDS_COULD_NOT_RECV, WSAGetLastError()); GlobalFree(Buffer); return FALSE; } @@ -598,7 +673,7 @@ if (Status == 0) { - printf("Request timed out.\n"); + FormatOutput(IDS_REQUEST_TIMEOUT); GlobalFree(Buffer); return TRUE; } @@ -611,20 +686,21 @@ /* Program entry point */ -int main(int argc, char* argv[]) +int wmain(int argc, LPWSTR argv[]) { UINT Count; - CHAR MinTime[20]; - CHAR MaxTime[20]; - CHAR AvgTime[20]; + WCHAR MinTime[20]; + WCHAR MaxTime[20]; + WCHAR AvgTime[20]; + + hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); Reset(); if ((ParseCmdline(argc, argv)) && (Setup())) { - printf("\nPinging %s [%s] with %d bytes of data:\n\n", - TargetName, TargetIP, DataSize); + FormatOutput(IDS_PING_WITH_BYTES, TargetName, TargetIP, DataSize); Count = 0; while ((NeverStop) || (Count < PingCount)) @@ -654,15 +730,14 @@ TimeToMsString(AvgTime, AvgRTT); /* Print statistics */ - printf("\nPing statistics for %s:\n", TargetIP); - printf(" Packets: Sent = %d, Received = %d, Lost = %d (%d%% loss),\n", + FormatOutput(IDS_PING_STATISTICS, TargetIP); + FormatOutput(IDS_PACKETS_SENT_RECEIVED_LOST, SentCount, SentCount - LostCount, LostCount, Count); /* Print approximate times or NO approximate times if 100% loss */ if ((SentCount - LostCount) > 0) { - printf("Approximate round trip times in milli-seconds:\n"); - printf(" Minimum = %s, Maximum = %s, Average = %s\n", - MinTime, MaxTime, AvgTime); + FormatOutput(IDS_APPROXIMATE_ROUND_TRIP); + FormatOutput(IDS_MIN_MAX_AVERAGE, MinTime, MaxTime, AvgTime); } } return 0;