ReactOS  0.4.14-dev-614-gbfd8a84
netstat.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <windef.h>
#include <winbase.h>
#include <winsock2.h>
#include <iphlpapi.h>
#include <conutils.h>
#include "netstat.h"
#include "resource.h"
Include dependency graph for netstat.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 

Enumerations

enum  ProtoType { IP, TCP, UDP, ICMP }
 

Functions

VOID DoFormatMessage (DWORD ErrorCode)
 
BOOL ParseCmdline (int argc, wchar_t *argv[])
 
VOID DisplayTableHeader (VOID)
 
BOOL DisplayOutput (VOID)
 
VOID ShowIpStatistics (VOID)
 
VOID ShowIcmpStatistics (VOID)
 
VOID ShowTcpStatistics (VOID)
 
VOID ShowUdpStatistics (VOID)
 
VOID ShowEthernetStatistics (VOID)
 
BOOL ShowTcpTable (VOID)
 
BOOL ShowUdpTable (VOID)
 
PCHAR GetPortName (UINT Port, PCSTR Proto, CHAR Name[], INT NameLen)
 
PCHAR GetIpHostName (BOOL Local, UINT IpAddr, CHAR Name[], INT NameLen)
 
int wmain (int argc, wchar_t *argv[])
 

Variables

enum ProtoType Protocol
 
DWORD Interval
 
PCWSTR TcpState []
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 23 of file netstat.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 20 of file netstat.c.

Enumeration Type Documentation

◆ ProtoType

Enumerator
IP 
TCP 
UDP 
ICMP 

Definition at line 32 of file netstat.c.

32 {IP, TCP, UDP, ICMP} Protocol;
Definition: netstat.c:32
Definition: netstat.c:32
Definition: netstat.c:32
enum ProtoType Protocol
Definition: netstat.c:32

Function Documentation

◆ DisplayOutput()

BOOL DisplayOutput ( VOID  )

Definition at line 174 of file netstat.c.

175 {
176  if (bNoOptions)
177  {
180  return ShowTcpTable();
181  }
182 
183  if (bDoShowRouteTable)
184  {
185  if (_wsystem(L"route print") == -1)
186  {
188  return FALSE;
189  }
190  return TRUE;
191  }
192 
193  if (bDoShowEthStats)
194  {
196  return TRUE;
197  }
198 
199  if (bDoShowProtoCons)
200  {
201  switch (Protocol)
202  {
203  case IP:
204  if (bDoShowProtoStats)
206  return TRUE;
207  case ICMP:
208  if (bDoShowProtoStats)
210  return TRUE;
211  case TCP:
212  if (bDoShowProtoStats)
216  return ShowTcpTable();
217  case UDP:
218  if (bDoShowProtoStats)
222  return (bDoShowAllCons ? ShowUdpTable() : TRUE);
223  default:
224  break;
225  }
226  }
227  else if (bDoShowProtoStats)
228  {
233  return TRUE;
234  }
235  else
236  {
239  if (ShowTcpTable() && bDoShowAllCons)
240  ShowUdpTable();
241  }
242 
243  return TRUE;
244 }
BOOL bDoShowProtoCons
Definition: netstat.h:13
#define TRUE
Definition: types.h:120
BOOL ShowUdpTable(VOID)
Definition: netstat.c:484
Definition: netstat.c:32
VOID ShowIpStatistics(VOID)
Definition: netstat.c:246
#define IDS_ACTIVE_CONNECT
Definition: resource.h:6
VOID ShowUdpStatistics(VOID)
Definition: netstat.c:352
BOOL ShowTcpTable(VOID)
Definition: netstat.c:409
VOID ShowEthernetStatistics(VOID)
Definition: netstat.c:371
VOID ShowTcpStatistics(VOID)
Definition: netstat.c:329
BOOL bDoShowEthStats
Definition: netstat.h:11
VOID DisplayTableHeader(VOID)
Definition: netstat.c:162
Definition: netstat.c:32
_CRTIMP int __cdecl _wsystem(_In_opt_z_ const wchar_t *_Command)
#define StdErr
Definition: stream.h:77
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1250
Definition: netstat.c:32
BOOL bDoShowProtoStats
Definition: netstat.h:15
#define IDS_ERROR_ROUTE
Definition: resource.h:13
BOOL bDoShowAllCons
Definition: netstat.h:9
BOOL bNoOptions
Definition: netstat.h:8
Definition: netstat.c:32
#define StdOut
Definition: stream.h:76
VOID ShowIcmpStatistics(VOID)
Definition: netstat.c:282
BOOL bDoShowRouteTable
Definition: netstat.h:14

Referenced by wmain().

◆ DisplayTableHeader()

VOID DisplayTableHeader ( VOID  )

Definition at line 162 of file netstat.c.

