📄 tdiq.c
字号:
/////////////////////////////////////////////////////////////////////////////
//// INCLUDE FILES
#include <windows.h>
#include <stdio.h>
#include <winsock.h>
#include <crtdbg.h>
#include <winioctl.h> // PCAUSA
#include "tdiinfo.h" // from recent NT4DDK "\ddk\src\network\inc\tdiinfo.h"
#include "smpletcp.h" // from recent NT4DDK "\ddk\src\network\wshsmple\smpletcp.h"
#include "TDIQHelp.h"
// Copyright And Configuration Management ----------------------------------
//
// TDI Query (TDIQ) Test Tool
// For
// Windows 95 And Windows NT
//
// MAIN Entry Point - TDIQ.c
//
// Copyright (c) 2000, Printing Communications Associates, Inc.
//
// Thomas F. Divine
// 4201 Brunswick Court
// Smyrna, Georgia 30080 USA
// (770) 432-4580
// tdivine@pcausa.com
//
// End ---------------------------------------------------------------------
#define TDIQ_VERSION "1.00.00.01"
#define SHOW_IPCONFIG 0x01
#define SHOW_IPROUTE 0x02
#define SHOW_IPSTAT 0x04
#define SHOW_ATTABLE 0x08
ULONG g_ShowFlags = 0;
//
// An Unsuccessful Experment...
//
UCHAR g_AtTable[ 2048 ];
#pragma pack(push,1) // x86, MS compiler; MIPS, MIPS compiler
typedef
struct _ATTableEntry
{
ULONG atIfIndex; // Interface Index
ULONG ate_type; // Interface Type??? 6 -> Ethernet...
ULONG ate_3;
ULONG ate_4;
ULONG atNetAddress; // IP Address
ULONG ate_6; // So far always 0x00000003
}
ATTableEntry, *PATTableEntry;
#pragma pack(pop) // x86, MS compiler; MIPS, MIPS compiler
extern int
TDIQ_GetAtTable(
PUCHAR pQueryBuffer,
PULONG pQueryBufferSize
);
VOID
DisplayATTableEntry(
PUCHAR pQueryBuffer,
ULONG nQueryBufferSize
)
{
DWORD nEntryCount;
PATTableEntry pATTableEntry;
struct in_addr inadDest;
char szDestIp[128];
int i;
if( !nQueryBufferSize )
{
printf( "AT Table Is Empty\n" );
return;
}
nEntryCount = nQueryBufferSize/sizeof( ATTableEntry );
pATTableEntry = (PATTableEntry )pQueryBuffer;
for( i = 0; i < nEntryCount; ++i )
{
inadDest.s_addr = pATTableEntry->atNetAddress;
strcpy(szDestIp, inet_ntoa(inadDest));
printf( "%d %d 0x%8.8X 0x%8.8X %s 0x%8.8X\n",
pATTableEntry->atIfIndex,
pATTableEntry->ate_type,
pATTableEntry->ate_3,
pATTableEntry->ate_4,
szDestIp,
pATTableEntry->ate_6
);
++pATTableEntry;
}
}
VOID
TDIQ_DisplayIPRouteTable(
PUCHAR pIPRouteTableBuffer,
IPSNMPInfo *pIPSNMPInfo,
IPAddrEntry *pIPAddrTable
)
{
int i, j, result;
IPRouteEntry *pIPRouteEntry;
printf( "==========================================================================\n");
printf( "Interface List:\n" );
for( i = 0; i < pIPSNMPInfo->ipsi_numif; i++ )
{
ULONG IFEntryBufferSize = sizeof( IFEntry ) + MAX_IFDESCR_LEN;
UCHAR IFEntryBuffer[ sizeof( IFEntry ) + MAX_IFDESCR_LEN ];
IFEntry *pIFEntry = (IFEntry * )IFEntryBuffer;
//
// Get IFEntry For Address
//
result = TDIQ_GetIFEntryForIFIndex(
pIPAddrTable[pIPSNMPInfo->ipsi_numif - 1 - i].iae_index,
(PUCHAR )pIFEntry,
&IFEntryBufferSize
);
if( result )
{
fprintf(stderr, "%s(%d) TdiQueryDeviceControl failed (%ld)\n", __FILE__, __LINE__,
WSAGetLastError());
continue;
}
printf( "0x%x ...",
0xFF & pIPAddrTable[pIPSNMPInfo->ipsi_numif - 1 - i].iae_index
);
//
// Display Physical Address
//
for( j = 0; j < pIFEntry->if_physaddrlen; ++j )
{
printf( "%2.2X", pIFEntry->if_physaddr[j] );
if( j < pIFEntry->if_physaddrlen - 1 )
{
printf("-" );
}
}
while( j++ < MAX_PHYSADDR_SIZE )
{
printf( "..." );
}
if( pIFEntry->if_physaddrlen )
{
printf( "." ); // Asthetics...
}
printf( " %*.*s\n",
pIFEntry->if_descrlen,
pIFEntry->if_descrlen,
pIFEntry->if_descr
);
}
printf( "==========================================================================\n");
printf( "==========================================================================\n");
printf( "Active Routes:\n" );
printf( "Network Address Netmask Gateway Address Interface Metric\n");
pIPRouteEntry = (IPRouteEntry * )pIPRouteTableBuffer;
for( i = 0; i < pIPSNMPInfo->ipsi_numroutes; i++ )
{
IPAddrEntry *pIPAddrEntry = NULL;
struct in_addr inadDest;
struct in_addr inadMask;
struct in_addr inadGateway;
struct in_addr inadInterface;
char szDestIp[128];
char szMaskIp[128];
char szGatewayIp[128];
char szInterfaceIp[128];
for( j = 0; j < pIPSNMPInfo->ipsi_numaddr; j++ )
{
if( pIPAddrTable[j].iae_index == pIPRouteEntry->ire_index )
{
pIPAddrEntry = &pIPAddrTable[j];
break;
}
}
if( !pIPAddrEntry )
{
//
// Move To Next Route
//
pIPRouteEntry = TDIQ_GetNextIPRouteTableEntry( pIPRouteEntry );
continue;
}
inadDest.s_addr = pIPRouteEntry->ire_dest;
inadMask.s_addr = pIPRouteEntry->ire_mask;
inadGateway.s_addr = pIPRouteEntry->ire_nexthop;
inadInterface.s_addr = pIPAddrEntry->iae_addr;
strcpy(szDestIp, inet_ntoa(inadDest));
strcpy(szMaskIp, inet_ntoa(inadMask));
strcpy(szGatewayIp, inet_ntoa(inadGateway));
strcpy(szInterfaceIp, inet_ntoa(inadInterface));
printf("%15s %16s %16s %16s %7d\n",
szDestIp,
szMaskIp,
szGatewayIp,
szInterfaceIp,
pIPRouteEntry->ire_metric1
);
//
// Move To Next Route
//
pIPRouteEntry = TDIQ_GetNextIPRouteTableEntry( pIPRouteEntry );
}
printf( "==========================================================================\n");
//
// Newline After Displaying Route Information
//
printf( "\n" );
}
VOID
TDIQ_DisplayIPAddrTable(
PUCHAR pIPRouteTableBuffer,
IPSNMPInfo *pIPSNMPInfo,
IPAddrEntry *pIPAddrTable
)
{
int i, j, result;
printf( "IP Configuration:\n" );
for( i = 0; i < pIPSNMPInfo->ipsi_numaddr; i++ )
{
ULONG IFEntryBufferSize;
UCHAR IFEntryBuffer[ sizeof( IFEntry ) + MAX_IFDESCR_LEN ];
IFEntry *pIFEntry;
ULONG InterfaceInfoSize;
UCHAR InterfaceInfo[ sizeof( IPInterfaceInfo ) + MAX_PHYSADDR_SIZE ];
IPInterfaceInfo *pIPInterfaceInfo;
struct in_addr inaddrScratch;
IPRouteEntry *pIPRouteTableEntry;
IPRouteEntry *pIPRouteEntry;
//
// Get IPInterfaceInfo For Address
//
InterfaceInfoSize = sizeof( InterfaceInfo );
pIPInterfaceInfo = (IPInterfaceInfo * )InterfaceInfo;
result = TDIQ_GetIPInterfaceInfoForAddr(
pIPAddrTable[i].iae_addr,
(PUCHAR )pIPInterfaceInfo,
&InterfaceInfoSize
);
if( result )
{
pIPInterfaceInfo = NULL;
}
//
// Get IFEntry For Address
//
IFEntryBufferSize = sizeof( IFEntryBuffer );
pIFEntry = (IFEntry * )IFEntryBuffer;
result = TDIQ_GetIFEntryForIFIndex(
pIPAddrTable[i].iae_index,
(PUCHAR )pIFEntry,
&IFEntryBufferSize
);
if( result )
{
fprintf(stderr, "%s(%d) TdiQueryDeviceControl failed (%ld)\n", __FILE__, __LINE__,
WSAGetLastError());
continue;
}
//
// Display Adapter Banner
//
switch( pIFEntry->if_type )
{
case IF_TYPE_OTHER: // MIB_IF_TYPE_OTHER
printf( "OTHER Type Adapter:\n\n" );
break;
case IF_TYPE_ETHERNET: // MIB_IF_TYPE_ETHERNET
printf( "Ethernet Adapter:\n\n" );
break;
case IF_TYPE_TOKENRING: // MIB_IF_TYPE_TOKENRING
printf( "Tokenring Adapter:\n\n" );
break;
case IF_TYPE_FDDI: // MIB_IF_TYPE_FDDI
printf( "FDDI Adapter:\n\n" );
break;
case IF_TYPE_PPP: // MIB_IF_TYPE_PPP
printf( "PPP Adapter:\n\n" );
break;
case IF_TYPE_LOOPBACK: // MIB_IF_TYPE_LOOPBACK
printf( "Loopback Adapter:\n\n" );
break;
case IF_TYPE_SLIP: // MIB_IF_TYPE_SLIP
printf( "SLIP Adapter:\n\n" );
break;
default:
printf( "UNKNOWN Adapter Type:\n\n" );
break;
}
//
// Display Description
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -