ReactOS  0.4.12-dev-714-gfaac916
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  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 
134  100,
135  (PBYTE*)&WorkstationInfo);
136  if (Status != NERR_Success)
137  goto done;
138 
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 */
268  PrintNetMessage(MSG_STATISTICS_SYNTAX);
269  return 0;
270  }
271 
272  if (_wcsicmp(argv[i], L"/help") == 0)
273  {
274  /* Print full help text*/
276  PrintNetMessage(MSG_STATISTICS_SYNTAX);
277  PrintNetMessage(MSG_STATISTICS_HELP);
278  return 0;
279  }
280  }
281 
282  if (bServer)
283  {
285  }
286  else if (bWorkstation)
287  {
289  }
290  else
291  {
293  }
294 
295  if (result == 0)
297 
298  return result;
299 }
static int argc
Definition: ServiceArgs.c:12
#define IDS_STATISTICS_WKS_NAME
Definition: resource.h:63
#define IDS_STATISTICS_WKS_SESSIONS
Definition: resource.h:76
#define TRUE
Definition: types.h:120
#define IDS_STATISTICS_SRV_KBRCVD
Definition: resource.h:52
#define ERROR_SUCCESS
Definition: deptool.c:10
#define IDS_STATISTICS_TEXT
Definition: resource.h:45
WORD wMonth
Definition: winbase.h:871
#define IDS_STATISTICS_WKS_RECONNECTS
Definition: resource.h:74
__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:81
#define IDS_STATISTICS_SINCE
Definition: resource.h:46
#define IDS_STATISTICS_SRV_BIGBUFFERS
Definition: resource.h:61
#define IDS_STATISTICS_WKS_READOPS
Definition: resource.h:68
NET_API_STATUS WINAPI NetStatisticsGet(_In_ LPWSTR server, _In_ LPWSTR service, _In_ DWORD level, _In_ DWORD options, _Out_ LPBYTE *bufptr)
Definition: misc.c:55
#define IDS_STATISTICS_SRV_SESSERROR
Definition: resource.h:50
#define IDS_STATISTICS_SRV_JOBS
Definition: resource.h:59
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:149
#define IDS_STATISTICS_WKS_WRITEOPS
Definition: resource.h:69
#define IDS_STATISTICS_SRV_KBSENT
Definition: resource.h:51
#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
#define IDS_STATISTICS_SRV_PWERRORS
Definition: resource.h:56
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
#define IDS_GENERIC_SYNTAX
Definition: resource.h:118
unsigned char * LPBYTE
Definition: typedefs.h:52
#define IDS_STATISTICS_WKS_BYTESTRANS
Definition: resource.h:66
#define IDS_STATISTICS_WKS_READDENIED
Definition: resource.h:70
#define IDS_STATISTICS_WKS_FAILSESSIONS
Definition: resource.h:78
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
#define IDS_STATISTICS_WKS_WRITEDENIED
Definition: resource.h:71
WORD wMinute
Definition: winbase.h:875
smooth NULL
Definition: ftsmooth.c:416
#define IDS_STATISTICS_SRV_SESSTIME
Definition: resource.h:49
#define IDS_STATISTICS_SRV_SYSERRORS
Definition: resource.h:54
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:57
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:64
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1250
#define IDS_STATISTICS_SRV_NAME
Definition: resource.h:47
#define IDS_STATISTICS_WKS_USECOUNT
Definition: resource.h:80
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
#define IDS_STATISTICS_WKS_HUNGSESSIONS
Definition: resource.h:77
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 PrintPaddedResourceString(UINT uID, INT nPaddedLength)
Definition: main.c:52
#define IDS_STATISTICS_SRV_PMERRORS
Definition: resource.h:55
INT cmdStatistics(INT argc, WCHAR **argv)
WORD wHour
Definition: winbase.h:874
#define IDS_STATISTICS_WKS_SMBSTRANS
Definition: resource.h:67
static INT DisplayServerStatistics(VOID)
Definition: cmdStatistics.c:14
#define IDS_STATISTICS_WKS_SMBSRCVD
Definition: resource.h:65
struct _LARGE_INTEGER::@2190 u
#define IDS_STATISTICS_SRV_SESACCEPT
Definition: resource.h:48
#define StdOut
Definition: stream.h:76
#define IDS_STATISTICS_SRV_DEVICES
Definition: resource.h:58
#define IDS_STATISTICS_WKS_DISCONNECTS
Definition: resource.h:75
GLuint64EXT * result
Definition: glext.h:11304
#define IDS_STATISTICS_WKS_NETWORKERROR
Definition: resource.h:72
BYTE * PBYTE
Definition: pedump.c:66
#define IDS_STATISTICS_WKS_FAILEDOPS
Definition: resource.h:79
#define IDS_STATISTICS_WKS_CONNECTS
Definition: resource.h:73
_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_SRV_BUFFERS
Definition: resource.h:60
LONGLONG QuadPart
Definition: typedefs.h:112
#define IDS_STATISTICS_SRV_REQBUFFERS
Definition: resource.h:62
#define IDS_STATISTICS_SRV_MRESPTIME
Definition: resource.h:53