--- trunk/reactos/apps/utils/net/netstat/netstat.c 2005-12-20 13:24:47 UTC (rev 20275)
+++ trunk/reactos/apps/utils/net/netstat/netstat.c 2005-12-20 19:54:25 UTC (rev 20276)
@@ -108,7 +108,7 @@
TCHAR Proto[5];
- if ((argc == 1) || (isdigit(*argv[1])))
+ if ((argc == 1) || (_istdigit(*argv[1])))
bNoOptions = TRUE;
/* Parse command line for options we have been given. */
@@ -123,23 +123,18 @@
switch (tolower(c))
{
case 'a' :
- //_tprintf(_T("got a\n"));
bDoShowAllCons = TRUE;
break;
case 'e' :
- //_tprintf(_T("got e\n"));
bDoShowEthStats = TRUE;
break;
case 'n' :
- //_tprintf(_T("got n\n"));
bDoShowNumbers = TRUE;
break;
case 's' :
- //_tprintf(_T("got s\n"));
bDoShowProtoStats = TRUE;
break;
case 'p' :
- //_tprintf(_T("got p\n"));
bDoShowProtoCons = TRUE;
strncpy(Proto, (++argv)[i], sizeof(Proto));
@@ -171,10 +166,12 @@
}
}
}
- else if (isdigit(*argv[i]))
+ else if (_istdigit(*argv[i]))
{
- _stscanf(argv[i], "%lu", &Interval);
- bLoopOutput = TRUE;
+ if (_stscanf(argv[i], "%lu", &Interval) != EOF)
+ bLoopOutput = TRUE;
+ else
+ return EXIT_FAILURE;
}
// else
// {
@@ -278,7 +275,7 @@
PMIB_IPSTATS pIpStats;
DWORD dwRetVal;
- pIpStats = (MIB_IPSTATS*) malloc(sizeof(MIB_IPSTATS));
+ pIpStats = (MIB_IPSTATS*) HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IPSTATS));
if ((dwRetVal = GetIpStatistics(pIpStats)) == NO_ERROR)
{
@@ -303,6 +300,8 @@
}
else
DoFormatMessage(dwRetVal);
+
+ HeapFree(GetProcessHeap(), 0, pIpStats);
}
VOID ShowIcmpStatistics()
@@ -310,7 +309,7 @@
PMIB_ICMP pIcmpStats;
DWORD dwRetVal;
- pIcmpStats = (MIB_ICMP*) malloc(sizeof(MIB_ICMP));
+ pIcmpStats = (MIB_ICMP*) HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_ICMP));
if ((dwRetVal = GetIcmpStatistics(pIcmpStats)) == NO_ERROR)
{
@@ -346,6 +345,8 @@
else
DoFormatMessage(dwRetVal);
+ HeapFree(GetProcessHeap(), 0, pIcmpStats);
+
}
VOID ShowTcpStatistics()
@@ -353,7 +354,7 @@
PMIB_TCPSTATS pTcpStats;
DWORD dwRetVal;
- pTcpStats = (MIB_TCPSTATS*) malloc(sizeof(MIB_TCPSTATS));
+ pTcpStats = (MIB_TCPSTATS*) HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_TCPSTATS));
if ((dwRetVal = GetTcpStatistics(pTcpStats)) == NO_ERROR)
{
@@ -369,6 +370,8 @@
}
else
DoFormatMessage(dwRetVal);
+
+ HeapFree(GetProcessHeap(), 0, pTcpStats);
}
VOID ShowUdpStatistics()
@@ -376,7 +379,7 @@
PMIB_UDPSTATS pUdpStats;
DWORD dwRetVal;
- pUdpStats = (MIB_UDPSTATS*) malloc(sizeof(MIB_UDPSTATS));
+ pUdpStats = (MIB_UDPSTATS*) HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_UDPSTATS));
if ((dwRetVal = GetUdpStatistics(pUdpStats)) == NO_ERROR)
{
@@ -388,6 +391,8 @@
}
else
DoFormatMessage(dwRetVal);
+
+ HeapFree(GetProcessHeap(), 0, pUdpStats);
}
VOID ShowEthernetStatistics()
@@ -396,12 +401,12 @@
DWORD dwSize = 0;
DWORD dwRetVal = 0;
- pIfTable = (MIB_IFTABLE*) malloc(sizeof(MIB_IFTABLE));
+ pIfTable = (MIB_IFTABLE*) HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IFTABLE));
if (GetIfTable(pIfTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER)
{
- GlobalFree(pIfTable);
- pIfTable = (MIB_IFTABLE*) malloc(dwSize);
+ HeapFree(GetProcessHeap(), 0, pIfTable);
+ pIfTable = (MIB_IFTABLE*) HeapAlloc(GetProcessHeap(), 0, dwSize);
if ((dwRetVal = GetIfTable(pIfTable, &dwSize, 0)) == NO_ERROR)
{
@@ -423,6 +428,7 @@
else
DoFormatMessage(dwRetVal);
}
+ HeapFree(GetProcessHeap(), 0, pIfTable);
}
VOID ShowTcpTable()
@@ -444,12 +450,13 @@
DoFormatMessage(error);
exit(EXIT_FAILURE);
}
- tcpTable = (PMIB_TCPTABLE)malloc(dwSize);
+ tcpTable = (PMIB_TCPTABLE) HeapAlloc(GetProcessHeap(), 0, dwSize);
error = GetTcpTable(tcpTable, &dwSize, TRUE );
if (error)
{
printf("Failed to snapshot TCP endpoints table.\n");
DoFormatMessage(error);
+ HeapFree(GetProcessHeap(), 0, tcpTable);
exit(EXIT_FAILURE);
}
@@ -475,6 +482,7 @@
Host, Remote, TcpState[tcpTable->table[i].dwState]);
}
}
+ HeapFree(GetProcessHeap(), 0, tcpTable);
}
@@ -495,12 +503,13 @@
DoFormatMessage(error);
exit(EXIT_FAILURE);
}
- udpTable = (PMIB_UDPTABLE)malloc(dwSize);
+ udpTable = (PMIB_UDPTABLE) HeapAlloc(GetProcessHeap(), 0, dwSize);
error = GetUdpTable(udpTable, &dwSize, TRUE);
if (error)
{
printf("Failed to snapshot UDP endpoints table.\n");
DoFormatMessage(error);
+ HeapFree(GetProcessHeap(), 0, udpTable);
exit(EXIT_FAILURE);
}
@@ -516,6 +525,8 @@
_tprintf(_T(" %-6s %-22s %-22s\n"), _T("UDP"), Host, _T(":*:"));
}
+
+ HeapFree(GetProcessHeap(), 0, udpTable);
}