mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 16:36:33 +00:00
[IPHLPAPI] Implement getNumUdpEntries() and getUdpTable()
CORE-5401
This commit is contained in:
parent
678204790c
commit
e3cb9697a4
1 changed files with 98 additions and 45 deletions
|
@ -351,11 +351,6 @@ DWORD getUDPStats(MIB_UDPSTATS *stats, DWORD family)
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DWORD getNumWithOneHeader(const char *filename)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD getNumRoutes(void)
|
DWORD getNumRoutes(void)
|
||||||
{
|
{
|
||||||
DWORD numEntities, numRoutes = 0;
|
DWORD numEntities, numRoutes = 0;
|
||||||
|
@ -597,54 +592,112 @@ PMIB_IPNETTABLE getArpTable(void)
|
||||||
|
|
||||||
DWORD getNumUdpEntries(void)
|
DWORD getNumUdpEntries(void)
|
||||||
{
|
{
|
||||||
return getNumWithOneHeader("/proc/net/udp");
|
DWORD numEntities;
|
||||||
|
TDIEntityID *entitySet = NULL;
|
||||||
|
HANDLE tcpFile;
|
||||||
|
int i, totalNumber = 0;
|
||||||
|
NTSTATUS status;
|
||||||
|
PMIB_UDPROW IpUdpTable = NULL;
|
||||||
|
DWORD returnSize;
|
||||||
|
|
||||||
|
TRACE("called.\n");
|
||||||
|
|
||||||
|
status = openTcpFile( &tcpFile, FILE_READ_DATA );
|
||||||
|
if( !NT_SUCCESS(status) ) {
|
||||||
|
ERR("openTcpFile returned 0x%08lx\n", status);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities );
|
||||||
|
|
||||||
|
for( i = 0; i < numEntities; i++ ) {
|
||||||
|
if( isInterface( &entitySet[i] ) &&
|
||||||
|
hasArp( tcpFile, &entitySet[i] ) ) {
|
||||||
|
|
||||||
|
status = tdiGetSetOfThings( tcpFile,
|
||||||
|
INFO_CLASS_PROTOCOL,
|
||||||
|
INFO_TYPE_PROVIDER,
|
||||||
|
IP_MIB_ARPTABLE_ENTRY_ID,
|
||||||
|
CL_TL_ENTITY,
|
||||||
|
entitySet[i].tei_instance,
|
||||||
|
0,
|
||||||
|
sizeof(MIB_UDPROW),
|
||||||
|
(PVOID *)&IpUdpTable,
|
||||||
|
&returnSize );
|
||||||
|
|
||||||
|
if( status == STATUS_SUCCESS ) totalNumber += returnSize;
|
||||||
|
if( IpUdpTable ) {
|
||||||
|
tdiFreeThingSet( IpUdpTable );
|
||||||
|
IpUdpTable = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closeTcpFile( tcpFile );
|
||||||
|
if( IpUdpTable ) tdiFreeThingSet( IpUdpTable );
|
||||||
|
if( entitySet ) tdiFreeThingSet( entitySet );
|
||||||
|
return totalNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
PMIB_UDPTABLE getUdpTable(void)
|
PMIB_UDPTABLE getUdpTable(void)
|
||||||
{
|
{
|
||||||
DWORD numEntries = getNumUdpEntries();
|
DWORD numEntities, returnSize;
|
||||||
PMIB_UDPTABLE ret;
|
TDIEntityID *entitySet;
|
||||||
|
HANDLE tcpFile;
|
||||||
|
int i, totalNumber, TmpIdx, CurrIdx = 0;
|
||||||
|
NTSTATUS status;
|
||||||
|
PMIB_UDPTABLE IpUdpTable = NULL;
|
||||||
|
PMIB_UDPROW AdapterUdpTable = NULL;
|
||||||
|
|
||||||
ret = (PMIB_UDPTABLE)calloc(1, sizeof(MIB_UDPTABLE) +
|
TRACE("called.\n");
|
||||||
(numEntries - 1) * sizeof(MIB_UDPROW));
|
|
||||||
if (ret) {
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
/* get from /proc/net/udp, no error if can't */
|
totalNumber = getNumTcpEntries();
|
||||||
fp = fopen("/proc/net/udp", "r");
|
|
||||||
if (fp) {
|
|
||||||
char buf[512] = { 0 }, *ptr;
|
|
||||||
|
|
||||||
/* skip header line */
|
status = openTcpFile( &tcpFile, FILE_READ_DATA );
|
||||||
ptr = fgets(buf, sizeof(buf), fp);
|
if( !NT_SUCCESS(status) ) {
|
||||||
while (ptr && ret->dwNumEntries < numEntries) {
|
ERR("openTcpFile returned 0x%08lx\n", status);
|
||||||
ptr = fgets(buf, sizeof(buf), fp);
|
return 0;
|
||||||
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;
|
IpUdpTable = HeapAlloc
|
||||||
|
( GetProcessHeap(), 0,
|
||||||
|
sizeof(DWORD) + (sizeof(MIB_UDPROW) * totalNumber) );
|
||||||
|
if (!IpUdpTable) {
|
||||||
|
closeTcpFile(tcpFile);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities );
|
||||||
|
|
||||||
|
for( i = 0; i < numEntities; i++ ) {
|
||||||
|
if( isInterface( &entitySet[i] ) &&
|
||||||
|
hasArp( tcpFile, &entitySet[i] ) ) {
|
||||||
|
|
||||||
|
status = tdiGetSetOfThings( tcpFile,
|
||||||
|
INFO_CLASS_PROTOCOL,
|
||||||
|
INFO_TYPE_PROVIDER,
|
||||||
|
IP_MIB_ARPTABLE_ENTRY_ID,
|
||||||
|
CL_TL_ENTITY,
|
||||||
|
entitySet[i].tei_instance,
|
||||||
|
0,
|
||||||
|
sizeof(MIB_UDPROW),
|
||||||
|
(PVOID *)&AdapterUdpTable,
|
||||||
|
&returnSize );
|
||||||
|
|
||||||
|
if( status == STATUS_SUCCESS ) {
|
||||||
|
for( TmpIdx = 0; TmpIdx < returnSize; TmpIdx++, CurrIdx++ )
|
||||||
|
IpUdpTable->table[CurrIdx] = AdapterUdpTable[TmpIdx];
|
||||||
|
tdiFreeThingSet( AdapterUdpTable );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closeTcpFile( tcpFile );
|
||||||
|
|
||||||
|
tdiFreeThingSet( entitySet );
|
||||||
|
IpUdpTable->dwNumEntries = CurrIdx;
|
||||||
|
|
||||||
|
return IpUdpTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD getNumTcpEntries(void)
|
DWORD getNumTcpEntries(void)
|
||||||
|
|
Loading…
Reference in a new issue