Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

253 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. ethstat.c
  5. Abstract:
  6. This module displays counters for ethernet devices.
  7. Author:
  8. Rod Gamache (rodga) 26-Apr-1995
  9. Revision History:
  10. --*/
  11. #include "ethstat.h"
  12. DEVICE DeviceList[MAX_NIC] = {0};
  13. NTSTATUS
  14. NetStatsClose(
  15. VOID
  16. );
  17. NTSTATUS
  18. NetStatsInit(
  19. OUT LONG *NumberNetCards
  20. );
  21. NTSTATUS
  22. NetStatsReadSample(
  23. PNET_SAMPLE_STATISTICS PNetSampleStatistics
  24. );
  25. //
  26. // The following warning being disabled and the conversions into High and Low
  27. // below are all hacks to get around the fact that we cannot easily print out
  28. // LONGLONGs in the present versions of Windows NT - except for Alpha. This
  29. // should be fixed later, but the code should probably not change for a long
  30. // time, so that we can continue to build and use it on older versions of
  31. // Windows NT.
  32. //
  33. #pragma warning(disable:4244) // skip warnings about loss of data
  34. int
  35. __cdecl main( argc, argv )
  36. int argc;
  37. char *argv[];
  38. {
  39. NET_SAMPLE_STATISTICS NetSampleStatistics[MAX_NIC];
  40. PDEVICE device;
  41. ULONG NumberNetCards;
  42. ULONG i;
  43. ULONG High;
  44. ULONG Low;
  45. ULONG Div = 1000000000;
  46. ULONGLONG Number;
  47. ULONGLONG Number2;
  48. ULONGLONG Number3;
  49. //
  50. // Determine the number of net cards in the system and do an open
  51. // on the driver.
  52. //
  53. NumberNetCards = 0;
  54. NetStatsInit(&NumberNetCards);
  55. NetStatsReadSample( NetSampleStatistics );
  56. device = &DeviceList[0];
  57. for (i = 0; i < NumberNetCards; i++) {
  58. printf("\n\nCounters for Network Card: %s\n\n", device->DeviceName);
  59. Number = NetSampleStatistics[i].OidGenDirectedFramesRcv;
  60. High = (ULONG) (Number / Div);
  61. Low = (ULONG) (Number % Div);
  62. if ( Number != -1 ) printf("Frames Received: %0.0u%u\n", High, Low);
  63. Number = NetSampleStatistics[i].OidGenMulticastFramesRcv;
  64. High = (ULONG) (Number / Div);
  65. Low = (ULONG) (Number % Div);
  66. if ( Number != -1 ) printf("Multicast Frames Received: %0.0u%u\n", High, Low);
  67. Number = NetSampleStatistics[i].OidGenBroadcastFramesRcv;
  68. High = (ULONG) (Number / Div);
  69. Low = (ULONG) (Number % Div);
  70. if ( Number != -1 ) printf("Broadcast Frames Received: %0.0u%u\n\n", High, Low);
  71. Number = NetSampleStatistics[i].OidGenDirectedFramesXmit;
  72. High = (ULONG) (Number / Div);
  73. Low = (ULONG) (Number % Div);
  74. if ( Number != -1 ) printf("Frames Transmitted: %0.0u%u\n", High, Low);
  75. Number = NetSampleStatistics[i].OidGenMulticastFramesXmit;
  76. High = (ULONG) (Number / Div);
  77. Low = (ULONG) (Number % Div);
  78. if ( Number != -1 ) printf("Multicast Frames Transmitted: %0.0u%u\n", High, Low);
  79. Number = NetSampleStatistics[i].OidGenBroadcastFramesXmit;
  80. High = (ULONG) (Number / Div);
  81. Low = (ULONG) (Number % Div);
  82. if ( Number != -1 ) printf("Broadcast Frames Transmitted: %0.0u%u\n\n", High, Low);
  83. Number = NetSampleStatistics[i].OidGenDirectedBytesRcv;
  84. High = (ULONG) (Number / Div);
  85. Low = (ULONG) (Number % Div);
  86. if ( Number != -1 ) printf("Bytes Received: %0.0u%u\n", High, Low);
  87. Number = NetSampleStatistics[i].OidGenMulticastBytesRcv;
  88. High = (ULONG) (Number / Div);
  89. Low = (ULONG) (Number % Div);
  90. if ( Number != -1 ) printf("Multicast Bytes Received: %0.0u%u\n", High, Low);
  91. Number = NetSampleStatistics[i].OidGenBroadcastBytesRcv;
  92. High = (ULONG) (Number / Div);
  93. Low = (ULONG) (Number % Div);
  94. if ( Number != -1 ) printf("Broadcast Bytes Received: %0.0u%u\n", High, Low);
  95. Number2 = NetSampleStatistics[i].OidGenDirectedBytesRcv;
  96. Number3 = NetSampleStatistics[i].OidGenDirectedFramesRcv;
  97. Number = Number2 / Number3;
  98. High = (ULONG) (Number / Div);
  99. Low = (ULONG) (Number % Div);
  100. if ( Number2 != -1 && Number3 != -1 ) printf("Bytes Per Receive Frame: %0.0u%u\n\n", High, Low);
  101. Number = NetSampleStatistics[i].OidGenDirectedBytesXmit;
  102. High = (ULONG) (Number / Div);
  103. Low = (ULONG) (Number % Div);
  104. if ( Number != -1 ) printf("Bytes Transmitted: %0.0u%u\n", High, Low);
  105. Number = NetSampleStatistics[i].OidGenMulticastBytesXmit;
  106. High = (ULONG) (Number / Div);
  107. Low = (ULONG) (Number % Div);
  108. if ( Number != -1 ) printf("Multicast Bytes Transmitted: %0.0u%u\n", High, Low);
  109. Number = NetSampleStatistics[i].OidGenBroadcastBytesXmit;
  110. High = (ULONG) (Number / Div);
  111. Low = (ULONG) (Number % Div);
  112. if ( Number != -1 ) printf("Broadcast Bytes Transmitted: %0.0u%u\n", High, Low);
  113. Number2 = NetSampleStatistics[i].OidGenDirectedBytesXmit;
  114. Number3 = NetSampleStatistics[i].OidGenDirectedFramesXmit;
  115. Number = Number2 / Number3;
  116. High = (ULONG) (Number / Div);
  117. Low = (ULONG) (Number % Div);
  118. if ( Number2 != -1 && Number3 != -1 ) printf("Bytes Per Transmit Frame: %0.0u%u\n", High, Low);
  119. Number2 = NetSampleStatistics[i].OidGenDirectedBytesRcv;
  120. Number3 = NetSampleStatistics[i].OidGenDirectedBytesXmit;
  121. Number = Number2 + Number3;
  122. High = (ULONG) (Number / Div);
  123. Low = (ULONG) (Number % Div);
  124. if ( Number2 != -1 && Number3 != -1 ) printf("Bytes Total (xmt + rcv): %0.0u%u\n\n", High, Low);
  125. Number = NetSampleStatistics[i].OidGenMediaInUse;
  126. High = (ULONG) (Number / Div);
  127. Low = (ULONG) (Number % Div);
  128. if ( Number != -1 ) printf("Media In Use: %0.0u%u\n", High, Low);
  129. Number = NetSampleStatistics[i].OidGenLinkSpeed;
  130. High = (ULONG) (Number / Div);
  131. Low = (ULONG) (Number % Div);
  132. if ( Number != -1 ) printf("Link Speed: %0.0u%u\n", High, Low);
  133. Number = NetSampleStatistics[i].OidGenXmitError;
  134. High = (ULONG) (Number / Div);
  135. Low = (ULONG) (Number % Div);
  136. if ( Number != -1 ) printf("Transmit Errors: %0.0u%u\n", High, Low);
  137. Number = NetSampleStatistics[i].OidGenRcvError;
  138. High = (ULONG) (Number / Div);
  139. Low = (ULONG) (Number % Div);
  140. if ( Number != -1 ) printf("Receive Errors: %0.0u%u\n", High, Low);
  141. Number = NetSampleStatistics[i].OidGenRcvNoBuffer;
  142. High = (ULONG) (Number / Div);
  143. Low = (ULONG) (Number % Div);
  144. if ( Number != -1 ) printf("Receive No Buffer Avail: %0.0u%u\n", High, Low);
  145. Number = NetSampleStatistics[i].OidGenRcvCrcError;
  146. High = (ULONG) (Number / Div);
  147. Low = (ULONG) (Number % Div);
  148. if ( Number != -1 ) printf("Receive CRC Errors: %0.0u%u\n\n", High, Low);
  149. Number = NetSampleStatistics[i].OidGenTransmitQueueLength;
  150. High = (ULONG) (Number / Div);
  151. Low = (ULONG) (Number % Div);
  152. if ( Number != -1 ) printf("Transmit Queue Length: %0.0u%u\n", High, Low);
  153. Number = NetSampleStatistics[i].Oid802_3RcvErrorAlignment;
  154. High = (ULONG) (Number / Div);
  155. Low = (ULONG) (Number % Div);
  156. if ( Number != -1 ) printf("Receive Error Alignment: %0.0u%u\n", High, Low);
  157. Number = NetSampleStatistics[i].Oid802_3XmitOneCollision;
  158. High = (ULONG) (Number / Div);
  159. Low = (ULONG) (Number % Div);
  160. if ( Number != -1 ) printf("Transmit One Collision: %0.0u%u\n", High, Low);
  161. Number = NetSampleStatistics[i].Oid802_3XmitMoreCollisions;
  162. High = (ULONG) (Number / Div);
  163. Low = (ULONG) (Number % Div);
  164. if ( Number != -1 ) printf("Transmit Multiple Collisions: %0.0u%u\n", High, Low);
  165. Number = NetSampleStatistics[i].Oid802_3XmitDeferred;
  166. High = (ULONG) (Number / Div);
  167. Low = (ULONG) (Number % Div);
  168. if ( Number != -1 ) printf("Transmits Deferred: %0.0u%u\n", High, Low);
  169. Number = NetSampleStatistics[i].Oid802_3XmitMaxCollisions;
  170. High = (ULONG) (Number / Div);
  171. Low = (ULONG) (Number % Div);
  172. if ( Number != -1 ) printf("Transmits Max Collisions: %0.0u%u\n", High, Low);
  173. Number = NetSampleStatistics[i].Oid802_3RcvOverRun;
  174. High = (ULONG) (Number / Div);
  175. Low = (ULONG) (Number % Div);
  176. if ( Number != -1 ) printf("Receive Over Runs: %0.0u%u\n", High, Low);
  177. Number = NetSampleStatistics[i].Oid802_3XmitUnderRun;
  178. High = (ULONG) (Number / Div);
  179. Low = (ULONG) (Number % Div);
  180. if ( Number != -1 ) printf("Transmit Under Runs: %0.0u%u\n", High, Low);
  181. Number = NetSampleStatistics[i].Oid802_3XmitTimesCrsLost;
  182. High = (ULONG) (Number / Div);
  183. Low = (ULONG) (Number % Div);
  184. if ( Number != -1 ) printf("Transmit Carrier Lost: %0.0u%u\n", High, Low);
  185. Number = NetSampleStatistics[i].Oid802_3XmitLateCollisions;
  186. High = (ULONG) (Number / Div);
  187. Low = (ULONG) (Number % Div);
  188. if ( Number != -1 ) printf("Transmit Late Collisions: %0.0u%u\n\n\n", High, Low);
  189. device += 1;
  190. }
  191. NetStatsClose();
  192. return 0;
  193. } // end of main