163 {
165  if (bDoShowProcessId)
167  else
168  ConPuts(StdOut, L"\n");
169 }
BOOL bDoShowProcessId
Definition: netstat.h:16
#define IDS_DISPLAY_PROCESS
Definition: resource.h:5
#define IDS_DISPLAY_THEADER
Definition: resource.h:4
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1250
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define StdOut
Definition: stream.h:76

Referenced by DisplayOutput().

◆ DoFormatMessage()

VOID DoFormatMessage ( DWORD  ErrorCode)

Definition at line 55 of file netstat.c.

56 {
57  if (ErrorCode == ERROR_SUCCESS)
58  return;
59 
62 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:837
#define StdErr
Definition: stream.h:77
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50

Referenced by GetIpHostName(), ShowEthernetStatistics(), ShowIcmpStatistics(), ShowIpStatistics(), ShowTcpStatistics(), ShowTcpTable(), ShowUdpStatistics(), and ShowUdpTable().

◆ GetIpHostName()

PCHAR GetIpHostName ( BOOL  Local,
UINT  IpAddr,
CHAR  Name[],
INT  NameLen 
)

Definition at line 563 of file netstat.c.

564 {
565 // struct hostent *phostent;
566  UINT nIpAddr;
567 
568  /* display dotted decimal */
569  nIpAddr = htonl(IpAddr);
570  if (bDoShowNumbers) {
571  sprintf(Name, "%d.%d.%d.%d",
572  (nIpAddr >> 24) & 0xFF,
573  (nIpAddr >> 16) & 0xFF,
574  (nIpAddr >> 8) & 0xFF,
575  (nIpAddr) & 0xFF);
576  return Name;
577  }
578 
579  Name[0] = '\0';
580 
581  /* try to resolve the name */
582  if (!IpAddr) {
583  if (!Local) {
584  sprintf(Name, "%d.%d.%d.%d",
585  (nIpAddr >> 24) & 0xFF,
586  (nIpAddr >> 16) & 0xFF,
587  (nIpAddr >> 8) & 0xFF,
588  (nIpAddr) & 0xFF);
589  } else {
590  if (gethostname(Name, NameLen) != 0)
592  }
593  } else if (IpAddr == 0x0100007f) {
594  if (Local) {
595  if (gethostname(Name, NameLen) != 0)
597  } else {
598  strncpy(Name, "localhost", 10);
599  }
600 // } else if (phostent = gethostbyaddr((char*)&ipaddr, sizeof(nipaddr), PF_INET)) {
601 // strcpy(name, phostent->h_name);
602  } else {
603  sprintf(Name, "%d.%d.%d.%d",
604  ((nIpAddr >> 24) & 0x000000FF),
605  ((nIpAddr >> 16) & 0x000000FF),
606  ((nIpAddr >> 8) & 0x000000FF),
607  ((nIpAddr) & 0x000000FF));
608  }
609  return Name;
610 }
#define htonl(x)
Definition: module.h:212
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
BOOL bDoShowNumbers
Definition: netstat.h:12
#define sprintf(buf, format,...)
Definition: sprintf.c:55
INT WSAAPI gethostname(OUT char FAR *name, IN INT namelen)
Definition: getxbyxx.c:397
struct NameRec_ * Name
Definition: cdprocs.h:464
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
unsigned int UINT
Definition: ndis.h:50
VOID DoFormatMessage(DWORD ErrorCode)
Definition: netstat.c:55

Referenced by ShowTcpTable(), and ShowUdpTable().

◆ GetPortName()

PCHAR GetPortName ( UINT  Port,
PCSTR  Proto,
CHAR  Name[],
INT  NameLen 
)

Definition at line 542 of file netstat.c.

543 {
544  struct servent *pServent;
545 
546  if (bDoShowNumbers)
547  {
548  sprintf(Name, "%d", htons((WORD)Port));
549  return Name;
550  }
551  /* Try to translate to a name */
552  if ((pServent = getservbyport(Port, Proto)))
553  strcpy(Name, pServent->s_name );
554  else
555  sprintf(Name, "%d", htons((WORD)Port));
556  return Name;
557 }
CPPORT Port[4]
Definition: headless.c:34
BOOL bDoShowNumbers
Definition: netstat.h:12
#define sprintf(buf, format,...)
Definition: sprintf.c:55
struct NameRec_ * Name
Definition: cdprocs.h:464
char * s_name
Definition: winsock.h:159
unsigned short WORD
Definition: ntddk_ex.h:93
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define htons(x)
Definition: module.h:213
PSERVENT WSAAPI getservbyport(IN int port, IN const char FAR *proto)
Definition: getxbyxx.c:431

Referenced by ShowTcpTable(), and ShowUdpTable().

◆ ParseCmdline()

BOOL ParseCmdline ( int  argc,
wchar_t argv[] 
)

Definition at line 69 of file netstat.c.

70 {
71  LPWSTR Proto;
72  WCHAR c;
73  INT i;
74 
75  if ((argc == 1) || (iswdigit(*argv[1])))
76  bNoOptions = TRUE;
77 
78  /* Parse command line for options we have been given. */
79  for (i = 1; i < argc; i++)
80  {
81  if ((argc > 1) && (argv[i][0] == L'-' || argv[i][0] == L'/'))
82  {
83  while ((c = *++argv[i]) != L'\0')
84  {
85  switch (towlower(c))
86  {
87  case L'a':
89  break;
90  case L'b':
91  // UNIMPLEMENTED.
92  ConPuts(StdErr, L"'b' option is FIXME (Accepted option though unimplemented feature).\n");
94  break;
95  case L'e':
97  break;
98  case L'n':
100  break;
101  case L'o':
103  break;
104  case L'p':
106  Proto = argv[i+1];
107  if (!_wcsicmp(L"IP", Proto))
108  Protocol = IP;
109  else if (!_wcsicmp(L"ICMP", Proto))
110  Protocol = ICMP;
111  else if (!_wcsicmp(L"TCP", Proto))
112  Protocol = TCP;
113  else if (!_wcsicmp(L"UDP", Proto))
114  Protocol = UDP;
115  else
116  {
118  return FALSE;
119  }
120  break;
121  case L'r':
123  break;
124  case L's':
126  break;
127  case L't':
128  // UNIMPLEMENTED.
129  ConPuts(StdErr, L"'t' option is FIXME (Accepted option though unimplemented feature).\n");
130  break;
131  case L'v':
132  // UNIMPLEMENTED.
133  ConPuts(StdErr, L"'v' option is FIXME (Accepted option though unimplemented feature).\n");
135  break;
136  default :
138  return FALSE;
139  }
140  }
141  }
142  else if (iswdigit(*argv[i]) != 0)
143  {
144  if (swscanf(argv[i], L"%lu", &Interval) != EOF)
145  bLoopOutput = TRUE;
146  else
147  return FALSE;
148  }
149 // else
150 // {
151 // ConResPrintf(StdErr, IDS_USAGE);
152 // return FALSE;
153 // }
154  }
155 
156  return TRUE;
157 }
BOOL bDoShowProtoCons
Definition: netstat.h:13
static int argc
Definition: ServiceArgs.c:12
BOOL bDoShowProcessId
Definition: netstat.h:16
#define TRUE
Definition: types.h:120
Definition: netstat.c:32
#define iswdigit(_c)
Definition: ctype.h:667
#define IDS_USAGE
Definition: resource.h:3
BOOL bDoShowNumbers
Definition: netstat.h:12
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:56
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
BOOL bDoDispSeqComp
Definition: netstat.h:17
BOOL bDoShowEthStats
Definition: netstat.h:11
DWORD Interval
Definition: netstat.c:33
__wchar_t WCHAR
Definition: xmlstorage.h:180
const GLubyte * c
Definition: glext.h:8905
Definition: netstat.c:32
#define StdErr
Definition: stream.h:77
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1250
Definition: netstat.c:32
BOOL bDoShowProtoStats
Definition: netstat.h:15
BOOL bDoShowAllCons
Definition: netstat.h:9
BOOL bNoOptions
Definition: netstat.h:8
Definition: netstat.c:32
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define EOF
Definition: stdio.h:24
#define c
Definition: ke_i.h:80
#define towlower(c)
Definition: wctype.h:97
BOOL bLoopOutput
Definition: netstat.h:18
WCHAR * LPWSTR
Definition: xmlstorage.h:184
_Check_return_ _CRTIMP int __cdecl swscanf(_In_z_ const wchar_t *_Src, _In_z_ _Scanf_format_string_ const wchar_t *_Format,...)
BOOL bDoShowRouteTable
Definition: netstat.h:14
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
BOOL bDoShowProcName
Definition: netstat.h:10

Referenced by wmain().

◆ ShowEthernetStatistics()

VOID ShowEthernetStatistics ( VOID  )

Definition at line 371 of file netstat.c.

372 {
373  PMIB_IFTABLE pIfTable;
374  DWORD dwSize = 0;
375  DWORD dwRetVal = 0;
376 
377  pIfTable = (MIB_IFTABLE*) HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IFTABLE));
378 
379  if (GetIfTable(pIfTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER)
380  {
381  HeapFree(GetProcessHeap(), 0, pIfTable);
382  pIfTable = (MIB_IFTABLE*) HeapAlloc(GetProcessHeap(), 0, dwSize);
383 
384  if ((dwRetVal = GetIfTable(pIfTable, &dwSize, 0)) == NO_ERROR)
385  {
389  pIfTable->table[0].dwInOctets, pIfTable->table[0].dwOutOctets);
391  pIfTable->table[0].dwInUcastPkts, pIfTable->table[0].dwOutUcastPkts);
393  pIfTable->table[0].dwInNUcastPkts, pIfTable->table[0].dwOutNUcastPkts);
395  pIfTable->table[0].dwInDiscards, pIfTable->table[0].dwOutDiscards);
397  pIfTable->table[0].dwInErrors, pIfTable->table[0].dwOutErrors);
399  pIfTable->table[0].dwInUnknownProtos);
400  }
401  else
402  {
403  DoFormatMessage(dwRetVal);
404  }
405  }
406  HeapFree(GetProcessHeap(), 0, pIfTable);
407 }
MIB_IFROW table[1]
Definition: ifmib.h:66
DWORD dwInOctets
Definition: ifmib.h:47
DWORD dwInUcastPkts
Definition: ifmib.h:48
DWORD dwInNUcastPkts
Definition: ifmib.h:49
DWORD dwInDiscards
Definition: ifmib.h:50
#define IDS_ETHERNET_BYTES
Definition: resource.h:67
#define NO_ERROR
Definition: dderror.h:5
#define IDS_ETHERNET_UNKNOWN
Definition: resource.h:72
#define IDS_ETHERNET_UNICAST_PACKET
Definition: resource.h:68
DWORD dwInUnknownProtos
Definition: ifmib.h:52
DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
DWORD dwOutDiscards
Definition: ifmib.h:56
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define IDS_ETHERNET_NON_UNICAST_PACKET
Definition: resource.h:69
#define IDS_ETHERNET_ERROR
Definition: resource.h:71
struct _MIB_IFTABLE MIB_IFTABLE
#define IDS_ETHERNET_THEADER
Definition: resource.h:66
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwOutUcastPkts
Definition: ifmib.h:54
DWORD dwInErrors
Definition: ifmib.h:51
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
#define IDS_ETHERNET_INTERFACE_STAT
Definition: resource.h:65
#define IDS_ETHERNET_DISCARD
Definition: resource.h:70
DWORD dwOutOctets
Definition: ifmib.h:53
#define StdOut
Definition: stream.h:76
VOID DoFormatMessage(DWORD ErrorCode)
Definition: netstat.c:55
DWORD dwOutErrors
Definition: ifmib.h:57
#define HeapFree(x, y, z)
Definition: compat.h:402
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
DWORD dwOutNUcastPkts
Definition: ifmib.h:55
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by DisplayOutput().

◆ ShowIcmpStatistics()

VOID ShowIcmpStatistics ( VOID  )

Definition at line 282 of file netstat.c.

283 {
284  PMIB_ICMP pIcmpStats;
285  DWORD dwRetVal;
286 
287  pIcmpStats = (MIB_ICMP*) HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_ICMP));
288 
289  if ((dwRetVal = GetIcmpStatistics(pIcmpStats)) == NO_ERROR)
290  {
294  pIcmpStats->stats.icmpInStats.dwMsgs, pIcmpStats->stats.icmpOutStats.dwMsgs);
296  pIcmpStats->stats.icmpInStats.dwErrors, pIcmpStats->stats.icmpOutStats.dwErrors);
300  pIcmpStats->stats.icmpInStats.dwTimeExcds, pIcmpStats->stats.icmpOutStats.dwTimeExcds);
302  pIcmpStats->stats.icmpInStats.dwParmProbs, pIcmpStats->stats.icmpOutStats.dwParmProbs);
304  pIcmpStats->stats.icmpInStats.dwSrcQuenchs, pIcmpStats->stats.icmpOutStats.dwSrcQuenchs);
306  pIcmpStats->stats.icmpInStats.dwRedirects, pIcmpStats->stats.icmpOutStats.dwRedirects);
308  pIcmpStats->stats.icmpInStats.dwEchos, pIcmpStats->stats.icmpOutStats.dwEchos);
310  pIcmpStats->stats.icmpInStats.dwEchoReps, pIcmpStats->stats.icmpOutStats.dwEchoReps);
312  pIcmpStats->stats.icmpInStats.dwTimestamps, pIcmpStats->stats.icmpOutStats.dwTimestamps);
316  pIcmpStats->stats.icmpInStats.dwAddrMasks, pIcmpStats->stats.icmpOutStats.dwAddrMasks);
319  }
320  else
321  {
322  DoFormatMessage(dwRetVal);
323  }
324 
325  HeapFree(GetProcessHeap(), 0, pIcmpStats);
326 
327 }
#define IDS_ICMP_SRC_QUENCHES
Definition: resource.h:41
DWORD dwEchos
Definition: ipmib.h:183
#define IDS_ICMP_THEADER
Definition: resource.h:9
MIBICMPSTATS icmpInStats
Definition: ipmib.h:193
DWORD dwTimestamps
Definition: ipmib.h:185
#define IDS_ICMP_REDIRECT
Definition: resource.h:42
#define IDS_ICMP_PARAM_PROBLEM
Definition: resource.h:40
DWORD dwTimeExcds
Definition: ipmib.h:179
DWORD dwEchoReps
Definition: ipmib.h:184
#define NO_ERROR
Definition: dderror.h:5
#define IDS_ICMP4_STAT_HEADER
Definition: resource.h:8
#define IDS_ICMP_ECHO_REPLY
Definition: resource.h:44
#define IDS_ICMP_TIMESTAMP_REPLY
Definition: resource.h:46
MIBICMPINFO stats
Definition: ipmib.h:199
DWORD dwErrors
Definition: ipmib.h:177
#define IDS_ICMP_ADDRESSS_MASK_REPLY
Definition: resource.h:48
DWORD dwTimestampReps
Definition: ipmib.h:186
#define IDS_ICMP_ERROR
Definition: resource.h:37
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
DWORD dwParmProbs
Definition: ipmib.h:180
#define IDS_ICMP_MSG
Definition: resource.h:36
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define IDS_ICMP_ECHO
Definition: resource.h:43
DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
unsigned long DWORD
Definition: ntddk_ex.h:95
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
DWORD dwRedirects
Definition: ipmib.h:182
DWORD dwAddrMasks
Definition: ipmib.h:187
#define IDS_ICMP_TIMESTAMP
Definition: resource.h:45
MIBICMPSTATS icmpOutStats
Definition: ipmib.h:194
DWORD dwSrcQuenchs
Definition: ipmib.h:181
struct _MIB_ICMP MIB_ICMP
#define StdOut
Definition: stream.h:76
DWORD dwDestUnreachs
Definition: ipmib.h:178
VOID DoFormatMessage(DWORD ErrorCode)
Definition: netstat.c:55
DWORD dwAddrMaskReps
Definition: ipmib.h:188
#define HeapFree(x, y, z)
Definition: compat.h:402
#define IDS_ICMP_TIME_EXCEED
Definition: resource.h:39
#define IDS_ICMP_ADDRESSS_MASK
Definition: resource.h:47
#define IDS_ICMP_DEST_UNREACH
Definition: resource.h:38
DWORD dwMsgs
Definition: ipmib.h:176

