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