📄 tdiq.c
字号:
//
printf( " Description..........: %*.*s\n",
pIFEntry->if_descrlen,
pIFEntry->if_descrlen,
pIFEntry->if_descr
);
//
// Display Physical Address
//
printf( " Physical Address.....: " );
for( j = 0; j < pIFEntry->if_physaddrlen; ++j )
{
printf( "%2.2X", pIFEntry->if_physaddr[j] );
if( j < pIFEntry->if_physaddrlen - 1 )
{
printf("-" );
}
}
printf( "\n" );
//
// Display IP Address
//
inaddrScratch.s_addr = pIPAddrTable[i].iae_addr;
printf( " IP Address...........: %s\n", inet_ntoa(inaddrScratch) );
//
// Display Subnet Mask
//
inaddrScratch.s_addr = pIPAddrTable[i].iae_mask;
printf( " Subnet Mask..........: %s\n", inet_ntoa(inaddrScratch) );
//
// Display Gateway
//
pIPRouteTableEntry = (IPRouteEntry * )pIPRouteTableBuffer;
pIPRouteEntry = NULL;
if( pIPInterfaceInfo )
{
for( j = 0; j < pIPSNMPInfo->ipsi_numroutes; j++ )
{
if( pIPAddrTable[i].iae_index == pIPRouteTableEntry->ire_index )
{
if( pIPRouteTableEntry->ire_dest == 0 )
{
pIPRouteEntry = pIPRouteTableEntry;
break;
}
}
//
// Move To Next Route
//
pIPRouteTableEntry = TDIQ_GetNextIPRouteTableEntry( pIPRouteTableEntry );
}
}
if( pIPRouteEntry )
{
inaddrScratch.s_addr = pIPRouteEntry->ire_nexthop;
printf( " Default Gateway......: %s\n", inet_ntoa(inaddrScratch) );
}
else
{
inaddrScratch.s_addr = pIPAddrTable[i].iae_addr;
printf( " Default Gateway......: %s\n", inet_ntoa(inaddrScratch) );
}
//
// Display IP Interface Speed
//
if( pIPInterfaceInfo )
{
printf( " Speed................: %d bits/second\n", pIPInterfaceInfo->iii_speed );
}
else
{
printf( " Speed................: Not Available\n" );
}
//
// Display MTU
//
if( pIPInterfaceInfo )
{
printf( " MTU (Local Nodes)....: %d bytes\n", pIPInterfaceInfo->iii_mtu );
}
else
{
printf( " MTU (Local Nodes)....: Not Available\n" );
}
//
// Newline After Displaying Each Adapter's Information
//
printf( "\n" );
}
}
VOID
TDIQ_DisplayIPStats( IPSNMPInfo *pIPSNMPInfo )
{
printf( "IP Statistics:\n" );
printf( " dwForwarding = %d\n", pIPSNMPInfo->ipsi_forwarding );
printf( " dwDefaultTTL = %d\n", pIPSNMPInfo->ipsi_defaultttl );
printf( " dwInReceives = %d\n", pIPSNMPInfo->ipsi_inreceives );
printf( " dwInHdrErrors = %d\n", pIPSNMPInfo->ipsi_inhdrerrors );
printf( " dwInAddrErrors = %d\n", pIPSNMPInfo->ipsi_inaddrerrors );
printf( " dwForwDatagrams = %d\n", pIPSNMPInfo->ipsi_forwdatagrams );
printf( " dwInUnknownProtos = %d\n", pIPSNMPInfo->ipsi_inunknownprotos );
printf( " dwInDiscards = %d\n", pIPSNMPInfo->ipsi_indiscards );
printf( " dwInDelivers = %d\n", pIPSNMPInfo->ipsi_indelivers );
printf( " dwOutRequests = %d\n", pIPSNMPInfo->ipsi_outrequests );
printf( " dwRoutingDiscards = %d\n", pIPSNMPInfo->ipsi_routingdiscards );
printf( " dwOutDiscards = %d\n", pIPSNMPInfo->ipsi_outdiscards );
printf( " dwOutNoRoutes = %d\n", pIPSNMPInfo->ipsi_outnoroutes );
printf( " dwReasmTimeout = %d\n", pIPSNMPInfo->ipsi_reasmtimeout );
printf( " dwReasmReqds = %d\n", pIPSNMPInfo->ipsi_reasmreqds );
printf( " dwReasmOks = %d\n", pIPSNMPInfo->ipsi_reasmoks );
printf( " dwReasmFails = %d\n", pIPSNMPInfo->ipsi_reasmfails );
printf( " dwFragOks = %d\n", pIPSNMPInfo->ipsi_fragoks );
printf( " dwFragFails = %d\n", pIPSNMPInfo->ipsi_fragfails );
printf( " dwFragCreates = %d\n", pIPSNMPInfo->ipsi_fragcreates );
printf( " dwNumIf = %d\n", pIPSNMPInfo->ipsi_numif );
printf( " dwNumAddr = %d\n", pIPSNMPInfo->ipsi_numaddr );
printf( " dwNumRoutes = %d\n", pIPSNMPInfo->ipsi_numroutes );
//
// Newline After Displaying Statistics
//
printf( "\n" );
}
//
// Usage Message
//
char Usage[] = "\
Usage: tdiq [-options]\n\
Options:\n\
-ipconfig - Display IP configuration information\n\
-iproute - Display IP route information\n\
-ipstat - Display IP statistics information\n\
-all - Display all information\n\
";
int main(int argc, char **argv)
{
int result = ERROR_SUCCESS;
BOOL bResult;
IPSNMPInfo ipSnmpInfo;
DWORD ipSnmpInfoSize;
DWORD ipAddrTableSize;
IPAddrEntry *pIPAddrTable = NULL;
DWORD ipRouteTableBufSize;
PUCHAR pIPRouteTableBuffer = NULL;
DWORD AtInfoSize;
if( argc < 2 )
{
fprintf(stderr,Usage);
exit( 0 );
}
while( *++argv )
{
char *s = *argv;
if( *s == '-' || *s == '/' )
{
++s;
}
if( !stricmp( s, "ipconfig" ) )
{
g_ShowFlags |= SHOW_IPCONFIG;
}
else if( !stricmp( s, "iproute" ) )
{
g_ShowFlags |= SHOW_IPROUTE;
}
else if( !stricmp( s, "ipstat" ) )
{
g_ShowFlags |= SHOW_IPSTAT;
}
else if( !stricmp( s, "xlat" ) )
{
g_ShowFlags |= SHOW_ATTABLE;
}
else if( !stricmp( s, "all" ) )
{
g_ShowFlags |= SHOW_IPCONFIG;
g_ShowFlags |= SHOW_IPROUTE;
g_ShowFlags |= SHOW_IPSTAT;
}
}
if( !g_ShowFlags )
{
fprintf(stderr,Usage);
exit( 0 );
}
result = TDIQ_Startup();
if( result )
{
fprintf(stderr, "TDIQ_Startup failed (%ld)\n", result);
return EXIT_FAILURE;
}
printf( "TDI Query (TDIQ) Test Tool for Windows %s - V%s\n",
TDIQ_IsWindows95() ? "95" : "NT",
TDIQ_VERSION
);
printf( "Copyright (c) 2000 Printing Communications Assoc., Inc (PCAUSA)\n\n" );
//
// Confirm That TCP/IP Is Installed
//
bResult = TDIQ_IsIPInstalled();
if( !bResult )
{
fprintf(stderr, "%s(%d) IP Not Installed\n", __FILE__, __LINE__ );
TDIQ_Cleanup();
return EXIT_FAILURE;
}
//get ip snmp info
ipSnmpInfoSize = sizeof(ipSnmpInfo);
result = TDIQ_GetIPSNMPInfo( &ipSnmpInfo, &ipSnmpInfoSize );
if (result)
{
fprintf(stderr, "%s(%d) TdiQueryDeviceControl failed (%ld)\n", __FILE__, __LINE__,
WSAGetLastError());
TDIQ_Cleanup();
return EXIT_FAILURE;
}
//
// Get IP Address Table
//
ipAddrTableSize = sizeof(IPAddrEntry) * ipSnmpInfo.ipsi_numaddr;
pIPAddrTable = (IPAddrEntry *)calloc(ipAddrTableSize, 1);
result = TDIQ_GetIPAddrTable(
(PUCHAR )pIPAddrTable,
&ipAddrTableSize
);
if (result)
{
fprintf(stderr, "%s(%d) TdiQueryDeviceControl failed (%ld)\n", __FILE__, __LINE__,
WSAGetLastError());
TDIQ_Cleanup();
return EXIT_FAILURE;
}
//
// Get IP Route Table
//
ipRouteTableBufSize = sizeof(IPRouteEntry) * ipSnmpInfo.ipsi_numroutes;
pIPRouteTableBuffer = (PUCHAR )calloc(ipRouteTableBufSize, 1);
result = TDIQ_GetIPRouteTable(
pIPRouteTableBuffer,
&ipRouteTableBufSize
);
if (result)
{
fprintf(stderr, "%s(%d) TdiQueryDeviceControl failed (%ld)\n", __FILE__, __LINE__,
WSAGetLastError());
TDIQ_Cleanup();
return EXIT_FAILURE;
}
//
// Display IP Address Table
//
if( g_ShowFlags & SHOW_IPCONFIG )
{
TDIQ_DisplayIPAddrTable( pIPRouteTableBuffer, &ipSnmpInfo, pIPAddrTable );
}
//
// Display Route Table
//
if( g_ShowFlags & SHOW_IPROUTE )
{
TDIQ_DisplayIPRouteTable( pIPRouteTableBuffer, &ipSnmpInfo, pIPAddrTable );
}
//
// Display IP Statistics
//
if( g_ShowFlags & SHOW_IPSTAT )
{
TDIQ_DisplayIPStats( &ipSnmpInfo );
}
if( g_ShowFlags & SHOW_ATTABLE )
{
//get address translation table
AtInfoSize = sizeof(g_AtTable);
result = TDIQ_GetAtTable( g_AtTable, &AtInfoSize );
if (result)
{
fprintf(stderr, "%s(%d) TdiQueryDeviceControl failed (%ld)\n", __FILE__, __LINE__,
WSAGetLastError());
AtInfoSize = 0;
}
else
{
DisplayATTableEntry( g_AtTable, AtInfoSize );
}
}
TDIQ_Cleanup();
return( EXIT_SUCCESS );
}
//end of code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -