Source code of Windows XP (NT5)
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.

138 lines
3.3 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. netperf.c
  5. Abstract:
  6. Command line test for getting the connection performance.
  7. Author:
  8. Cory West [corywest] 17-April-96
  9. ***/
  10. #include "ndsapi32.h"
  11. #include "ntddnwfs.h"
  12. int
  13. _cdecl main(
  14. int argc,
  15. char **argv
  16. ) {
  17. NTSTATUS ntstatus;
  18. IO_STATUS_BLOCK IoStatusBlock;
  19. OBJECT_ATTRIBUTES ObjectAttributes;
  20. ACCESS_MASK DesiredAccess = SYNCHRONIZE | FILE_LIST_DIRECTORY;
  21. HANDLE hRdr;
  22. WCHAR OpenString[] = L"\\Device\\Nwrdr\\*";
  23. UNICODE_STRING OpenName;
  24. OEM_STRING OemArg;
  25. UNICODE_STRING ConnectionName;
  26. PNWR_REQUEST_PACKET Request;
  27. ULONG BufferSize = 512;
  28. ULONG RequestSize;
  29. //
  30. // Check the arguments.
  31. //
  32. if ( argc != 2 ) {
  33. printf( "Usage: netperf [remote name]\n" );
  34. return -1;
  35. }
  36. //
  37. // Allocate buffer space.
  38. //
  39. Request = (PNWR_REQUEST_PACKET) LocalAlloc( LMEM_ZEROINIT, BufferSize );
  40. if ( !Request ) {
  41. printf( "Insufficient memory to complete the request.\n" );
  42. return -1;
  43. }
  44. //
  45. // Convert the connect name to unicode.
  46. //
  47. ConnectionName.Length = 0;
  48. ConnectionName.MaximumLength = (USHORT) ( BufferSize - sizeof( NWR_REQUEST_PACKET ) );
  49. ConnectionName.Buffer = &(Request->Parameters.GetConnPerformance.RemoteName[0]);
  50. OemArg.Length = strlen( argv[1] );
  51. OemArg.MaximumLength = OemArg.Length;
  52. OemArg.Buffer = argv[1];
  53. RtlOemStringToUnicodeString( &ConnectionName, &OemArg, FALSE );
  54. //
  55. // Set up the object attributes.
  56. //
  57. RtlInitUnicodeString( &OpenName, OpenString );
  58. InitializeObjectAttributes( &ObjectAttributes,
  59. &OpenName,
  60. OBJ_CASE_INSENSITIVE,
  61. NULL,
  62. NULL );
  63. ntstatus = NtOpenFile( &hRdr,
  64. DesiredAccess,
  65. &ObjectAttributes,
  66. &IoStatusBlock,
  67. FILE_SHARE_VALID_FLAGS,
  68. FILE_SYNCHRONOUS_IO_NONALERT );
  69. if ( !NT_SUCCESS(ntstatus) )
  70. return ntstatus;
  71. //
  72. // Fill out the request packet for FSCTL_NWR_GET_CONN_PERFORMANCE.
  73. //
  74. Request->Parameters.GetConnPerformance.RemoteNameLength = ConnectionName.Length;
  75. RequestSize = sizeof( NWR_REQUEST_PACKET ) + ConnectionName.Length;
  76. ntstatus = NtFsControlFile( hRdr,
  77. NULL,
  78. NULL,
  79. NULL,
  80. &IoStatusBlock,
  81. FSCTL_NWR_GET_CONN_PERFORMANCE,
  82. (PVOID) Request,
  83. RequestSize,
  84. NULL,
  85. 0 );
  86. if ( !NT_SUCCESS( ntstatus ) ) {
  87. goto ExitWithClose;
  88. }
  89. //
  90. // Print out the speed and packet size.
  91. //
  92. printf( "Speed: %d\n", Request->Parameters.GetConnPerformance.dwSpeed );
  93. printf( "Flags: %d\n", Request->Parameters.GetConnPerformance.dwFlags );
  94. printf( "Delay: %d\n", Request->Parameters.GetConnPerformance.dwDelay );
  95. printf( "Packet Size: %d\n", Request->Parameters.GetConnPerformance.dwOptDataSize );
  96. ExitWithClose:
  97. LocalFree( Request );
  98. NtClose( hRdr );
  99. return ntstatus;
  100. }