Implement the TCP table query, netstat.exe now shows TCP listening and

connected sockets.
This commit is contained in:
Juan Lang 2003-11-28 23:12:05 +00:00 committed by Alexandre Julliard
parent 2835ebee12
commit 94670d40ef
2 changed files with 47 additions and 4 deletions

View File

@ -421,9 +421,7 @@ DWORD WINAPI WsControl(DWORD protocol,
break;
}
/* FIXME: not real name. Value is 0x101. Obviously it's a bad name,
* too, because it can be used to get the ARP table--see below. */
case IP_MIB_ROUTETABLE_ENTRY_ID:
case IP_MIB_TABLE_ENTRY_ID:
{
switch (pcommand->toi_entity.tei_entity)
{
@ -517,6 +515,51 @@ DWORD WINAPI WsControl(DWORD protocol,
}
break;
case CO_TL_ENTITY:
{
DWORD tcpTableSize, numEntries, ret;
PMIB_TCPTABLE table;
DWORD i;
if (!pcbResponseInfoLen)
return ERROR_BAD_ENVIRONMENT;
GetTcpTable(NULL, &tcpTableSize, FALSE);
numEntries = min(tcpTableSize - sizeof(MIB_TCPTABLE),
0) / sizeof(MIB_TCPROW) + 1;
if (*pcbResponseInfoLen < sizeof(MIB_TCPROW) * numEntries)
return (ERROR_LOCK_VIOLATION);
table = (PMIB_TCPTABLE)calloc(1, tcpTableSize);
if (!table)
return ERROR_NOT_ENOUGH_MEMORY;
ret = GetTcpTable(table, &tcpTableSize, FALSE);
if (ret != NO_ERROR)
return ret;
if (*pcbResponseInfoLen < sizeof(MIB_TCPROW) *
table->dwNumEntries)
{
free(table);
return ERROR_LOCK_VIOLATION;
}
for (i = 0; i < table->dwNumEntries; i++)
{
USHORT sPort;
sPort = ntohs((USHORT)table->table[i].dwLocalPort);
table->table[i].dwLocalPort = (DWORD)sPort;
sPort = ntohs((USHORT)table->table[i].dwRemotePort);
table->table[i].dwRemotePort = (DWORD)sPort;
}
memcpy(pResponseInfo, table->table, sizeof(MIB_TCPROW) *
table->dwNumEntries);
/* calculate the length of the data in the output buffer */
*pcbResponseInfoLen = sizeof(MIB_TCPROW) *
table->dwNumEntries;
free(table);
}
break;
default:
{
FIXME ("Command ID Not Supported -> toi_id=0x%lx, toi_entity={tei_entity=0x%lx, tei_instance=0x%lx}, toi_class=0x%lx\n",

View File

@ -119,7 +119,7 @@ typedef struct IPRouteEntry {
/* Constants for use in the toi_id field */
#define ENTITY_LIST_ID 0 /* to get the list of entity IDs */
#define ENTITY_TYPE_ID 1 /* it's an interface; what type of interface is it? */
#define IP_MIB_ROUTETABLE_ENTRY_ID 0x101 /* not real name */
#define IP_MIB_TABLE_ENTRY_ID 0x101 /* not real name */
#define IP_MIB_ADDRTABLE_ENTRY_ID 0x102
/* Constants for use in the toi_class field */