Referenced by DisplayOutput().

◆ ShowIpStatistics()

VOID ShowIpStatistics ( VOID  )

Definition at line 246 of file netstat.c.

247 {
248  PMIB_IPSTATS pIpStats;
249  DWORD dwRetVal;
250 
251  pIpStats = (MIB_IPSTATS*) HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IPSTATS));
252 
253  if ((dwRetVal = GetIpStatistics(pIpStats)) == NO_ERROR)
254  {
273  }
274  else
275  {
276  DoFormatMessage(dwRetVal);
277  }
278 
279  HeapFree(GetProcessHeap(), 0, pIpStats);
280 }
struct _MIB_IPSTATS MIB_IPSTATS
#define IDS_IP_DISCARD_OUT_PACK
Definition: resource.h:27
#define IDS_IP_REASSEMBLE_SUCCESS
Definition: resource.h:30
DWORD dwInReceives
Definition: ipmib.h:148
DWORD dwReasmReqds
Definition: ipmib.h:160
DWORD dwInDiscards
Definition: ipmib.h:153
#define IDS_IP4_STAT_HEADER
Definition: resource.h:7
#define IDS_IP_DATAG_FRAG_CREATE
Definition: resource.h:34
#define IDS_IP_REC_PACK_DELIVER
Definition: resource.h:24
DWORD dwInHdrErrors
Definition: ipmib.h:149
DWORD dwInDelivers
Definition: ipmib.h:154
#define NO_ERROR
Definition: dderror.h:5
DWORD dwForwDatagrams
Definition: ipmib.h:151
DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
#define IDS_IP_OUT_PACKET_NO_ROUTE
Definition: resource.h:28
DWORD dwInUnknownProtos
Definition: ipmib.h:152
#define IDS_IP_ROUTE_DISCARD
Definition: resource.h:26
#define IDS_IP_DATAG_FWD
Definition: resource.h:21
DWORD dwOutDiscards
Definition: ipmib.h:157
DWORD dwFragCreates
Definition: ipmib.h:165
#define IDS_IP_REC_PACK_DISCARD
Definition: resource.h:23
DWORD dwRoutingDiscards
Definition: ipmib.h:156
#define IDS_IP_DATAG_FRAG_FAILURE
Definition: resource.h:33
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
DWORD dwReasmOks
Definition: ipmib.h:161
DWORD dwOutRequests
Definition: ipmib.h:155
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define IDS_IP_DATAG_FRAG_SUCCESS
Definition: resource.h:32
DWORD dwReasmFails
Definition: ipmib.h:162
DWORD dwOutNoRoutes
Definition: ipmib.h:158
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDS_IP_ADDR_REC_ERROR
Definition: resource.h:20
#define IDS_IP_REASSEMBLE_FAILURE
Definition: resource.h:31
#define IDS_IP_UNKNOWN_PRO_REC
Definition: resource.h:22
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
DWORD dwInAddrErrors
Definition: ipmib.h:150
#define IDS_IP_PACK_REC
Definition: resource.h:18
#define IDS_IP_HEAD_REC_ERROR
Definition: resource.h:19
DWORD dwFragOks
Definition: ipmib.h:163
#define StdOut
Definition: stream.h:76
VOID DoFormatMessage(DWORD ErrorCode)
Definition: netstat.c:55
#define IDS_IP_OUT_REQUEST
Definition: resource.h:25
#define IDS_IP_REASSEMBLE_REQUIRED
Definition: resource.h:29
DWORD dwFragFails
Definition: ipmib.h:164
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by DisplayOutput().

