Reactos
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE: base/applications/network/net/cmdStatistics.c
5 * PROGRAMMERS: Eric Kohl <eric.kohl@reactos.org>
6 */
7
8#include "net.h"
9#include <rtltypes.h>
10#include <rtlfuncs.h>
11
12static
13INT
14DisplayServerStatistics(VOID)
15{
16 PSERVER_INFO_100 ServerInfo = NULL;
17 PSTAT_SERVER_0 StatisticsInfo = NULL;
18 LARGE_INTEGER LargeValue;
19 FILETIME FileTime, LocalFileTime;
20 SYSTEMTIME SystemTime;
21 WCHAR DateBuffer[32], TimeBuffer[32];
22 INT nPaddedLength = 35;
23 NET_API_STATUS Status;
24
25 Status = NetServerGetInfo(NULL, 100, (PBYTE*)&ServerInfo);
26 if (Status != NERR_Success)
27 goto done;
28
29 Status = NetStatisticsGet(NULL,
30 SERVICE_SERVER,
31 0,
32 0,
33 (LPBYTE*)&StatisticsInfo);
34 if (Status != NERR_Success)
35 goto done;
36
37 PrintMessageStringV(4624, ServerInfo->sv100_name);
38 ConPrintf(StdOut, L"\n\n");
39
40 RtlSecondsSince1970ToTime(StatisticsInfo->sts0_start,
41 &LargeValue);
42 FileTime.dwLowDateTime = LargeValue.u.LowPart;
43 FileTime.dwHighDateTime = LargeValue.u.HighPart;
44 FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
45 FileTimeToSystemTime(&LocalFileTime, &SystemTime);
46
47 GetDateFormatW(LOCALE_USER_DEFAULT,
48 DATE_SHORTDATE,
49 &SystemTime,
50 NULL,
51 DateBuffer,
52 ARRAYSIZE(DateBuffer));
53
54 GetTimeFormatW(LOCALE_USER_DEFAULT,
55 0,
56 &SystemTime,
57 NULL,
58 TimeBuffer,
59 ARRAYSIZE(TimeBuffer));
60
61 PrintMessageString(4600);
62 ConPrintf(StdOut, L" %s %s\n\n\n", DateBuffer, TimeBuffer);
63
64 PrintPaddedMessageString(4601, nPaddedLength);
65 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_sopens);
66
67 PrintPaddedMessageString(4602, nPaddedLength);
68 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_stimedout);
69
70 PrintPaddedMessageString(4603, nPaddedLength);
71 ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_serrorout);
72
73 LargeValue.u.LowPart = StatisticsInfo->sts0_bytessent_low;
74 LargeValue.u.HighPart = StatisticsInfo->sts0_bytessent_high;
75 PrintPaddedMessageString(4604, nPaddedLength);
76 ConPrintf(StdOut, L"%I64u\n", LargeValue.QuadPart / 1024);
77
78 LargeValue.u.LowPart = StatisticsInfo->sts0_bytesrcvd_low;
79 LargeValue.u.HighPart = StatisticsInfo->sts0_bytesrcvd_high;
80 PrintPaddedMessageString(4605, nPaddedLength);
81 ConPrintf(StdOut, L"%I64u\n", LargeValue.QuadPart / 1024);
82
83 PrintPaddedMessageString(4606, nPaddedLength);
84 ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_avresponse);
85
86 PrintPaddedMessageString(4610, nPaddedLength);
87 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_syserrors);
88
89 PrintPaddedMessageString(4612, nPaddedLength);
90 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_permerrors);
91
92 PrintPaddedMessageString(4611, nPaddedLength);
93 ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_pwerrors);
94
95 PrintPaddedMessageString(4608, nPaddedLength);
96 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_fopens);
97
98 PrintPaddedMessageString(4613, nPaddedLength);
99 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_devopens);
100
101 PrintPaddedMessageString(4609, nPaddedLength);
102 ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_jobsqueued);
103
104 PrintMessageString(4620);
105 ConPrintf(StdOut, L"\n");
106
107 ConPrintf(StdOut, L" ");
108 PrintPaddedMessageString(4621, nPaddedLength - 2);
109 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_bigbufneed);
110
111 ConPrintf(StdOut, L" ");
112 PrintPaddedMessageString(4622, nPaddedLength - 2);
113 ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_reqbufneed);
114
115done:
116 if (StatisticsInfo != NULL)
117 NetApiBufferFree(StatisticsInfo);
118
119 if (ServerInfo != NULL)
120 NetApiBufferFree(ServerInfo);
121
122 return 0;
123}
124
125
126static
127INT
128DisplayWorkstationStatistics(VOID)
129{
130 PWKSTA_INFO_100 WorkstationInfo = NULL;
131 PSTAT_WORKSTATION_0 StatisticsInfo = NULL;
132 LARGE_INTEGER LargeValue;
133 FILETIME FileTime, LocalFileTime;
134 SYSTEMTIME SystemTime;
135 WCHAR DateBuffer[32], TimeBuffer[32];
136 INT nPaddedLength = 47;
137 NET_API_STATUS Status;
138
139 Status = NetWkstaGetInfo(NULL,
140 100,
141 (PBYTE*)&WorkstationInfo);
142 if (Status != NERR_Success)
143 goto done;
144
145 Status = NetStatisticsGet(NULL,
146 SERVICE_WORKSTATION,
147 0,
148 0,
149 (LPBYTE*)&StatisticsInfo);
150 if (Status != NERR_Success)
151 goto done;
152
153 PrintMessageStringV(4623, WorkstationInfo->wki100_computername);
154 ConPrintf(StdOut, L"\n\n");
155
156 RtlSecondsSince1970ToTime(StatisticsInfo->StatisticsStartTime.u.LowPart,
157 &LargeValue);
158 FileTime.dwLowDateTime = LargeValue.u.LowPart;
159 FileTime.dwHighDateTime = LargeValue.u.HighPart;
160 FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
161 FileTimeToSystemTime(&LocalFileTime, &SystemTime);
162
163 GetDateFormatW(LOCALE_USER_DEFAULT,
164 DATE_SHORTDATE,
165 &SystemTime,
166 NULL,
167 DateBuffer,
168 ARRAYSIZE(DateBuffer));
169
170 GetTimeFormatW(LOCALE_USER_DEFAULT,
171 0,
172 &SystemTime,
173 NULL,
174 TimeBuffer,
175 ARRAYSIZE(TimeBuffer));
176
177 PrintMessageString(4600);
178 ConPrintf(StdOut, L" %s %s\n\n\n", DateBuffer, TimeBuffer);
179
180 PrintPaddedMessageString(4630, nPaddedLength);
181 ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->BytesReceived.QuadPart);
182
183 PrintPaddedMessageString(4631, nPaddedLength);
184 ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->SmbsReceived.QuadPart);
185
186 PrintPaddedMessageString(4632, nPaddedLength);
187 ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->BytesTransmitted.QuadPart);
188
189 PrintPaddedMessageString(4633, nPaddedLength);
190 ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->SmbsTransmitted.QuadPart);
191
192 PrintPaddedMessageString(4634, nPaddedLength);
193 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->ReadOperations);
194
195 PrintPaddedMessageString(4635, nPaddedLength);
196 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->WriteOperations);
197
198 PrintPaddedMessageString(4636, nPaddedLength);
199 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->RawReadsDenied);
200
201 PrintPaddedMessageString(4637, nPaddedLength);
202 ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->RawWritesDenied);
203
204 PrintPaddedMessageString(4638, nPaddedLength);
205 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->NetworkErrors);
206
207 PrintPaddedMessageString(4639, nPaddedLength);
208 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->CoreConnects +
209 StatisticsInfo->Lanman20Connects +
210 StatisticsInfo->Lanman21Connects +
211 StatisticsInfo->LanmanNtConnects);
212
213 PrintPaddedMessageString(4640, nPaddedLength);
214 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->Reconnects);
215
216 PrintPaddedMessageString(4641, nPaddedLength);
217 ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->ServerDisconnects);
218
219 PrintPaddedMessageString(4642, nPaddedLength);
220 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->Sessions);
221
222 PrintPaddedMessageString(4643, nPaddedLength);
223 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->HungSessions);
224
225 PrintPaddedMessageString(4644, nPaddedLength);
226 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->FailedSessions);
227
228 PrintPaddedMessageString(4645, nPaddedLength);
229 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->InitiallyFailedOperations +
230 StatisticsInfo->FailedCompletionOperations);
231
232 PrintPaddedMessageString(4646, nPaddedLength);
233 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->UseCount);
234
235 PrintPaddedMessageString(4647, nPaddedLength);
236 ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->FailedUseCount);
237
238done:
239 if (StatisticsInfo != NULL)
240 NetApiBufferFree(StatisticsInfo);
241
242 if (WorkstationInfo != NULL)
243 NetApiBufferFree(WorkstationInfo);
244
245 return 0;
246}
247
248
249INT
250cmdStatistics(
251 INT argc,
252 WCHAR **argv)
253{
254 INT i, result = 0;
255 BOOL bServer = FALSE;
256 BOOL bWorkstation = FALSE;
257
258 for (i = 2; i < argc; i++)
259 {
260 if (_wcsicmp(argv[i], L"server") == 0)
261 {
262 if (bWorkstation == FALSE)
263 bServer = TRUE;
264 continue;
265 }
266
267 if (_wcsicmp(argv[i], L"workstation") == 0)
268 {
269 if (bServer == FALSE)
270 bWorkstation = TRUE;
271 continue;
272 }
273
274 if (_wcsicmp(argv[i], L"help") == 0)
275 {
276 /* Print short syntax help */
277 PrintMessageString(4381);
278 ConPuts(StdOut, L"\n");
279 PrintNetMessage(MSG_STATISTICS_SYNTAX);
280 return 0;
281 }
282
283 if (_wcsicmp(argv[i], L"/help") == 0)
284 {
285 /* Print full help text*/
286 PrintMessageString(4381);
287 ConPuts(StdOut, L"\n");
288 PrintNetMessage(MSG_STATISTICS_SYNTAX);
289 PrintNetMessage(MSG_STATISTICS_HELP);
290 return 0;
291 }
292 }
293
294 if (bServer)
295 {
296 result = DisplayServerStatistics();
297 }
298 else if (bWorkstation)
299 {
300 result = DisplayWorkstationStatistics();
301 }
302 else
303 {
304 PrintMessageString(4379);
305 ConPuts(StdOut, L"\n");
306 ConPuts(StdOut, L" Server\n");
307 ConPuts(StdOut, L" Workstation\n");
308 ConPuts(StdOut, L"\n");
309 }
310
311 if (result == 0)
312 PrintErrorMessage(ERROR_SUCCESS);
313
314 return result;
315}