[NETSTAT] Fix output formats and more (#1709)

* [NETSTAT] Restore expected output formats

"Revert" parts of bd3c852012.

CORE-16119

* [NETSTAT] Improve default and ICMPv4 output formats

* [NETSTAT] Fix a few typos, in output strings

* [NETSTAT] Output usage to StdErr

* [NETSTAT] Be more explicit about unimplemented -b/-t/-v options
This commit is contained in:
Serge Gautherie 2019-11-29 08:26:19 +01:00 committed by Timo Kreuzer
parent 5734570a15
commit 1fa2780796
2 changed files with 69 additions and 59 deletions

View file

@ -3,10 +3,11 @@ 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\
NETSTAT [-a] [-b] [-e] [-n] [-o] [-p proto] [-r] [-s] [-t] [-v] [interval]\n\n\
-a Displays all connections and listening ports.\n\
-b FIXME (Accepted option though unimplemented feature).\n\
-e Displays Ethernet statistics. May be combined with -s\n\
option\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\
@ -16,9 +17,11 @@ NETSTAT [-a] [-e] [-n] [-o] [-p proto] [-r] [-s] [interval]\n\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\
-t FIXME (Accepted option though unimplemented feature).\n\
-v FIXME (Accepted option though unimplemented feature).\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"
print the current information only once.\n"
IDS_DISPLAY_THEADER "\n Proto Local Address Foreign Address State"
IDS_DISPLAY_PROCESS " Process\n"
IDS_ACTIVE_CONNECT "\nActive Connections\n"
@ -27,76 +30,76 @@ 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"
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 Packet No Route = %lu\n"
IDS_IP_REASSEMBLE_REQUIRED " Reassembly Required = %lu\n"
IDS_IP_REASSEMBLE_SUCCESS " Reassembly Successful = %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"
IDS_ICMP_MSG " Messages %-11lu %-10lu\n"
IDS_ICMP_ERROR " Errors %-11lu %-10lu\n"
IDS_ICMP_DEST_UNREACH " Destination Unreachable %-11lu %-10lu\n"
IDS_ICMP_TIME_EXCEED " Time Exceeded %-11lu %-10lu\n"
IDS_ICMP_PARAM_PROBLEM " Parameter Problems %-11lu %-10lu\n"
IDS_ICMP_SRC_QUENCHES " Source Quenches %-11lu %-10lu\n"
IDS_ICMP_REDIRECT " Redirects %-11lu %-10lu\n"
IDS_ICMP_ECHO " Echos %-11lu %-10lu\n"
IDS_ICMP_ECHO_REPLY " Echo Replies %-11lu %-10lu\n"
IDS_ICMP_TIMESTAMP " Timestamps %-11lu %-10lu\n"
IDS_ICMP_TIMESTAMP_REPLY " Timestamp Replies %-11lu %-10lu\n"
IDS_ICMP_ADDRESSS_MASK " Address Masks %-11lu %-10lu\n"
IDS_ICMP_ADDRESSS_MASK_REPLY " Address Mask Replies %-11lu %-10lu\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"
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"
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"
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

View file

@ -8,7 +8,7 @@
/*
* TODO:
* sort function return values.
* implement -b, -o and -v
* implement -b, -t and -v
* clean up GetIpHostName
* command line parser needs more work
*/
@ -88,6 +88,8 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
bDoShowAllCons = TRUE;
break;
case L'b':
// UNIMPLEMENTED.
ConPuts(StdErr, L"'b' option is FIXME (Accepted option though unimplemented feature).\n");
bDoShowProcName = TRUE;
break;
case L'e':
@ -96,6 +98,9 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
case L'n':
bDoShowNumbers = TRUE;
break;
case L'o':
bDoShowProcessId = TRUE;
break;
case L'p':
bDoShowProtoCons = TRUE;
Proto = argv[i+1];
@ -109,7 +114,7 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
Protocol = UDP;
else
{
ConResPuts(StdOut, IDS_USAGE);
ConResPuts(StdErr, IDS_USAGE);
return FALSE;
}
break;
@ -119,16 +124,17 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
case L's':
bDoShowProtoStats = TRUE;
break;
case L'o':
bDoShowProcessId = TRUE;
case L't':
// UNIMPLEMENTED.
ConPuts(StdErr, L"'t' option is FIXME (Accepted option though unimplemented feature).\n");
break;
case L'v':
// FIXME!
ConPuts(StdOut, L"got v\n");
// UNIMPLEMENTED.
ConPuts(StdErr, L"'v' option is FIXME (Accepted option though unimplemented feature).\n");
bDoDispSeqComp = TRUE;
break;
default :
ConResPuts(StdOut, IDS_USAGE);
ConResPuts(StdErr, IDS_USAGE);
return FALSE;
}
}
@ -142,7 +148,7 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
}
// else
// {
// ConResPrintf(StdOut, IDS_USAGE);
// ConResPrintf(StdErr, IDS_USAGE);
// return FALSE;
// }
}
@ -169,6 +175,7 @@ BOOL DisplayOutput(VOID)
{
if (bNoOptions)
{
ConResPuts(StdOut, IDS_ACTIVE_CONNECT);
DisplayTableHeader();
return ShowTcpTable();
}