◆ ShowTcpStatistics()

VOID ShowTcpStatistics ( VOID  )

Definition at line 329 of file netstat.c.

330 {
332  DWORD dwRetVal;
333 
334  if ((dwRetVal = GetTcpStatistics(&tcpStats)) == NO_ERROR)
335  {
345  }
346  else
347  {
348  DoFormatMessage(dwRetVal);
349  }
350 }
DWORD dwAttemptFails
Definition: tcpmib.h:181
#define NO_ERROR
Definition: dderror.h:5
#define IDS_TCP_SEG_RETRANSMIT
Definition: resource.h:57
DWORD dwInSegs
Definition: tcpmib.h:184
DWORD dwOutSegs
Definition: tcpmib.h:185
DWORD dwCurrEstab
Definition: tcpmib.h:183
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
#define IDS_TCP_RESET_CONNECT
Definition: resource.h:53
DWORD dwEstabResets
Definition: tcpmib.h:182
DWORD dwRetransSegs
Definition: tcpmib.h:186
unsigned long DWORD
Definition: ntddk_ex.h:95
static MIB_TCPSTATS tcpStats
Definition: main.c:1076
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
DWORD dwPassiveOpens
Definition: tcpmib.h:180
#define IDS_TCP_FAIL_CONNECT
Definition: resource.h:52
#define IDS_TCP_SEG_RECEIVE
Definition: resource.h:55
#define IDS_TCP_SEG_SENT
Definition: resource.h:56
#define IDS_TCP_CURRENT_CONNECT
Definition: resource.h:54
#define IDS_TCP_ACTIVE_OPEN
Definition: resource.h:50
#define IDS_TCP4_HEADER
Definition: resource.h:10
#define StdOut
Definition: stream.h:76
VOID DoFormatMessage(DWORD ErrorCode)
Definition: netstat.c:55
#define IDS_TCP_PASS_OPEN
Definition: resource.h:51
DWORD dwActiveOpens
Definition: tcpmib.h:179
DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)

Referenced by DisplayOutput().

◆ ShowTcpTable()

BOOL ShowTcpTable ( VOID  )

Definition at line 409 of file netstat.c.

410 {
411  PMIB_TCPTABLE_OWNER_PID tcpTable;
412  DWORD error, dwSize;
413  DWORD i;
414  CHAR HostIp[HOSTNAMELEN], HostPort[PORTNAMELEN];
415  CHAR RemoteIp[HOSTNAMELEN], RemotePort[PORTNAMELEN];
416  CHAR Host[ADDRESSLEN];
418  CHAR PID[64];
419 
420  /* Get the table of TCP endpoints */
421  dwSize = sizeof (MIB_TCPTABLE_OWNER_PID);
422  /* Should also work when we get new connections between 2 GetTcpTable()
423  * calls: */
424  do
425  {
428  if ( error != NO_ERROR )
429  HeapFree(GetProcessHeap(), 0, tcpTable);
430  }
431  while ( error == ERROR_INSUFFICIENT_BUFFER );
432 
433  if (error != NO_ERROR)
434  {
437  HeapFree(GetProcessHeap(), 0, tcpTable);
438  return FALSE;
439  }
440 
441  /* Dump the TCP table */
442  for (i = 0; i < tcpTable->dwNumEntries; i++)
443  {
444  /* If we aren't showing all connections, only display established, close wait
445  * and time wait. This is the default output for netstat */
446  if (bDoShowAllCons || (tcpTable->table[i].dwState == MIB_TCP_STATE_ESTAB)
447  || (tcpTable->table[i].dwState == MIB_TCP_STATE_CLOSE_WAIT)
448  || (tcpTable->table[i].dwState == MIB_TCP_STATE_TIME_WAIT))
449  {
450  /* I've split this up so it's easier to follow */
451  GetIpHostName(TRUE, tcpTable->table[i].dwLocalAddr, HostIp, sizeof(HostIp));
452  GetPortName(tcpTable->table[i].dwLocalPort, "tcp", HostPort, sizeof(HostPort));
453  sprintf(Host, "%s:%s", HostIp, HostPort);
454 
455  if (tcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN)
456  {
457  sprintf(Remote, "%s:0", HostIp);
458  }
459  else
460  {
461  GetIpHostName(FALSE, tcpTable->table[i].dwRemoteAddr, RemoteIp, sizeof(RemoteIp));
462  GetPortName(tcpTable->table[i].dwRemotePort, "tcp", RemotePort, sizeof(RemotePort));
463  sprintf(Remote, "%s:%s", RemoteIp, RemotePort);
464  }
465 
466  if (bDoShowProcessId)
467  {
468  sprintf(PID, "%ld", tcpTable->table[i].dwOwningPid);
469  }
470  else
471  {
472  PID[0] = 0;
473  }
474 
475  ConPrintf(StdOut, L" %-6s %-22S %-22S %-11s %S\n", L"TCP",
476  Host, Remote, TcpState[tcpTable->table[i].dwState], PID);
477  }
478  }
479 
480  HeapFree(GetProcessHeap(), 0, tcpTable);
481  return TRUE;
482 }
BOOL bDoShowProcessId
Definition: netstat.h:16
#define TRUE
Definition: types.h:120
#define error(str)
Definition: mkdosfs.c:1605
struct _MIB_TCPTABLE_OWNER_PID MIB_TCPTABLE_OWNER_PID
char CHAR
Definition: xmlstorage.h:175
#define NO_ERROR
Definition: dderror.h:5
#define sprintf(buf, format,...)
Definition: sprintf.c:55
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
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
PCHAR GetIpHostName(BOOL Local, UINT IpAddr, CHAR Name[], INT NameLen)
Definition: netstat.c:563
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
#define PORTNAMELEN
Definition: netstat.h:4
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define StdErr
Definition: stream.h:77
static const WCHAR L[]
Definition: oid.c:1250
BOOL bDoShowAllCons
Definition: netstat.h:9
struct _MIB_TCPTABLE_OWNER_PID * PMIB_TCPTABLE_OWNER_PID
#define IDS_ERROR_TCP_SNAPSHOT
Definition: resource.h:14
DWORD WINAPI GetExtendedTcpTable(PVOID pTcpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, TCP_TABLE_CLASS TableClass, ULONG Reserved)
#define StdOut
Definition: stream.h:76
VOID DoFormatMessage(DWORD ErrorCode)
Definition: netstat.c:55
#define AF_INET
Definition: tcpip.h:117
#define ADDRESSLEN
Definition: netstat.h:5
PCHAR GetPortName(UINT Port, PCSTR Proto, CHAR Name[], INT NameLen)
Definition: netstat.c:542
#define HeapFree(x, y, z)
Definition: compat.h:402
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
PCWSTR TcpState[]
Definition: netstat.c:36
#define HOSTNAMELEN
Definition: netstat.h:3
MIB_TCPROW_OWNER_PID table[1]
Definition: tcpmib.h:115
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by DisplayOutput().

