ReactOS  0.4.13-dev-100-gc8611ae
cmdStatistics.c
Go to the documentation of this file.
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
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;
24 
25  Status = NetServerGetInfo(NULL, 100, (PBYTE*)&ServerInfo);
26  if (Status != NERR_Success)
27  goto done;
28 
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
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;
137 
139  100,
140  (PBYTE*)&WorkstationInfo);
141  if (Status != NERR_Success)
142  goto done;
143 
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
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  PrintMessageString(4381);
276  ConPuts(StdOut, L"\n");
277  PrintNetMessage(MSG_STATISTICS_SYNTAX);
278  return 0;
279  }
280 
281  if (_wcsicmp(argv[i], L"/help") == 0)
282  {
283  /* Print full help text*/
284  PrintMessageString(4381);
285  ConPuts(StdOut, L"\n");
286  PrintNetMessage(MSG_STATISTICS_SYNTAX);
287  PrintNetMessage(MSG_STATISTICS_HELP);
288  return 0;
289  }
290  }
291 
292  if (bServer)
293  {
295  }
296  else if (bWorkstation)
297  {
299  }
300  else
301  {
302  PrintMessageString(4379);
303  ConPuts(StdOut, L"\n");
304  ConPuts(StdOut, L" Server\n");
305  ConPuts(StdOut, L" Workstation\n");
306  ConPuts(StdOut, L"\n");
307  }
308 
309  if (result == 0)
311 
312  return result;
313 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
VOID PrintMessageStringV(DWORD dwMessage,...)
Definition: main.c:82
#define ERROR_SUCCESS
Definition: deptool.c:10
WORD wMonth
Definition: winbase.h:871
static INT DisplayWorkstationStatistics(VOID)
NTSYSAPI VOID NTAPI RtlSecondsSince1970ToTime(_In_ ULONG SecondsSince1970, _Out_ PLARGE_INTEGER Time)
NET_API_STATUS WINAPI NetStatisticsGet(_In_ LPWSTR server, _In_ LPWSTR service, _In_ DWORD level, _In_ DWORD options, _Out_ LPBYTE *bufptr)
Definition: misc.c:55
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:228
#define argv
Definition: mplay32.c:18
BOOL WINAPI FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime, OUT LPFILETIME lpLocalFileTime)
Definition: time.c:211
int32_t INT
Definition: typedefs.h:56
#define SERVICE_SERVER
Definition: lmsname.h:7
#define NERR_Success
Definition: lmerr.h:5
DWORD dwHighDateTime
Definition: mapidefs.h:66
WORD wYear
Definition: winbase.h:870
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
WORD wMinute
Definition: winbase.h:875
smooth NULL
Definition: ftsmooth.c:416
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:178
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned short WORD
Definition: ntddk_ex.h:93
static const WCHAR L[]
Definition: oid.c:1250
NET_API_STATUS WINAPI NetWkstaGetInfo(LMSTR servername, DWORD level, LPBYTE *bufptr)
Definition: wksta.c:472
NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE *bufptr)
Definition: srvsvc.c:369
Status
Definition: gdiplustypes.h:24
WORD wDay
Definition: winbase.h:873
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
VOID PrintPaddedMessageString(DWORD dwMessage, INT nPaddedLength)
Definition: main.c:132
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:109
INT cmdStatistics(INT argc, WCHAR **argv)
WORD wHour
Definition: winbase.h:874
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
static INT DisplayServerStatistics(VOID)
Definition: cmdStatistics.c:14
struct _LARGE_INTEGER::@2192 u
#define StdOut
Definition: stream.h:76
GLuint64EXT * result
Definition: glext.h:11304
BYTE * PBYTE
Definition: pedump.c:66
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
DWORD dwLowDateTime
Definition: mapidefs.h:65
LONGLONG QuadPart
Definition: typedefs.h:112