mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 15:13:05 +00:00
Misc updates and additions to as yet only partial applications.
svn path=/trunk/; revision=3541
This commit is contained in:
parent
edfa8a7002
commit
55fe4b8ca1
4 changed files with 529 additions and 24 deletions
|
@ -35,25 +35,19 @@ NhpAllocateAndGetInterfaceInfoFromStack
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TCHAR* GetNodeTypeName(int nNodeType)
|
static TCHAR* GetNodeTypeName(int nNodeType)
|
||||||
{
|
{
|
||||||
switch (nNodeType) {
|
switch (nNodeType) {
|
||||||
case 0:
|
case 0: return _T("zero");
|
||||||
return _T("zero");
|
case 1: return _T("one");
|
||||||
case 1:
|
case 2: return _T("two");
|
||||||
return _T("one");
|
case 3: return _T("three");
|
||||||
case 2:
|
case 4: return _T("mixed");
|
||||||
return _T("two");
|
default: return _T("unknown");
|
||||||
case 3:
|
|
||||||
return _T("three");
|
|
||||||
case 4:
|
|
||||||
return _T("mixed");
|
|
||||||
default:
|
|
||||||
return _T("unknown");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowNetworkFixedInfo()
|
static void ShowNetworkFixedInfo()
|
||||||
{
|
{
|
||||||
FIXED_INFO* pFixedInfo = NULL;
|
FIXED_INFO* pFixedInfo = NULL;
|
||||||
ULONG OutBufLen = 0;
|
ULONG OutBufLen = 0;
|
||||||
|
@ -73,15 +67,25 @@ void ShowNetworkFixedInfo()
|
||||||
|
|
||||||
result = GetNetworkParams(pFixedInfo, &OutBufLen);
|
result = GetNetworkParams(pFixedInfo, &OutBufLen);
|
||||||
if (result == ERROR_SUCCESS) {
|
if (result == ERROR_SUCCESS) {
|
||||||
|
IP_ADDR_STRING* pIPAddr;
|
||||||
|
|
||||||
printf("\tHostName. . . . . . . . . . . : %s\n", pFixedInfo->HostName);
|
printf("\tHostName. . . . . . . . . . . : %s\n", pFixedInfo->HostName);
|
||||||
printf("\tDomainName. . . . . . . . . . : %s\n", pFixedInfo->DomainName);
|
printf("\tDomainName. . . . . . . . . . : %s\n", pFixedInfo->DomainName);
|
||||||
|
//
|
||||||
|
printf("\tDNS Servers . . . . . . . . . : %s\n", pFixedInfo->DnsServerList.IpAddress.String);
|
||||||
|
pIPAddr = pFixedInfo->DnsServerList.Next;
|
||||||
|
while (pIPAddr) {
|
||||||
|
printf("\t\t\t\t : %s\n", pIPAddr->IpAddress.String);
|
||||||
|
pIPAddr = pIPAddr->Next;
|
||||||
|
}
|
||||||
|
//
|
||||||
_tprintf(_T("\tNodeType. . . . . . . . . . . : %d (%s)\n"), pFixedInfo->NodeType, GetNodeTypeName(pFixedInfo->NodeType));
|
_tprintf(_T("\tNodeType. . . . . . . . . . . : %d (%s)\n"), pFixedInfo->NodeType, GetNodeTypeName(pFixedInfo->NodeType));
|
||||||
printf("\tScopeId . . . . . . . . . . . : %s\n", pFixedInfo->ScopeId);
|
printf("\tScopeId . . . . . . . . . . . : %s\n", pFixedInfo->ScopeId);
|
||||||
_tprintf(_T("\tEnableRouting . . . . . . . . : %s\n"), pFixedInfo->EnableRouting ? _T("yes") : _T("no"));
|
_tprintf(_T("\tEnableRouting . . . . . . . . : %s\n"), pFixedInfo->EnableRouting ? _T("yes") : _T("no"));
|
||||||
_tprintf(_T("\tEnableProxy . . . . . . . . . : %s\n"), pFixedInfo->EnableProxy ? _T("yes") : _T("no"));
|
_tprintf(_T("\tEnableProxy . . . . . . . . . : %s\n"), pFixedInfo->EnableProxy ? _T("yes") : _T("no"));
|
||||||
_tprintf(_T("\tEnableDns . . . . . . . . . . : %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no"));
|
_tprintf(_T("\tEnableDns . . . . . . . . . . : %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no"));
|
||||||
_tprintf(_T("\n"));
|
_tprintf(_T("\n"));
|
||||||
//_tprintf(_T("\n"), );
|
//_tprintf(_T("\n"),);
|
||||||
//_tprintf(_T("GetNetworkParams() returned with %d\n"), pIfTable->NumAdapters);
|
//_tprintf(_T("GetNetworkParams() returned with %d\n"), pIfTable->NumAdapters);
|
||||||
|
|
||||||
// _tprintf(_T("\tConnection specific DNS suffix: %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no"));
|
// _tprintf(_T("\tConnection specific DNS suffix: %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no"));
|
||||||
|
@ -107,7 +111,7 @@ void ShowNetworkFixedInfo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowNetworkInterfaces()
|
static void ShowNetworkInterfaces()
|
||||||
{
|
{
|
||||||
IP_INTERFACE_INFO* pIfTable = NULL;
|
IP_INTERFACE_INFO* pIfTable = NULL;
|
||||||
DWORD result;
|
DWORD result;
|
||||||
|
@ -162,6 +166,31 @@ void ShowNetworkInterfaces()
|
||||||
free(pIfTable);
|
free(pIfTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ShowAdapterInfo()
|
||||||
|
{
|
||||||
|
IP_ADAPTER_INFO* pAdaptorInfo;
|
||||||
|
ULONG ulOutBufLen;
|
||||||
|
DWORD dwRetVal;
|
||||||
|
|
||||||
|
_tprintf(_T("\nAdaptor Information\t\n"));
|
||||||
|
pAdaptorInfo = (IP_ADAPTER_INFO*)GlobalAlloc(GPTR, sizeof(IP_ADAPTER_INFO));
|
||||||
|
ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
||||||
|
|
||||||
|
if (ERROR_BUFFER_OVERFLOW == GetAdaptersInfo(pAdaptorInfo, &ulOutBufLen)) {
|
||||||
|
GlobalFree(pAdaptorInfo);
|
||||||
|
pAdaptorInfo = (IP_ADAPTER_INFO*)GlobalAlloc(GPTR, ulOutBufLen);
|
||||||
|
}
|
||||||
|
if (dwRetVal = GetAdaptersInfo(pAdaptorInfo, &ulOutBufLen)) {
|
||||||
|
_tprintf(_T("Call to GetAdaptersInfo failed. Return Value: %08x\n"), dwRetVal);
|
||||||
|
} else {
|
||||||
|
while (pAdaptorInfo) {
|
||||||
|
printf(" AdapterName: %s\n", pAdaptorInfo->AdapterName);
|
||||||
|
printf(" Description: %s\n", pAdaptorInfo->Description);
|
||||||
|
pAdaptorInfo = pAdaptorInfo->Next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char szUsage[] = { "USAGE:\n" \
|
const char szUsage[] = { "USAGE:\n" \
|
||||||
" ipconfig [/? | /all | /release [adapter] | /renew [adapter]\n" \
|
" ipconfig [/? | /all | /release [adapter] | /renew [adapter]\n" \
|
||||||
" | /flushdns | /registerdns\n" \
|
" | /flushdns | /registerdns\n" \
|
||||||
|
@ -185,7 +214,6 @@ const char szUsage[] = { "USAGE:\n" \
|
||||||
"The default is to display only the IP address, subnet mask and\n" \
|
"The default is to display only the IP address, subnet mask and\n" \
|
||||||
"default gateway for each adapter bound to TCP/IP.\n"
|
"default gateway for each adapter bound to TCP/IP.\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
"\n" \
|
"\n" \
|
||||||
"For Release and Renew, if no adapter name is specified, then the IP address\n" \
|
"For Release and Renew, if no adapter name is specified, then the IP address\n" \
|
||||||
|
@ -202,7 +230,7 @@ const char szUsage[] = { "USAGE:\n" \
|
||||||
eg. ELINK-21, myELELINKi21adapter.\n"
|
eg. ELINK-21, myELELINKi21adapter.\n"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
fputs(szUsage, stderr);
|
fputs(szUsage, stderr);
|
||||||
}
|
}
|
||||||
|
@ -210,7 +238,6 @@ void usage(void)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
// 10.0.0.100 // As of build 0.0.20 this is hardcoded in the ip stack
|
// 10.0.0.100 // As of build 0.0.20 this is hardcoded in the ip stack
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
|
@ -220,6 +247,6 @@ int main(int argc, char *argv[])
|
||||||
_tprintf(_T("ReactOS IP Configuration\n"));
|
_tprintf(_T("ReactOS IP Configuration\n"));
|
||||||
ShowNetworkFixedInfo();
|
ShowNetworkFixedInfo();
|
||||||
ShowNetworkInterfaces();
|
ShowNetworkInterfaces();
|
||||||
|
ShowAdapterInfo();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ TARGET_APPTYPE = console
|
||||||
|
|
||||||
TARGET_NAME = netstat
|
TARGET_NAME = netstat
|
||||||
|
|
||||||
TARGET_SDKLIBS = user32.a snmpapi.a
|
TARGET_SDKLIBS = user32.a snmpapi.a iphlpapi.a ws2_32.a
|
||||||
|
|
||||||
TARGET_OBJECTS = $(TARGET_NAME).o
|
TARGET_OBJECTS = $(TARGET_NAME).o
|
||||||
|
|
||||||
|
|
|
@ -5,22 +5,192 @@
|
||||||
*
|
*
|
||||||
* Robert Dickenson <robd@reactos.org>, August 15, 2002.
|
* Robert Dickenson <robd@reactos.org>, August 15, 2002.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Extensive reference made and use of source to netstatp by:
|
||||||
|
// Copyright (C) 1998-2002 Mark Russinovich
|
||||||
|
// www.sysinternals.com
|
||||||
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <winsock.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#undef WINAPI
|
||||||
|
#define WINAPI
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <iptypes.h>
|
#include <iptypes.h>
|
||||||
#include <ipexport.h>
|
#include <ipexport.h>
|
||||||
|
#include <tlhelp32.h>
|
||||||
#include <iphlpapi.h>
|
#include <iphlpapi.h>
|
||||||
#include <snmp.h>
|
#include <snmp.h>
|
||||||
|
|
||||||
|
//#include "windows.h"
|
||||||
|
//#include "stdio.h"
|
||||||
|
//#include "winsock.h"
|
||||||
|
//#include "iprtrmib.h"
|
||||||
|
//#include "tlhelp32.h"
|
||||||
|
//#include "iphlpapi.h"
|
||||||
|
//#include "netstatp.h"
|
||||||
|
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
|
|
||||||
#define MAX_RESLEN 4000
|
#define MAX_RESLEN 4000
|
||||||
|
|
||||||
|
//
|
||||||
|
// Possible TCP endpoint states
|
||||||
|
//
|
||||||
|
static char TcpState[][32] = {
|
||||||
|
"???",
|
||||||
|
"CLOSED",
|
||||||
|
"LISTENING",
|
||||||
|
"SYN_SENT",
|
||||||
|
"SYN_RCVD",
|
||||||
|
"ESTABLISHED",
|
||||||
|
"FIN_WAIT1",
|
||||||
|
"FIN_WAIT2",
|
||||||
|
"CLOSE_WAIT",
|
||||||
|
"CLOSING",
|
||||||
|
"LAST_ACK",
|
||||||
|
"TIME_WAIT",
|
||||||
|
"DELETE_TCB"
|
||||||
|
};
|
||||||
|
|
||||||
|
VOID PrintError(DWORD ErrorCode)
|
||||||
|
{
|
||||||
|
LPVOID lpMsgBuf;
|
||||||
|
|
||||||
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||||
|
NULL, ErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
(LPTSTR)&lpMsgBuf, 0, NULL);
|
||||||
|
printf("%s\n", lpMsgBuf);
|
||||||
|
LocalFree(lpMsgBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ShowTcpStatistics()
|
||||||
|
{
|
||||||
|
MIB_TCPSTATS TcpStatsMIB;
|
||||||
|
GetTcpStatistics(&TcpStatsMIB);
|
||||||
|
|
||||||
|
_tprintf(_T("TCP/IP Statistics\t\n"));
|
||||||
|
_tprintf(_T(" time-out algorithm:\t\t%d\n"), TcpStatsMIB.dwRtoAlgorithm);
|
||||||
|
_tprintf(_T(" minimum time-out:\t\t%d\n"), TcpStatsMIB.dwRtoMin);
|
||||||
|
_tprintf(_T(" maximum time-out:\t\t%d\n"), TcpStatsMIB.dwRtoMax);
|
||||||
|
_tprintf(_T(" maximum connections:\t\t%d\n"), TcpStatsMIB.dwMaxConn);
|
||||||
|
_tprintf(_T(" active opens:\t\t\t%d\n"), TcpStatsMIB.dwActiveOpens);
|
||||||
|
_tprintf(_T(" passive opens:\t\t\t%d\n"), TcpStatsMIB.dwPassiveOpens);
|
||||||
|
_tprintf(_T(" failed attempts:\t\t%d\n"), TcpStatsMIB.dwAttemptFails);
|
||||||
|
_tprintf(_T(" established connections reset:\t%d\n"), TcpStatsMIB.dwEstabResets);
|
||||||
|
_tprintf(_T(" established connections:\t%d\n"), TcpStatsMIB.dwCurrEstab);
|
||||||
|
_tprintf(_T(" segments received:\t\t%d\n"), TcpStatsMIB.dwInSegs);
|
||||||
|
_tprintf(_T(" segment sent:\t\t\t%d\n"), TcpStatsMIB.dwOutSegs);
|
||||||
|
_tprintf(_T(" segments retransmitted:\t\t%d\n"), TcpStatsMIB.dwRetransSegs);
|
||||||
|
_tprintf(_T(" incoming errors:\t\t%d\n"), TcpStatsMIB.dwInErrs);
|
||||||
|
_tprintf(_T(" outgoing resets:\t\t%d\n"), TcpStatsMIB.dwOutRsts);
|
||||||
|
_tprintf(_T(" cumulative connections:\t\t%d\n"), TcpStatsMIB.dwNumConns);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ShowUdpStatistics()
|
||||||
|
{
|
||||||
|
MIB_UDPSTATS UDPStatsMIB;
|
||||||
|
GetUdpStatistics(&UDPStatsMIB);
|
||||||
|
|
||||||
|
_tprintf(_T("UDP Statistics\t\n"));
|
||||||
|
_tprintf(_T(" received datagrams:\t\t\t%d\n"), UDPStatsMIB.dwInDatagrams);
|
||||||
|
_tprintf(_T(" datagrams for which no port exists:\t%d\n"), UDPStatsMIB.dwNoPorts);
|
||||||
|
_tprintf(_T(" errors on received datagrams:\t\t%d\n"), UDPStatsMIB.dwInErrors);
|
||||||
|
_tprintf(_T(" sent datagrams:\t\t\t\t%d\n"), UDPStatsMIB.dwOutDatagrams);
|
||||||
|
_tprintf(_T(" number of entries in listener table:\t%d\n"), UDPStatsMIB.dwNumAddrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ShowIpStatistics()
|
||||||
|
{
|
||||||
|
MIB_IPSTATS IPStatsMIB;
|
||||||
|
GetIpStatistics(&IPStatsMIB);
|
||||||
|
|
||||||
|
_tprintf(_T("IP Statistics\t\n"));
|
||||||
|
_tprintf(_T(" IP forwarding enabled or disabled:\t%d\n"), IPStatsMIB.dwForwarding);
|
||||||
|
_tprintf(_T(" default time-to-live:\t\t\t%d\n"), IPStatsMIB.dwDefaultTTL);
|
||||||
|
_tprintf(_T(" datagrams received:\t\t\t%d\n"), IPStatsMIB.dwInReceives);
|
||||||
|
_tprintf(_T(" received header errors:\t\t\t%d\n"), IPStatsMIB.dwInHdrErrors);
|
||||||
|
_tprintf(_T(" received address errors:\t\t%d\n"), IPStatsMIB.dwInAddrErrors);
|
||||||
|
_tprintf(_T(" datagrams forwarded:\t\t\t%d\n"), IPStatsMIB.dwForwDatagrams);
|
||||||
|
_tprintf(_T(" datagrams with unknown protocol:\t%d\n"), IPStatsMIB.dwInUnknownProtos);
|
||||||
|
_tprintf(_T(" received datagrams discarded:\t\t%d\n"), IPStatsMIB.dwInDiscards);
|
||||||
|
_tprintf(_T(" received datagrams delivered:\t\t%d\n"), IPStatsMIB.dwInDelivers);
|
||||||
|
_tprintf(_T(" sent datagrams discarded:\t\t%d\n"), IPStatsMIB.dwOutDiscards);
|
||||||
|
_tprintf(_T(" datagrams for which no route exists:\t%d\n"), IPStatsMIB.dwOutNoRoutes);
|
||||||
|
_tprintf(_T(" datagrams for which frags didn't arrive:%d\n"), IPStatsMIB.dwReasmTimeout);
|
||||||
|
_tprintf(_T(" datagrams requiring reassembly:\t\t%d\n"), IPStatsMIB.dwReasmReqds);
|
||||||
|
_tprintf(_T(" successful reassemblies:\t\t%d\n"), IPStatsMIB.dwReasmOks);
|
||||||
|
_tprintf(_T(" failed reassemblies:\t\t\t%d\n"), IPStatsMIB.dwReasmFails);
|
||||||
|
_tprintf(_T(" successful fragmentations:\t\t%d\n"), IPStatsMIB.dwFragOks);
|
||||||
|
_tprintf(_T(" failed fragmentations:\t\t\t%d\n"), IPStatsMIB.dwFragFails);
|
||||||
|
_tprintf(_T(" datagrams fragmented:\t\t\t%d\n"), IPStatsMIB.dwFragCreates);
|
||||||
|
_tprintf(_T(" number of interfaces on computer:\t%d\n"), IPStatsMIB.dwNumIf);
|
||||||
|
_tprintf(_T(" number of IP address on computer:\t%d\n"), IPStatsMIB.dwNumAddr);
|
||||||
|
_tprintf(_T(" number of routes in routing table:\t%d\n"), IPStatsMIB.dwNumRoutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ShowNetworkParams()
|
||||||
|
{
|
||||||
|
FIXED_INFO* FixedInfo;
|
||||||
|
IP_ADDR_STRING* pIPAddr;
|
||||||
|
ULONG ulOutBufLen;
|
||||||
|
DWORD dwRetVal;
|
||||||
|
|
||||||
|
_tprintf(_T("Network Parameters\t\n"));
|
||||||
|
|
||||||
|
FixedInfo = (FIXED_INFO*)GlobalAlloc(GPTR, sizeof(FIXED_INFO));
|
||||||
|
ulOutBufLen = sizeof(FIXED_INFO);
|
||||||
|
if (ERROR_BUFFER_OVERFLOW == GetNetworkParams(FixedInfo, &ulOutBufLen)) {
|
||||||
|
GlobalFree(FixedInfo);
|
||||||
|
FixedInfo =(FIXED_INFO*)GlobalAlloc(GPTR, ulOutBufLen);
|
||||||
|
}
|
||||||
|
if (dwRetVal = GetNetworkParams(FixedInfo, &ulOutBufLen)) {
|
||||||
|
_tprintf(_T("Call to GetNetworkParams failed. Return Value: %08x\n"), dwRetVal);
|
||||||
|
} else {
|
||||||
|
printf(" Host Name: %s", FixedInfo->HostName);
|
||||||
|
printf("\n Domain Name: %s", FixedInfo->DomainName);
|
||||||
|
printf("\n DNS Servers:\t%s\n", FixedInfo->DnsServerList.IpAddress.String);
|
||||||
|
pIPAddr = FixedInfo->DnsServerList.Next;
|
||||||
|
while (pIPAddr) {
|
||||||
|
printf("\t\t\t%s\n", pIPAddr->IpAddress.String);
|
||||||
|
pIPAddr = pIPAddr->Next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ShowAdapterInfo()
|
||||||
|
{
|
||||||
|
IP_ADAPTER_INFO* pAdaptorInfo;
|
||||||
|
ULONG ulOutBufLen;
|
||||||
|
DWORD dwRetVal;
|
||||||
|
|
||||||
|
_tprintf(_T("\nAdaptor Information\t\n"));
|
||||||
|
pAdaptorInfo = (IP_ADAPTER_INFO*)GlobalAlloc(GPTR, sizeof(IP_ADAPTER_INFO));
|
||||||
|
ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
||||||
|
|
||||||
|
if (ERROR_BUFFER_OVERFLOW == GetAdaptersInfo(pAdaptorInfo, &ulOutBufLen)) {
|
||||||
|
GlobalFree(pAdaptorInfo);
|
||||||
|
pAdaptorInfo = (IP_ADAPTER_INFO*)GlobalAlloc(GPTR, ulOutBufLen);
|
||||||
|
}
|
||||||
|
if (dwRetVal = GetAdaptersInfo(pAdaptorInfo, &ulOutBufLen)) {
|
||||||
|
_tprintf(_T("Call to GetAdaptersInfo failed. Return Value: %08x\n"), dwRetVal);
|
||||||
|
} else {
|
||||||
|
while (pAdaptorInfo) {
|
||||||
|
printf(" AdapterName: %s\n", pAdaptorInfo->AdapterName);
|
||||||
|
printf(" Description: %s\n", pAdaptorInfo->Description);
|
||||||
|
pAdaptorInfo = pAdaptorInfo->Next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT idLength;
|
UINT idLength;
|
||||||
|
@ -52,23 +222,309 @@ void test_snmp(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maximum string lengths for ASCII ip address and port names
|
||||||
|
//
|
||||||
|
#define HOSTNAMELEN 256
|
||||||
|
#define PORTNAMELEN 256
|
||||||
|
#define ADDRESSLEN HOSTNAMELEN+PORTNAMELEN
|
||||||
|
|
||||||
void usage(void)
|
//
|
||||||
|
// Our option flags
|
||||||
|
//
|
||||||
|
#define FLAG_SHOW_ALL_ENDPOINTS 1
|
||||||
|
#define FLAG_SHOW_ETH_STATS 2
|
||||||
|
#define FLAG_SHOW_NUMBERS 3
|
||||||
|
#define FLAG_SHOW_PROT_CONNECTIONS 4
|
||||||
|
#define FLAG_SHOW_ROUTE_TABLE 5
|
||||||
|
#define FLAG_SHOW_PROT_STATS 6
|
||||||
|
#define FLAG_SHOW_INTERVAL 7
|
||||||
|
|
||||||
|
|
||||||
|
// 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[ANY_SIZE];
|
||||||
|
} 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[ANY_SIZE];
|
||||||
|
} MIB_UDPEXTABLE, *PMIB_UDPEXTABLE;
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// GetPortName
|
||||||
|
//
|
||||||
|
// Translate port numbers into their text equivalent if there is one
|
||||||
|
//
|
||||||
|
PCHAR
|
||||||
|
GetPortName(DWORD Flags, UINT port, PCHAR proto, PCHAR name, int namelen)
|
||||||
|
{
|
||||||
|
struct servent *psrvent;
|
||||||
|
|
||||||
|
if (Flags & FLAG_SHOW_NUMBERS) {
|
||||||
|
sprintf(name, "%d", htons((WORD)port));
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
// Try to translate to a name
|
||||||
|
if (psrvent = getservbyport(port, proto)) {
|
||||||
|
strcpy(name, psrvent->s_name );
|
||||||
|
} else {
|
||||||
|
sprintf(name, "%d", htons((WORD)port));
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// GetIpHostName
|
||||||
|
//
|
||||||
|
// Translate IP addresses into their name-resolved form if possible.
|
||||||
|
//
|
||||||
|
PCHAR
|
||||||
|
GetIpHostName(DWORD Flags, BOOL local, UINT ipaddr, PCHAR name, int namelen)
|
||||||
|
{
|
||||||
|
// struct hostent *phostent;
|
||||||
|
UINT nipaddr;
|
||||||
|
|
||||||
|
// Does the user want raw numbers?
|
||||||
|
nipaddr = htonl(ipaddr);
|
||||||
|
if (Flags & FLAG_SHOW_NUMBERS ) {
|
||||||
|
sprintf(name, "%d.%d.%d.%d",
|
||||||
|
(nipaddr >> 24) & 0xFF,
|
||||||
|
(nipaddr >> 16) & 0xFF,
|
||||||
|
(nipaddr >> 8) & 0xFF,
|
||||||
|
(nipaddr) & 0xFF);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
name[0] = _T('\0');
|
||||||
|
|
||||||
|
// Try to translate to a name
|
||||||
|
if (!ipaddr) {
|
||||||
|
if (!local) {
|
||||||
|
sprintf(name, "%d.%d.%d.%d",
|
||||||
|
(nipaddr >> 24) & 0xFF,
|
||||||
|
(nipaddr >> 16) & 0xFF,
|
||||||
|
(nipaddr >> 8) & 0xFF,
|
||||||
|
(nipaddr) & 0xFF);
|
||||||
|
} else {
|
||||||
|
//gethostname(name, namelen);
|
||||||
|
}
|
||||||
|
} else if (ipaddr == 0x0100007f) {
|
||||||
|
if (local) {
|
||||||
|
//gethostname(name, namelen);
|
||||||
|
} else {
|
||||||
|
strcpy(name, "localhost");
|
||||||
|
}
|
||||||
|
// } else if (phostent = gethostbyaddr((char*)&ipaddr, sizeof(nipaddr), PF_INET)) {
|
||||||
|
// strcpy(name, phostent->h_name);
|
||||||
|
} else {
|
||||||
|
#if 0
|
||||||
|
int i1, i2, i3, i4;
|
||||||
|
|
||||||
|
i1 = (nipaddr >> 24) & 0x000000FF;
|
||||||
|
i2 = (nipaddr >> 16) & 0x000000FF;
|
||||||
|
i3 = (nipaddr >> 8) & 0x000000FF;
|
||||||
|
i4 = (nipaddr) & 0x000000FF;
|
||||||
|
|
||||||
|
i1 = 10;
|
||||||
|
i2 = 20;
|
||||||
|
i3 = 30;
|
||||||
|
i4 = 40;
|
||||||
|
|
||||||
|
sprintf(name, "%d.%d.%d.%d", i1,i2,i3,i4);
|
||||||
|
#else
|
||||||
|
sprintf(name, "%d.%d.%d.%d",
|
||||||
|
((nipaddr >> 24) & 0x000000FF),
|
||||||
|
((nipaddr >> 16) & 0x000000FF),
|
||||||
|
((nipaddr >> 8) & 0x000000FF),
|
||||||
|
((nipaddr) & 0x000000FF));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOLEAN usage(void)
|
||||||
{
|
{
|
||||||
TCHAR buffer[MAX_RESLEN];
|
TCHAR buffer[MAX_RESLEN];
|
||||||
|
|
||||||
int length = LoadString(GetModuleHandle(NULL), IDS_APP_USAGE, buffer, sizeof(buffer)/sizeof(buffer[0]));
|
int length = LoadString(GetModuleHandle(NULL), IDS_APP_USAGE, buffer, sizeof(buffer)/sizeof(buffer[0]));
|
||||||
_fputts(buffer, stderr);
|
_fputts(buffer, stderr);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// GetOptions
|
||||||
|
//
|
||||||
|
// Parses the command line arguments.
|
||||||
|
//
|
||||||
|
BOOLEAN
|
||||||
|
GetOptions(int argc, char *argv[], PDWORD pFlags)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
BOOLEAN skipArgument;
|
||||||
|
|
||||||
|
*pFlags = 0;
|
||||||
|
for (i = 1; i < argc; i++) {
|
||||||
|
skipArgument = FALSE;
|
||||||
|
switch (argv[i][0]) {
|
||||||
|
case '-':
|
||||||
|
case '/':
|
||||||
|
j = 1;
|
||||||
|
while (argv[i][j]) {
|
||||||
|
switch (toupper(argv[i][j])) {
|
||||||
|
case 'A':
|
||||||
|
*pFlags |= FLAG_SHOW_ALL_ENDPOINTS;
|
||||||
|
break;
|
||||||
|
case 'E':
|
||||||
|
*pFlags |= FLAG_SHOW_ETH_STATS;
|
||||||
|
break;
|
||||||
|
case 'N':
|
||||||
|
*pFlags |= FLAG_SHOW_NUMBERS;
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
*pFlags |= FLAG_SHOW_PROT_CONNECTIONS;
|
||||||
|
break;
|
||||||
|
case 'R':
|
||||||
|
*pFlags |= FLAG_SHOW_ROUTE_TABLE;
|
||||||
|
break;
|
||||||
|
case 'S':
|
||||||
|
*pFlags |= FLAG_SHOW_PROT_STATS;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
if (skipArgument) break;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
*pFlags |= FLAG_SHOW_INTERVAL;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
|
||||||
|
CHAR localname[HOSTNAMELEN], remotename[HOSTNAMELEN];
|
||||||
|
CHAR remoteport[PORTNAMELEN], localport[PORTNAMELEN];
|
||||||
|
CHAR localaddr[ADDRESSLEN], remoteaddr[ADDRESSLEN];
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
PMIB_TCPTABLE tcpTable;
|
||||||
|
PMIB_UDPTABLE udpTable;
|
||||||
|
DWORD error, dwSize;
|
||||||
|
DWORD i, flags;
|
||||||
|
|
||||||
|
// Get options
|
||||||
|
if (!GetOptions(argc, argv, &flags)) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
// Get the table of TCP endpoints
|
||||||
|
dwSize = 0;
|
||||||
|
error = GetTcpTable(NULL, &dwSize, TRUE);
|
||||||
|
if (error != ERROR_INSUFFICIENT_BUFFER) {
|
||||||
|
printf("Failed to snapshot TCP endpoints.\n");
|
||||||
|
PrintError(error);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
tcpTable = (PMIB_TCPTABLE)malloc(dwSize);
|
||||||
|
error = GetTcpTable(tcpTable, &dwSize, TRUE );
|
||||||
|
if (error) {
|
||||||
|
printf("Failed to snapshot TCP endpoints table.\n");
|
||||||
|
PrintError(error);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the table of UDP endpoints
|
||||||
|
dwSize = 0;
|
||||||
|
error = GetUdpTable(NULL, &dwSize, TRUE);
|
||||||
|
if (error != ERROR_INSUFFICIENT_BUFFER) {
|
||||||
|
printf("Failed to snapshot UDP endpoints.\n");
|
||||||
|
PrintError(error);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
udpTable = (PMIB_UDPTABLE)malloc(dwSize);
|
||||||
|
error = GetUdpTable(udpTable, &dwSize, TRUE);
|
||||||
|
if (error) {
|
||||||
|
printf("Failed to snapshot UDP endpoints table.\n");
|
||||||
|
PrintError(error);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dump the TCP table
|
||||||
|
for (i = 0; i < tcpTable->dwNumEntries; i++) {
|
||||||
|
if (flags & FLAG_SHOW_ALL_ENDPOINTS ||
|
||||||
|
tcpTable->table[i].dwState == MIB_TCP_STATE_ESTAB) {
|
||||||
|
sprintf(localaddr, "%s:%s",
|
||||||
|
GetIpHostName(flags, TRUE, tcpTable->table[i].dwLocalAddr, localname, HOSTNAMELEN),
|
||||||
|
GetPortName(flags, tcpTable->table[i].dwLocalPort, "tcp", localport, PORTNAMELEN));
|
||||||
|
sprintf(remoteaddr, "%s:%s",
|
||||||
|
GetIpHostName(flags, FALSE, tcpTable->table[i].dwRemoteAddr, remotename, HOSTNAMELEN),
|
||||||
|
tcpTable->table[i].dwRemoteAddr ?
|
||||||
|
GetPortName(flags, tcpTable->table[i].dwRemotePort, "tcp", remoteport, PORTNAMELEN):
|
||||||
|
"0");
|
||||||
|
printf("%4s\tState: %s\n", "[TCP]", TcpState[tcpTable->table[i].dwState]);
|
||||||
|
printf(" Local: %s\n Remote: %s\n", localaddr, remoteaddr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Dump the UDP table
|
||||||
|
if (flags & FLAG_SHOW_ALL_ENDPOINTS) {
|
||||||
|
for (i = 0; i < udpTable->dwNumEntries; i++) {
|
||||||
|
sprintf(localaddr, "%s:%s",
|
||||||
|
GetIpHostName(flags, TRUE, udpTable->table[i].dwLocalAddr, localname, HOSTNAMELEN),
|
||||||
|
GetPortName(flags, udpTable->table[i].dwLocalPort, "tcp", localport, PORTNAMELEN));
|
||||||
|
printf("%4s", "[UDP]");
|
||||||
|
printf(" Local: %s\n Remote: %s\n", localaddr, "*.*.*.*:*");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
usage();
|
usage();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_tprintf(_T("\nActive Connections\n\n")\
|
_tprintf(_T("\nActive Connections\n\n")\
|
||||||
_T(" Proto Local Address Foreign Address State\n\n"));
|
_T(" Proto Local Address Foreign Address State\n\n"));
|
||||||
test_snmp();
|
test_snmp();
|
||||||
|
|
||||||
|
ShowTcpStatistics();
|
||||||
|
ShowUdpStatistics();
|
||||||
|
ShowIpStatistics();
|
||||||
|
ShowNetworkParams();
|
||||||
|
ShowAdapterInfo();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: niclist.c,v 1.1 2002/07/09 19:34:41 robd Exp $
|
/* $Id: niclist.c,v 1.2 2002/09/24 14:26:47 robd Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS packet driver interface list utility
|
* PROJECT: ReactOS packet driver interface list utility
|
||||||
|
@ -18,6 +18,8 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "trace.h"
|
||||||
|
|
||||||
|
|
||||||
#define MAX_ADAPTERS 10
|
#define MAX_ADAPTERS 10
|
||||||
#define NIC_BUFFER_SIZE 2048
|
#define NIC_BUFFER_SIZE 2048
|
||||||
|
@ -34,6 +36,7 @@ NIC_INFO_NT nic_info[MAX_ADAPTERS];
|
||||||
|
|
||||||
// pointer to exported function in winpcap library
|
// pointer to exported function in winpcap library
|
||||||
BOOLEAN (*PacketGetAdapterNames)(PTSTR, PULONG) = NULL;
|
BOOLEAN (*PacketGetAdapterNames)(PTSTR, PULONG) = NULL;
|
||||||
|
PCHAR (*PacketGetVersion)(VOID) = NULL;
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -45,17 +48,29 @@ int main(int argc, char **argv)
|
||||||
int nAdapterCount;
|
int nAdapterCount;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
char* PacketLibraryVersion;
|
||||||
|
|
||||||
|
|
||||||
// Attemp to load the WinPCap dynamic link library
|
// Attemp to load the WinPCap dynamic link library
|
||||||
HINSTANCE hPacket = LoadLibrary("PACKET.DLL");
|
HINSTANCE hPacket = LoadLibrary("PACKET.DLL");
|
||||||
if (hPacket) {
|
if (hPacket) {
|
||||||
PacketGetAdapterNames = (BOOLEAN (*)(PTSTR, PULONG))GetProcAddress(hPacket, "PacketGetAdapterNames");
|
PacketGetAdapterNames = (BOOLEAN (*)(PTSTR, PULONG))GetProcAddress(hPacket, "PacketGetAdapterNames");
|
||||||
|
PacketGetVersion = (BOOLEAN (*)(PTSTR, PULONG))GetProcAddress(hPacket, "PacketGetVersion");
|
||||||
} else {
|
} else {
|
||||||
printf("Could not load WinPCap driver! for more information goto:\n");
|
printf("Could not load WinPCap driver! for more information goto:\n");
|
||||||
printf ("http://netgroup-serv.polito.it/winpcap\n");
|
printf ("http://netgroup-serv.polito.it/winpcap\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
PacketGetAdapterNames(AdapterInfo, &AdapterLength);
|
if (!(PacketLibraryVersion = PacketGetVersion())) {
|
||||||
|
printf("ERROR: Could not get Packet DLL Version string.\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
printf("Packet Library Version: %s\n", PacketLibraryVersion);
|
||||||
|
|
||||||
|
if (!PacketGetAdapterNames(AdapterInfo, &AdapterLength)) {
|
||||||
|
printf("ERROR: Could not get Packet Adaptor Names.\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
wstrName = (LPWSTR)AdapterInfo;
|
wstrName = (LPWSTR)AdapterInfo;
|
||||||
|
|
||||||
// Enumerate all the adapters names found...
|
// Enumerate all the adapters names found...
|
||||||
|
@ -64,9 +79,16 @@ int main(int argc, char **argv)
|
||||||
nic_info[nAdapterCount].wstrName = wstrName;
|
nic_info[nAdapterCount].wstrName = wstrName;
|
||||||
wstrName += lstrlenW(wstrName) + 1;
|
wstrName += lstrlenW(wstrName) + 1;
|
||||||
nAdapterCount++;
|
nAdapterCount++;
|
||||||
|
if (nAdapterCount > 9) break;
|
||||||
}
|
}
|
||||||
strDesc = (LPSTR)++wstrName;
|
strDesc = (LPSTR)++wstrName;
|
||||||
|
|
||||||
|
if (!nAdapterCount) {
|
||||||
|
printf("No Packet Adaptors found (%d)\n", AdapterLength);
|
||||||
|
} else {
|
||||||
|
printf("Adaptor count: %d\n", nAdapterCount);
|
||||||
|
}
|
||||||
|
|
||||||
// And obtain the adapter description strings....
|
// And obtain the adapter description strings....
|
||||||
for (i = 0; i < nAdapterCount; i++) {
|
for (i = 0; i < nAdapterCount; i++) {
|
||||||
nic_info[i].strDesc = strDesc;
|
nic_info[i].strDesc = strDesc;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue