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.

111 lines
3.9 KiB

  1. // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil -*- (for GNU Emacs)
  2. //
  3. // Copyright (c) 1985-2000 Microsoft Corporation
  4. //
  5. // This file is part of the Microsoft Research IPv6 Network Protocol Stack.
  6. // You should have received a copy of the Microsoft End-User License Agreement
  7. // for this software along with this release; see the file "license.txt".
  8. // If not, please see http://www.research.microsoft.com/msripv6/license.htm,
  9. // or write to Microsoft Research, One Microsoft Way, Redmond, WA 98052-6399.
  10. //
  11. #include "inc.h"
  12. #pragma hdrstop
  13. #include "localmsg.h"
  14. struct ErrorTable {
  15. IP_STATUS Error;
  16. DWORD ErrorCode;
  17. } ErrorTable[] =
  18. {
  19. { IP_BUF_TOO_SMALL, IP_MESSAGE_BUF_TOO_SMALL },
  20. { IP_DEST_NO_ROUTE, IP_MESSAGE_DEST_NO_ROUTE },
  21. { IP_DEST_PROHIBITED, IP_MESSAGE_DEST_PROHIBITED },
  22. { IP_DEST_SCOPE_MISMATCH, IP_MESSAGE_DEST_SCOPE_MISMATCH },
  23. { IP_DEST_ADDR_UNREACHABLE, IP_MESSAGE_DEST_ADDR_UNREACHABLE },
  24. { IP_DEST_PORT_UNREACHABLE, IP_MESSAGE_DEST_PORT_UNREACHABLE },
  25. { IP_DEST_UNREACHABLE, IP_MESSAGE_DEST_UNREACHABLE },
  26. { IP_NO_RESOURCES, IP_MESSAGE_NO_RESOURCES },
  27. { IP_BAD_OPTION, IP_MESSAGE_BAD_OPTION },
  28. { IP_HW_ERROR, IP_MESSAGE_HW_ERROR },
  29. { IP_PACKET_TOO_BIG, IP_MESSAGE_PACKET_TOO_BIG },
  30. { IP_REQ_TIMED_OUT, IP_MESSAGE_REQ_TIMED_OUT },
  31. { IP_BAD_REQ, IP_MESSAGE_BAD_REQ },
  32. { IP_BAD_ROUTE, IP_MESSAGE_BAD_ROUTE },
  33. { IP_HOP_LIMIT_EXCEEDED, IP_MESSAGE_HOP_LIMIT_EXCEEDED },
  34. { IP_REASSEMBLY_TIME_EXCEEDED, IP_MESSAGE_REASSEMBLY_TIME_EXCEEDED },
  35. { IP_PARAMETER_PROBLEM, IP_MESSAGE_PARAMETER_PROBLEM },
  36. { IP_OPTION_TOO_BIG, IP_MESSAGE_OPTION_TOO_BIG },
  37. { IP_BAD_DESTINATION, IP_MESSAGE_BAD_DESTINATION },
  38. { IP_TIME_EXCEEDED, IP_MESSAGE_TIME_EXCEEDED },
  39. { IP_BAD_HEADER, IP_MESSAGE_BAD_HEADER },
  40. { IP_UNRECOGNIZED_NEXT_HEADER, IP_MESSAGE_UNRECOGNIZED_NEXT_HEADER },
  41. { IP_ICMP_ERROR, IP_MESSAGE_ICMP_ERROR },
  42. // the following error must be last - it is used as a sentinel
  43. { IP_GENERAL_FAILURE, IP_MESSAGE_GENERAL_FAILURE }
  44. };
  45. DWORD
  46. WINAPI
  47. GetIpErrorString(
  48. IN IP_STATUS ErrorCode,
  49. OUT PWCHAR Buffer,
  50. IN OUT PDWORD Size
  51. )
  52. /*++
  53. Routine Description:
  54. Returns the error message corresponding to the specified error code
  55. in the user supplied buffer.
  56. Arguments:
  57. ErrorCode - Supplies the code identifying the error.
  58. Buffer - Returns the error message.
  59. Size - Supplies the number of characters that can be stored in 'Buffer',
  60. excluding the terminating nul. Returns the required character count.
  61. Return Value:
  62. NO_ERROR or ERROR_INSUFFICIENT_BUFFER.
  63. --*/
  64. {
  65. DWORD Count, Status = NO_ERROR;
  66. PWCHAR Message = NULL;
  67. int i;
  68. for (i = 0; ErrorTable[i].Error != IP_GENERAL_FAILURE; i++) {
  69. if (ErrorTable[i].Error == ErrorCode) {
  70. break;
  71. }
  72. }
  73. Count = FormatMessageW(
  74. FORMAT_MESSAGE_FROM_HMODULE |
  75. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  76. FORMAT_MESSAGE_IGNORE_INSERTS |
  77. FORMAT_MESSAGE_MAX_WIDTH_MASK,
  78. g_hModule,
  79. ErrorTable[i].ErrorCode,
  80. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  81. (LPWSTR) &Message,
  82. 0,
  83. NULL);
  84. if (*Size < Count) {
  85. *Size = Count;
  86. Status = ERROR_INSUFFICIENT_BUFFER;
  87. } else if (Count) {
  88. wcscpy(Buffer, Message);
  89. }
  90. if (Count) {
  91. LocalFree(Message);
  92. }
  93. return Status;
  94. }