ReactOS  0.4.11-dev-946-g431643b
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 
29  Status = NetStatisticsGet(NULL,
31  0,
32  0,
33  (LPBYTE*)&StatisticsInfo);
34  if (Status != NERR_Success)
35  goto done;
36 
37  ConResPrintf(StdOut, IDS_STATISTICS_SRV_NAME, ServerInfo->sv100_name);
38 
39  RtlSecondsSince1970ToTime(StatisticsInfo->sts0_start,
40  &LargeValue);
41  FileTime.dwLowDateTime = LargeValue.u.LowPart;
42  FileTime.dwHighDateTime = LargeValue.u.HighPart;
43  FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
44  FileTimeToSystemTime(&LocalFileTime, &SystemTime);
45 
46  wHour = SystemTime.wHour;
47  if (wHour == 0)
48  {
49  wHour = 12;
50  }
51  else if (wHour > 12)
52  {
53  wHour = wHour - 12;
54  }
55 
57  SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear,
58  wHour, SystemTime.wMinute,
59  (SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM");
60 
62  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_sopens);
63 
65  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_stimedout);
66 
68  ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_serrorout);
69 
70  LargeValue.u.LowPart = StatisticsInfo->sts0_bytessent_low;
71  LargeValue.u.HighPart = StatisticsInfo->sts0_bytessent_high;
73  ConPrintf(StdOut, L"%I64u\n", LargeValue.QuadPart / 1024);
74 
75  LargeValue.u.LowPart = StatisticsInfo->sts0_bytesrcvd_low;
76  LargeValue.u.HighPart = StatisticsInfo->sts0_bytesrcvd_high;
78  ConPrintf(StdOut, L"%I64u\n", LargeValue.QuadPart / 1024);
79 
81  ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_avresponse);
82 
84  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_syserrors);
85 
87  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_permerrors);
88 
90  ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_pwerrors);
91 
93  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_fopens);
94 
96  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_devopens);
97 
99  ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_jobsqueued);
100 
102 
104  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_bigbufneed);
105 
107  ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_reqbufneed);
108 
109 done:
110  if (StatisticsInfo != NULL)
111  NetApiBufferFree(StatisticsInfo);
112 
113  if (ServerInfo != NULL)
114  NetApiBufferFree(ServerInfo);
115 
116  return 0;
117 }
118 
119 
120 static
121 INT
123 {
124  PWKSTA_INFO_100 WorkstationInfo = NULL;
125  PSTAT_WORKSTATION_0 StatisticsInfo = NULL;
126  LARGE_INTEGER LargeValue;
127  FILETIME FileTime, LocalFileTime;
128  SYSTEMTIME SystemTime;
129  WORD wHour;
130  INT nPaddedLength = 47;
132 
133  Status = NetWkstaGetInfo(NULL,
134  100,
135  (PBYTE*)&WorkstationInfo);
136  if (Status != NERR_Success)
137  goto done;
138 
139  Status = NetStatisticsGet(NULL,
141  0,
142  0,
143  (LPBYTE*)&StatisticsInfo);
144  if (Status != NERR_Success)
145  goto done;
146 
147  ConResPrintf(StdOut, IDS_STATISTICS_WKS_NAME, WorkstationInfo->wki100_computername);
148 
149  RtlSecondsSince1970ToTime(StatisticsInfo->StatisticsStartTime.u.LowPart,
150  &LargeValue);
151  FileTime.dwLowDateTime = LargeValue.u.LowPart;
152  FileTime.dwHighDateTime = LargeValue.u.HighPart;
153  FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
154  FileTimeToSystemTime(&LocalFileTime, &SystemTime);
155 
156  wHour = SystemTime.wHour;
157  if (wHour == 0)
158  {
159  wHour = 12;
160  }
161  else if (wHour > 12)
162  {
163  wHour = wHour - 12;
164  }
165 
167  SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear,
168  wHour, SystemTime.wMinute, (SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM");
169 
171  ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->BytesReceived.QuadPart);
172 
174  ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->SmbsReceived.QuadPart);
175 
177  ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->BytesTransmitted.QuadPart);
178 
180  ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->SmbsTransmitted.QuadPart);
181 
183  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->ReadOperations);
184 
186  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->WriteOperations);
187 
189  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->RawReadsDenied);
190 
192  ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->RawWritesDenied);
193 
195  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->NetworkErrors);
196 
198  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->CoreConnects +
199  StatisticsInfo->Lanman20Connects +
200  StatisticsInfo->Lanman21Connects +
201  StatisticsInfo->LanmanNtConnects);
202 
204  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->Reconnects);
205 
207  ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->ServerDisconnects);
208 
210  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->Sessions);
211 
213  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->HungSessions);
214 
216  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->FailedSessions);
217 
219  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->InitiallyFailedOperations +
220  StatisticsInfo->FailedCompletionOperations);
221 
223  ConPrintf(StdOut, L"%lu\n", StatisticsInfo->UseCount);
224 
226  ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->FailedUseCount);
227 
228 done:
229  if (StatisticsInfo != NULL)
230  NetApiBufferFree(StatisticsInfo);
231 
232  if (WorkstationInfo != NULL)
233  NetApiBufferFree(WorkstationInfo);
234 
235  return 0;
236 }
237 
238 
239 INT
241  INT argc,
242  WCHAR **argv)
243 {
244  INT i, result = 0;
245  BOOL bServer = FALSE;
246  BOOL bWorkstation = FALSE;
247 
248  for (i = 2; i < argc; i++)
249  {
250  if (_wcsicmp(argv[i], L"server") == 0)
251  {
252  if (bWorkstation == FALSE)
253  bServer = TRUE;
254  continue;
255  }
256 
257  if (_wcsicmp(argv[i], L"workstation") == 0)
258  {
259  if (bServer == FALSE)
260  bWorkstation = TRUE;
261  continue;
262  }
263 
264  if (_wcsicmp(argv[i], L"help") == 0)
265  {
266  /* Print short syntax help */
269  return 0;
270  }
271 
272  if (_wcsicmp(argv[i], L"/help") == 0)
273  {
274  /* Print full help text*/
279  return 0;
280  }
281  }
282 
283  if (bServer)
284  {
285  result = DisplayServerStatistics();
286  }
287  else if (bWorkstation)
288  {
289  result = DisplayWorkstationStatistics();
290  }
291  else
292  {
294  }
295 
296  if (result == 0)
298 
299  return result;
300 }
static int argc
Definition: ServiceArgs.c:12
#define IDS_STATISTICS_WKS_NAME
Definition: resource.h:147
#define IDS_STATISTICS_WKS_SESSIONS
Definition: resource.h:160
struct _LARGE_INTEGER::@2193 u
#define TRUE
Definition: types.h:120
#define IDS_STATISTICS_SRV_KBRCVD
Definition: resource.h:136
#define IDS_STATISTICS_TEXT
Definition: resource.h:129
WORD wMonth
Definition: winbase.h:871
#define IDS_STATISTICS_WKS_RECONNECTS
Definition: resource.h:158
__wchar_t WCHAR
Definition: xmlstorage.h:180
static INT DisplayWorkstationStatistics(VOID)
NTSYSAPI VOID NTAPI RtlSecondsSince1970ToTime(_In_ ULONG SecondsSince1970, _Out_ PLARGE_INTEGER Time)
#define IDS_STATISTICS_WKS_FAILUSECOUNT
Definition: resource.h:165
#define IDS_STATISTICS_SINCE
Definition: resource.h:130
#define IDS_STATISTICS_SRV_BIGBUFFERS
Definition: resource.h:145
#define IDS_STATISTICS_WKS_READOPS
Definition: resource.h:152
NET_API_STATUS WINAPI NetStatisticsGet(_In_ LPWSTR server, _In_ LPWSTR service, _In_ DWORD level, _In_ DWORD options, _Out_ LPBYTE *bufptr)
Definition: misc.c:23
#define IDS_STATISTICS_SRV_SESSERROR
Definition: resource.h:134
#define IDS_STATISTICS_SRV_JOBS
Definition: resource.h:143
#define IDS_STATISTICS_WKS_WRITEOPS
Definition: resource.h:153
#define IDS_STATISTICS_SRV_KBSENT
Definition: resource.h:135
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
static char ** argv
Definition: ServiceArgs.c:11
#define NERR_Success
Definition: lmerr.h:5
#define IDS_STATISTICS_SRV_PWERRORS
Definition: resource.h:140
DWORD dwHighDateTime
Definition: mapidefs.h:66
WORD wYear
Definition: winbase.h:870
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define IDS_GENERIC_SYNTAX
Definition: resource.h:202
unsigned char * LPBYTE
Definition: typedefs.h:52
#define IDS_STATISTICS_WKS_BYTESTRANS
Definition: resource.h:150
#define IDS_STATISTICS_WKS_READDENIED
Definition: resource.h:154
#define IDS_STATISTICS_WKS_FAILSESSIONS
Definition: resource.h:162
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
#define IDS_STATISTICS_WKS_WRITEDENIED
Definition: resource.h:155
WORD wMinute
Definition: winbase.h:875
smooth NULL
Definition: ftsmooth.c:416
#define IDS_STATISTICS_SRV_SESSTIME
Definition: resource.h:133
#define IDS_STATISTICS_HELP_2
Definition: resource.h:72
#define IDS_STATISTICS_SRV_SYSERRORS
Definition: resource.h:138
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define IDS_STATISTICS_SRV_FILES
Definition: resource.h:141
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:178
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned short WORD
Definition: ntddk_ex.h:93
#define IDS_STATISTICS_WKS_BYTESRCVD
Definition: resource.h:148
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1087
#define IDS_STATISTICS_SRV_NAME
Definition: resource.h:131
#define IDS_STATISTICS_WKS_USECOUNT
Definition: resource.h:164
NET_API_STATUS WINAPI NetWkstaGetInfo(LMSTR servername, DWORD level, LPBYTE *bufptr)
Definition: wksta.c:472
#define IDS_ERROR_NO_ERROR
Definition: resource.h:208
NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE *bufptr)
Definition: srvsvc.c:369
Status
Definition: gdiplustypes.h:24
#define IDS_STATISTICS_WKS_HUNGSESSIONS
Definition: resource.h:161
WORD wDay
Definition: winbase.h:873
#define IDS_STATISTICS_SYNTAX
Definition: resource.h:70
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
VOID PrintPaddedResourceString(UINT uID, INT nPaddedLength)
Definition: main.c:51
#define IDS_STATISTICS_SRV_PMERRORS
Definition: resource.h:139
INT cmdStatistics(INT argc, WCHAR **argv)
WORD wHour
Definition: winbase.h:874
#define IDS_STATISTICS_WKS_SMBSTRANS
Definition: resource.h:151
static INT DisplayServerStatistics(VOID)
Definition: cmdStatistics.c:14
#define IDS_STATISTICS_WKS_SMBSRCVD
Definition: resource.h:149
#define IDS_STATISTICS_SRV_SESACCEPT
Definition: resource.h:132
#define StdOut
Definition: stream.h:76
#define IDS_STATISTICS_SRV_DEVICES
Definition: resource.h:142
#define IDS_STATISTICS_WKS_DISCONNECTS
Definition: resource.h:159
GLuint64EXT * result
Definition: glext.h:11304
#define IDS_STATISTICS_WKS_NETWORKERROR
Definition: resource.h:156
BYTE * PBYTE
Definition: pedump.c:66
#define IDS_STATISTICS_WKS_FAILEDOPS
Definition: resource.h:163
#define IDS_STATISTICS_WKS_CONNECTS
Definition: resource.h:157
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
DWORD dwLowDateTime
Definition: mapidefs.h:65
#define IDS_STATISTICS_HELP_1
Definition: resource.h:71
#define IDS_STATISTICS_SRV_BUFFERS
Definition: resource.h:144
LONGLONG QuadPart
Definition: typedefs.h:112
#define IDS_STATISTICS_SRV_REQBUFFERS
Definition: resource.h:146
#define IDS_STATISTICS_SRV_MRESPTIME
Definition: resource.h:137