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

99
rosapps/net/arp/arp.c Normal file
View file

@ -0,0 +1,99 @@
/*
* arp - display ARP cache from the IP stack parameters.
*
* This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
*
* Robert Dickenson <robd@reactos.org>, August 15, 2002.
*/
#include <stdio.h>
#include <windows.h>
#include <tchar.h>
#include <time.h>
#include <iptypes.h>
#include <ipexport.h>
#include <iphlpapi.h>
#include <snmp.h>
#include "trace.h"
VOID SNMP_FUNC_TYPE SnmpSvcInitUptime();
DWORD SNMP_FUNC_TYPE SnmpSvcGetUptime();
////////////////////////////////////////////////////////////////////////////////
const char szUsage[] = { "\n" \
"Displays and modifies the IP Protocol to physical address translation tables\n" \
"used by address resolution protocol (ARP).\n" \
"\n" \
"ARP -s inet_addr eth_addr [if_addr]\n" \
"ARP -d inet_addr [if_addr]\n" \
"ARP -a [inet_addr] [-N if_addr]\n" \
"\n" \
" -a Displays the active ARP table by querying the current protocol\n" \
" data. If inet_addr is specified, the IP and physical addresses\n" \
" for the specified address are displayed. If more than one\n" \
" network interface is using ARP, each interfaces ARP table is\n" \
" displayed.\n" \
" -g Indentical to -a.\n" \
" inet_addr Specifies the IP address.\n" \
" -N if_addr Displays the ARP table for the specified interface only\n" \
" -d Deletes the host entry specified by inet_addr. inet_addr may be\n" \
" wildcarded with * to delete all host entries in the ARP table.\n" \
" -s Adds the host and associates the IP address inet_addr with the\n" \
" physical address eth_addr. The physical address must be specified\n" \
" as 6 hexadecimal characters delimited by hyphens. The new entry\n" \
" will become permanent in the ARP table.\n" \
" eth_addr Specifies the interface physical address.\n" \
" if_addr If present, this specifies the IP address of the interface whose\n" \
" address translation table should be modified. If not present, the\n" \
" first applicable interface will be used.\n" \
"Example:\n" \
" > arp -s 192.168.0.12 55-AA-55-01-02-03 .... Static entry creation.\n" \
" > arp -a .... ARP table display.\n" \
" > arp -d * .... Delete all ARP table entries.\n"
};
void usage(void)
{
// fprintf(stderr,"USAGE:\n");
fputs(szUsage, stderr);
}
int main(int argc, char *argv[])
{
TCHAR szComputerName[50];
DWORD dwSize = 50;
int nBytes = 500;
BYTE* pCache;
if (argc > 1) {
usage();
return 1;
}
SnmpSvcInitUptime();
GetComputerName(szComputerName, &dwSize);
_tprintf(_T("ReactOS ARP cache on Computer Name: %s\n"), szComputerName);
pCache = (BYTE*)SnmpUtilMemAlloc(nBytes);
Sleep(2500);
if (pCache != NULL) {
DWORD dwUptime = SnmpSvcGetUptime();
_tprintf(_T("SNMP uptime: %d\n"), dwUptime);
SnmpUtilMemFree(pCache);
} else {
_tprintf(_T("ERROR: call to SnmpUtilMemAlloc() failed\n"));
return 1;
}
return 0;
}

39
rosapps/net/arp/arp.rc Normal file
View file

@ -0,0 +1,39 @@
#include <defines.h>
#include <reactos/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 arp\0"
VALUE "FileVersion", RES_STR_FILE_VERSION
VALUE "InternalName", "arp\0"
VALUE "LegalCopyright", RES_STR_LEGAL_COPYRIGHT
VALUE "OriginalCopyright", "Robert Dickenson (robd@reactos.org)\0"
VALUE "OriginalFilename", "arp.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

18
rosapps/net/arp/makefile Normal file
View file

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

53
rosapps/net/arp/trace.c Normal file
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
/////////////////////////////////////////////////////////////////////////////

61
rosapps/net/arp/trace.h Normal file
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__
/////////////////////////////////////////////////////////////////////////////