◆ ShowUdpStatistics()

VOID ShowUdpStatistics ( VOID  )

Definition at line 352 of file netstat.c.

353 {
355  DWORD dwRetVal;
356 
357  if ((dwRetVal = GetUdpStatistics(&udpStats)) == NO_ERROR)
358  {
364  }
365  else
366  {
367  DoFormatMessage(dwRetVal);
368  }
369 }
#define NO_ERROR
Definition: dderror.h:5
#define IDS_UDP_DATAG_SEND
Definition: resource.h:63
DWORD dwInDatagrams
Definition: udpmib.h:78
DWORD dwOutDatagrams
Definition: udpmib.h:81
DWORD dwNoPorts
Definition: udpmib.h:79
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
#define IDS_UDP_DATAG_RECEIVE
Definition: resource.h:60
static MIB_UDPSTATS udpStats
Definition: main.c:1137
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwInErrors
Definition: udpmib.h:80
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
#define IDS_UDP_NO_PORT
Definition: resource.h:61
#define IDS_UDP_RECEIVE_ERROR
Definition: resource.h:62
#define IDS_UDP_IP4_HEADER
Definition: resource.h:59
#define StdOut
Definition: stream.h:76
VOID DoFormatMessage(DWORD ErrorCode)
Definition: netstat.c:55

Referenced by DisplayOutput().

◆ ShowUdpTable()

BOOL ShowUdpTable ( VOID  )

Definition at line 484 of file netstat.c.

