Created framework for new network utility applications.

svn path=/trunk/; revision=3376
This commit is contained in:
Robert Dickenson 2002-08-23 08:23:28 +00:00
parent ed21a6af20
commit 3a41864fff
16 changed files with 934 additions and 0 deletions

View file

@ -0,0 +1,18 @@
PATH_TO_TOP = ../../../reactos
TARGET_TYPE = program
TARGET_APPTYPE = console
TARGET_NAME = netstat
TARGET_SDKLIBS = user32.a snmpapi.a
TARGET_OBJECTS = $(TARGET_NAME).o
include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk
# EOF

View file

@ -0,0 +1,74 @@
/*
* netstat - display IP stack statistics.
*
* This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
*
* Robert Dickenson <robd@reactos.org>, August 15, 2002.
*/
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <time.h>
#include <iptypes.h>
#include <ipexport.h>
#include <iphlpapi.h>
#include <snmp.h>
#include "trace.h"
#include "resource.h"
#define MAX_RESLEN 4000
/*
typedef struct {
UINT idLength;
UINT* ids;
} AsnObjectIdentifier;
VOID SnmpUtilPrintAsnAny(AsnAny* pAny); // pointer to value to print
VOID SnmpUtilPrintOid(AsnObjectIdentifier* Oid); // object identifier to print
*/
void test_snmp(void)
{
int nBytes = 500;
BYTE* pCache;
pCache = (BYTE*)SnmpUtilMemAlloc(nBytes);
if (pCache != NULL) {
AsnObjectIdentifier* pOidSrc = NULL;
AsnObjectIdentifier AsnObId;
if (SnmpUtilOidCpy(&AsnObId, pOidSrc)) {
//
//
//
SnmpUtilOidFree(&AsnObId);
}
SnmpUtilMemFree(pCache);
} else {
_tprintf(_T("ERROR: call to SnmpUtilMemAlloc() failed\n"));
}
}
void usage(void)
{
TCHAR buffer[MAX_RESLEN];
int length = LoadString(GetModuleHandle(NULL), IDS_APP_USAGE, buffer, sizeof(buffer)/sizeof(buffer[0]));
_fputts(buffer, stderr);
}
int main(int argc, char *argv[])
{
if (argc > 1) {
usage();
return 1;
}
_tprintf(_T("\nActive Connections\n\n")\
_T(" Proto Local Address Foreign Address State\n\n"));
test_snmp();
return 0;
}

View file

@ -0,0 +1,69 @@
#include <defines.h>
#include <reactos/resource.h>
#include "resource.h"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
VS_VERSION_INFO VERSIONINFO
FILEVERSION RES_UINT_FV_MAJOR,RES_UINT_FV_MINOR,RES_UINT_FV_REVISION,RES_UINT_FV_BUILD
PRODUCTVERSION RES_UINT_PV_MAJOR,RES_UINT_PV_MINOR,RES_UINT_PV_REVISION,RES_UINT_PV_BUILD
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", RES_STR_COMPANY_NAME
VALUE "FileDescription", "ReactOS TCP/IPv4 Win32 netstat\0"
VALUE "FileVersion", RES_STR_FILE_VERSION
VALUE "InternalName", "netstat\0"
VALUE "LegalCopyright", RES_STR_LEGAL_COPYRIGHT
VALUE "OriginalCopyright", "Robert Dickenson (robd@reactos.org)\0"
VALUE "OriginalFilename", "netstat.exe\0"
VALUE "ProductName", RES_STR_PRODUCT_NAME
VALUE "ProductVersion", RES_STR_PRODUCT_VERSION
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
#ifdef __GNUC__
STRINGTABLE DISCARDABLE
BEGIN
IDS_APP_TITLE "ReactOS netstat"
IDS_APP_USAGE "\n"\
"Displays current TCP/IP protocol statistics and network connections.\n\n"\
"NETSTAT [-a] [-e] [-n] [-s] [-p proto] [-r] [interval]\n\n"\
" -a Displays all connections and listening ports.\n"\
" -e Displays Ethernet statistics. May be combined with -s\n"\
" -n Displays address and port numbers in numeric form.\n"\
" -p proto Shows connections for protocol 'proto' TCP or UDP.\n"\
" If used with the -s option to display\n"\
" per-protocol statistics, 'proto' may be TCP, UDP, or IP.\n"\
" -r Displays the current routing table.\n"\
" -s Displays per-protocol statistics. Statistics are shown for\n"\
" TCP, UDP and IP by default; use -p option to display\n"\
" information about a subset of the protocols only.\n"\
" interval Redisplays selected statistics every 'interval' seconds.\n"\
" Press CTRL+C to stop redisplaying. By default netstat will\n"\
" print the current information only once.\n"
END
#endif

View file

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

View file

@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////////////////
// 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

@ -0,0 +1,61 @@
/////////////////////////////////////////////////////////////////////////////
// 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__
/////////////////////////////////////////////////////////////////////////////