[2/2] netstat: Implement the UDP stats output (try 2)
André Hentschel
nerv at dawncrow.de
Mon Jan 21 14:12:47 CST 2013
---
programs/netstat/netstat.c | 25 +++++++++++++++++++++++++
programs/netstat/netstat.h | 5 +++++
programs/netstat/netstat.rc | 5 +++++
3 files changed, 35 insertions(+)
diff --git a/programs/netstat/netstat.c b/programs/netstat/netstat.c
index 55aa466..b7fee0e 100644
--- a/programs/netstat/netstat.c
+++ b/programs/netstat/netstat.c
@@ -47,6 +47,7 @@ static const WCHAR fmtethheader[] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', '%', '-', '1', '9', 's', ' ', '%', 's', '\n', '\n', 0};
static const WCHAR fmttcpstat[] = {' ', ' ', '%', '-', '3', '5', 's', ' ', '=', ' ', '%', 'l', 'u', '\n', 0};
+static const WCHAR fmtudpstat[] = {' ', ' ', '%', '-', '2', '1', 's', ' ', '=', ' ', '%', 'l', 'u', '\n', 0};
static const WCHAR tcpstatesW[][16] = {
{'?', '?', '?', 0},
@@ -322,6 +323,25 @@ static void NETSTAT_udp_table(void)
HeapFree(GetProcessHeap(), 0, table);
}
+static void NETSTAT_udp_stats(void)
+{
+ PMIB_UDPSTATS stats;
+
+ stats = (PMIB_UDPSTATS)HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_UDPSTATS));
+
+ if (GetUdpStatistics(stats) == NO_ERROR)
+ {
+ NETSTAT_wprintf(fmtnn, NETSTAT_load_message(IDS_UDP_STAT));
+ NETSTAT_wprintf(fmtn);
+ NETSTAT_wprintf(fmtudpstat, NETSTAT_load_message(IDS_UDP_DGRAMS_RECV), stats->dwInDatagrams);
+ NETSTAT_wprintf(fmtudpstat, NETSTAT_load_message(IDS_UDP_NO_PORTS), stats->dwNoPorts);
+ NETSTAT_wprintf(fmtudpstat, NETSTAT_load_message(IDS_UDP_RECV_ERRORS), stats->dwInErrors);
+ NETSTAT_wprintf(fmtudpstat, NETSTAT_load_message(IDS_UDP_DGRAMS_SENT), stats->dwOutDatagrams);
+ }
+
+ HeapFree(GetProcessHeap(), 0, stats);
+}
+
static NETSTATPROTOCOLS NETSTAT_get_protocol(WCHAR name[])
{
if (!strcmpiW(name, ipW)) return PROT_IP;
@@ -381,6 +401,8 @@ int wmain(int argc, WCHAR *argv[])
NETSTAT_tcp_table();
break;
case PROT_UDP:
+ if (output_stats)
+ NETSTAT_udp_stats();
NETSTAT_conn_header();
NETSTAT_udp_table();
break;
@@ -396,7 +418,10 @@ int wmain(int argc, WCHAR *argv[])
}
if (output_stats)
+ {
NETSTAT_tcp_stats();
+ NETSTAT_udp_stats();
+ }
return 0;
}
diff --git a/programs/netstat/netstat.h b/programs/netstat/netstat.h
index a1458a1..2f62c87 100644
--- a/programs/netstat/netstat.h
+++ b/programs/netstat/netstat.h
@@ -53,3 +53,8 @@ typedef enum _NETSTATPROTOCOLS {
#define IDS_TCP_SEGM_RECV 21
#define IDS_TCP_SEGM_SENT 22
#define IDS_TCP_SEGM_RETRAN 23
+#define IDS_UDP_STAT 24
+#define IDS_UDP_DGRAMS_RECV 25
+#define IDS_UDP_NO_PORTS 26
+#define IDS_UDP_RECV_ERRORS 27
+#define IDS_UDP_DGRAMS_SENT 28
diff --git a/programs/netstat/netstat.rc b/programs/netstat/netstat.rc
index 59e4575..0e5b32e 100644
--- a/programs/netstat/netstat.rc
+++ b/programs/netstat/netstat.rc
@@ -47,4 +47,9 @@ STRINGTABLE
IDS_TCP_SEGM_RECV, "Segments Received"
IDS_TCP_SEGM_SENT, "Segments Sent"
IDS_TCP_SEGM_RETRAN, "Segments Retransmitted"
+ IDS_UDP_STAT, "UDP Statistics for IPv4"
+ IDS_UDP_DGRAMS_RECV, "Datagrams Received"
+ IDS_UDP_NO_PORTS, "No Ports"
+ IDS_UDP_RECV_ERRORS, "Recieve Errors"
+ IDS_UDP_DGRAMS_SENT, "Datagrams Sent"
}
--
1.8.0
--
Best Regards, André Hentschel
More information about the wine-patches
mailing list