2004-02-25 07:41:50 +00:00
|
|
|
/* Copyright (C) 2003 Art Yerkes
|
|
|
|
* A reimplementation of ifenum.c by Juan Lang
|
2004-02-15 07:17:00 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-10-27 10:34:16 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-02-15 07:17:00 +00:00
|
|
|
*
|
2004-02-25 07:41:50 +00:00
|
|
|
* This file is implemented on the IOCTL_TCP_QUERY_INFORMATION_EX ioctl on
|
|
|
|
* tcpip.sys
|
2004-02-15 07:17:00 +00:00
|
|
|
*/
|
|
|
|
|
2004-02-25 07:41:50 +00:00
|
|
|
#include "iphlpapi_private.h"
|
2004-02-15 07:17:00 +00:00
|
|
|
|
2007-07-26 15:13:36 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
|
|
|
|
|
2004-02-15 07:17:00 +00:00
|
|
|
#ifndef TCPS_ESTABLISHED
|
|
|
|
# define TCPS_ESTABLISHED TCP_ESTABLISHED
|
|
|
|
#endif
|
|
|
|
#ifndef TCPS_SYN_SENT
|
|
|
|
# define TCPS_SYN_SENT TCP_SYN_SENT
|
|
|
|
#endif
|
|
|
|
#ifndef TCPS_SYN_RECEIVED
|
|
|
|
# define TCPS_SYN_RECEIVED TCP_SYN_RECV
|
|
|
|
#endif
|
|
|
|
#ifndef TCPS_FIN_WAIT_1
|
|
|
|
# define TCPS_FIN_WAIT_1 TCP_FIN_WAIT1
|
|
|
|
#endif
|
|
|
|
#ifndef TCPS_FIN_WAIT_2
|
|
|
|
# define TCPS_FIN_WAIT_2 TCP_FIN_WAIT2
|
|
|
|
#endif
|
|
|
|
#ifndef TCPS_TIME_WAIT
|
|
|
|
# define TCPS_TIME_WAIT TCP_TIME_WAIT
|
|
|
|
#endif
|
|
|
|
#ifndef TCPS_CLOSED
|
|
|
|
# define TCPS_CLOSED TCP_CLOSE
|
|
|
|
#endif
|
|
|
|
#ifndef TCPS_CLOSE_WAIT
|
|
|
|
# define TCPS_CLOSE_WAIT TCP_CLOSE_WAIT
|
|
|
|
#endif
|
|
|
|
#ifndef TCPS_LAST_ACK
|
|
|
|
# define TCPS_LAST_ACK TCP_LAST_ACK
|
|
|
|
#endif
|
|
|
|
#ifndef TCPS_LISTEN
|
|
|
|
# define TCPS_LISTEN TCP_LISTEN
|
|
|
|
#endif
|
|
|
|
#ifndef TCPS_CLOSING
|
|
|
|
# define TCPS_CLOSING TCP_CLOSING
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BOOL isIpEntity( HANDLE tcpFile, TDIEntityID *ent ) {
|
2009-10-09 02:40:38 +00:00
|
|
|
return (ent->tei_entity == CL_NL_ENTITY ||
|
|
|
|
ent->tei_entity == CO_NL_ENTITY);
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS getNthIpEntity( HANDLE tcpFile, DWORD index, TDIEntityID *ent ) {
|
|
|
|
DWORD numEntities = 0;
|
|
|
|
DWORD numRoutes = 0;
|
|
|
|
TDIEntityID *entitySet = 0;
|
|
|
|
NTSTATUS status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities );
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if( !NT_SUCCESS(status) )
|
2004-02-25 20:29:15 +00:00
|
|
|
return status;
|
2004-02-15 07:17:00 +00:00
|
|
|
|
|
|
|
for( i = 0; i < numEntities; i++ ) {
|
2004-02-25 20:29:15 +00:00
|
|
|
if( isIpEntity( tcpFile, &entitySet[i] ) ) {
|
2007-07-26 15:13:36 +00:00
|
|
|
TRACE("Entity %d is an IP Entity\n", i);
|
2004-02-25 20:29:15 +00:00
|
|
|
if( numRoutes == index ) break;
|
|
|
|
else numRoutes++;
|
|
|
|
}
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( numRoutes == index && i < numEntities ) {
|
2007-10-19 23:21:45 +00:00
|
|
|
TRACE("Index %d is entity #%d - %04x:%08x\n", index, i,
|
2004-02-25 20:29:15 +00:00
|
|
|
entitySet[i].tei_entity, entitySet[i].tei_instance );
|
|
|
|
memcpy( ent, &entitySet[i], sizeof(*ent) );
|
|
|
|
tdiFreeThingSet( entitySet );
|
|
|
|
return STATUS_SUCCESS;
|
2004-02-15 07:17:00 +00:00
|
|
|
} else {
|
2004-02-25 20:29:15 +00:00
|
|
|
tdiFreeThingSet( entitySet );
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS tdiGetMibForIpEntity
|
|
|
|
( HANDLE tcpFile, TDIEntityID *ent, IPSNMPInfo *entry ) {
|
|
|
|
TCP_REQUEST_QUERY_INFORMATION_EX req = TCP_REQUEST_QUERY_INFORMATION_INIT;
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
DWORD returnSize;
|
|
|
|
|
|
|
|
memset( entry, 0, sizeof( *entry ) );
|
|
|
|
|
2007-07-26 15:13:36 +00:00
|
|
|
TRACE("TdiGetMibForIpEntity(tcpFile %x,entityId %x)\n",
|
2004-02-25 20:29:15 +00:00
|
|
|
(DWORD)tcpFile, ent->tei_instance);
|
2004-02-15 07:17:00 +00:00
|
|
|
|
|
|
|
req.ID.toi_class = INFO_CLASS_PROTOCOL;
|
|
|
|
req.ID.toi_type = INFO_TYPE_PROVIDER;
|
|
|
|
req.ID.toi_id = IP_MIB_STATS_ID;
|
|
|
|
req.ID.toi_entity = *ent;
|
|
|
|
|
|
|
|
status = DeviceIoControl( tcpFile,
|
2004-02-25 20:29:15 +00:00
|
|
|
IOCTL_TCP_QUERY_INFORMATION_EX,
|
|
|
|
&req,
|
|
|
|
sizeof(req),
|
|
|
|
entry,
|
|
|
|
sizeof(*entry),
|
|
|
|
&returnSize,
|
|
|
|
NULL );
|
2004-02-15 07:17:00 +00:00
|
|
|
|
2007-07-26 15:13:36 +00:00
|
|
|
TRACE("TdiGetMibForIpEntity() => {\n"
|
2004-02-25 20:29:15 +00:00
|
|
|
" ipsi_forwarding ............ %d\n"
|
|
|
|
" ipsi_defaultttl ............ %d\n"
|
|
|
|
" ipsi_inreceives ............ %d\n"
|
|
|
|
" ipsi_indelivers ............ %d\n"
|
|
|
|
" ipsi_outrequests ........... %d\n"
|
|
|
|
" ipsi_routingdiscards ....... %d\n"
|
|
|
|
" ipsi_outdiscards ........... %d\n"
|
|
|
|
" ipsi_outnoroutes ........... %d\n"
|
|
|
|
" ipsi_numif ................. %d\n"
|
|
|
|
" ipsi_numaddr ............... %d\n"
|
|
|
|
" ipsi_numroutes ............. %d\n"
|
|
|
|
"} status %08x\n",
|
|
|
|
entry->ipsi_forwarding,
|
|
|
|
entry->ipsi_defaultttl,
|
|
|
|
entry->ipsi_inreceives,
|
|
|
|
entry->ipsi_indelivers,
|
|
|
|
entry->ipsi_outrequests,
|
|
|
|
entry->ipsi_routingdiscards,
|
|
|
|
entry->ipsi_outdiscards,
|
|
|
|
entry->ipsi_outnoroutes,
|
|
|
|
entry->ipsi_numif,
|
|
|
|
entry->ipsi_numaddr,
|
|
|
|
entry->ipsi_numroutes,
|
|
|
|
status);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
|
|
|
return status;
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS tdiGetRoutesForIpEntity
|
2004-02-25 07:41:50 +00:00
|
|
|
( HANDLE tcpFile, TDIEntityID *ent, IPRouteEntry **routes, PDWORD numRoutes ) {
|
2004-02-15 07:17:00 +00:00
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
|
2007-07-26 15:13:36 +00:00
|
|
|
TRACE("TdiGetRoutesForIpEntity(tcpFile %x,entityId %x)\n",
|
2004-02-25 20:29:15 +00:00
|
|
|
(DWORD)tcpFile, ent->tei_instance);
|
2004-02-15 07:17:00 +00:00
|
|
|
|
2004-02-25 07:41:50 +00:00
|
|
|
status = tdiGetSetOfThings( tcpFile,
|
2004-02-25 20:29:15 +00:00
|
|
|
INFO_CLASS_PROTOCOL,
|
|
|
|
INFO_TYPE_PROVIDER,
|
2009-10-09 02:40:38 +00:00
|
|
|
IP_MIB_ARPTABLE_ENTRY_ID,
|
|
|
|
CL_NL_ENTITY,
|
|
|
|
ent->tei_instance,
|
2004-02-25 20:29:15 +00:00
|
|
|
0,
|
|
|
|
sizeof(IPRouteEntry),
|
|
|
|
(PVOID *)routes,
|
|
|
|
numRoutes);
|
2004-02-15 07:17:00 +00:00
|
|
|
|
2007-10-19 23:21:45 +00:00
|
|
|
return status;
|
2004-02-25 07:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS tdiGetIpAddrsForIpEntity
|
|
|
|
( HANDLE tcpFile, TDIEntityID *ent, IPAddrEntry **addrs, PDWORD numAddrs ) {
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2007-07-26 15:13:36 +00:00
|
|
|
TRACE("TdiGetIpAddrsForIpEntity(tcpFile %x,entityId %x)\n",
|
2004-02-25 20:29:15 +00:00
|
|
|
(DWORD)tcpFile, ent->tei_instance);
|
2004-02-25 07:41:50 +00:00
|
|
|
|
2007-10-19 23:21:45 +00:00
|
|
|
status = tdiGetSetOfThings( tcpFile,
|
|
|
|
INFO_CLASS_PROTOCOL,
|
2004-02-25 20:29:15 +00:00
|
|
|
INFO_TYPE_PROVIDER,
|
|
|
|
IP_MIB_ADDRTABLE_ENTRY_ID,
|
2009-10-09 02:40:38 +00:00
|
|
|
CL_NL_ENTITY,
|
|
|
|
ent->tei_instance,
|
2004-02-25 20:29:15 +00:00
|
|
|
0,
|
|
|
|
sizeof(IPAddrEntry),
|
|
|
|
(PVOID *)addrs,
|
|
|
|
numAddrs );
|
2004-02-15 07:17:00 +00:00
|
|
|
|
2007-10-19 23:21:45 +00:00
|
|
|
return status;
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD getInterfaceStatsByName(const char *name, PMIB_IFROW entry)
|
|
|
|
{
|
|
|
|
if (!name)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
if (!entry)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD getInterfaceStatsByIndex(DWORD index, PMIB_IFROW entry)
|
|
|
|
{
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD getICMPStats(MIB_ICMP *stats)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
if (!stats)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
memset(stats, 0, sizeof(MIB_ICMP));
|
|
|
|
/* get most of these stats from /proc/net/snmp, no error if can't */
|
|
|
|
fp = fopen("/proc/net/snmp", "r");
|
|
|
|
if (fp) {
|
|
|
|
const char hdr[] = "Icmp:";
|
|
|
|
char buf[512] = { 0 }, *ptr;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ptr = fgets(buf, sizeof(buf), fp);
|
|
|
|
} while (ptr && strncasecmp(buf, hdr, sizeof(hdr) - 1));
|
|
|
|
if (ptr) {
|
|
|
|
/* last line was a header, get another */
|
|
|
|
ptr = fgets(buf, sizeof(buf), fp);
|
|
|
|
if (ptr && strncasecmp(buf, hdr, sizeof(hdr) - 1) == 0) {
|
|
|
|
char *endPtr;
|
|
|
|
|
|
|
|
ptr += sizeof(hdr);
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwMsgs = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwErrors = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwDestUnreachs = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwTimeExcds = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwParmProbs = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwSrcQuenchs = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwRedirects = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwEchoReps = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwTimestamps = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwTimestampReps = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwAddrMasks = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpInStats.dwAddrMaskReps = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwMsgs = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwErrors = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwDestUnreachs = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwTimeExcds = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwParmProbs = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwSrcQuenchs = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwRedirects = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwEchoReps = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwTimestamps = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwTimestampReps = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwAddrMasks = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
stats->stats.icmpOutStats.dwAddrMaskReps = strtoul(ptr, &endPtr, 10);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD getIPStats(PMIB_IPSTATS stats, DWORD family)
|
|
|
|
{
|
|
|
|
if (!stats)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD getTCPStats(MIB_TCPSTATS *stats, DWORD family)
|
|
|
|
{
|
|
|
|
if (!stats)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD getUDPStats(MIB_UDPSTATS *stats, DWORD family)
|
|
|
|
{
|
|
|
|
if (!stats)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD getNumWithOneHeader(const char *filename)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD getNumRoutes(void)
|
|
|
|
{
|
|
|
|
DWORD numEntities, numRoutes = 0;
|
|
|
|
TDIEntityID *entitySet;
|
|
|
|
HANDLE tcpFile;
|
|
|
|
int i;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("called.\n");
|
|
|
|
|
2015-02-15 17:57:34 +00:00
|
|
|
status = openTcpFile( &tcpFile, FILE_READ_DATA );
|
2004-02-15 07:17:00 +00:00
|
|
|
|
|
|
|
if( !NT_SUCCESS(status) ) {
|
2004-02-25 20:29:15 +00:00
|
|
|
TRACE("failure: %08x\n", (int)status );
|
|
|
|
return 0;
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities );
|
|
|
|
|
|
|
|
if( !NT_SUCCESS(status) ) {
|
2004-02-25 20:29:15 +00:00
|
|
|
TRACE("failure: %08x\n", (int)status );
|
2007-12-29 21:40:31 +00:00
|
|
|
closeTcpFile( tcpFile );
|
2004-02-25 20:29:15 +00:00
|
|
|
return 0;
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( i = 0; i < numEntities; i++ ) {
|
2004-02-25 20:29:15 +00:00
|
|
|
if( isIpEntity( tcpFile, &entitySet[i] ) ) {
|
|
|
|
IPSNMPInfo isnmp;
|
|
|
|
memset( &isnmp, 0, sizeof( isnmp ) );
|
|
|
|
status = tdiGetMibForIpEntity( tcpFile, &entitySet[i], &isnmp );
|
|
|
|
if( !NT_SUCCESS(status) ) {
|
2018-02-23 17:35:02 +00:00
|
|
|
WARN("tdiGetMibForIpEntity failed for i = %d", i);
|
|
|
|
numRoutes = 0;
|
|
|
|
break;
|
2004-02-25 20:29:15 +00:00
|
|
|
}
|
|
|
|
numRoutes += isnmp.ipsi_numroutes;
|
|
|
|
}
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("numRoutes: %d\n", (int)numRoutes);
|
|
|
|
|
2018-02-21 17:40:23 +00:00
|
|
|
tdiFreeThingSet( entitySet );
|
2004-02-15 07:17:00 +00:00
|
|
|
closeTcpFile( tcpFile );
|
|
|
|
|
|
|
|
return numRoutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID HexDump( PCHAR Data, DWORD Len ) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for( i = 0; i < Len; i++ ) {
|
2004-02-25 20:29:15 +00:00
|
|
|
if( !(i & 0xf) ) {
|
|
|
|
if( i ) fprintf(stderr,"\n");
|
|
|
|
fprintf(stderr,"%08x:", i);
|
|
|
|
}
|
|
|
|
fprintf( stderr, " %02x", Data[i] & 0xff );
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
fprintf(stderr,"\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
RouteTable *getRouteTable(void)
|
|
|
|
{
|
|
|
|
RouteTable *out_route_table;
|
|
|
|
DWORD numRoutes = getNumRoutes(), routesAdded = 0;
|
|
|
|
TDIEntityID ent;
|
|
|
|
HANDLE tcpFile;
|
2015-02-15 17:57:34 +00:00
|
|
|
NTSTATUS status = openTcpFile( &tcpFile, FILE_READ_DATA );
|
2004-02-15 07:17:00 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if( !NT_SUCCESS(status) )
|
2004-02-25 20:29:15 +00:00
|
|
|
return 0;
|
2004-02-15 07:17:00 +00:00
|
|
|
|
2007-07-26 15:13:36 +00:00
|
|
|
TRACE("GETTING ROUTE TABLE\n");
|
2004-03-05 04:50:01 +00:00
|
|
|
|
2007-10-19 23:21:45 +00:00
|
|
|
out_route_table = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
sizeof(RouteTable) +
|
2004-02-25 20:29:15 +00:00
|
|
|
(sizeof(RouteEntry) * (numRoutes - 1)) );
|
2009-08-18 20:30:58 +00:00
|
|
|
if (!out_route_table) {
|
|
|
|
closeTcpFile(tcpFile);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2004-02-15 07:17:00 +00:00
|
|
|
out_route_table->numRoutes = numRoutes;
|
|
|
|
|
2009-10-09 05:18:35 +00:00
|
|
|
for( i = 0; routesAdded < out_route_table->numRoutes; i++ ) {
|
2004-02-25 20:29:15 +00:00
|
|
|
int j;
|
|
|
|
IPRouteEntry *route_set;
|
2004-02-15 07:17:00 +00:00
|
|
|
|
2004-02-25 20:29:15 +00:00
|
|
|
getNthIpEntity( tcpFile, i, &ent );
|
2004-02-15 07:17:00 +00:00
|
|
|
|
2004-12-27 16:50:56 +00:00
|
|
|
tdiGetRoutesForIpEntity( tcpFile, &ent, &route_set, &numRoutes );
|
2009-10-09 05:18:35 +00:00
|
|
|
|
2004-02-25 20:29:15 +00:00
|
|
|
if( !route_set ) {
|
|
|
|
closeTcpFile( tcpFile );
|
|
|
|
HeapFree( GetProcessHeap(), 0, out_route_table );
|
|
|
|
return 0;
|
|
|
|
}
|
2004-02-15 07:17:00 +00:00
|
|
|
|
2009-10-09 05:18:35 +00:00
|
|
|
TRACE( "%d routes in instance %d\n", numRoutes, i );
|
2004-02-15 07:17:00 +00:00
|
|
|
#if 0
|
2007-10-19 23:21:45 +00:00
|
|
|
HexDump( route_set,
|
|
|
|
sizeof( IPRouteEntry ) *
|
2004-02-25 20:29:15 +00:00
|
|
|
snmpInfo.ipsi_numroutes );
|
2004-02-15 07:17:00 +00:00
|
|
|
#endif
|
|
|
|
|
2009-10-09 05:18:35 +00:00
|
|
|
for( j = 0; j < numRoutes; j++ ) {
|
2004-02-25 20:29:15 +00:00
|
|
|
int routeNum = j + routesAdded;
|
2007-10-19 23:21:45 +00:00
|
|
|
out_route_table->routes[routeNum].dest =
|
2004-02-25 20:29:15 +00:00
|
|
|
route_set[j].ire_dest;
|
|
|
|
out_route_table->routes[routeNum].mask =
|
|
|
|
route_set[j].ire_mask;
|
|
|
|
out_route_table->routes[routeNum].gateway =
|
|
|
|
route_set[j].ire_gw;
|
|
|
|
out_route_table->routes[routeNum].ifIndex =
|
|
|
|
route_set[j].ire_index;
|
|
|
|
out_route_table->routes[routeNum].metric =
|
2004-03-05 04:50:01 +00:00
|
|
|
route_set[j].ire_metric1;
|
2004-02-25 20:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( route_set ) tdiFreeThingSet( route_set );
|
|
|
|
|
2009-10-09 05:18:35 +00:00
|
|
|
routesAdded += numRoutes;
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
2007-12-29 21:40:31 +00:00
|
|
|
closeTcpFile( tcpFile );
|
|
|
|
|
2007-07-26 15:13:36 +00:00
|
|
|
TRACE("Return: %08x, %08x\n", status, out_route_table);
|
2004-03-05 04:50:01 +00:00
|
|
|
|
2004-02-15 07:17:00 +00:00
|
|
|
return out_route_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD getNumArpEntries(void)
|
|
|
|
{
|
2006-09-22 08:10:11 +00:00
|
|
|
DWORD numEntities;
|
|
|
|
TDIEntityID *entitySet = NULL;
|
|
|
|
HANDLE tcpFile;
|
|
|
|
int i, totalNumber = 0;
|
|
|
|
NTSTATUS status;
|
|
|
|
PMIB_IPNETROW IpArpTable = NULL;
|
|
|
|
DWORD returnSize;
|
|
|
|
|
|
|
|
TRACE("called.\n");
|
|
|
|
|
2015-02-15 17:57:34 +00:00
|
|
|
status = openTcpFile( &tcpFile, FILE_READ_DATA );
|
2006-09-22 08:10:11 +00:00
|
|
|
|
|
|
|
if( !NT_SUCCESS(status) ) {
|
|
|
|
TRACE("failure: %08x\n", (int)status );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities );
|
|
|
|
|
|
|
|
for( i = 0; i < numEntities; i++ ) {
|
2007-10-19 23:21:45 +00:00
|
|
|
if( isInterface( &entitySet[i] ) &&
|
2009-10-20 03:54:27 +00:00
|
|
|
hasArp( tcpFile, &entitySet[i] ) ) {
|
2006-09-22 08:10:11 +00:00
|
|
|
|
|
|
|
status = tdiGetSetOfThings( tcpFile,
|
|
|
|
INFO_CLASS_PROTOCOL,
|
|
|
|
INFO_TYPE_PROVIDER,
|
|
|
|
IP_MIB_ARPTABLE_ENTRY_ID,
|
|
|
|
AT_ENTITY,
|
|
|
|
entitySet[i].tei_instance,
|
|
|
|
0,
|
|
|
|
sizeof(MIB_IPNETROW),
|
|
|
|
(PVOID *)&IpArpTable,
|
|
|
|
&returnSize );
|
|
|
|
|
|
|
|
if( status == STATUS_SUCCESS ) totalNumber += returnSize;
|
2008-12-30 12:04:47 +00:00
|
|
|
if( IpArpTable ) {
|
|
|
|
tdiFreeThingSet( IpArpTable );
|
|
|
|
IpArpTable = NULL;
|
|
|
|
}
|
2006-09-22 08:10:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closeTcpFile( tcpFile );
|
|
|
|
if( IpArpTable ) tdiFreeThingSet( IpArpTable );
|
|
|
|
if( entitySet ) tdiFreeThingSet( entitySet );
|
|
|
|
return totalNumber;
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PMIB_IPNETTABLE getArpTable(void)
|
|
|
|
{
|
2006-09-22 08:10:11 +00:00
|
|
|
DWORD numEntities, returnSize;
|
|
|
|
TDIEntityID *entitySet;
|
|
|
|
HANDLE tcpFile;
|
2009-09-20 01:37:40 +00:00
|
|
|
int i, totalNumber, TmpIdx, CurrIdx = 0;
|
2006-09-22 08:10:11 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
PMIB_IPNETTABLE IpArpTable = NULL;
|
|
|
|
PMIB_IPNETROW AdapterArpTable = NULL;
|
|
|
|
|
|
|
|
TRACE("called.\n");
|
|
|
|
|
|
|
|
totalNumber = getNumArpEntries();
|
|
|
|
|
2015-02-15 17:57:34 +00:00
|
|
|
status = openTcpFile( &tcpFile, FILE_READ_DATA );
|
2006-09-22 08:10:11 +00:00
|
|
|
|
|
|
|
if( !NT_SUCCESS(status) ) {
|
|
|
|
TRACE("failure: %08x\n", (int)status );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IpArpTable = HeapAlloc
|
2007-10-19 23:21:45 +00:00
|
|
|
( GetProcessHeap(), 0,
|
2006-09-22 08:10:11 +00:00
|
|
|
sizeof(DWORD) + (sizeof(MIB_IPNETROW) * totalNumber) );
|
2009-08-18 20:30:58 +00:00
|
|
|
if (!IpArpTable) {
|
|
|
|
closeTcpFile(tcpFile);
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-09-22 08:10:11 +00:00
|
|
|
|
|
|
|
status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities );
|
|
|
|
|
|
|
|
for( i = 0; i < numEntities; i++ ) {
|
2009-09-20 01:37:40 +00:00
|
|
|
if( isInterface( &entitySet[i] ) &&
|
2009-10-20 03:54:27 +00:00
|
|
|
hasArp( tcpFile, &entitySet[i] ) ) {
|
2006-09-22 08:10:11 +00:00
|
|
|
|
|
|
|
status = tdiGetSetOfThings( tcpFile,
|
|
|
|
INFO_CLASS_PROTOCOL,
|
|
|
|
INFO_TYPE_PROVIDER,
|
|
|
|
IP_MIB_ARPTABLE_ENTRY_ID,
|
|
|
|
AT_ENTITY,
|
|
|
|
entitySet[i].tei_instance,
|
|
|
|
0,
|
|
|
|
sizeof(MIB_IPNETROW),
|
|
|
|
(PVOID *)&AdapterArpTable,
|
|
|
|
&returnSize );
|
|
|
|
|
2012-08-22 09:39:57 +00:00
|
|
|
if( status == STATUS_SUCCESS ) {
|
|
|
|
for( TmpIdx = 0; TmpIdx < returnSize; TmpIdx++, CurrIdx++ )
|
|
|
|
IpArpTable->table[CurrIdx] = AdapterArpTable[TmpIdx];
|
|
|
|
tdiFreeThingSet( AdapterArpTable );
|
|
|
|
}
|
|
|
|
}
|
2006-09-22 08:10:11 +00:00
|
|
|
}
|
|
|
|
|
2007-12-29 21:40:31 +00:00
|
|
|
closeTcpFile( tcpFile );
|
|
|
|
|
2006-09-22 08:10:11 +00:00
|
|
|
tdiFreeThingSet( entitySet );
|
2009-09-20 01:37:40 +00:00
|
|
|
IpArpTable->dwNumEntries = CurrIdx;
|
2006-09-22 08:10:11 +00:00
|
|
|
|
|
|
|
return IpArpTable;
|
2004-02-15 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD getNumUdpEntries(void)
|
|
|
|
{
|
|
|
|
return getNumWithOneHeader("/proc/net/udp");
|
|
|
|
}
|
|
|
|
|
|
|
|
PMIB_UDPTABLE getUdpTable(void)
|
|
|
|
{
|
|
|
|
DWORD numEntries = getNumUdpEntries();
|
|
|
|
PMIB_UDPTABLE ret;
|
|
|
|
|
|
|
|
ret = (PMIB_UDPTABLE)calloc(1, sizeof(MIB_UDPTABLE) +
|
|
|
|
(numEntries - 1) * sizeof(MIB_UDPROW));
|
|
|
|
if (ret) {
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
/* get from /proc/net/udp, no error if can't */
|
|
|
|
fp = fopen("/proc/net/udp", "r");
|
|
|
|
if (fp) {
|
|
|
|
char buf[512] = { 0 }, *ptr;
|
|
|
|
|
|
|
|
/* skip header line */
|
|
|
|
ptr = fgets(buf, sizeof(buf), fp);
|
|
|
|
while (ptr && ret->dwNumEntries < numEntries) {
|
|
|
|
ptr = fgets(buf, sizeof(buf), fp);
|
|
|
|
if (ptr) {
|
|
|
|
char *endPtr;
|
|
|
|
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
strtoul(ptr, &endPtr, 16); /* skip */
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
ptr++;
|
|
|
|
ret->table[ret->dwNumEntries].dwLocalAddr = strtoul(ptr, &endPtr,
|
|
|
|
16);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
if (ptr && *ptr) {
|
|
|
|
ptr++;
|
|
|
|
ret->table[ret->dwNumEntries].dwLocalPort = strtoul(ptr, &endPtr,
|
|
|
|
16);
|
|
|
|
ptr = endPtr;
|
|
|
|
}
|
|
|
|
ret->dwNumEntries++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD getNumTcpEntries(void)
|
|
|
|
{
|
|
|
|
return getNumWithOneHeader("/proc/net/tcp");
|
|
|
|
}
|
|
|
|
|
|
|
|
PMIB_TCPTABLE getTcpTable(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|