ReactOS  0.4.14-dev-115-g4576127
netstat.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MIB_TCPEXROW
 
struct  MIB_TCPEXTABLE
 
struct  MIB_UDPEXROW
 
struct  MIB_UDPEXTABLE
 

Macros

#define HOSTNAMELEN   256
 
#define PORTNAMELEN   256
 
#define ADDRESSLEN   HOSTNAMELEN+PORTNAMELEN
 

Typedefs

typedef struct MIB_TCPEXROWPMIB_TCPEXROW
 
typedef struct MIB_TCPEXTABLEPMIB_TCPEXTABLE
 
typedef struct MIB_UDPEXROWPMIB_UDPEXROW
 
typedef struct MIB_UDPEXTABLEPMIB_UDPEXTABLE
 

Functions

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)
 

Variables

BOOL bNoOptions = FALSE
 
BOOL bDoShowAllCons = FALSE
 
BOOL bDoShowProcName = FALSE
 
BOOL bDoShowEthStats = FALSE
 
BOOL bDoShowNumbers = FALSE
 
BOOL bDoShowProtoCons = FALSE
 
BOOL bDoShowRouteTable = FALSE
 
BOOL bDoShowProtoStats = FALSE
 
BOOL bDoShowProcessId = FALSE
 
BOOL bDoDispSeqComp = FALSE
 
BOOL bLoopOutput = FALSE
 

Macro Definition Documentation

◆ ADDRESSLEN

#define ADDRESSLEN   HOSTNAMELEN+PORTNAMELEN

Definition at line 5 of file netstat.h.

◆ HOSTNAMELEN

#define HOSTNAMELEN   256

Definition at line 3 of file netstat.h.

◆ PORTNAMELEN

#define PORTNAMELEN   256

Definition at line 4 of file netstat.h.

Typedef Documentation

◆ PMIB_TCPEXROW

◆ PMIB_TCPEXTABLE

◆ PMIB_UDPEXROW

◆ PMIB_UDPEXTABLE

Function Documentation

◆ GetIpHostName()

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

Definition at line 556 of file netstat.c.

557 {
558 // struct hostent *phostent;
559  UINT nIpAddr;
560 
561  /* display dotted decimal */
562  nIpAddr = htonl(IpAddr);
563  if (bDoShowNumbers) {
564  sprintf(Name, "%d.%d.%d.%d",
565  (nIpAddr >> 24) & 0xFF,
566  (nIpAddr >> 16) & 0xFF,
567  (nIpAddr >> 8) & 0xFF,
568  (nIpAddr) & 0xFF);
569  return Name;
570  }
571 
572  Name[0] = '\0';
573 
574  /* try to resolve the name */
575  if (!IpAddr) {
576  if (!Local) {
577  sprintf(Name, "%d.%d.%d.%d",
578  (nIpAddr >> 24) & 0xFF,
579  (nIpAddr >> 16) & 0xFF,
580  (nIpAddr >> 8) & 0xFF,
581  (nIpAddr) & 0xFF);
582  } else {
583  if (gethostname(Name, NameLen) != 0)
585  }
586  } else if (IpAddr == 0x0100007f) {
587  if (Local) {
588  if (gethostname(Name, NameLen) != 0)
590  } else {
591  strncpy(Name, "localhost", 10);
592  }
593 // } else if (phostent = gethostbyaddr((char*)&ipaddr, sizeof(nipaddr), PF_INET)) {
594 // strcpy(name, phostent->h_name);
595  } else {
596  sprintf(Name, "%d.%d.%d.%d",
597  ((nIpAddr >> 24) & 0x000000FF),
598  ((nIpAddr >> 16) & 0x000000FF),
599  ((nIpAddr >> 8) & 0x000000FF),
600  ((nIpAddr) & 0x000000FF));
601  }
602  return Name;
603 }
#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 535 of file netstat.c.

