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:
Ged Murphy 2005-10-10 17:49:19 +00:00
parent 361bbd4d9d
commit 7cd2f8dbb5
6 changed files with 690 additions and 580 deletions

File diff suppressed because it is too large Load diff

View 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);

View file

@ -9,6 +9,5 @@
<library>snmpapi</library>
<library>iphlpapi</library>
<file>netstat.c</file>
<file>trace.c</file>
<file>netstat.rc</file>
</module>

View file

@ -1,7 +0,0 @@
#define RES_FIRST_INDEX 1
#define RES_LAST_INDEX 25
#define IDS_APP_TITLE 100
#define IDS_APP_USAGE 101

View file

@ -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
/////////////////////////////////////////////////////////////////////////////

View file

@ -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__
/////////////////////////////////////////////////////////////////////////////