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.

908 lines
32 KiB

  1. /*++
  2. Copyright (c) 1992-1996 Microsoft Corporation
  3. Module Name:
  4. test.c
  5. Abstract:
  6. Test the LM MIB and its supporting functions.
  7. Environment:
  8. User Mode - Win32
  9. Revision History:
  10. 10-May-1996 DonRyan
  11. Removed banner from Technology Dynamics, Inc.
  12. --*/
  13. //--------------------------- WINDOWS DEPENDENCIES --------------------------
  14. //--------------------------- STANDARD DEPENDENCIES -- #include<xxxxx.h> ----
  15. #include <stdio.h>
  16. #include <memory.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include <time.h>
  20. //--------------------------- MODULE DEPENDENCIES -- #include"xxxxx.h" ------
  21. #include <snmp.h>
  22. #include <snmputil.h>
  23. #include "mib.h"
  24. #include "mibfuncs.h"
  25. #include "hash.h"
  26. //--------------------------- SELF-DEPENDENCY -- ONE #include"module.h" -----
  27. //--------------------------- PUBLIC VARIABLES --(same as in module.h file)--
  28. //--------------------------- PRIVATE CONSTANTS -----------------------------
  29. //--------------------------- PRIVATE STRUCTS -------------------------------
  30. //--------------------------- PRIVATE VARIABLES -----------------------------
  31. //--------------------------- PRIVATE PROTOTYPES ----------------------------
  32. SNMPAPI SnmpExtensionQuery(
  33. IN AsnInteger ReqType, // 1157 Request type
  34. IN OUT RFC1157VarBindList *VarBinds, // Var Binds to resolve
  35. OUT AsnInteger *ErrorStatus, // Error status returned
  36. OUT AsnInteger *ErrorIndex // Var Bind containing error
  37. );
  38. //--------------------------- PRIVATE PROCEDURES ----------------------------
  39. //--------------------------- PUBLIC PROCEDURES -----------------------------
  40. BYTE pBuffer[2000];
  41. UINT nLength;
  42. SnmpMgmtCom Msg;
  43. MIB_ENTRY *MibPtr;
  44. void *pResult;
  45. void main( )
  46. {
  47. //
  48. // Init hashing system
  49. //
  50. MIB_HashInit();
  51. //
  52. // Title
  53. //
  54. printf( "Tests for MIB root: " );
  55. SnmpUtilPrintOid( &MIB_OidPrefix ); printf( "\n--------------------------\n\n" );
  56. //
  57. // Display significant Mib variables
  58. //
  59. printf( "Common start: " );
  60. SnmpUtilPrintOid( &Mib[MIB_COM_START].Oid );
  61. putchar( '\n' );
  62. printf( "Server start: " );
  63. SnmpUtilPrintOid( &Mib[MIB_SV_START].Oid );
  64. putchar( '\n' );
  65. printf( "Workstation start: " );
  66. SnmpUtilPrintOid( &Mib[MIB_WKSTA_START].Oid );
  67. putchar( '\n' );
  68. printf( "Domain start: " );
  69. SnmpUtilPrintOid( &Mib[MIB_DOM_START].Oid );
  70. putchar( '\n' );
  71. printf( "Last MIB variable: " );
  72. SnmpUtilPrintOid( &Mib[MIB_num_variables-1].Oid );
  73. putchar( '\n' );
  74. putchar( '\n' );
  75. //
  76. // Specific tests for integrity
  77. //
  78. printf( "FIRST leaf get\n" );
  79. {
  80. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 1, 1, 0 };
  81. RFC1157VarBindList varBinds;
  82. AsnInteger errorStatus = 0;
  83. AsnInteger errorIndex = 0;
  84. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  85. varBinds.len = 1;
  86. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  87. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  88. varBinds.list[0].name.idLength );
  89. memcpy( varBinds.list[0].name.ids, &itemn,
  90. sizeof(UINT)*varBinds.list[0].name.idLength );
  91. varBinds.list[0].value.asnType = ASN_NULL;
  92. SnmpUtilPrintOid( &varBinds.list[0].name ); printf ( " = " );
  93. SnmpExtensionQuery( ASN_RFC1157_GETREQUEST,
  94. &varBinds,
  95. &errorStatus,
  96. &errorIndex
  97. );
  98. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  99. {
  100. SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  101. }
  102. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  103. // Free the memory
  104. SnmpUtilVarBindListFree( &varBinds );
  105. }
  106. printf( "LAST leaf get\n" );
  107. {
  108. #if 1
  109. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 4, 5, 0 };
  110. #else
  111. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 4, 7, 0 };
  112. #endif
  113. RFC1157VarBindList varBinds;
  114. AsnInteger errorStatus = 0;
  115. AsnInteger errorIndex = 0;
  116. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  117. varBinds.len = 1;
  118. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  119. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  120. varBinds.list[0].name.idLength );
  121. memcpy( varBinds.list[0].name.ids, &itemn,
  122. sizeof(UINT)*varBinds.list[0].name.idLength );
  123. varBinds.list[0].value.asnType = ASN_NULL;
  124. SnmpUtilPrintOid( &varBinds.list[0].name ); printf ( " = " );
  125. SnmpExtensionQuery( ASN_RFC1157_GETREQUEST,
  126. &varBinds,
  127. &errorStatus,
  128. &errorIndex
  129. );
  130. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  131. {
  132. SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  133. }
  134. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  135. // Free the memory
  136. SnmpUtilVarBindListFree( &varBinds );
  137. }
  138. printf( "GET on an AGGREGATE\n" );
  139. {
  140. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1 };
  141. RFC1157VarBindList varBinds;
  142. AsnInteger errorStatus = 0;
  143. AsnInteger errorIndex = 0;
  144. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  145. varBinds.len = 1;
  146. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  147. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  148. varBinds.list[0].name.idLength );
  149. memcpy( varBinds.list[0].name.ids, &itemn,
  150. sizeof(UINT)*varBinds.list[0].name.idLength );
  151. varBinds.list[0].value.asnType = ASN_NULL;
  152. SnmpUtilPrintOid( &varBinds.list[0].name ); printf ( " = " );
  153. SnmpExtensionQuery( ASN_RFC1157_GETREQUEST,
  154. &varBinds,
  155. &errorStatus,
  156. &errorIndex
  157. );
  158. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  159. {
  160. SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  161. }
  162. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  163. // Free the memory
  164. SnmpUtilVarBindListFree( &varBinds );
  165. }
  166. printf( "GET on a TABLE root\n" );
  167. {
  168. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 3, 8, 1 };
  169. RFC1157VarBindList varBinds;
  170. AsnInteger errorStatus = 0;
  171. AsnInteger errorIndex = 0;
  172. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  173. varBinds.len = 1;
  174. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  175. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  176. varBinds.list[0].name.idLength );
  177. memcpy( varBinds.list[0].name.ids, &itemn,
  178. sizeof(UINT)*varBinds.list[0].name.idLength );
  179. varBinds.list[0].value.asnType = ASN_NULL;
  180. SnmpUtilPrintOid( &varBinds.list[0].name ); printf ( " = " );
  181. SnmpExtensionQuery( ASN_RFC1157_GETREQUEST,
  182. &varBinds,
  183. &errorStatus,
  184. &errorIndex
  185. );
  186. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  187. {
  188. SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  189. }
  190. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  191. // Free the memory
  192. SnmpUtilVarBindListFree( &varBinds );
  193. }
  194. printf( "GET on a NON existent variable\n" );
  195. {
  196. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 100, 8 };
  197. RFC1157VarBindList varBinds;
  198. AsnInteger errorStatus = 0;
  199. AsnInteger errorIndex = 0;
  200. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  201. varBinds.len = 1;
  202. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  203. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  204. varBinds.list[0].name.idLength );
  205. memcpy( varBinds.list[0].name.ids, &itemn,
  206. sizeof(UINT)*varBinds.list[0].name.idLength );
  207. varBinds.list[0].value.asnType = ASN_NULL;
  208. SnmpUtilPrintOid( &varBinds.list[0].name ); printf ( " = " );
  209. SnmpExtensionQuery( ASN_RFC1157_GETREQUEST,
  210. &varBinds,
  211. &errorStatus,
  212. &errorIndex
  213. );
  214. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  215. {
  216. SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  217. }
  218. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  219. // Free the memory
  220. SnmpUtilVarBindListFree( &varBinds );
  221. }
  222. printf( "GET-NEXT on hole with MIB-TABLE following\n" );
  223. {
  224. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 2, 20, 0 };
  225. RFC1157VarBindList varBinds;
  226. AsnInteger errorStatus = 0;
  227. AsnInteger errorIndex = 0;
  228. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  229. varBinds.len = 1;
  230. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  231. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  232. varBinds.list[0].name.idLength );
  233. memcpy( varBinds.list[0].name.ids, &itemn,
  234. sizeof(UINT)*varBinds.list[0].name.idLength );
  235. varBinds.list[0].value.asnType = ASN_NULL;
  236. printf( "GET-NEXT of: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  237. printf( " " );
  238. SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST,
  239. &varBinds,
  240. &errorStatus,
  241. &errorIndex
  242. );
  243. printf( "\n is " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  244. printf( "\n = " );
  245. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  246. {
  247. SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  248. }
  249. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  250. // Free the memory
  251. SnmpUtilVarBindListFree( &varBinds );
  252. }
  253. printf( "GET-NEXT on hole with MIB-AGGREGATE following\n" );
  254. {
  255. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 2, 26, 0 };
  256. RFC1157VarBindList varBinds;
  257. AsnInteger errorStatus = 0;
  258. AsnInteger errorIndex = 0;
  259. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  260. varBinds.len = 1;
  261. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  262. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  263. varBinds.list[0].name.idLength );
  264. memcpy( varBinds.list[0].name.ids, &itemn,
  265. sizeof(UINT)*varBinds.list[0].name.idLength );
  266. varBinds.list[0].value.asnType = ASN_NULL;
  267. printf( "GET-NEXT of: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  268. printf( " " );
  269. SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST,
  270. &varBinds,
  271. &errorStatus,
  272. &errorIndex
  273. );
  274. printf( "\n is " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  275. printf( "\n = " );
  276. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  277. {
  278. SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  279. }
  280. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  281. // Free the memory
  282. SnmpUtilVarBindListFree( &varBinds );
  283. }
  284. printf( "GET-NEXT on hole with LEAF following\n" );
  285. {
  286. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 4, 1 };
  287. RFC1157VarBindList varBinds;
  288. AsnInteger errorStatus = 0;
  289. AsnInteger errorIndex = 0;
  290. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  291. varBinds.len = 1;
  292. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  293. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  294. varBinds.list[0].name.idLength );
  295. memcpy( varBinds.list[0].name.ids, &itemn,
  296. sizeof(UINT)*varBinds.list[0].name.idLength );
  297. varBinds.list[0].value.asnType = ASN_NULL;
  298. printf( "GET-NEXT of: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  299. printf( " " );
  300. SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST,
  301. &varBinds,
  302. &errorStatus,
  303. &errorIndex
  304. );
  305. printf( "\n is " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  306. printf( "\n = " );
  307. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  308. {
  309. SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  310. }
  311. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  312. // Free the memory
  313. SnmpUtilVarBindListFree( &varBinds );
  314. }
  315. printf( "GET-NEXT on variable BEFORE Beginning of LM MIB\n" );
  316. {
  317. UINT itemn[] = { 1 };
  318. RFC1157VarBindList varBinds;
  319. AsnInteger errorStatus = 0;
  320. AsnInteger errorIndex = 0;
  321. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  322. varBinds.len = 1;
  323. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  324. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  325. varBinds.list[0].name.idLength );
  326. memcpy( varBinds.list[0].name.ids, &itemn,
  327. sizeof(UINT)*varBinds.list[0].name.idLength );
  328. varBinds.list[0].value.asnType = ASN_NULL;
  329. printf( "GET-NEXT of: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  330. printf( " " );
  331. SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST,
  332. &varBinds,
  333. &errorStatus,
  334. &errorIndex
  335. );
  336. printf( "\n is " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  337. printf( "\n = " );
  338. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  339. {
  340. SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  341. }
  342. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  343. // Free the memory
  344. SnmpUtilVarBindListFree( &varBinds );
  345. }
  346. printf( "GET-NEXT on variable past end of MIB\n" );
  347. {
  348. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 2 };
  349. RFC1157VarBindList varBinds;
  350. AsnInteger errorStatus = 0;
  351. AsnInteger errorIndex = 0;
  352. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  353. varBinds.len = 1;
  354. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  355. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  356. varBinds.list[0].name.idLength );
  357. memcpy( varBinds.list[0].name.ids, &itemn,
  358. sizeof(UINT)*varBinds.list[0].name.idLength );
  359. varBinds.list[0].value.asnType = ASN_NULL;
  360. printf( "GET-NEXT of: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  361. printf( " " );
  362. SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST,
  363. &varBinds,
  364. &errorStatus,
  365. &errorIndex
  366. );
  367. printf( "\n is " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  368. printf( "\n = " );
  369. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  370. {
  371. SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  372. }
  373. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  374. // Free the memory
  375. SnmpUtilVarBindListFree( &varBinds );
  376. }
  377. printf( "SET on Server Description\n" );
  378. {
  379. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 2, 1, 0 };
  380. BYTE *Value = "This server sux";
  381. RFC1157VarBindList varBinds;
  382. AsnInteger errorStatus = 0;
  383. AsnInteger errorIndex = 0;
  384. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  385. varBinds.len = 1;
  386. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  387. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  388. varBinds.list[0].name.idLength );
  389. memcpy( varBinds.list[0].name.ids, &itemn,
  390. sizeof(UINT)*varBinds.list[0].name.idLength );
  391. varBinds.list[0].value.asnType = ASN_RFC1213_DISPSTRING;
  392. varBinds.list[0].value.asnValue.string.stream = Value;
  393. varBinds.list[0].value.asnValue.string.length = strlen( Value );
  394. varBinds.list[0].value.asnValue.string.dynamic = FALSE;
  395. printf( "SET: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  396. printf( " to " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  397. SnmpExtensionQuery( ASN_RFC1157_SETREQUEST,
  398. &varBinds,
  399. &errorStatus,
  400. &errorIndex
  401. );
  402. printf( "\nSET Errorstatus: %lu\n\n", errorStatus );
  403. SnmpExtensionQuery( ASN_RFC1157_GETREQUEST,
  404. &varBinds,
  405. &errorStatus,
  406. &errorIndex
  407. );
  408. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  409. {
  410. printf( "New Value: " );
  411. SnmpUtilPrintAsnAny( &varBinds.list[0].value ); putchar( '\n' );
  412. }
  413. printf( "\nGET Errorstatus: %lu\n\n", errorStatus );
  414. // Free the memory
  415. SnmpUtilVarBindListFree( &varBinds );
  416. }
  417. printf( "Try and SET Server Description with WRONG type\n" );
  418. {
  419. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 2, 1, 0 };
  420. RFC1157VarBindList varBinds;
  421. AsnInteger errorStatus = 0;
  422. AsnInteger errorIndex = 0;
  423. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  424. varBinds.len = 1;
  425. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  426. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  427. varBinds.list[0].name.idLength );
  428. memcpy( varBinds.list[0].name.ids, &itemn,
  429. sizeof(UINT)*varBinds.list[0].name.idLength );
  430. varBinds.list[0].value.asnType = ASN_INTEGER;
  431. printf( "SET: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  432. printf( " to " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  433. SnmpExtensionQuery( ASN_RFC1157_SETREQUEST,
  434. &varBinds,
  435. &errorStatus,
  436. &errorIndex
  437. );
  438. printf( "\nSET Errorstatus: %lu\n\n", errorStatus );
  439. SnmpExtensionQuery( ASN_RFC1157_GETREQUEST,
  440. &varBinds,
  441. &errorStatus,
  442. &errorIndex
  443. );
  444. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  445. {
  446. printf( "New Value: " );
  447. SnmpUtilPrintAsnAny( &varBinds.list[0].value ); putchar( '\n' );
  448. }
  449. printf( "\nGET Errorstatus: %lu\n\n", errorStatus );
  450. // Free the memory
  451. SnmpUtilVarBindListFree( &varBinds );
  452. }
  453. printf( "Try and SET a LEAF that is READ-ONLY\n" );
  454. {
  455. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 1, 1, 0 };
  456. RFC1157VarBindList varBinds;
  457. AsnInteger errorStatus = 0;
  458. AsnInteger errorIndex = 0;
  459. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  460. varBinds.len = 1;
  461. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  462. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  463. varBinds.list[0].name.idLength );
  464. memcpy( varBinds.list[0].name.ids, &itemn,
  465. sizeof(UINT)*varBinds.list[0].name.idLength );
  466. varBinds.list[0].value.asnType = ASN_INTEGER;
  467. printf( "SET: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  468. printf( " to " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  469. SnmpExtensionQuery( ASN_RFC1157_SETREQUEST,
  470. &varBinds,
  471. &errorStatus,
  472. &errorIndex
  473. );
  474. printf( "\nSET Errorstatus: %lu\n\n", errorStatus );
  475. SnmpExtensionQuery( ASN_RFC1157_GETREQUEST,
  476. &varBinds,
  477. &errorStatus,
  478. &errorIndex
  479. );
  480. if ( errorStatus == SNMP_ERRORSTATUS_NOERROR )
  481. {
  482. printf( "New Value: " );
  483. SnmpUtilPrintAsnAny( &varBinds.list[0].value ); putchar( '\n' );
  484. }
  485. printf( "\nGET Errorstatus: %lu\n\n", errorStatus );
  486. // Free the memory
  487. SnmpUtilVarBindListFree( &varBinds );
  488. }
  489. printf( "SET on the odom table to add entry\n" );
  490. {
  491. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 4, 4, 1, 1, 4, 'T', 'O', 'D', 'D' };
  492. RFC1157VarBindList varBinds;
  493. AsnInteger errorStatus = 0;
  494. AsnInteger errorIndex = 0;
  495. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  496. varBinds.len = 1;
  497. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  498. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  499. varBinds.list[0].name.idLength );
  500. memcpy( varBinds.list[0].name.ids, &itemn,
  501. sizeof(UINT)*varBinds.list[0].name.idLength );
  502. varBinds.list[0].value.asnType = ASN_RFC1213_DISPSTRING;
  503. varBinds.list[0].value.asnValue.string.length = 4;
  504. varBinds.list[0].value.asnValue.string.stream = "TODD";
  505. varBinds.list[0].value.asnValue.string.dynamic = FALSE;
  506. printf( "SET: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  507. printf( " to " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  508. SnmpExtensionQuery( ASN_RFC1157_SETREQUEST,
  509. &varBinds,
  510. &errorStatus,
  511. &errorIndex
  512. );
  513. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  514. // Free the memory
  515. SnmpUtilVarBindListFree( &varBinds );
  516. }
  517. printf( "SET on root of session table\n" );
  518. {
  519. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 2, 20 };
  520. RFC1157VarBindList varBinds;
  521. AsnInteger errorStatus = 0;
  522. AsnInteger errorIndex = 0;
  523. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  524. varBinds.len = 1;
  525. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  526. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  527. varBinds.list[0].name.idLength );
  528. memcpy( varBinds.list[0].name.ids, &itemn,
  529. sizeof(UINT)*varBinds.list[0].name.idLength );
  530. varBinds.list[0].value.asnType = ASN_INTEGER;
  531. varBinds.list[0].value.asnValue.number = 2;
  532. printf( "SET: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  533. printf( " to " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  534. SnmpExtensionQuery( ASN_RFC1157_SETREQUEST,
  535. &varBinds,
  536. &errorStatus,
  537. &errorIndex
  538. );
  539. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  540. // Free the memory
  541. SnmpUtilVarBindListFree( &varBinds );
  542. }
  543. printf( "SET on root entry of session table\n" );
  544. {
  545. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 2, 20, 1 };
  546. RFC1157VarBindList varBinds;
  547. AsnInteger errorStatus = 0;
  548. AsnInteger errorIndex = 0;
  549. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  550. varBinds.len = 1;
  551. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  552. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  553. varBinds.list[0].name.idLength );
  554. memcpy( varBinds.list[0].name.ids, &itemn,
  555. sizeof(UINT)*varBinds.list[0].name.idLength );
  556. varBinds.list[0].value.asnType = ASN_INTEGER;
  557. varBinds.list[0].value.asnValue.number = 2;
  558. printf( "SET: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  559. printf( " to " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  560. SnmpExtensionQuery( ASN_RFC1157_SETREQUEST,
  561. &varBinds,
  562. &errorStatus,
  563. &errorIndex
  564. );
  565. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  566. // Free the memory
  567. SnmpUtilVarBindListFree( &varBinds );
  568. }
  569. printf( "SET on an invalid field in session table\n" );
  570. {
  571. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 2, 20 };
  572. RFC1157VarBindList varBinds;
  573. AsnInteger errorStatus = 0;
  574. AsnInteger errorIndex = 0;
  575. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  576. varBinds.len = 1;
  577. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  578. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  579. varBinds.list[0].name.idLength );
  580. memcpy( varBinds.list[0].name.ids, &itemn,
  581. sizeof(UINT)*varBinds.list[0].name.idLength );
  582. varBinds.list[0].value.asnType = ASN_NULL;
  583. // Get entry in the session table to delete
  584. SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST,
  585. &varBinds,
  586. &errorStatus,
  587. &errorIndex
  588. );
  589. // Adjust to set a bad field
  590. varBinds.list[0].name.ids[11] = 7;
  591. varBinds.list[0].value.asnType = ASN_INTEGER;
  592. varBinds.list[0].value.asnValue.number = 2;
  593. printf( "SET: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  594. printf( " to " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  595. SnmpExtensionQuery( ASN_RFC1157_SETREQUEST,
  596. &varBinds,
  597. &errorStatus,
  598. &errorIndex
  599. );
  600. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  601. // Free the memory
  602. SnmpUtilVarBindListFree( &varBinds );
  603. }
  604. printf( "SET with invalid type on field in session table\n" );
  605. {
  606. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 2, 20 };
  607. RFC1157VarBindList varBinds;
  608. AsnInteger errorStatus = 0;
  609. AsnInteger errorIndex = 0;
  610. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  611. varBinds.len = 1;
  612. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  613. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  614. varBinds.list[0].name.idLength );
  615. memcpy( varBinds.list[0].name.ids, &itemn,
  616. sizeof(UINT)*varBinds.list[0].name.idLength );
  617. varBinds.list[0].value.asnType = ASN_NULL;
  618. // Get entry in the session table to delete
  619. SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST,
  620. &varBinds,
  621. &errorStatus,
  622. &errorIndex
  623. );
  624. // Adjust to set the svSesState to DELETED
  625. varBinds.list[0].name.ids[11] = 8;
  626. varBinds.list[0].value.asnType = ASN_NULL;
  627. printf( "SET: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  628. printf( " to " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  629. SnmpExtensionQuery( ASN_RFC1157_SETREQUEST,
  630. &varBinds,
  631. &errorStatus,
  632. &errorIndex
  633. );
  634. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  635. // Free the memory
  636. SnmpUtilVarBindListFree( &varBinds );
  637. }
  638. printf( "SET on non-existent entry in session table\n" );
  639. {
  640. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 2, 20, 1, 8, 1, 1 };
  641. RFC1157VarBindList varBinds;
  642. AsnInteger errorStatus = 0;
  643. AsnInteger errorIndex = 0;
  644. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  645. varBinds.len = 1;
  646. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  647. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  648. varBinds.list[0].name.idLength );
  649. memcpy( varBinds.list[0].name.ids, &itemn,
  650. sizeof(UINT)*varBinds.list[0].name.idLength );
  651. varBinds.list[0].value.asnType = ASN_INTEGER;
  652. varBinds.list[0].value.asnValue.number = 2;
  653. printf( "SET: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  654. printf( " to " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  655. SnmpExtensionQuery( ASN_RFC1157_SETREQUEST,
  656. &varBinds,
  657. &errorStatus,
  658. &errorIndex
  659. );
  660. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  661. // Free the memory
  662. SnmpUtilVarBindListFree( &varBinds );
  663. }
  664. printf( "SET on the session table to delete entry\n" );
  665. {
  666. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1, 2, 20 };
  667. RFC1157VarBindList varBinds;
  668. AsnInteger errorStatus = 0;
  669. AsnInteger errorIndex = 0;
  670. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  671. varBinds.len = 1;
  672. varBinds.list[0].name.idLength = sizeof itemn / sizeof(UINT);
  673. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  674. varBinds.list[0].name.idLength );
  675. memcpy( varBinds.list[0].name.ids, &itemn,
  676. sizeof(UINT)*varBinds.list[0].name.idLength );
  677. varBinds.list[0].value.asnType = ASN_NULL;
  678. // Get entry in the session table to delete
  679. SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST,
  680. &varBinds,
  681. &errorStatus,
  682. &errorIndex
  683. );
  684. // Adjust to set the svSesState to DELETED
  685. varBinds.list[0].name.ids[11] = 8;
  686. varBinds.list[0].value.asnType = ASN_INTEGER;
  687. varBinds.list[0].value.asnValue.number = 2;
  688. printf( "SET: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  689. printf( " to " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  690. SnmpExtensionQuery( ASN_RFC1157_SETREQUEST,
  691. &varBinds,
  692. &errorStatus,
  693. &errorIndex
  694. );
  695. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  696. // Free the memory
  697. SnmpUtilVarBindListFree( &varBinds );
  698. }
  699. printf( "GET-NEXT starting from ROOT of LM MIB\n" );
  700. {
  701. UINT itemn[] = { 1, 3, 6, 1, 4, 1, 77, 1 };
  702. RFC1157VarBindList varBinds;
  703. AsnInteger errorStatus;
  704. AsnInteger errorIndex;
  705. BOOL Continue = TRUE;
  706. time_t Time;
  707. while ( Continue )
  708. {
  709. errorStatus = 0;
  710. errorIndex = 0;
  711. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  712. varBinds.len = 1;
  713. SnmpUtilOidCpy( &varBinds.list[0].name, &MIB_OidPrefix );
  714. #if 0
  715. varBinds.list[0].name.idLength = MIB_PREFIX_LEN;
  716. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT)*
  717. varBinds.list[0].name.idLength );
  718. memcpy( varBinds.list[0].name.ids, &itemn,
  719. sizeof(UINT)*varBinds.list[0].name.idLength );
  720. #endif
  721. varBinds.list[0].value.asnType = ASN_NULL;
  722. do
  723. {
  724. Time = time( NULL );
  725. printf( "Time: %s", ctime(&Time) );
  726. printf( "GET-NEXT of: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  727. printf( " " );
  728. SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST,
  729. &varBinds,
  730. &errorStatus,
  731. &errorIndex
  732. );
  733. printf( "\n is " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  734. if ( errorStatus )
  735. {
  736. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  737. }
  738. else
  739. {
  740. printf( "\n = " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  741. }
  742. putchar( '\n' );
  743. }
  744. while ( varBinds.list[0].name.ids[MIB_PREFIX_LEN-1] != 1 );
  745. // Free the memory
  746. SnmpUtilVarBindListFree( &varBinds );
  747. // Prompt for next pass
  748. printf( "Press ENTER to continue, CTRL-C to quit\n" );
  749. getchar();
  750. } // while continue
  751. }
  752. } // test
  753. //-------------------------------- END --------------------------------------