536 {
537  struct servent *pServent;
538 
539  if (bDoShowNumbers)
540  {
541  sprintf(Name, "%d", htons((WORD)Port));
542  return Name;
543  }
544  /* Try to translate to a name */
545  if ((pServent = getservbyport(Port, Proto)))
546  strcpy(Name, pServent->s_name );
547  else
548  sprintf(Name, "%d", htons((WORD)Port));
549  return Name;
550 }
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().

◆ ShowEthernetStatistics()

VOID ShowEthernetStatistics ( VOID  )

Definition at line 364 of file netstat.c.

365 {
366  PMIB_IFTABLE pIfTable;
367  DWORD dwSize = 0;
368  DWORD dwRetVal = 0;
369 
370  pIfTable = (MIB_IFTABLE*) HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IFTABLE));
371 
372  if (GetIfTable(pIfTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER)
373  {
374  HeapFree(GetProcessHeap(), 0, pIfTable);
375  pIfTable = (MIB_IFTABLE*) HeapAlloc(GetProcessHeap(), 0, dwSize);
376 
377  if ((dwRetVal = GetIfTable(pIfTable, &dwSize, 0)) == NO_ERROR)
378  {
382  pIfTable->table[0].dwInOctets, pIfTable->table[0].dwOutOctets);
384  pIfTable->table[0].dwInUcastPkts, pIfTable->table[0].dwOutUcastPkts);
386  pIfTable->table[0].dwInNUcastPkts, pIfTable->table[0].dwOutNUcastPkts);
388  pIfTable->table[0].dwInDiscards, pIfTable->table[0].dwOutDiscards);
390  pIfTable->table[0].dwInErrors, pIfTable->table[0].dwOutErrors);
392  pIfTable->table[0].dwInUnknownProtos);
393  }
394  else
395  {
396  DoFormatMessage(dwRetVal);
397  }
398  }
399  HeapFree(GetProcessHeap(), 0, pIfTable);
400 }
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:395
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:394
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 275 of file netstat.c.

276 {
277  PMIB_ICMP pIcmpStats;
278  DWORD dwRetVal;
279 
280  pIcmpStats = (MIB_ICMP*) HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_ICMP));
281 
282  if ((dwRetVal = GetIcmpStatistics(pIcmpStats)) == NO_ERROR)
283  {
287  pIcmpStats->stats.icmpInStats.dwMsgs, pIcmpStats->stats.icmpOutStats.dwMsgs);
289  pIcmpStats->stats.icmpInStats.dwErrors, pIcmpStats->stats.icmpOutStats.dwErrors);
293  pIcmpStats->stats.icmpInStats.dwTimeExcds, pIcmpStats->stats.icmpOutStats.dwTimeExcds);
295  pIcmpStats->stats.icmpInStats.dwParmProbs, pIcmpStats->stats.icmpOutStats.dwParmProbs);
297  pIcmpStats->stats.icmpInStats.dwSrcQuenchs, pIcmpStats->stats.icmpOutStats.dwSrcQuenchs);
299  pIcmpStats->stats.icmpInStats.dwRedirects, pIcmpStats->stats.icmpOutStats.dwRedirects);
301  pIcmpStats->stats.icmpInStats.dwEchos, pIcmpStats->stats.icmpOutStats.dwEchos);
303  pIcmpStats->stats.icmpInStats.dwEchoReps, pIcmpStats->stats.icmpOutStats.dwEchoReps);
305  pIcmpStats->stats.icmpInStats.dwTimestamps, pIcmpStats->stats.icmpOutStats.dwTimestamps);
309  pIcmpStats->stats.icmpInStats.dwAddrMasks, pIcmpStats->stats.icmpOutStats.dwAddrMasks);
312  }
313  else
314  {
315  DoFormatMessage(dwRetVal);
316  }
317 
318  HeapFree(GetProcessHeap(), 0, pIcmpStats);
319 
320 }
#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:395
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:394
#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 239 of file netstat.c.

