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.

148 lines
2.9 KiB

  1. //=============================================================================
  2. //
  3. // MODULE: ASN1HAddress.cxx
  4. //
  5. // Description:
  6. //
  7. // Implementation of host address parsing logic
  8. //
  9. // Modification History
  10. //
  11. // Mark Pustilnik Date: 06/16/02 - created
  12. //
  13. //=============================================================================
  14. #include "ASN1Parser.hxx"
  15. char g_UnknownAddressType[] = "Unknown address type";
  16. char * g_AddressTypes[] =
  17. {
  18. "Unspecified",
  19. "Local",
  20. "IPv4",
  21. "IMPLINK",
  22. "PUP",
  23. "CHAOS",
  24. "NS",
  25. "NBS",
  26. "ECMA",
  27. "DATAKIT",
  28. "CCITT",
  29. "SNA",
  30. "DECnet",
  31. "DLI",
  32. "LAT",
  33. "HYLINK",
  34. "AppleTalk",
  35. "BSC",
  36. "DSS",
  37. "OSI",
  38. "NetBIOS",
  39. "X25",
  40. g_UnknownAddressType,
  41. g_UnknownAddressType,
  42. "IPv6",
  43. };
  44. DWORD
  45. ASN1ParserHostAddress::DisplayCollectedValues(
  46. IN ASN1FRAME * Frame,
  47. IN ULONG Length,
  48. IN ULPBYTE Address
  49. )
  50. {
  51. DWORD dw;
  52. ASN1VALUE * AddrType;
  53. ASN1VALUE * AddrValue;
  54. ASN1VALUE Value;
  55. char * AddrTypeString = NULL;
  56. if ( QueryCollectedCount() != 2 )
  57. {
  58. dw = ERROR_INTERNAL_ERROR;
  59. goto Cleanup;
  60. }
  61. //
  62. // Create a new value to be displayed, of the format Type: Value
  63. // Type: Value
  64. //
  65. AddrType = QueryCollectedValue( 0 );
  66. AddrValue = QueryCollectedValue( 1 );
  67. if ( AddrType->ut != utInteger )
  68. {
  69. dw = ERROR_INTERNAL_ERROR;
  70. goto Cleanup;
  71. }
  72. if ( AddrValue->ut != utGeneralString &&
  73. AddrValue->ut != utOctetString )
  74. {
  75. dw = ERROR_INTERNAL_ERROR;
  76. goto Cleanup;
  77. }
  78. //
  79. // Create an address display value that looks like
  80. // NetBIOS: HRUNDEL
  81. // or
  82. // IPv4: 192.15.98.126
  83. //
  84. if ( AddrType->dw <= ARRAY_COUNT( g_AddressTypes ))
  85. {
  86. AddrTypeString = g_AddressTypes[AddrType->dw];
  87. }
  88. else
  89. {
  90. AddrTypeString = g_UnknownAddressType;
  91. }
  92. ULONG l = strlen( AddrTypeString );
  93. Value.ut = utGeneralString;
  94. Value.string.l = l + strlen(": ") + AddrValue->string.l;
  95. Value.string.s = new BYTE[Value.string.l];
  96. if ( Value.string.s == NULL )
  97. {
  98. dw = ERROR_NOT_ENOUGH_MEMORY;
  99. goto Cleanup;
  100. }
  101. Value.Allocated = TRUE;
  102. RtlCopyMemory(
  103. Value.string.s,
  104. AddrTypeString,
  105. l
  106. );
  107. Value.string.s[l++] = ':';
  108. Value.string.s[l++] = ' ';
  109. RtlCopyMemory(
  110. &Value.string.s[l],
  111. AddrValue->string.s,
  112. AddrValue->string.l
  113. );
  114. dw = Display(
  115. Frame,
  116. &Value,
  117. PROP( HostAddresses_HostAddress ),
  118. 0
  119. );
  120. if ( dw != ERROR_SUCCESS )
  121. {
  122. goto Cleanup;
  123. }
  124. Cleanup:
  125. return dw;
  126. }