mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 03:05:40 +00:00
Start of a rewrite for netstat.exe
- Simulate the output of the MS netstat tool - implemented -a, -e, -n, -p, -r, -s and interval svn path=/trunk/; revision=18397
This commit is contained in:
parent
361bbd4d9d
commit
7cd2f8dbb5
6 changed files with 690 additions and 580 deletions
File diff suppressed because it is too large
Load diff
61
reactos/apps/utils/net/netstat/netstat.h
Normal file
61
reactos/apps/utils/net/netstat/netstat.h
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
|
||||||
|
// Maximum string lengths for ASCII ip address and port names
|
||||||
|
//
|
||||||
|
#define HOSTNAMELEN 256
|
||||||
|
#define PORTNAMELEN 256
|
||||||
|
#define ADDRESSLEN HOSTNAMELEN+PORTNAMELEN
|
||||||
|
|
||||||
|
/* command line options */
|
||||||
|
BOOL bNoOptions = FALSE; // print default
|
||||||
|
BOOL bDoShowAllCons = FALSE; // -a
|
||||||
|
BOOL bDoShowEthStats = FALSE; // -e
|
||||||
|
BOOL bDoShowNumbers = FALSE; // -n
|
||||||
|
BOOL bDoShowProtoCons = FALSE; // -p
|
||||||
|
BOOL bDoShowRouteTable = FALSE; // -r
|
||||||
|
BOOL bDoShowProtoStats = FALSE; // -s
|
||||||
|
BOOL bDoDispSeqComp = FALSE; // -v
|
||||||
|
BOOL bLoopOutput = FALSE; // interval
|
||||||
|
|
||||||
|
|
||||||
|
/* Undocumented extended information structures available only on XP and higher */
|
||||||
|
typedef struct {
|
||||||
|
DWORD dwState; // state of the connection
|
||||||
|
DWORD dwLocalAddr; // address on local computer
|
||||||
|
DWORD dwLocalPort; // port number on local computer
|
||||||
|
DWORD dwRemoteAddr; // address on remote computer
|
||||||
|
DWORD dwRemotePort; // port number on remote computer
|
||||||
|
DWORD dwProcessId;
|
||||||
|
} MIB_TCPEXROW, *PMIB_TCPEXROW;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
DWORD dwNumEntries;
|
||||||
|
MIB_TCPEXROW table;
|
||||||
|
} MIB_TCPEXTABLE, *PMIB_TCPEXTABLE;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
DWORD dwLocalAddr; // address on local computer
|
||||||
|
DWORD dwLocalPort; // port number on local computer
|
||||||
|
DWORD dwProcessId;
|
||||||
|
} MIB_UDPEXROW, *PMIB_UDPEXROW;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
DWORD dwNumEntries;
|
||||||
|
MIB_UDPEXROW table;
|
||||||
|
} MIB_UDPEXTABLE, *PMIB_UDPEXTABLE;
|
||||||
|
|
||||||
|
|
||||||
|
/* function declerations */
|
||||||
|
BOOL ParseCmdline(int argc, char* argv[]);
|
||||||
|
BOOL DisplayOutput(VOID);
|
||||||
|
DWORD DoFormatMessage(DWORD ErrorCode);
|
||||||
|
VOID ShowIpStatistics(VOID);
|
||||||
|
VOID ShowIcmpStatistics(VOID);
|
||||||
|
VOID ShowTcpStatistics(VOID);
|
||||||
|
VOID ShowUdpStatistics(VOID);
|
||||||
|
VOID ShowEthernetStatistics(VOID);
|
||||||
|
VOID ShowTcpTable(VOID);
|
||||||
|
VOID ShowUdpTable(VOID);
|
||||||
|
PCHAR GetPortName(UINT port, PCHAR proto, PCHAR name, int namelen);
|
||||||
|
PCHAR GetIpHostName(BOOL local, UINT ipaddr, PCHAR name, int namelen);
|
||||||
|
VOID Usage(VOID);
|
||||||
|
|
|
@ -9,6 +9,5 @@
|
||||||
<library>snmpapi</library>
|
<library>snmpapi</library>
|
||||||
<library>iphlpapi</library>
|
<library>iphlpapi</library>
|
||||||
<file>netstat.c</file>
|
<file>netstat.c</file>
|
||||||
<file>trace.c</file>
|
|
||||||
<file>netstat.rc</file>
|
<file>netstat.rc</file>
|
||||||
</module>
|
</module>
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
|
|
||||||
#define RES_FIRST_INDEX 1
|
|
||||||
#define RES_LAST_INDEX 25
|
|
||||||
|
|
||||||
#define IDS_APP_TITLE 100
|
|
||||||
#define IDS_APP_USAGE 101
|
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Diagnostic Trace
|
|
||||||
//
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#include <tchar.h>
|
|
||||||
#include "trace.h"
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
|
|
||||||
#undef THIS_FILE
|
|
||||||
static char THIS_FILE[] = __FILE__;
|
|
||||||
|
|
||||||
void _DebugBreak(void)
|
|
||||||
{
|
|
||||||
DebugBreak();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Trace(TCHAR* lpszFormat, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
int nBuf;
|
|
||||||
TCHAR szBuffer[512];
|
|
||||||
|
|
||||||
va_start(args, lpszFormat);
|
|
||||||
nBuf = _vsntprintf(szBuffer, sizeof(szBuffer)/sizeof(TCHAR), lpszFormat, args);
|
|
||||||
OutputDebugString(szBuffer);
|
|
||||||
// was there an error? was the expanded string too long?
|
|
||||||
//ASSERT(nBuf >= 0);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Assert(void* assert, TCHAR* file, int line, void* msg)
|
|
||||||
{
|
|
||||||
if (msg == NULL) {
|
|
||||||
printf("ASSERT -- %s occured on line %u of file %s.\n",
|
|
||||||
assert, line, file);
|
|
||||||
} else {
|
|
||||||
printf("ASSERT -- %s occured on line %u of file %s: Message = %s.\n",
|
|
||||||
assert, line, file, msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
void Trace(TCHAR* lpszFormat, ...) { };
|
|
||||||
void Assert(void* assert, TCHAR* file, int line, void* msg) { };
|
|
||||||
|
|
||||||
#endif //_DEBUG
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
|
@ -1,61 +0,0 @@
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Diagnostic Trace
|
|
||||||
//
|
|
||||||
#ifndef __TRACE_H__
|
|
||||||
#define __TRACE_H__
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
|
|
||||||
#ifdef _X86_
|
|
||||||
#define BreakPoint() _asm { int 3h }
|
|
||||||
#else
|
|
||||||
#define BreakPoint() _DebugBreak()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef ASSERT
|
|
||||||
#define ASSERT(exp) \
|
|
||||||
{ \
|
|
||||||
if (!(exp)) { \
|
|
||||||
Assert(#exp, __FILE__, __LINE__, NULL); \
|
|
||||||
BreakPoint(); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
|
|
||||||
#define ASSERTMSG(exp, msg) \
|
|
||||||
{ \
|
|
||||||
if (!(exp)) { \
|
|
||||||
Assert(#exp, __FILE__, __LINE__, msg); \
|
|
||||||
BreakPoint(); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//=============================================================================
|
|
||||||
// MACRO: TRACE()
|
|
||||||
//=============================================================================
|
|
||||||
|
|
||||||
#define TRACE Trace
|
|
||||||
|
|
||||||
|
|
||||||
#else // _DEBUG
|
|
||||||
|
|
||||||
//=============================================================================
|
|
||||||
// Define away MACRO's ASSERT() and TRACE() in non debug builds
|
|
||||||
//=============================================================================
|
|
||||||
|
|
||||||
#ifndef ASSERT
|
|
||||||
#define ASSERT(exp)
|
|
||||||
#define ASSERTMSG(exp, msg)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TRACE 0 ? (void)0 : Trace
|
|
||||||
|
|
||||||
#endif // !_DEBUG
|
|
||||||
|
|
||||||
|
|
||||||
void Assert(void* assert, TCHAR* file, int line, void* msg);
|
|
||||||
void Trace(TCHAR* lpszFormat, ...);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __TRACE_H__
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
Loading…
Add table
Add a link
Reference in a new issue