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.

269 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. tnetbios.c
  5. Abstract:
  6. This module contains code which exercises the NetBIOS dll and driver.
  7. Author:
  8. Colin Watson (ColinW) 13-Mar-1991
  9. Environment:
  10. Application mode
  11. Revision History:
  12. Dave Beaver (DBeaver) 10 August 1991
  13. Modify to support multiple LAN numbers
  14. --*/
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windows.h>
  19. #include <nb30.h>
  20. #include <stdio.h>
  21. // 1234567890123456
  22. #define SPACES " "
  23. #define Hi "Come here Dave, I need you"
  24. #define ClearNcb( PNCB ) { \
  25. RtlZeroMemory( PNCB , sizeof (NCB) ); \
  26. RtlMoveMemory( (PNCB)->ncb_name, SPACES, sizeof(SPACES)-1 );\
  27. RtlMoveMemory( (PNCB)->ncb_callname, SPACES, sizeof(SPACES)-1 );\
  28. }
  29. // Hard code lana-num that is mapped to XNS
  30. #define XNS 1
  31. int Limit = 20;
  32. VOID
  33. usage (
  34. VOID
  35. )
  36. {
  37. printf("usage: tnetbl [-n:lan number][-h] <remote computername> <my computername>\n");
  38. printf(" -n specifies the lan number (0 is the default)\n");
  39. printf(" -h specifies that addresses are hexadecimal numbers \n");
  40. printf(" rather than strings.\n");
  41. printf(" final two arguments are the remote and local computer names.\n");
  42. }
  43. int
  44. main (argc, argv)
  45. int argc;
  46. char *argv[];
  47. {
  48. NCB myncb;
  49. CHAR Buffer2[128];
  50. int i,j;
  51. CHAR localName[16];
  52. CHAR remoteName[16];
  53. CHAR localTemp[32];
  54. CHAR remoteTemp[32];
  55. ULONG lanNumber=0;
  56. BOOLEAN gotFirst=FALSE;
  57. BOOLEAN asHex=FALSE;
  58. UCHAR lsn;
  59. UCHAR name_number;
  60. USHORT length;
  61. if ( argc < 3 || argc > 5) {
  62. usage ();
  63. return 1;
  64. }
  65. //
  66. // dbeaver: added switch to allow 32 byte hex string as name to facilitate
  67. // testing under unusual circumstances
  68. //
  69. for (j=1;j<16;j++ ) {
  70. localTemp[j] = ' ';
  71. remoteTemp[j] = ' ';
  72. }
  73. //
  74. // parse the switches
  75. //
  76. for (i=1;i<argc ;i++ ) {
  77. if (argv[i][0] == '-') {
  78. switch (argv[i][1]) {
  79. case 'n':
  80. if (!NT_SUCCESS(RtlCharToInteger (&argv[i][3], 10, &lanNumber))) {
  81. usage ();
  82. return 1;
  83. }
  84. break;
  85. case 'h':
  86. asHex = TRUE;
  87. break;
  88. default:
  89. usage ();
  90. return 1;
  91. break;
  92. }
  93. } else {
  94. //
  95. // not a switch must be a name
  96. //
  97. if (gotFirst != TRUE) {
  98. RtlMoveMemory (remoteTemp, argv[i], lstrlen( argv[i] ));
  99. gotFirst = TRUE;
  100. } else {
  101. RtlMoveMemory (localTemp, argv[i], lstrlen( argv[i] ));
  102. }
  103. }
  104. }
  105. if (asHex) {
  106. RtlZeroMemory (localName, 16);
  107. RtlZeroMemory (remoteName, 16);
  108. for (j=0;j<16 ;j+=4) {
  109. RtlCharToInteger (&localTemp[j*2], 16, (PULONG)&localName[j]);
  110. }
  111. for (j=0;j<16 ;j+=4) {
  112. RtlCharToInteger (&remoteTemp[j*2], 16, (PULONG)&remoteName[j]);
  113. }
  114. } else {
  115. for (j=1;j<16;j++ ) {
  116. localName[j] = ' ';
  117. remoteName[j] = ' ';
  118. }
  119. RtlMoveMemory( localName, localTemp, 16);
  120. RtlMoveMemory( remoteName, remoteTemp, 16);
  121. }
  122. // Reset
  123. ClearNcb( &myncb );
  124. myncb.ncb_command = NCBRESET;
  125. myncb.ncb_lsn = 0; // Request resources
  126. myncb.ncb_lana_num = lanNumber;
  127. myncb.ncb_callname[0] = 0; // 16 sessions
  128. myncb.ncb_callname[1] = 0; // 16 commands
  129. myncb.ncb_callname[2] = 0; // 8 names
  130. Netbios( &myncb );
  131. // AddName
  132. ClearNcb( &myncb );
  133. myncb.ncb_command = NCBADDNAME;
  134. RtlMoveMemory( myncb.ncb_name, localName, 16);
  135. myncb.ncb_lana_num = (UCHAR)lanNumber;
  136. Netbios( &myncb );
  137. if ( myncb.ncb_retcode != NRC_GOODRET ) {
  138. printf( "Addname returned an error %lx", myncb.ncb_retcode );
  139. return 1;
  140. }
  141. name_number = myncb.ncb_num;
  142. printf( "Starting Listen test\n" );
  143. for ( j = 0; j <= Limit; j++ ) {
  144. printf( "\nStarting Listen " );
  145. // Listen
  146. ClearNcb( &myncb );
  147. myncb.ncb_command = NCBLISTEN | ASYNCH;
  148. RtlMoveMemory( myncb.ncb_name, localName, 16);
  149. RtlMoveMemory( myncb.ncb_callname, remoteName, 16);
  150. myncb.ncb_lana_num = (UCHAR)lanNumber;
  151. myncb.ncb_rto = myncb.ncb_rto = 0; //10; 10*500 milliseconds timeout
  152. myncb.ncb_num = name_number;
  153. Netbios( &myncb );
  154. printf( "Listen returned " );
  155. while ( myncb.ncb_cmd_cplt == NRC_PENDING ) {
  156. printf( "." );
  157. Sleep(500);
  158. }
  159. printf( " Listen completed\n" );
  160. if ( myncb.ncb_retcode != NRC_GOODRET ) {
  161. break;
  162. }
  163. lsn = myncb.ncb_lsn;
  164. while ( 1 ) {
  165. // Receive
  166. ClearNcb( &myncb );
  167. myncb.ncb_command = NCBRECV | ASYNCH;
  168. myncb.ncb_lana_num = (UCHAR)lanNumber;
  169. myncb.ncb_length = sizeof( Buffer2 );
  170. myncb.ncb_buffer = Buffer2;
  171. myncb.ncb_lsn = lsn;
  172. Netbios( &myncb );
  173. printf( "R" );
  174. while ( myncb.ncb_cmd_cplt == NRC_PENDING ) {
  175. // printf( "." );
  176. // Sleep(250);
  177. }
  178. printf( "r" );
  179. if ( myncb.ncb_retcode != NRC_GOODRET ) {
  180. break;
  181. }
  182. //printf( ":%s\n", Buffer2);
  183. length = myncb.ncb_length;
  184. // Send
  185. ClearNcb( &myncb );
  186. myncb.ncb_command = NCBSEND;
  187. myncb.ncb_lana_num = (UCHAR)lanNumber;
  188. myncb.ncb_length = length;
  189. myncb.ncb_buffer = Buffer2;
  190. myncb.ncb_lsn = lsn;
  191. Netbios( &myncb );
  192. if ( myncb.ncb_retcode != NRC_GOODRET ) {
  193. break;
  194. }
  195. }
  196. // Hangup
  197. ClearNcb( &myncb );
  198. myncb.ncb_command = NCBHANGUP;
  199. myncb.ncb_lana_num = (UCHAR)lanNumber;
  200. myncb.ncb_lsn = lsn;
  201. Netbios( &myncb );
  202. if ( myncb.ncb_retcode != NRC_GOODRET ) {
  203. break;
  204. }
  205. }
  206. // Reset
  207. ClearNcb( &myncb );
  208. myncb.ncb_command = NCBRESET;
  209. myncb.ncb_lsn = 1; // Free resources
  210. Netbios( &myncb );
  211. printf( "Ending NetBios\n" );
  212. return 0;
  213. }