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.

252 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1992-1997 Microsoft Corporation
  3. Module Name:
  4. print.c
  5. Abstract:
  6. Contains printing support.
  7. SnmpUtilPrintOid
  8. SnmpUtilPrintAsnAny
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // //
  15. // Include files //
  16. // //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <nt.h>
  19. #include <windef.h>
  20. #include <ntrtl.h>
  21. #include <nturtl.h>
  22. #include <windows.h>
  23. #include <snmp.h>
  24. #include <snmputil.h>
  25. #include <stdio.h>
  26. ///////////////////////////////////////////////////////////////////////////////
  27. // //
  28. // Public Procedures //
  29. // //
  30. ///////////////////////////////////////////////////////////////////////////////
  31. VOID
  32. SNMP_FUNC_TYPE
  33. SnmpUtilPrintOid(
  34. AsnObjectIdentifier * pOid
  35. )
  36. /*++
  37. Routine Description:
  38. Outputs object identifier to the console.
  39. Arguments:
  40. pOid - pointer to OID to display.
  41. Return Values:
  42. None.
  43. --*/
  44. {
  45. UINT i;
  46. // validate oid
  47. if ((pOid != NULL) &&
  48. (pOid->ids != NULL) &&
  49. (pOid->idLength != 0)) {
  50. // output first subidentifier
  51. fprintf(stdout, "%lu", pOid->ids[0]);
  52. // loop through subidentifiers
  53. for (i = 1; i < pOid->idLength; i++) {
  54. // output next subidentifier
  55. fprintf(stdout, ".%lu", pOid->ids[i]);
  56. }
  57. }
  58. }
  59. VOID
  60. SNMP_FUNC_TYPE
  61. SnmpUtilPrintAsnAny(
  62. AsnAny * pAsnAny
  63. )
  64. /*++
  65. Routine Description:
  66. Outputs variable value to the console.
  67. Arguments:
  68. pAsnAny - pointer to value structure from variable binding.
  69. Return Values:
  70. None.
  71. --*/
  72. {
  73. // validate
  74. if (pAsnAny != NULL) {
  75. // determine type
  76. switch (pAsnAny->asnType) {
  77. case ASN_INTEGER32:
  78. fprintf(stdout, "Integer32 %ld\n", pAsnAny->asnValue.number);
  79. break;
  80. case ASN_UNSIGNED32:
  81. fprintf(stdout, "Unsigned32 %lu\n", pAsnAny->asnValue.unsigned32);
  82. break;
  83. case ASN_COUNTER32:
  84. fprintf(stdout, "Counter32 %lu\n", pAsnAny->asnValue.counter);
  85. break;
  86. case ASN_GAUGE32:
  87. fprintf(stdout, "Gauge32 %lu\n", pAsnAny->asnValue.gauge);
  88. break;
  89. case ASN_TIMETICKS:
  90. fprintf(stdout, "TimeTicks %lu\n", pAsnAny->asnValue.ticks);
  91. break;
  92. case ASN_COUNTER64:
  93. fprintf(stdout, "Counter64 %I64u\n", pAsnAny->asnValue.counter64.QuadPart);
  94. break;
  95. case ASN_OBJECTIDENTIFIER:
  96. {
  97. UINT i;
  98. fprintf(stdout, "ObjectID ");
  99. // simply forward to helper function
  100. SnmpUtilPrintOid(&pAsnAny->asnValue.object);
  101. putchar('\n');
  102. }
  103. break;
  104. case ASN_OCTETSTRING:
  105. {
  106. UINT i;
  107. BOOL bDisplayString = TRUE;
  108. LPSTR StringFormat;
  109. // loop through string looking for non-printable characters
  110. for (i = 0; i < pAsnAny->asnValue.string.length && bDisplayString; i++ ) {
  111. bDisplayString = isprint(pAsnAny->asnValue.string.stream[i]);
  112. }
  113. // determine string format based on results
  114. StringFormat = bDisplayString ? "%c" : "<0x%02x>" ;
  115. fprintf(stdout, "String ");
  116. for (i = 0; i < pAsnAny->asnValue.string.length; i++) {
  117. fprintf(stdout, StringFormat, pAsnAny->asnValue.string.stream[i]);
  118. }
  119. putchar('\n');
  120. }
  121. break;
  122. case ASN_IPADDRESS:
  123. {
  124. UINT i;
  125. fprintf(stdout, "IpAddress " );
  126. if (pAsnAny->asnValue.string.stream && (pAsnAny->asnValue.string.length == 4))
  127. {
  128. fprintf(stdout, "%d.%d.%d.%d ",
  129. pAsnAny->asnValue.string.stream[0] ,
  130. pAsnAny->asnValue.string.stream[1] ,
  131. pAsnAny->asnValue.string.stream[2] ,
  132. pAsnAny->asnValue.string.stream[3]
  133. );
  134. }
  135. else
  136. {
  137. fprintf(stdout, "Invalid" );
  138. }
  139. putchar('\n');
  140. }
  141. break;
  142. case ASN_OPAQUE:
  143. {
  144. UINT i;
  145. fprintf(stdout, "Opaque ");
  146. for (i = 0; i < pAsnAny->asnValue.string.length; i++) {
  147. fprintf(stdout, "0x%x ", pAsnAny->asnValue.string.stream[i]);
  148. }
  149. putchar('\n');
  150. }
  151. break;
  152. case ASN_BITS:
  153. {
  154. UINT i;
  155. fprintf(stdout, "Bits ");
  156. for (i = 0; i < pAsnAny->asnValue.string.length; i++) {
  157. fprintf(stdout, "0x%x ", pAsnAny->asnValue.string.stream[i]);
  158. }
  159. putchar('\n');
  160. }
  161. break;
  162. case ASN_NULL:
  163. fprintf(stdout, "Null value\n");
  164. break;
  165. case SNMP_EXCEPTION_NOSUCHOBJECT:
  166. fprintf(stdout, "NOSUCHOBJECT\n");
  167. break;
  168. case SNMP_EXCEPTION_NOSUCHINSTANCE:
  169. fprintf(stdout, "NOSUCHINSTANCE\n");
  170. break;
  171. case SNMP_EXCEPTION_ENDOFMIBVIEW:
  172. fprintf(stdout, "ENDOFMIBVIEW\n");
  173. break;
  174. default:
  175. fprintf(stdout, "Invalid type %d\n", pAsnAny->asnType);
  176. break;
  177. }
  178. }
  179. }