ReactOS 0.4.15-dev-7924-g5949c20
netstat.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS netstat utility
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: display IP stack statistics
5 * COPYRIGHT: Copyright 2005 Ged Murphy <gedmurphy@gmail.com>
6 */
7/*
8 * TODO:
9 * implement -b, -t, -v
10 * clean up GetIpHostName
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <wchar.h>
16
17#define WIN32_NO_STATUS
18#include <windef.h>
19#include <winbase.h>
20#define _INC_WINDOWS
21#include <winsock2.h>
22#include <iphlpapi.h>
23
24#include <conutils.h>
25
26#include "netstat.h"
27#include "resource.h"
28
30DWORD Interval; /* time to pause between printing output */
31
32/* TCP endpoint states */
34 L"???",
35 L"CLOSED",
36 L"LISTENING",
37 L"SYN_SENT",
38 L"SYN_RCVD",
39 L"ESTABLISHED",
40 L"FIN_WAIT1",
41 L"FIN_WAIT2",
42 L"CLOSE_WAIT",
43 L"CLOSING",
44 L"LAST_ACK",
45 L"TIME_WAIT",
46 L"DELETE_TCB"
47};
48
49/*
50 * format message string and display output
51 */
53{
55 return;
56
59}
60
62{
67 else
68 ConPuts(StdOut, L"\n");
69}
70
71/*
72 * Parse command line parameters and set any options
73 */
74BOOL ParseCmdline(int argc, wchar_t* argv[])
75{
76 LPWSTR Proto;
77 WCHAR c;
78 INT i;
79
80 if ((argc == 1) || (iswdigit(*argv[1])))
82
83 /* Parse command line for options we have been given. */
84 for (i = 1; i < argc; i++)
85 {
86 if ((argc > 1) && (argv[i][0] == L'-' || argv[i][0] == L'/'))
87 {
88 while ((c = *++argv[i]) != L'\0')
89 {
90 switch (towlower(c))
91 {
92 case L'a':
94 break;
95 case L'b':
96 // UNIMPLEMENTED.
97 ConPuts(StdErr, L"'b' option is FIXME (Accepted option though unimplemented feature).\n");
99#if (_WIN32_WINNT < _WIN32_WINNT_VISTA)
101#endif
102 break;
103 case L'e':
105 break;
106 case L'n':
108 break;
109 case L'o':
111 break;
112 case L'p':
114 if (i+1 >= argc)
115 {
117 return TRUE;
118 }
119
120 Proto = argv[i+1];
121 if (!_wcsicmp(L"IP", Proto))
122 Protocol = IP;
123 else if (!_wcsicmp(L"ICMP", Proto))
124 Protocol = ICMP;
125 else if (!_wcsicmp(L"TCP", Proto))
126 Protocol = TCP;
127 else if (!_wcsicmp(L"UDP", Proto))
128 Protocol = UDP;
129 else
130 goto StopParsingAndShowUsageHelp;
131 break;
132 case L'r':
134 break;
135 case L's':
137 break;
138 case L't':
139 // UNIMPLEMENTED.
140 ConPuts(StdErr, L"'t' option is FIXME (Accepted option though unimplemented feature).\n");
141 break;
142 case L'v':
143 // UNIMPLEMENTED.
144 ConPuts(StdErr, L"'v' option is FIXME (Accepted option though unimplemented feature).\n");
146 break;
147 default:
148StopParsingAndShowUsageHelp:
150 return FALSE;
151 }
152 }
153 }
154 else if (iswdigit(*argv[i]) != 0)
155 {
156 if (swscanf(argv[i], L"%lu", &Interval) != EOF)
158 else
159 return FALSE;
160 }
161 }
162
163 return TRUE;
164}
165
167{
168 if (bNoOptions)
169 {
171 return ShowTcpTable();
172 }
173
175 {
176 if (_wsystem(L"route print") == -1)
177 {
179 return FALSE;
180 }
181 return TRUE;
182 }
183
184 if (bDoShowEthStats)
185 {
187 return TRUE;
188 }
189
191 {
192 switch (Protocol)
193 {
194 case IP:
197 return TRUE;
198 case ICMP:
201 return TRUE;
202 case TCP:
206 return ShowTcpTable();
207 case UDP:
211 return (bDoShowAllCons ? ShowUdpTable() : TRUE);
212 default:
213 break;
214 }
215 }
216 else if (bDoShowProtoStats)
217 {
222 return TRUE;
223 }
224 else
225 {
228 ShowUdpTable();
229 }
230
231 return TRUE;
232}
233
235{
236 MIB_IPSTATS IpStats;
237 DWORD dwRetVal;
238
239 if ((dwRetVal = GetIpStatistics(&IpStats)) == NO_ERROR)
240 {
259 }
260 else
261 {
262 DoFormatMessage(dwRetVal);
263 }
264}
265
267{
268 MIB_ICMP IcmpStats;
269 DWORD dwRetVal;
270
271 if ((dwRetVal = GetIcmpStatistics(&IcmpStats)) == NO_ERROR)
272 {
276 IcmpStats.stats.icmpInStats.dwMsgs, IcmpStats.stats.icmpOutStats.dwMsgs);
278 IcmpStats.stats.icmpInStats.dwErrors, IcmpStats.stats.icmpOutStats.dwErrors);
290 IcmpStats.stats.icmpInStats.dwEchos, IcmpStats.stats.icmpOutStats.dwEchos);
301 }
302 else
303 {
304 DoFormatMessage(dwRetVal);
305 }
306}
307
309{
311 DWORD dwRetVal;
312
313 if ((dwRetVal = GetTcpStatistics(&tcpStats)) == NO_ERROR)
314 {
324 }
325 else
326 {
327 DoFormatMessage(dwRetVal);
328 }
329}
330
332{
334 DWORD dwRetVal;
335
336 if ((dwRetVal = GetUdpStatistics(&udpStats)) == NO_ERROR)
337 {
343 }
344 else
345 {
346 DoFormatMessage(dwRetVal);
347 }
348}
349
351{
352 PMIB_IFTABLE pIfTable;
353 DWORD dwSize = 0;
354 DWORD dwRetVal = 0;
355
356 pIfTable = (MIB_IFTABLE*)HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IFTABLE));
357
358 if (GetIfTable(pIfTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER)
359 {
360 HeapFree(GetProcessHeap(), 0, pIfTable);
361 pIfTable = (MIB_IFTABLE*)HeapAlloc(GetProcessHeap(), 0, dwSize);
362
363 if ((dwRetVal = GetIfTable(pIfTable, &dwSize, 0)) == NO_ERROR)
364 {
368 pIfTable->table[0].dwInOctets, pIfTable->table[0].dwOutOctets);
370 pIfTable->table[0].dwInUcastPkts, pIfTable->table[0].dwOutUcastPkts);
372 pIfTable->table[0].dwInNUcastPkts, pIfTable->table[0].dwOutNUcastPkts);
374 pIfTable->table[0].dwInDiscards, pIfTable->table[0].dwOutDiscards);
376 pIfTable->table[0].dwInErrors, pIfTable->table[0].dwOutErrors);
378 pIfTable->table[0].dwInUnknownProtos);
379 }
380 else
381 {
382 DoFormatMessage(dwRetVal);
383 }
384 }
385 HeapFree(GetProcessHeap(), 0, pIfTable);
386}
387
389{
392 DWORD i;
393 CHAR HostIp[HOSTNAMELEN], HostPort[PORTNAMELEN];
394 CHAR RemoteIp[HOSTNAMELEN], RemotePort[PORTNAMELEN];
395 CHAR Host[ADDRESSLEN];
396 CHAR Remote[ADDRESSLEN];
397 CHAR PID[64];
398
399 /* Get the table of TCP endpoints */
401 /* Should also work when we get new connections between 2 GetTcpTable()
402 * calls: */
403 do
404 {
407 if (error != NO_ERROR)
408 HeapFree(GetProcessHeap(), 0, tcpTable);
409 }
411
412 if (error != NO_ERROR)
413 {
416 return FALSE;
417 }
418
419 /* Dump the TCP table */
420 for (i = 0; i < tcpTable->dwNumEntries; i++)
421 {
422 /* If we aren't showing all connections, only display established, close wait
423 * and time wait. This is the default output for netstat */
424 if (bDoShowAllCons || (tcpTable->table[i].dwState == MIB_TCP_STATE_ESTAB)
425 || (tcpTable->table[i].dwState == MIB_TCP_STATE_CLOSE_WAIT)
426 || (tcpTable->table[i].dwState == MIB_TCP_STATE_TIME_WAIT))
427 {
428 /* I've split this up so it's easier to follow */
429 GetIpHostName(TRUE, tcpTable->table[i].dwLocalAddr, HostIp, sizeof(HostIp));
430 GetPortName(tcpTable->table[i].dwLocalPort, "tcp", HostPort, sizeof(HostPort));
431 sprintf(Host, "%s:%s", HostIp, HostPort);
432
433 if (tcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN)
434 {
435 sprintf(Remote, "%s:0", HostIp);
436 }
437 else
438 {
439 GetIpHostName(FALSE, tcpTable->table[i].dwRemoteAddr, RemoteIp, sizeof(RemoteIp));
440 GetPortName(tcpTable->table[i].dwRemotePort, "tcp", RemotePort, sizeof(RemotePort));
441 sprintf(Remote, "%s:%s", RemoteIp, RemotePort);
442 }
443
445 {
446 sprintf(PID, "%ld", tcpTable->table[i].dwOwningPid);
447 }
448 else
449 {
450 PID[0] = 0;
451 }
452
453 ConPrintf(StdOut, L" %-6s %-22S %-22S %-11s %S\n", L"TCP",
454 Host, Remote, TcpState[tcpTable->table[i].dwState], PID);
455 }
456 }
457
458 HeapFree(GetProcessHeap(), 0, tcpTable);
459 return TRUE;
460}
461
463{
466 DWORD i;
467 CHAR HostIp[HOSTNAMELEN], HostPort[PORTNAMELEN];
468 CHAR Host[ADDRESSLEN];
469 CHAR PID[64];
470
471 /* Get the table of UDP endpoints */
472 dwSize = 0;
475 {
478 return FALSE;
479 }
482 if (error)
483 {
487 return FALSE;
488 }
489
490 /* Dump the UDP table */
491 for (i = 0; i < udpTable->dwNumEntries; i++)
492 {
493 /* I've split this up so it's easier to follow */
494 GetIpHostName(TRUE, udpTable->table[i].dwLocalAddr, HostIp, sizeof(HostIp));
495 GetPortName(udpTable->table[i].dwLocalPort, "udp", HostPort, sizeof(HostPort));
496
497 sprintf(Host, "%s:%s", HostIp, HostPort);
498
500 {
501 sprintf(PID, "%ld", udpTable->table[i].dwOwningPid);
502 }
503 else
504 {
505 PID[0] = 0;
506 }
507
508 ConPrintf(StdOut, L" %-6s %-22S %-34s %S\n", L"UDP", Host, L"*:*", PID);
509 }
510
512 return TRUE;
513}
514
515/*
516 * Translate port numbers into their text equivalent if there is one
517 */
518PCHAR
519GetPortName(UINT Port, PCSTR Proto, CHAR Name[], INT NameLen)
520{
521 struct servent *pServent;
522
523 if (bDoShowNumbers)
524 {
525 sprintf(Name, "%d", htons((WORD)Port));
526 return Name;
527 }
528 /* Try to translate to a name */
529 if ((pServent = getservbyport(Port, Proto)))
530 strcpy(Name, pServent->s_name);
531 else
532 sprintf(Name, "%d", htons((WORD)Port));
533 return Name;
534}
535
536/*
537 * convert addresses into dotted decimal or hostname
538 */
539PCHAR
540GetIpHostName(BOOL Local, UINT IpAddr, CHAR Name[], INT NameLen)
541{
542// struct hostent *phostent;
543 UINT nIpAddr;
544
545 /* display dotted decimal */
546 nIpAddr = htonl(IpAddr);
547 if (bDoShowNumbers) {
548 sprintf(Name, "%d.%d.%d.%d",
549 (nIpAddr >> 24) & 0xFF,
550 (nIpAddr >> 16) & 0xFF,
551 (nIpAddr >> 8) & 0xFF,
552 (nIpAddr) & 0xFF);
553 return Name;
554 }
555
556 Name[0] = '\0';
557
558 /* try to resolve the name */
559 if (!IpAddr) {
560 if (!Local) {
561 sprintf(Name, "%d.%d.%d.%d",
562 (nIpAddr >> 24) & 0xFF,
563 (nIpAddr >> 16) & 0xFF,
564 (nIpAddr >> 8) & 0xFF,
565 (nIpAddr) & 0xFF);
566 } else {
567 if (gethostname(Name, NameLen) != 0)
569 }
570 } else if (IpAddr == 0x0100007f) {
571 if (Local) {
572 if (gethostname(Name, NameLen) != 0)
574 } else {
575 strncpy(Name, "localhost", 10);
576 }
577// } else if (phostent = gethostbyaddr((char*)&ipaddr, sizeof(nipaddr), PF_INET)) {
578// strcpy(name, phostent->h_name);
579 } else {
580 sprintf(Name, "%d.%d.%d.%d",
581 ((nIpAddr >> 24) & 0x000000FF),
582 ((nIpAddr >> 16) & 0x000000FF),
583 ((nIpAddr >> 8) & 0x000000FF),
584 ((nIpAddr) & 0x000000FF));
585 }
586 return Name;
587}
588
589/*
590 * Parse command line parameters and set any options
591 * Run display output, looping over set interval if a number is given
592 */
593int wmain(int argc, wchar_t *argv[])
594{
596 WSADATA wsaData;
597
598 /* Initialize the Console Standard Streams */
600
601 if (!ParseCmdline(argc, argv))
602 return EXIT_FAILURE;
603
604 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
605 {
607 return EXIT_FAILURE;
608 }
609
611 while (bLoopOutput && Success)
612 {
613 Sleep(Interval*1000);
615 }
616
617 WSACleanup();
618 return (Success ? EXIT_SUCCESS : EXIT_FAILURE);
619}
static int argc
Definition: ServiceArgs.c:12
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
struct NameRec_ * Name
Definition: cdprocs.h:460
#define IDS_USAGE
Definition: resource.h:3
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define ConInitStdStreams()
Definition: fc.c:13
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define IDS_UDP_IP4_HEADER
Definition: resource.h:59
#define IDS_TCP_RESET_CONNECT
Definition: resource.h:53
#define IDS_ETHERNET_NON_UNICAST_PACKET
Definition: resource.h:69
#define IDS_IP_DATAG_FRAG_CREATE
Definition: resource.h:34
#define IDS_DISPLAY_THEADER
Definition: resource.h:4
#define IDS_IP_OUT_REQUEST
Definition: resource.h:25
#define IDS_ICMP_MSG
Definition: resource.h:36
#define IDS_ETHERNET_BYTES
Definition: resource.h:67
#define IDS_ETHERNET_DISCARD
Definition: resource.h:70
#define IDS_ICMP_DEST_UNREACH
Definition: resource.h:38
#define IDS_UDP_RECEIVE_ERROR
Definition: resource.h:62
#define IDS_ICMP_ECHO_REPLY
Definition: resource.h:44
#define IDS_ICMP_ADDRESSS_MASK
Definition: resource.h:47
#define IDS_ERROR_UDP_ENDPOINT
Definition: resource.h:15
#define IDS_IP_DATAG_FRAG_SUCCESS
Definition: resource.h:32
#define IDS_ERROR_WSA_START
Definition: resource.h:12
#define IDS_TCP_CURRENT_CONNECT
Definition: resource.h:54
#define IDS_TCP_SEG_SENT
Definition: resource.h:56
#define IDS_IP_REC_PACK_DISCARD
Definition: resource.h:23
#define IDS_ICMP_SRC_QUENCHES
Definition: resource.h:41
#define IDS_IP_DISCARD_OUT_PACK
Definition: resource.h:27
#define IDS_DISPLAY_PROCESS
Definition: resource.h:5
#define IDS_ETHERNET_INTERFACE_STAT
Definition: resource.h:65
#define IDS_IP_DATAG_FWD
Definition: resource.h:21
#define IDS_IP_UNKNOWN_PRO_REC
Definition: resource.h:22
#define IDS_TCP_SEG_RETRANSMIT
Definition: resource.h:57
#define IDS_ERROR_TCP_SNAPSHOT
Definition: resource.h:14
#define IDS_ETHERNET_UNKNOWN
Definition: resource.h:72
#define IDS_IP_REASSEMBLE_FAILURE
Definition: resource.h:31
#define IDS_IP_ADDR_REC_ERROR
Definition: resource.h:20
#define IDS_ICMP_ADDRESSS_MASK_REPLY
Definition: resource.h:48
#define IDS_IP_REASSEMBLE_REQUIRED
Definition: resource.h:29
#define IDS_ACTIVE_CONNECT
Definition: resource.h:6
#define IDS_TCP_ACTIVE_OPEN
Definition: resource.h:50
#define IDS_TCP_PASS_OPEN
Definition: resource.h:51
#define IDS_ICMP_TIMESTAMP
Definition: resource.h:45
#define IDS_ERROR_ROUTE
Definition: resource.h:13
#define IDS_ICMP_ECHO
Definition: resource.h:43
#define IDS_IP_HEAD_REC_ERROR
Definition: resource.h:19
#define IDS_UDP_DATAG_RECEIVE
Definition: resource.h:60
#define IDS_IP_REASSEMBLE_SUCCESS
Definition: resource.h:30
#define IDS_ICMP_TIMESTAMP_REPLY
Definition: resource.h:46
#define IDS_IP_ROUTE_DISCARD
Definition: resource.h:26
#define IDS_IP_OUT_PACKET_NO_ROUTE
Definition: resource.h:28
#define IDS_IP_REC_PACK_DELIVER
Definition: resource.h:24
#define IDS_ETHERNET_THEADER
Definition: resource.h:66
#define IDS_ICMP4_STAT_HEADER
Definition: resource.h:8
#define IDS_ICMP_ERROR
Definition: resource.h:37
#define IDS_ICMP_THEADER
Definition: resource.h:9
#define IDS_TCP_FAIL_CONNECT
Definition: resource.h:52
#define IDS_UDP_DATAG_SEND
Definition: resource.h:63
#define IDS_TCP_SEG_RECEIVE
Definition: resource.h:55
#define IDS_IP4_STAT_HEADER
Definition: resource.h:7
#define IDS_ERROR_UDP_ENDPOINT_TABLE
Definition: resource.h:16
#define IDS_UDP_NO_PORT
Definition: resource.h:61
#define IDS_ICMP_PARAM_PROBLEM
Definition: resource.h:40
#define IDS_ICMP_TIME_EXCEED
Definition: resource.h:39
#define IDS_ETHERNET_UNICAST_PACKET
Definition: resource.h:68
#define IDS_ETHERNET_ERROR
Definition: resource.h:71
#define IDS_IP_PACK_REC
Definition: resource.h:18
#define IDS_TCP4_HEADER
Definition: resource.h:10
#define IDS_IP_DATAG_FRAG_FAILURE
Definition: resource.h:33
#define IDS_ICMP_REDIRECT
Definition: resource.h:42
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
static MIB_UDPSTATS udpStats
Definition: main.c:1137
static PMIB_UDPTABLE udpTable
Definition: main.c:1187
static MIB_TCPSTATS tcpStats
Definition: main.c:1076
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define AF_INET
Definition: tcpip.h:117
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
PSERVENT WSAAPI getservbyport(IN int port, IN const char FAR *proto)
Definition: getxbyxx.c:431
INT WSAAPI gethostname(OUT char FAR *name, IN INT namelen)
Definition: getxbyxx.c:397
const GLubyte * c
Definition: glext.h:8905
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
CPPORT Port[4]
Definition: headless.c:35
struct _MIB_IFTABLE MIB_IFTABLE
#define iswdigit(_c)
Definition: ctype.h:667
_Check_return_ _CRTIMP int __cdecl swscanf(_In_z_ const wchar_t *_Src, _In_z_ _Scanf_format_string_ const wchar_t *_Format,...)
#define EOF
Definition: stdio.h:24
DWORD WINAPI GetExtendedUdpTable(PVOID pUdpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, UDP_TABLE_CLASS TableClass, ULONG Reserved)
DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
DWORD WINAPI GetExtendedTcpTable(PVOID pTcpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, TCP_TABLE_CLASS TableClass, ULONG Reserved)
DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
@ TCP_TABLE_OWNER_PID_ALL
Definition: iprtrmib.h:35
@ UDP_TABLE_OWNER_PID
Definition: iprtrmib.h:44
#define EXIT_FAILURE
Definition: jerror.c:33
#define c
Definition: ke_i.h:80
#define error(str)
Definition: mkdosfs.c:1605
#define htons(x)
Definition: module.h:215
#define htonl(x)
Definition: module.h:214
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define argv
Definition: mplay32.c:18
unsigned int UINT
Definition: ndis.h:50
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
BOOL ShowTcpTable(VOID)
Definition: netstat.c:388
VOID ShowTcpStatistics(VOID)
Definition: netstat.c:308
enum ProtoType Protocol
BOOL ParseCmdline(int argc, wchar_t *argv[])
Definition: netstat.c:74
BOOL ShowUdpTable(VOID)
Definition: netstat.c:462
DWORD Interval
Definition: netstat.c:30
VOID DoFormatMessage(DWORD ErrorCode)
Definition: netstat.c:52
ProtoType
Definition: netstat.c:29
@ IP
Definition: netstat.c:29
@ ICMP
Definition: netstat.c:29
@ TCP
Definition: netstat.c:29
@ UDP
Definition: netstat.c:29
VOID DisplayTableHeader(VOID)
Definition: netstat.c:61
PCWSTR TcpState[]
Definition: netstat.c:33
BOOL DisplayOutput(VOID)
Definition: netstat.c:166
VOID ShowEthernetStatistics(VOID)
Definition: netstat.c:350
PCHAR GetPortName(UINT Port, PCSTR Proto, CHAR Name[], INT NameLen)
Definition: netstat.c:519
VOID ShowIcmpStatistics(VOID)
Definition: netstat.c:266
VOID ShowIpStatistics(VOID)
Definition: netstat.c:234
PCHAR GetIpHostName(BOOL Local, UINT IpAddr, CHAR Name[], INT NameLen)
Definition: netstat.c:540
VOID ShowUdpStatistics(VOID)
Definition: netstat.c:331
BOOL bNoOptions
Definition: netstat.h:9
BOOL bDoShowNumbers
Definition: netstat.h:13
BOOL bDoShowProtoCons
Definition: netstat.h:15
BOOL bDoShowEthStats
Definition: netstat.h:12
BOOL bDoShowAllCons
Definition: netstat.h:10
#define HOSTNAMELEN
Definition: netstat.h:4
BOOL bLoopOutput
Definition: netstat.h:19
BOOL bDoShowProcName
Definition: netstat.h:11
BOOL bDoShowProcessId
Definition: netstat.h:14
BOOL bDoShowProtoStats
Definition: netstat.h:17
#define PORTNAMELEN
Definition: netstat.h:5
BOOL bDoShowRouteTable
Definition: netstat.h:16
#define ADDRESSLEN
Definition: netstat.h:6
BOOL bDoDispSeqComp
Definition: netstat.h:18
#define L(x)
Definition: ntvdm.h:50
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:837
int wmain()
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
_CRTIMP int __cdecl _wsystem(_In_opt_z_ const wchar_t *_Command)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
MIBICMPSTATS icmpOutStats
Definition: ipmib.h:194
MIBICMPSTATS icmpInStats
Definition: ipmib.h:193
DWORD dwTimeExcds
Definition: ipmib.h:179
DWORD dwAddrMasks
Definition: ipmib.h:187
DWORD dwEchoReps
Definition: ipmib.h:184
DWORD dwParmProbs
Definition: ipmib.h:180
DWORD dwAddrMaskReps
Definition: ipmib.h:188
DWORD dwSrcQuenchs
Definition: ipmib.h:181
DWORD dwTimestamps
Definition: ipmib.h:185
DWORD dwRedirects
Definition: ipmib.h:182
DWORD dwMsgs
Definition: ipmib.h:176
DWORD dwErrors
Definition: ipmib.h:177
DWORD dwEchos
Definition: ipmib.h:183
DWORD dwTimestampReps
Definition: ipmib.h:186
DWORD dwDestUnreachs
Definition: ipmib.h:178
MIBICMPINFO stats
Definition: ipmib.h:199
DWORD dwOutErrors
Definition: ifmib.h:57
DWORD dwOutNUcastPkts
Definition: ifmib.h:55
DWORD dwInOctets
Definition: ifmib.h:47
DWORD dwInDiscards
Definition: ifmib.h:50
DWORD dwInUcastPkts
Definition: ifmib.h:48
DWORD dwInErrors
Definition: ifmib.h:51
DWORD dwInUnknownProtos
Definition: ifmib.h:52
DWORD dwOutOctets
Definition: ifmib.h:53
DWORD dwOutDiscards
Definition: ifmib.h:56
DWORD dwOutUcastPkts
Definition: ifmib.h:54
DWORD dwInNUcastPkts
Definition: ifmib.h:49
MIB_IFROW table[1]
Definition: ifmib.h:66
DWORD dwInReceives
Definition: ipmib.h:148
DWORD dwInAddrErrors
Definition: ipmib.h:150
DWORD dwFragOks
Definition: ipmib.h:163
DWORD dwReasmOks
Definition: ipmib.h:161
DWORD dwOutNoRoutes
Definition: ipmib.h:158
DWORD dwInDelivers
Definition: ipmib.h:154
DWORD dwRoutingDiscards
Definition: ipmib.h:156
DWORD dwReasmReqds
Definition: ipmib.h:160
DWORD dwOutDiscards
Definition: ipmib.h:157
DWORD dwInHdrErrors
Definition: ipmib.h:149
DWORD dwForwDatagrams
Definition: ipmib.h:151
DWORD dwInDiscards
Definition: ipmib.h:153
DWORD dwOutRequests
Definition: ipmib.h:155
DWORD dwFragCreates
Definition: ipmib.h:165
DWORD dwInUnknownProtos
Definition: ipmib.h:152
DWORD dwReasmFails
Definition: ipmib.h:162
DWORD dwFragFails
Definition: ipmib.h:164
DWORD dwPassiveOpens
Definition: tcpmib.h:180
DWORD dwActiveOpens
Definition: tcpmib.h:179
DWORD dwRetransSegs
Definition: tcpmib.h:186
DWORD dwInSegs
Definition: tcpmib.h:184
DWORD dwOutSegs
Definition: tcpmib.h:185
DWORD dwEstabResets
Definition: tcpmib.h:182
DWORD dwCurrEstab
Definition: tcpmib.h:183
DWORD dwAttemptFails
Definition: tcpmib.h:181
MIB_TCPROW_OWNER_PID table[1]
Definition: tcpmib.h:115
DWORD dwLocalAddr
Definition: udpmib.h:28
DWORD dwLocalPort
Definition: udpmib.h:29
DWORD dwOutDatagrams
Definition: udpmib.h:81
DWORD dwInDatagrams
Definition: udpmib.h:78
DWORD dwNoPorts
Definition: udpmib.h:79
DWORD dwInErrors
Definition: udpmib.h:80
DWORD dwNumEntries
Definition: udpmib.h:34
MIB_UDPROW table[1]
Definition: udpmib.h:35
char * s_name
Definition: winsock.h:159
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
struct _MIB_TCPTABLE_OWNER_PID * PMIB_TCPTABLE_OWNER_PID
@ MIB_TCP_STATE_TIME_WAIT
Definition: tcpmib.h:38
@ MIB_TCP_STATE_ESTAB
Definition: tcpmib.h:32
@ MIB_TCP_STATE_LISTEN
Definition: tcpmib.h:29
@ MIB_TCP_STATE_CLOSE_WAIT
Definition: tcpmib.h:35
struct _MIB_TCPTABLE_OWNER_PID MIB_TCPTABLE_OWNER_PID
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define towlower(c)
Definition: wctype.h:97
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define MAKEWORD(a, b)
Definition: typedefs.h:248
int32_t INT
Definition: typedefs.h:58
const char * PCSTR
Definition: typedefs.h:52
char * PCHAR
Definition: typedefs.h:51
struct _MIB_UDPTABLE_OWNER_PID * PMIB_UDPTABLE_OWNER_PID
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
char CHAR
Definition: xmlstorage.h:175