mirror of
https://github.com/reactos/reactos.git
synced 2025-05-25 04:03:56 +00:00
[NETSTAT] Convert the netstat utility to Unicode, and localize it. (#1657)
CORE-16119 Also, change its resource file description to reflect that the utility isn't just for TCPv4.
This commit is contained in:
parent
79a0f2b430
commit
bd3c852012
6 changed files with 337 additions and 148 deletions
|
@ -1,5 +1,8 @@
|
|||
|
||||
include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils)
|
||||
|
||||
add_executable(netstat netstat.c netstat.rc)
|
||||
set_module_type(netstat win32cui)
|
||||
set_module_type(netstat win32cui UNICODE)
|
||||
target_link_libraries(netstat conutils ${PSEH_LIB})
|
||||
add_importlibs(netstat user32 ws2_32 snmpapi iphlpapi msvcrt kernel32)
|
||||
add_cd_file(TARGET netstat DESTINATION reactos/system32 FOR all)
|
||||
|
|
109
base/applications/network/netstat/lang/en-US.rc
Normal file
109
base/applications/network/netstat/lang/en-US.rc
Normal file
|
@ -0,0 +1,109 @@
|
|||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_USAGE "\nDisplays current TCP/IP protocol statistics and network connections.\n\n\
|
||||
NETSTAT [-a] [-e] [-n] [-o] [-p proto] [-r] [-s] [interval]\n\n\
|
||||
-a Displays all connections and listening ports.\n\
|
||||
-e Displays Ethernet statistics. May be combined with -s\n\
|
||||
option\n\
|
||||
-n Displays address and port numbers in numeric form.\n\
|
||||
-o Displays the process ID for each connection.\n\
|
||||
-p proto Shows connections for protocol 'proto' TCP or UDP.\n\
|
||||
If used with the -s option to display\n\
|
||||
per-protocol statistics, 'proto' may be TCP, UDP, or IP.\n\
|
||||
-r Displays the current routing table.\n\
|
||||
-s Displays per-protocol statistics. By default, Statistics are\n\
|
||||
shown for IP, ICMP, TCP and UDP;\n\
|
||||
the -p option may be used to specify a subset of the default.\n\
|
||||
interval Redisplays selected statistics every 'interval' seconds.\n\
|
||||
Press CTRL+C to stop redisplaying. By default netstat will\n\
|
||||
print the current information only once.\n\n"
|
||||
IDS_DISPLAY_THEADER "\n Proto Local Address Foreign Address State"
|
||||
IDS_DISPLAY_PROCESS " Process\n"
|
||||
IDS_ACTIVE_CONNECT "\nActive Connections\n"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_IP4_STAT_HEADER "\nIPv4 Statistics\n\n"
|
||||
IDS_IP_PACK_REC " Packets Received = %lu\n"
|
||||
IDS_IP_HEAD_REC_ERROR " Received Header Errors = %lu\n"
|
||||
IDS_IP_ADDR_REC_ERROR " Received Address Errors = %lu\n"
|
||||
IDS_IP_DATAG_FWD " Datagrams Forwarded = %lu\n"
|
||||
IDS_IP_UNKNOWN_PRO_REC " Unknown Protocols Received = %lu\n"
|
||||
IDS_IP_REC_PACK_DISCARD " Received Packets Discarded = %lu\n"
|
||||
IDS_IP_REC_PACK_DELIVER " Received Packets Delivered = %lu\n"
|
||||
IDS_IP_OUT_REQUEST " Output Requests = %lu\n"
|
||||
IDS_IP_ROUTE_DISCARD " Routing Discards = %lu\n"
|
||||
IDS_IP_DISCARD_OUT_PACK " Discarded Output Packets = %lu\n"
|
||||
IDS_IP_OUT_PACKET_NO_ROUTE " Output Packets No Route = %lu\n"
|
||||
IDS_IP_REASSEMBLE_REQUIRED " Reassembly Required = %lu\n"
|
||||
IDS_IP_REASSEMBLE_SUCCESS " Reassembly Succesful = %lu\n"
|
||||
IDS_IP_REASSEMBLE_FAILURE " Reassembly Failures = %lu\n"
|
||||
IDS_IP_DATAG_FRAG_SUCCESS " Datagrams Successfully Fragmented = %lu\n"
|
||||
IDS_IP_DATAG_FRAG_FAILURE " Datagrams Failing Fragmentation = %lu\n"
|
||||
IDS_IP_DATAG_FRAG_CREATE " Fragments Created = %lu\n"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_ICMP4_STAT_HEADER "\nICMPv4 Statistics\n\n"
|
||||
IDS_ICMP_THEADER " Received Sent\n"
|
||||
IDS_ICMP_MSG " Messages %-11lu %lu\n"
|
||||
IDS_ICMP_ERROR " Errors %-11lu %lu\n"
|
||||
IDS_ICMP_DEST_UNREACH " Destination Unreachable %-11lu %lu\n"
|
||||
IDS_ICMP_TIME_EXCEED " Time Exceeded %-11lu %lu\n"
|
||||
IDS_ICMP_PARAM_PROBLEM " Parameter Problems %-11lu %lu\n"
|
||||
IDS_ICMP_SRC_QUENCHES " Source Quenches %-11lu %lu\n"
|
||||
IDS_ICMP_REDIRECT " Redirects %-11lu %lu\n"
|
||||
IDS_ICMP_ECHO " Echos %-11lu %lu\n"
|
||||
IDS_ICMP_ECHO_REPLY " Echo Replies %-11lu %lu\n"
|
||||
IDS_ICMP_TIMESTAMP " Timestamps %-11lu %lu\n"
|
||||
IDS_ICMP_TIMESTAMP_REPLY " Timestamp Replies %-11lu %lu\n"
|
||||
IDS_ICMP_ADDRESSS_MASK " Address Masks %-11lu %lu\n"
|
||||
IDS_ICMP_ADDRESSS_MASK_REPLY " Address Mask Replies %-11lu %lu\n"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_TCP4_HEADER "\nTCP Statistics for IPv4\n\n"
|
||||
IDS_TCP_ACTIVE_OPEN " Active Opens = %lu\n"
|
||||
IDS_TCP_PASS_OPEN " Passive Opens = %lu\n"
|
||||
IDS_TCP_FAIL_CONNECT " Failed Connection Attempts = %lu\n"
|
||||
IDS_TCP_RESET_CONNECT " Reset Connections = %lu\n"
|
||||
IDS_TCP_CURRENT_CONNECT " Current Connections = %lu\n"
|
||||
IDS_TCP_SEG_RECEIVE " Segments Received = %lu\n"
|
||||
IDS_TCP_SEG_SENT " Segments Sent = %lu\n"
|
||||
IDS_TCP_SEG_RETRANSMIT " Segments Retransmitted = %lu\n"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_UDP_IP4_HEADER "\nUDP Statistics for IPv4\n\n"
|
||||
IDS_UDP_DATAG_RECEIVE " Datagrams Received = %lu\n"
|
||||
IDS_UDP_NO_PORT " No Ports = %lu\n"
|
||||
IDS_UDP_RECEIVE_ERROR " Receive Errors = %lu\n"
|
||||
IDS_UDP_DATAG_SEND " Datagrams Sent = %lu\n"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_ETHERNET_INTERFACE_STAT "Interface Statistics\n\n"
|
||||
IDS_ETHERNET_THEADER " Received Sent\n\n"
|
||||
IDS_ETHERNET_BYTES " Bytes %14lu %15lu\n"
|
||||
IDS_ETHERNET_UNICAST_PACKET " Unicast packets %14lu %15lu\n"
|
||||
IDS_ETHERNET_NON_UNICAST_PACKET " Non-unicast packets %14lu %15lu\n"
|
||||
IDS_ETHERNET_DISCARD " Discards %14lu %15lu\n"
|
||||
IDS_ETHERNET_ERROR " Errors %14lu %15lu\n"
|
||||
IDS_ETHERNET_UNKNOWN " Unknown Protocols %14lu\n"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_ERROR_WSA_START "ERROR: WSAStartup() failed : %d\n"
|
||||
IDS_ERROR_ROUTE "ERROR: Cannot find 'route.exe'\n"
|
||||
IDS_ERROR_TCP_SNAPSHOT "ERROR: Failed to snapshot TCP endpoints.\n"
|
||||
IDS_ERROR_UDP_ENDPOINT "ERROR: Failed to snapshot UDP endpoints.\n"
|
||||
IDS_ERROR_UDP_ENDPOINT_TABLE "ERROR: Failed to snapshot UDP endpoints table.\n"
|
||||
END
|
|
@ -19,31 +19,34 @@
|
|||
#include <winbase.h>
|
||||
#define _INC_WINDOWS
|
||||
#include <winsock2.h>
|
||||
#include <tchar.h>
|
||||
#include <wchar.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <iphlpapi.h>
|
||||
|
||||
#include <conutils.h>
|
||||
|
||||
#include "netstat.h"
|
||||
#include "resource.h"
|
||||
|
||||
enum ProtoType {IP, TCP, UDP, ICMP} Protocol;
|
||||
DWORD Interval; /* time to pause between printing output */
|
||||
|
||||
/* TCP endpoint states */
|
||||
TCHAR TcpState[][32] = {
|
||||
_T("???"),
|
||||
_T("CLOSED"),
|
||||
_T("LISTENING"),
|
||||
_T("SYN_SENT"),
|
||||
_T("SYN_RCVD"),
|
||||
_T("ESTABLISHED"),
|
||||
_T("FIN_WAIT1"),
|
||||
_T("FIN_WAIT2"),
|
||||
_T("CLOSE_WAIT"),
|
||||
_T("CLOSING"),
|
||||
_T("LAST_ACK"),
|
||||
_T("TIME_WAIT"),
|
||||
_T("DELETE_TCB")
|
||||
PCWSTR TcpState[] = {
|
||||
L"???",
|
||||
L"CLOSED",
|
||||
L"LISTENING",
|
||||
L"SYN_SENT",
|
||||
L"SYN_RCVD",
|
||||
L"ESTABLISHED",
|
||||
L"FIN_WAIT1",
|
||||
L"FIN_WAIT2",
|
||||
L"CLOSE_WAIT",
|
||||
L"CLOSING",
|
||||
L"LAST_ACK",
|
||||
L"TIME_WAIT",
|
||||
L"DELETE_TCB"
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -61,11 +64,11 @@ DWORD DoFormatMessage(DWORD ErrorCode)
|
|||
NULL,
|
||||
ErrorCode,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
|
||||
(LPTSTR) &lpMsgBuf,
|
||||
(LPWSTR) &lpMsgBuf,
|
||||
0,
|
||||
NULL )))
|
||||
{
|
||||
_tprintf(_T("%s"), (LPTSTR)lpMsgBuf);
|
||||
wprintf(L"%s", (LPWSTR)lpMsgBuf);
|
||||
|
||||
LocalFree(lpMsgBuf);
|
||||
/* return number of TCHAR's stored in output buffer
|
||||
|
@ -81,83 +84,84 @@ DWORD DoFormatMessage(DWORD ErrorCode)
|
|||
* Parse command line parameters and set any options
|
||||
*
|
||||
*/
|
||||
BOOL ParseCmdline(int argc, char* argv[])
|
||||
BOOL ParseCmdline(int argc, wchar_t* argv[])
|
||||
{
|
||||
LPSTR Proto;
|
||||
CHAR c;
|
||||
LPWSTR Proto;
|
||||
WCHAR c;
|
||||
INT i;
|
||||
|
||||
if ((argc == 1) || (_istdigit(*argv[1])))
|
||||
if ((argc == 1) || (iswdigit(*argv[1])))
|
||||
bNoOptions = TRUE;
|
||||
|
||||
/* Parse command line for options we have been given. */
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if ((argc > 1) && (argv[i][0] == '-' || argv[i][0] == '/'))
|
||||
if ((argc > 1) && (argv[i][0] == L'-' || argv[i][0] == L'/'))
|
||||
{
|
||||
while ((c = *++argv[i]) != '\0')
|
||||
while ((c = *++argv[i]) != L'\0')
|
||||
{
|
||||
switch (tolower(c))
|
||||
switch (towlower(c))
|
||||
{
|
||||
case 'a' :
|
||||
case L'a':
|
||||
bDoShowAllCons = TRUE;
|
||||
break;
|
||||
case 'b' :
|
||||
case L'b':
|
||||
bDoShowProcName = TRUE;
|
||||
break;
|
||||
case 'e' :
|
||||
case L'e':
|
||||
bDoShowEthStats = TRUE;
|
||||
break;
|
||||
case 'n' :
|
||||
case L'n':
|
||||
bDoShowNumbers = TRUE;
|
||||
break;
|
||||
case 'p' :
|
||||
case L'p':
|
||||
bDoShowProtoCons = TRUE;
|
||||
Proto = argv[i+1];
|
||||
if (!_stricmp("IP", Proto))
|
||||
if (!_wcsicmp(L"IP", Proto))
|
||||
Protocol = IP;
|
||||
else if (!_stricmp("ICMP", Proto))
|
||||
else if (!_wcsicmp(L"ICMP", Proto))
|
||||
Protocol = ICMP;
|
||||
else if (!_stricmp("TCP", Proto))
|
||||
else if (!_wcsicmp(L"TCP", Proto))
|
||||
Protocol = TCP;
|
||||
else if (!_stricmp("UDP", Proto))
|
||||
else if (!_wcsicmp(L"UDP", Proto))
|
||||
Protocol = UDP;
|
||||
else
|
||||
{
|
||||
Usage();
|
||||
ConResPuts(StdOut, IDS_USAGE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
break;
|
||||
case 'r' :
|
||||
case L'r':
|
||||
bDoShowRouteTable = TRUE;
|
||||
break;
|
||||
case 's' :
|
||||
case L's':
|
||||
bDoShowProtoStats = TRUE;
|
||||
break;
|
||||
case 'o' :
|
||||
case L'o':
|
||||
bDoShowProcessId = TRUE;
|
||||
break;
|
||||
case 'v' :
|
||||
_tprintf(_T("got v\n"));
|
||||
case L'v':
|
||||
// FIXME!
|
||||
ConPuts(StdOut, L"got v\n");
|
||||
bDoDispSeqComp = TRUE;
|
||||
break;
|
||||
default :
|
||||
Usage();
|
||||
ConResPuts(StdOut, IDS_USAGE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_istdigit(*argv[i]))
|
||||
else if (iswdigit(*argv[i]) != 0)
|
||||
{
|
||||
if (_stscanf(argv[i], "%lu", &Interval) != EOF)
|
||||
if (swscanf(argv[i], L"%lu", &Interval) != EOF)
|
||||
bLoopOutput = TRUE;
|
||||
else
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// Usage();
|
||||
// EXIT_FAILURE;
|
||||
// ConResPrintf(StdOut, IDS_USAGE);
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
}
|
||||
|
||||
|
@ -169,11 +173,11 @@ BOOL ParseCmdline(int argc, char* argv[])
|
|||
*/
|
||||
VOID DisplayTableHeader()
|
||||
{
|
||||
_tprintf(_T("\n Proto Local Address Foreign Address State"));
|
||||
ConResPuts(StdOut, IDS_DISPLAY_THEADER);
|
||||
if (bDoShowProcessId)
|
||||
_tprintf(_T(" Process\n"));
|
||||
ConResPuts(StdOut, IDS_DISPLAY_PROCESS);
|
||||
else
|
||||
_tprintf(_T("\n"));
|
||||
ConPuts(StdOut, L"\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -194,7 +198,7 @@ BOOL DisplayOutput()
|
|||
/* mingw doesn't have lib for _tsystem */
|
||||
if (system("route print") == -1)
|
||||
{
|
||||
_tprintf(_T("cannot find 'route.exe'\n"));
|
||||
ConResPuts(StdErr, IDS_ERROR_ROUTE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -210,31 +214,31 @@ BOOL DisplayOutput()
|
|||
{
|
||||
switch (Protocol)
|
||||
{
|
||||
case IP :
|
||||
case IP:
|
||||
if (bDoShowProtoStats)
|
||||
{
|
||||
ShowIpStatistics();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
case ICMP :
|
||||
case ICMP:
|
||||
if (bDoShowProtoStats)
|
||||
{
|
||||
ShowIcmpStatistics();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
case TCP :
|
||||
case TCP:
|
||||
if (bDoShowProtoStats)
|
||||
ShowTcpStatistics();
|
||||
_tprintf(_T("\nActive Connections\n"));
|
||||
ConResPuts(StdOut, IDS_ACTIVE_CONNECT);
|
||||
DisplayTableHeader();
|
||||
ShowTcpTable();
|
||||
break;
|
||||
case UDP :
|
||||
case UDP:
|
||||
if (bDoShowProtoStats)
|
||||
ShowUdpStatistics();
|
||||
_tprintf(_T("\nActive Connections\n"));
|
||||
ConResPuts(StdOut, IDS_ACTIVE_CONNECT);
|
||||
DisplayTableHeader();
|
||||
ShowUdpTable();
|
||||
break;
|
||||
|
@ -252,7 +256,7 @@ BOOL DisplayOutput()
|
|||
}
|
||||
else
|
||||
{
|
||||
_tprintf(_T("\nActive Connections\n"));
|
||||
ConResPuts(StdOut, IDS_ACTIVE_CONNECT);
|
||||
DisplayTableHeader();
|
||||
ShowTcpTable();
|
||||
if (bDoShowAllCons)
|
||||
|
@ -270,27 +274,29 @@ VOID ShowIpStatistics()
|
|||
|
||||
if ((dwRetVal = GetIpStatistics(pIpStats)) == NO_ERROR)
|
||||
{
|
||||
_tprintf(_T("\nIPv4 Statistics\n\n"));
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Packets Received"), pIpStats->dwInReceives);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Received Header Errors"), pIpStats->dwInHdrErrors);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Received Address Errors"), pIpStats->dwInAddrErrors);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Datagrams Forwarded"), pIpStats->dwForwDatagrams);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Unknown Protocols Received"), pIpStats->dwInUnknownProtos);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Received Packets Discarded"), pIpStats->dwInDiscards);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Received Packets Delivered"), pIpStats->dwInDelivers);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Output Requests"), pIpStats->dwOutRequests);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Routing Discards"), pIpStats->dwRoutingDiscards);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Discarded Output Packets"), pIpStats->dwOutDiscards);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Output Packets No Route"), pIpStats->dwOutNoRoutes);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Reassembly Required"), pIpStats->dwReasmReqds);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Reassembly Succesful"), pIpStats->dwReasmOks);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Reassembly Failures"), pIpStats->dwReasmFails);
|
||||
// _tprintf(_T(" %-34s = %lu\n"), _T("Datagrams successfully fragmented"), NULL); /* FIXME: what is this one? */
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Datagrams Failing Fragmentation"), pIpStats->dwFragFails);
|
||||
_tprintf(_T(" %-34s = %lu\n"), _T("Fragments Created"), pIpStats->dwFragCreates);
|
||||
ConResPuts(StdOut, IDS_IP4_STAT_HEADER);
|
||||
ConResPrintf(StdOut, IDS_IP_PACK_REC, pIpStats->dwInReceives);
|
||||
ConResPrintf(StdOut, IDS_IP_HEAD_REC_ERROR, pIpStats->dwInHdrErrors);
|
||||
ConResPrintf(StdOut, IDS_IP_ADDR_REC_ERROR, pIpStats->dwInAddrErrors);
|
||||
ConResPrintf(StdOut, IDS_IP_DATAG_FWD, pIpStats->dwForwDatagrams);
|
||||
ConResPrintf(StdOut, IDS_IP_UNKNOWN_PRO_REC, pIpStats->dwInUnknownProtos);
|
||||
ConResPrintf(StdOut, IDS_IP_REC_PACK_DISCARD, pIpStats->dwInDiscards);
|
||||
ConResPrintf(StdOut, IDS_IP_REC_PACK_DELIVER, pIpStats->dwInDelivers);
|
||||
ConResPrintf(StdOut, IDS_IP_OUT_REQUEST, pIpStats->dwOutRequests);
|
||||
ConResPrintf(StdOut, IDS_IP_ROUTE_DISCARD, pIpStats->dwRoutingDiscards);
|
||||
ConResPrintf(StdOut, IDS_IP_DISCARD_OUT_PACK, pIpStats->dwOutDiscards);
|
||||
ConResPrintf(StdOut, IDS_IP_OUT_PACKET_NO_ROUTE, pIpStats->dwOutNoRoutes);
|
||||
ConResPrintf(StdOut, IDS_IP_REASSEMBLE_REQUIRED, pIpStats->dwReasmReqds);
|
||||
ConResPrintf(StdOut, IDS_IP_REASSEMBLE_SUCCESS, pIpStats->dwReasmOks);
|
||||
ConResPrintf(StdOut, IDS_IP_REASSEMBLE_FAILURE, pIpStats->dwReasmFails);
|
||||
ConResPrintf(StdOut, IDS_IP_DATAG_FRAG_SUCCESS, pIpStats->dwFragOks);
|
||||
ConResPrintf(StdOut, IDS_IP_DATAG_FRAG_FAILURE, pIpStats->dwFragFails);
|
||||
ConResPrintf(StdOut, IDS_IP_DATAG_FRAG_CREATE, pIpStats->dwFragCreates);
|
||||
}
|
||||
else
|
||||
{
|
||||
DoFormatMessage(dwRetVal);
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, pIpStats);
|
||||
}
|
||||
|
@ -304,37 +310,39 @@ VOID ShowIcmpStatistics()
|
|||
|
||||
if ((dwRetVal = GetIcmpStatistics(pIcmpStats)) == NO_ERROR)
|
||||
{
|
||||
_tprintf(_T("\nICMPv4 Statistics\n\n"));
|
||||
_tprintf(_T(" Received Sent\n"));
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Messages"),
|
||||
ConResPuts(StdOut, IDS_ICMP4_STAT_HEADER);
|
||||
ConResPuts(StdOut, IDS_ICMP_THEADER);
|
||||
ConResPrintf(StdOut, IDS_ICMP_MSG,
|
||||
pIcmpStats->stats.icmpInStats.dwMsgs, pIcmpStats->stats.icmpOutStats.dwMsgs);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Errors"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_ERROR,
|
||||
pIcmpStats->stats.icmpInStats.dwErrors, pIcmpStats->stats.icmpOutStats.dwErrors);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Destination Unreachable"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_DEST_UNREACH,
|
||||
pIcmpStats->stats.icmpInStats.dwDestUnreachs, pIcmpStats->stats.icmpOutStats.dwDestUnreachs);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Time Exceeded"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_TIME_EXCEED,
|
||||
pIcmpStats->stats.icmpInStats.dwTimeExcds, pIcmpStats->stats.icmpOutStats.dwTimeExcds);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Parameter Problems"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_PARAM_PROBLEM,
|
||||
pIcmpStats->stats.icmpInStats.dwParmProbs, pIcmpStats->stats.icmpOutStats.dwParmProbs);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Source Quenches"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_SRC_QUENCHES,
|
||||
pIcmpStats->stats.icmpInStats.dwSrcQuenchs, pIcmpStats->stats.icmpOutStats.dwSrcQuenchs);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Redirects"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_REDIRECT,
|
||||
pIcmpStats->stats.icmpInStats.dwRedirects, pIcmpStats->stats.icmpOutStats.dwRedirects);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Echos"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_ECHO,
|
||||
pIcmpStats->stats.icmpInStats.dwEchos, pIcmpStats->stats.icmpOutStats.dwEchos);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Echo Replies"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_ECHO_REPLY,
|
||||
pIcmpStats->stats.icmpInStats.dwEchoReps, pIcmpStats->stats.icmpOutStats.dwEchoReps);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Timestamps"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_TIMESTAMP,
|
||||
pIcmpStats->stats.icmpInStats.dwTimestamps, pIcmpStats->stats.icmpOutStats.dwTimestamps);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Timestamp Replies"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_TIMESTAMP_REPLY,
|
||||
pIcmpStats->stats.icmpInStats.dwTimestampReps, pIcmpStats->stats.icmpOutStats.dwTimestampReps);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Address Masks"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_ADDRESSS_MASK,
|
||||
pIcmpStats->stats.icmpInStats.dwAddrMasks, pIcmpStats->stats.icmpOutStats.dwAddrMasks);
|
||||
_tprintf(_T(" %-25s %-11lu %lu\n"), _T("Address Mask Replies"),
|
||||
ConResPrintf(StdOut, IDS_ICMP_ADDRESSS_MASK_REPLY,
|
||||
pIcmpStats->stats.icmpInStats.dwAddrMaskReps, pIcmpStats->stats.icmpOutStats.dwAddrMaskReps);
|
||||
}
|
||||
else
|
||||
{
|
||||
DoFormatMessage(dwRetVal);
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, pIcmpStats);
|
||||
|
||||
|
@ -349,18 +357,20 @@ VOID ShowTcpStatistics()
|
|||
|
||||
if ((dwRetVal = GetTcpStatistics(pTcpStats)) == NO_ERROR)
|
||||
{
|
||||
_tprintf(_T("\nTCP Statistics for IPv4\n\n"));
|
||||
_tprintf(_T(" %-35s = %lu\n"), _T("Active Opens"), pTcpStats->dwActiveOpens);
|
||||
_tprintf(_T(" %-35s = %lu\n"), _T("Passive Opens"), pTcpStats->dwPassiveOpens);
|
||||
_tprintf(_T(" %-35s = %lu\n"), _T("Failed Connection Attempts"), pTcpStats->dwAttemptFails);
|
||||
_tprintf(_T(" %-35s = %lu\n"), _T("Reset Connections"), pTcpStats->dwEstabResets);
|
||||
_tprintf(_T(" %-35s = %lu\n"), _T("Current Connections"), pTcpStats->dwCurrEstab);
|
||||
_tprintf(_T(" %-35s = %lu\n"), _T("Segments Received"), pTcpStats->dwInSegs);
|
||||
_tprintf(_T(" %-35s = %lu\n"), _T("Segments Sent"), pTcpStats->dwOutSegs);
|
||||
_tprintf(_T(" %-35s = %lu\n"), _T("Segments Retransmitted"), pTcpStats->dwRetransSegs);
|
||||
ConResPuts(StdOut, IDS_TCP4_HEADER);
|
||||
ConResPrintf(StdOut, IDS_TCP_ACTIVE_OPEN, pTcpStats->dwActiveOpens);
|
||||
ConResPrintf(StdOut, IDS_TCP_PASS_OPEN, pTcpStats->dwPassiveOpens);
|
||||
ConResPrintf(StdOut, IDS_TCP_FAIL_CONNECT, pTcpStats->dwAttemptFails);
|
||||
ConResPrintf(StdOut, IDS_TCP_RESET_CONNECT, pTcpStats->dwEstabResets);
|
||||
ConResPrintf(StdOut, IDS_TCP_CURRENT_CONNECT, pTcpStats->dwCurrEstab);
|
||||
ConResPrintf(StdOut, IDS_TCP_SEG_RECEIVE, pTcpStats->dwInSegs);
|
||||
ConResPrintf(StdOut, IDS_TCP_SEG_SENT, pTcpStats->dwOutSegs);
|
||||
ConResPrintf(StdOut, IDS_TCP_SEG_RETRANSMIT, pTcpStats->dwRetransSegs);
|
||||
}
|
||||
else
|
||||
{
|
||||
DoFormatMessage(dwRetVal);
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, pTcpStats);
|
||||
}
|
||||
|
@ -374,14 +384,16 @@ VOID ShowUdpStatistics()
|
|||
|
||||
if ((dwRetVal = GetUdpStatistics(pUdpStats)) == NO_ERROR)
|
||||
{
|
||||
_tprintf(_T("\nUDP Statistics for IPv4\n\n"));
|
||||
_tprintf(_T(" %-21s = %lu\n"), _T("Datagrams Received"), pUdpStats->dwInDatagrams);
|
||||
_tprintf(_T(" %-21s = %lu\n"), _T("No Ports"), pUdpStats->dwNoPorts);
|
||||
_tprintf(_T(" %-21s = %lu\n"), _T("Receive Errors"), pUdpStats->dwInErrors);
|
||||
_tprintf(_T(" %-21s = %lu\n"), _T("Datagrams Sent"), pUdpStats->dwOutDatagrams);
|
||||
ConResPuts(StdOut, IDS_UDP_IP4_HEADER);
|
||||
ConResPrintf(StdOut, IDS_UDP_DATAG_RECEIVE, pUdpStats->dwInDatagrams);
|
||||
ConResPrintf(StdOut, IDS_UDP_NO_PORT, pUdpStats->dwNoPorts);
|
||||
ConResPrintf(StdOut, IDS_UDP_RECEIVE_ERROR, pUdpStats->dwInErrors);
|
||||
ConResPrintf(StdOut, IDS_UDP_DATAG_SEND, pUdpStats->dwOutDatagrams);
|
||||
}
|
||||
else
|
||||
{
|
||||
DoFormatMessage(dwRetVal);
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, pUdpStats);
|
||||
}
|
||||
|
@ -401,24 +413,26 @@ VOID ShowEthernetStatistics()
|
|||
|
||||
if ((dwRetVal = GetIfTable(pIfTable, &dwSize, 0)) == NO_ERROR)
|
||||
{
|
||||
_tprintf(_T("Interface Statistics\n\n"));
|
||||
_tprintf(_T(" Received Sent\n\n"));
|
||||
_tprintf(_T("%-20s %14lu %15lu\n"), _T("Bytes"),
|
||||
ConResPuts(StdOut, IDS_ETHERNET_INTERFACE_STAT);
|
||||
ConResPuts(StdOut, IDS_ETHERNET_THEADER);
|
||||
ConResPrintf(StdOut, IDS_ETHERNET_BYTES,
|
||||
pIfTable->table[0].dwInOctets, pIfTable->table[0].dwOutOctets);
|
||||
_tprintf(_T("%-20s %14lu %15lu\n"), _T("Unicast packets"),
|
||||
ConResPrintf(StdOut, IDS_ETHERNET_UNICAST_PACKET,
|
||||
pIfTable->table[0].dwInUcastPkts, pIfTable->table[0].dwOutUcastPkts);
|
||||
_tprintf(_T("%-20s %14lu %15lu\n"), _T("Non-unicast packets"),
|
||||
ConResPrintf(StdOut, IDS_ETHERNET_NON_UNICAST_PACKET,
|
||||
pIfTable->table[0].dwInNUcastPkts, pIfTable->table[0].dwOutNUcastPkts);
|
||||
_tprintf(_T("%-20s %14lu %15lu\n"), _T("Discards"),
|
||||
ConResPrintf(StdOut, IDS_ETHERNET_DISCARD,
|
||||
pIfTable->table[0].dwInDiscards, pIfTable->table[0].dwOutDiscards);
|
||||
_tprintf(_T("%-20s %14lu %15lu\n"), _T("Errors"),
|
||||
ConResPrintf(StdOut, IDS_ETHERNET_ERROR,
|
||||
pIfTable->table[0].dwInErrors, pIfTable->table[0].dwOutErrors);
|
||||
_tprintf(_T("%-20s %14lu\n"), _T("Unknown Protocols"),
|
||||
ConResPrintf(StdOut, IDS_ETHERNET_UNKNOWN,
|
||||
pIfTable->table[0].dwInUnknownProtos);
|
||||
}
|
||||
else
|
||||
{
|
||||
DoFormatMessage(dwRetVal);
|
||||
}
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, pIfTable);
|
||||
}
|
||||
|
||||
|
@ -448,7 +462,7 @@ VOID ShowTcpTable()
|
|||
|
||||
if (error != NO_ERROR)
|
||||
{
|
||||
printf("Failed to snapshot TCP endpoints.\n");
|
||||
ConResPrintf(StdErr, IDS_ERROR_TCP_SNAPSHOT);
|
||||
DoFormatMessage(error);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -487,7 +501,7 @@ VOID ShowTcpTable()
|
|||
PID[0] = 0;
|
||||
}
|
||||
|
||||
_tprintf(_T(" %-6s %-22s %-22s %-11s %s\n"), _T("TCP"),
|
||||
ConPuts(StdOut, L" %-6s %-22s %-22s %-11s %s\n", L"TCP",
|
||||
Host, Remote, TcpState[tcpTable->table[i].dwState], PID);
|
||||
}
|
||||
}
|
||||
|
@ -508,7 +522,7 @@ VOID ShowUdpTable()
|
|||
error = GetExtendedUdpTable(NULL, &dwSize, TRUE, AF_INET, UDP_TABLE_OWNER_PID, 0);
|
||||
if (error != ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
printf("Failed to snapshot UDP endpoints.\n");
|
||||
ConResPuts(StdErr, IDS_ERROR_UDP_ENDPOINT);
|
||||
DoFormatMessage(error);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -516,7 +530,7 @@ VOID ShowUdpTable()
|
|||
error = GetExtendedUdpTable(udpTable, &dwSize, TRUE, AF_INET, UDP_TABLE_OWNER_PID, 0);
|
||||
if (error)
|
||||
{
|
||||
printf("Failed to snapshot UDP endpoints table.\n");
|
||||
ConResPuts(StdErr, IDS_ERROR_UDP_ENDPOINT_TABLE);
|
||||
DoFormatMessage(error);
|
||||
HeapFree(GetProcessHeap(), 0, udpTable);
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -541,7 +555,7 @@ VOID ShowUdpTable()
|
|||
PID[0] = 0;
|
||||
}
|
||||
|
||||
_tprintf(_T(" %-6s %-22s %-34s %s\n"), _T("UDP"), Host, _T("*:*"), PID);
|
||||
ConPuts(StdOut, L" %-6s %-22s %-34s %s\n", L"UDP", Host, L"*:*", PID);
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, udpTable);
|
||||
|
@ -588,7 +602,7 @@ GetIpHostName(BOOL Local, UINT IpAddr, CHAR Name[], int NameLen)
|
|||
return Name;
|
||||
}
|
||||
|
||||
Name[0] = _T('\0');
|
||||
Name[0] = '\0';
|
||||
|
||||
/* try to resolve the name */
|
||||
if (!IpAddr) {
|
||||
|
@ -607,7 +621,7 @@ GetIpHostName(BOOL Local, UINT IpAddr, CHAR Name[], int NameLen)
|
|||
if (gethostname(Name, NameLen) != 0)
|
||||
DoFormatMessage(WSAGetLastError());
|
||||
} else {
|
||||
_tcsncpy(Name, _T("localhost"), 10);
|
||||
strncpy(Name, "localhost", 10);
|
||||
}
|
||||
// } else if (phostent = gethostbyaddr((char*)&ipaddr, sizeof(nipaddr), PF_INET)) {
|
||||
// strcpy(name, phostent->h_name);
|
||||
|
@ -621,40 +635,22 @@ GetIpHostName(BOOL Local, UINT IpAddr, CHAR Name[], int NameLen)
|
|||
return Name;
|
||||
}
|
||||
|
||||
VOID Usage()
|
||||
{
|
||||
_tprintf(_T("\nDisplays current TCP/IP protocol statistics and network connections.\n\n"
|
||||
"NETSTAT [-a] [-e] [-n] [-p proto] [-r] [-s] [interval]\n\n"
|
||||
" -a Displays all connections and listening ports.\n"
|
||||
" -e Displays Ethernet statistics. May be combined with -s\n"
|
||||
" option\n"
|
||||
" -n Displays address and port numbers in numeric form.\n"
|
||||
" -p proto Shows connections for protocol 'proto' TCP or UDP.\n"
|
||||
" If used with the -s option to display\n"
|
||||
" per-protocol statistics, 'proto' may be TCP, UDP, or IP.\n"
|
||||
" -r Displays the current routing table.\n"
|
||||
" -s Displays per-protocol statistics. By default, Statistics are\n"
|
||||
" shown for IP, ICMP, TCP and UDP;\n"
|
||||
" the -p option may be used to specify a subset of the default.\n"
|
||||
" -o Displays the process ID for each connection.\n"
|
||||
" interval Redisplays selected statistics every 'interval' seconds.\n"
|
||||
" Press CTRL+C to stop redisplaying. By default netstat will\n"
|
||||
" print the current information only once.\n"));
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Parse command line parameters and set any options
|
||||
* Run display output, looping over set intervals if a number is given
|
||||
*
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
int wmain(int argc, wchar_t *argv[])
|
||||
{
|
||||
WSADATA wsaData;
|
||||
|
||||
/* Initialize the Console Standard Streams */
|
||||
ConInitStdStreams();
|
||||
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
|
||||
{
|
||||
_tprintf(_T("WSAStartup() failed : %d\n"), WSAGetLastError());
|
||||
ConResPrintf(StdErr, IDS_ERROR_WSA_START, WSAGetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ typedef struct {
|
|||
} MIB_UDPEXTABLE, *PMIB_UDPEXTABLE;
|
||||
|
||||
/* function declarations */
|
||||
BOOL ParseCmdline(int argc, char* argv[]);
|
||||
BOOL DisplayOutput(VOID);
|
||||
DWORD DoFormatMessage(DWORD ErrorCode);
|
||||
VOID ShowIpStatistics(VOID);
|
||||
|
@ -56,4 +55,3 @@ VOID ShowTcpTable(VOID);
|
|||
VOID ShowUdpTable(VOID);
|
||||
PCHAR GetPortName(UINT Port, PCSTR Proto, CHAR Name[PORTNAMELEN], INT NameLen);
|
||||
PCHAR GetIpHostName(BOOL local, UINT ipaddr, CHAR name[HOSTNAMELEN], int namelen);
|
||||
VOID Usage(VOID);
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS TCP/IPv4 Win32 netstat"
|
||||
#include <windef.h>
|
||||
#include <winuser.h>
|
||||
#include "resource.h"
|
||||
|
||||
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Network Statistics Utility"
|
||||
#define REACTOS_STR_INTERNAL_NAME "netstat"
|
||||
#define REACTOS_STR_ORIGINAL_FILENAME "netstat.exe"
|
||||
#define REACTOS_STR_ORIGINAL_COPYRIGHT "Ged Murphy (gedmurphy@gmail.com)"
|
||||
#include <reactos/version.rc>
|
||||
|
||||
/* UTF-8 */
|
||||
#pragma code_page(65001)
|
||||
|
||||
#ifdef LANGUAGE_EN_US
|
||||
#include "lang/en-US.rc"
|
||||
#endif
|
||||
|
|
72
base/applications/network/netstat/resource.h
Normal file
72
base/applications/network/netstat/resource.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
#pragma once
|
||||
|
||||
#define IDS_USAGE 0
|
||||
#define IDS_DISPLAY_THEADER 1
|
||||
#define IDS_DISPLAY_PROCESS 2
|
||||
#define IDS_ACTIVE_CONNECT 3
|
||||
#define IDS_IP4_STAT_HEADER 4
|
||||
#define IDS_ICMP4_STAT_HEADER 5
|
||||
#define IDS_ICMP_THEADER 6
|
||||
#define IDS_TCP4_HEADER 7
|
||||
|
||||
#define IDS_ERROR_WSA_START 10
|
||||
#define IDS_ERROR_ROUTE 11
|
||||
#define IDS_ERROR_TCP_SNAPSHOT 12
|
||||
#define IDS_ERROR_UDP_ENDPOINT 13
|
||||
#define IDS_ERROR_UDP_ENDPOINT_TABLE 14
|
||||
|
||||
#define IDS_IP_PACK_REC 20
|
||||
#define IDS_IP_HEAD_REC_ERROR 21
|
||||
#define IDS_IP_ADDR_REC_ERROR 22
|
||||
#define IDS_IP_DATAG_FWD 23
|
||||
#define IDS_IP_UNKNOWN_PRO_REC 24
|
||||
#define IDS_IP_REC_PACK_DISCARD 25
|
||||
#define IDS_IP_REC_PACK_DELIVER 26
|
||||
#define IDS_IP_OUT_REQUEST 27
|
||||
#define IDS_IP_ROUTE_DISCARD 28
|
||||
#define IDS_IP_DISCARD_OUT_PACK 29
|
||||
#define IDS_IP_OUT_PACKET_NO_ROUTE 30
|
||||
#define IDS_IP_REASSEMBLE_REQUIRED 31
|
||||
#define IDS_IP_REASSEMBLE_SUCCESS 32
|
||||
#define IDS_IP_REASSEMBLE_FAILURE 33
|
||||
#define IDS_IP_DATAG_FRAG_SUCCESS 34
|
||||
#define IDS_IP_DATAG_FRAG_FAILURE 35
|
||||
#define IDS_IP_DATAG_FRAG_CREATE 36
|
||||
|
||||
#define IDS_ICMP_MSG 50
|
||||
#define IDS_ICMP_ERROR 51
|
||||
#define IDS_ICMP_DEST_UNREACH 52
|
||||
#define IDS_ICMP_TIME_EXCEED 53
|
||||
#define IDS_ICMP_PARAM_PROBLEM 54
|
||||
#define IDS_ICMP_SRC_QUENCHES 55
|
||||
#define IDS_ICMP_REDIRECT 56
|
||||
#define IDS_ICMP_ECHO 57
|
||||
#define IDS_ICMP_ECHO_REPLY 58
|
||||
#define IDS_ICMP_TIMESTAMP 59
|
||||
#define IDS_ICMP_TIMESTAMP_REPLY 60
|
||||
#define IDS_ICMP_ADDRESSS_MASK 61
|
||||
#define IDS_ICMP_ADDRESSS_MASK_REPLY 62
|
||||
|
||||
#define IDS_TCP_ACTIVE_OPEN 80
|
||||
#define IDS_TCP_PASS_OPEN 81
|
||||
#define IDS_TCP_FAIL_CONNECT 82
|
||||
#define IDS_TCP_RESET_CONNECT 83
|
||||
#define IDS_TCP_CURRENT_CONNECT 84
|
||||
#define IDS_TCP_SEG_RECEIVE 85
|
||||
#define IDS_TCP_SEG_SENT 86
|
||||
#define IDS_TCP_SEG_RETRANSMIT 87
|
||||
|
||||
#define IDS_UDP_IP4_HEADER 90
|
||||
#define IDS_UDP_DATAG_RECEIVE 91
|
||||
#define IDS_UDP_NO_PORT 92
|
||||
#define IDS_UDP_RECEIVE_ERROR 93
|
||||
#define IDS_UDP_DATAG_SEND 94
|
||||
|
||||
#define IDS_ETHERNET_INTERFACE_STAT 100
|
||||
#define IDS_ETHERNET_THEADER 101
|
||||
#define IDS_ETHERNET_BYTES 102
|
||||
#define IDS_ETHERNET_UNICAST_PACKET 103
|
||||
#define IDS_ETHERNET_NON_UNICAST_PACKET 104
|
||||
#define IDS_ETHERNET_DISCARD 105
|
||||
#define IDS_ETHERNET_ERROR 106
|
||||
#define IDS_ETHERNET_UNKNOWN 107
|
Loading…
Reference in a new issue