240 {
241  PMIB_IPSTATS pIpStats;
242  DWORD dwRetVal;
243 
244  pIpStats = (MIB_IPSTATS*) HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IPSTATS));
245 
246  if ((dwRetVal = GetIpStatistics(pIpStats)) == NO_ERROR)
247  {
266  }
267  else
268  {
269  DoFormatMessage(dwRetVal);
270  }
271 
272  HeapFree(GetProcessHeap(), 0, pIpStats);
273 }
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:395
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:394

Referenced by DisplayOutput().

◆ ShowTcpStatistics()

VOID ShowTcpStatistics ( VOID  )

Definition at line 322 of file netstat.c.

323 {
325  DWORD dwRetVal;
326 
327  if ((dwRetVal = GetTcpStatistics(&tcpStats)) == NO_ERROR)
328  {
338  }
339  else
340  {
341  DoFormatMessage(dwRetVal);
342  }
343 }
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:1077
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 402 of file netstat.c.

403 {
404  PMIB_TCPTABLE_OWNER_PID tcpTable;
405  DWORD error, dwSize;
406  DWORD i;
407  CHAR HostIp[HOSTNAMELEN], HostPort[PORTNAMELEN];
408  CHAR RemoteIp[HOSTNAMELEN], RemotePort[PORTNAMELEN];
409  CHAR Host[ADDRESSLEN];
411  CHAR PID[64];
412 
413  /* Get the table of TCP endpoints */
414  dwSize = sizeof (MIB_TCPTABLE_OWNER_PID);
415  /* Should also work when we get new connections between 2 GetTcpTable()
416  * calls: */
417  do
418  {
421  if ( error != NO_ERROR )
422  HeapFree(GetProcessHeap(), 0, tcpTable);
423  }
424  while ( error == ERROR_INSUFFICIENT_BUFFER );
425 
426  if (error != NO_ERROR)
427  {
430  HeapFree(GetProcessHeap(), 0, tcpTable);
431  return FALSE;
432  }
433 
434  /* Dump the TCP table */
435  for (i = 0; i < tcpTable->dwNumEntries; i++)
436  {
437  /* If we aren't showing all connections, only display established, close wait
438  * and time wait. This is the default output for netstat */
439  if (bDoShowAllCons || (tcpTable->table[i].dwState == MIB_TCP_STATE_ESTAB)
440  || (tcpTable->table[i].dwState == MIB_TCP_STATE_CLOSE_WAIT)
441  || (tcpTable->table[i].dwState == MIB_TCP_STATE_TIME_WAIT))
442  {
443  /* I've split this up so it's easier to follow */
444  GetIpHostName(TRUE, tcpTable->table[i].dwLocalAddr, HostIp, sizeof(HostIp));
445  GetPortName(tcpTable->table[i].dwLocalPort, "tcp", HostPort, sizeof(HostPort));
446  sprintf(Host, "%s:%s", HostIp, HostPort);
447 
448  if (tcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN)
449  {
450  sprintf(Remote, "%s:0", HostIp);
451  }
452  else
453  {
454  GetIpHostName(FALSE, tcpTable->table[i].dwRemoteAddr, RemoteIp, sizeof(RemoteIp));
455  GetPortName(tcpTable->table[i].dwRemotePort, "tcp", RemotePort, sizeof(RemotePort));
456  sprintf(Remote, "%s:%s", RemoteIp, RemotePort);
457  }
458 
459  if (bDoShowProcessId)
460  {
461  sprintf(PID, "%ld", tcpTable->table[i].dwOwningPid);
462  }
463  else
464  {
465  PID[0] = 0;
466  }
467 
468  ConPrintf(StdOut, L" %-6s %-22S %-22S %-11s %S\n", L"TCP",
469  Host, Remote, TcpState[tcpTable->table[i].dwState], PID);
470  }
471  }
472 
473  HeapFree(GetProcessHeap(), 0, tcpTable);
474  return TRUE;
475 }
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:556
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:395
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:535
#define HeapFree(x, y, z)
Definition: compat.h:394
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 345 of file netstat.c.

346 {
348  DWORD dwRetVal;
349 
350  if ((dwRetVal = GetUdpStatistics(&udpStats)) == NO_ERROR)
351  {
357  }
358  else
359  {
360  DoFormatMessage(dwRetVal);
361  }
362 }
#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:1138
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 477 of file netstat.c.

478 {
480  DWORD error, dwSize;
481  DWORD i;
482  CHAR HostIp[HOSTNAMELEN], HostPort[PORTNAMELEN];
483  CHAR Host[ADDRESSLEN];
484  CHAR PID[64];
485 
486  /* Get the table of UDP endpoints */
487  dwSize = 0;
490  {
493  return FALSE;
494  }
497  if (error)
498  {
502  return FALSE;
503  }
504 
505  /* Dump the UDP table */
506  for (i = 0; i < udpTable->dwNumEntries; i++)
507  {
508 
509  /* I've split this up so it's easier to follow */
510  GetIpHostName(TRUE, udpTable->table[i].dwLocalAddr, HostIp, sizeof(HostIp));
511  GetPortName(udpTable->table[i].dwLocalPort, "udp", HostPort, sizeof(HostPort));
512 
513  sprintf(Host, "%s:%s", HostIp, HostPort);
514 
515  if (bDoShowProcessId)
516  {
517  sprintf(PID, "%ld", udpTable->table[i].dwOwningPid);
518  }
519  else
520  {
521  PID[0] = 0;
522  }
523 
524  ConPrintf(StdOut, L" %-6s %-22S %-34s %S\n", L"UDP", Host, L"*:*", PID);
525  }
526 
528  return TRUE;
529 }
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:556
#define PORTNAMELEN
Definition: netstat.h:4
#define GetProcessHeap()
Definition: compat.h:395
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:1188
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:535
#define HeapFree(x, y, z)
Definition: compat.h:394
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().

Variable Documentation

◆ bDoDispSeqComp

BOOL bDoDispSeqComp = FALSE

Definition at line 17 of file netstat.h.

Referenced by ParseCmdline().

◆ bDoShowAllCons

BOOL bDoShowAllCons = FALSE

Definition at line 9 of file netstat.h.

Referenced by DisplayOutput(), ParseCmdline(), and ShowTcpTable().

◆ bDoShowEthStats

BOOL bDoShowEthStats = FALSE

Definition at line 11 of file netstat.h.

Referenced by DisplayOutput(), and ParseCmdline().

◆ bDoShowNumbers

BOOL bDoShowNumbers = FALSE

Definition at line 12 of file netstat.h.

Referenced by GetIpHostName(), GetPortName(), and ParseCmdline().

◆ bDoShowProcessId

BOOL bDoShowProcessId = FALSE

Definition at line 16 of file netstat.h.

Referenced by DisplayTableHeader(), ParseCmdline(), ShowTcpTable(), and ShowUdpTable().

◆ bDoShowProcName

BOOL bDoShowProcName = FALSE

Definition at line 10 of file netstat.h.

Referenced by ParseCmdline().

◆ bDoShowProtoCons

BOOL bDoShowProtoCons = FALSE

Definition at line 13 of file netstat.h.

Referenced by DisplayOutput(), and ParseCmdline().

◆ bDoShowProtoStats

BOOL bDoShowProtoStats = FALSE

Definition at line 15 of file netstat.h.

Referenced by DisplayOutput(), and ParseCmdline().

◆ bDoShowRouteTable

BOOL bDoShowRouteTable = FALSE

Definition at line 14 of file netstat.h.

Referenced by DisplayOutput(), and ParseCmdline().

◆ bLoopOutput

BOOL bLoopOutput = FALSE

Definition at line 18 of file netstat.h.

Referenced by ParseCmdline(), and wmain().

◆ bNoOptions

BOOL bNoOptions = FALSE

Definition at line 8 of file netstat.h.

Referenced by DisplayOutput(), and ParseCmdline().