485 {
487  DWORD error, dwSize;
488  DWORD i;
489  CHAR HostIp[HOSTNAMELEN], HostPort[PORTNAMELEN];
490  CHAR Host[ADDRESSLEN];
491  CHAR PID[64];
492 
493  /* Get the table of UDP endpoints */
494  dwSize = 0;
497  {
500  return FALSE;
501  }
504  if (error)
505  {
509  return FALSE;
510  }
511 
512  /* Dump the UDP table */
513  for (i = 0; i < udpTable->dwNumEntries; i++)
514  {
515 
516  /* I've split this up so it's easier to follow */
517  GetIpHostName(TRUE, udpTable->table[i].dwLocalAddr, HostIp, sizeof(HostIp));
518  GetPortName(udpTable->table[i].dwLocalPort, "udp", HostPort, sizeof(HostPort));
519 
520  sprintf(Host, "%s:%s", HostIp, HostPort);
521 
522  if (bDoShowProcessId)
523  {
524  sprintf(PID, "%ld", udpTable->table[i].dwOwningPid);
525  }
526  else
527  {
528  PID[0] = 0;
529  }
530 
531  ConPrintf(StdOut, L" %-6s %-22S %-34s %S\n", L"UDP", Host, L"*:*", PID);
532  }
533 
535  return TRUE;
536 }
BOOL bDoShowProcessId
Definition: netstat.h:16
#define TRUE
Definition: types.h:120
#define error(str)
Definition: mkdosfs.c:1605
char CHAR
Definition: xmlstorage.h:175
DWORD dwLocalAddr
Definition: udpmib.h:28
struct _MIB_UDPTABLE_OWNER_PID * PMIB_UDPTABLE_OWNER_PID
#define sprintf(buf, format,...)
Definition: sprintf.c:55
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
DWORD dwNumEntries
Definition: udpmib.h:34
#define IDS_ERROR_UDP_ENDPOINT_TABLE
Definition: resource.h:16
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
PCHAR GetIpHostName(BOOL Local, UINT IpAddr, CHAR Name[], INT NameLen)
Definition: netstat.c:563
#define PORTNAMELEN
Definition: netstat.h:4
#define GetProcessHeap()
Definition: compat.h:403
MIB_UDPROW table[1]
Definition: udpmib.h:35
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define StdErr
Definition: stream.h:77
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1250
static PMIB_UDPTABLE udpTable
Definition: main.c:1187
DWORD WINAPI GetExtendedUdpTable(PVOID pUdpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, UDP_TABLE_CLASS TableClass, ULONG Reserved)
#define IDS_ERROR_UDP_ENDPOINT
Definition: resource.h:15
#define StdOut
Definition: stream.h:76
VOID DoFormatMessage(DWORD ErrorCode)
Definition: netstat.c:55
#define AF_INET
Definition: tcpip.h:117
DWORD dwLocalPort
Definition: udpmib.h:29
#define ADDRESSLEN
Definition: netstat.h:5
PCHAR GetPortName(UINT Port, PCSTR Proto, CHAR Name[], INT NameLen)
Definition: netstat.c:542
#define HeapFree(x, y, z)
Definition: compat.h:402
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define HOSTNAMELEN
Definition: netstat.h:3
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by DisplayOutput().

◆ wmain()

int wmain ( int  argc,
wchar_t argv[] 
)

Definition at line 618 of file netstat.c.

619 {
620  BOOL Success;
621  WSADATA wsaData;
622 
623  /* Initialize the Console Standard Streams */
625 
626  if (!ParseCmdline(argc, argv))
627  return EXIT_FAILURE;
628 
629  if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
630  {
632  return EXIT_FAILURE;
633  }
634 
636  while (bLoopOutput && Success)
637  {
638  Sleep(Interval*1000);
640  }
641 
642  WSACleanup();
643  return (Success ? EXIT_SUCCESS : EXIT_FAILURE);
644 }
static int argc
Definition: ServiceArgs.c:12
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define MAKEWORD(a, b)
Definition: typedefs.h:247
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
#define argv
Definition: mplay32.c:18
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
#define ConInitStdStreams()
Definition: stream.h:122
unsigned int BOOL
Definition: ntddk_ex.h:94
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
DWORD Interval
Definition: netstat.c:33
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
BOOL ParseCmdline(int argc, wchar_t *argv[])
Definition: netstat.c:69
#define EXIT_FAILURE
Definition: jerror.c:33
#define StdErr
Definition: stream.h:77
#define IDS_ERROR_WSA_START
Definition: resource.h:12
BOOL DisplayOutput(VOID)
Definition: netstat.c:174
BOOL bLoopOutput
Definition: netstat.h:18

Variable Documentation

◆ Interval

◆ Protocol

◆ TcpState

PCWSTR TcpState[]
Initial value:
= {
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"
}
static const WCHAR L[]
Definition: oid.c:1250

Definition at line 36 of file netstat.c.

Referenced by ShowTcpTable().