NbtException.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // This code is derived from jcifs smb client library <jcifs at samba dot org>
  2. // Ported by J. Arturo <webmaster at komodosoft dot net>
  3. //
  4. // This library is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public
  6. // License as published by the Free Software Foundation; either
  7. // version 2.1 of the License, or (at your option) any later version.
  8. //
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public
  15. // License along with this library; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. using System.IO;
  18. namespace SharpCifs.Netbios
  19. {
  20. public class NbtException : IOException
  21. {
  22. public const int Success = 0;
  23. public const int ErrNamSrvc = unchecked(0x01);
  24. public const int ErrSsnSrvc = unchecked(0x02);
  25. public const int FmtErr = unchecked(0x1);
  26. public const int SrvErr = unchecked(0x2);
  27. public const int ImpErr = unchecked(0x4);
  28. public const int RfsErr = unchecked(0x5);
  29. public const int ActErr = unchecked(0x6);
  30. public const int CftErr = unchecked(0x7);
  31. public const int ConnectionRefused = -1;
  32. public const int NotListeningCalled = unchecked(0x80);
  33. public const int NotListeningCalling = unchecked(0x81);
  34. public const int CalledNotPresent = unchecked(0x82);
  35. public const int NoResources = unchecked(0x83);
  36. public const int Unspecified = unchecked(0x8F);
  37. public int ErrorClass;
  38. public int ErrorCode;
  39. // error classes
  40. // name service error codes
  41. // session service error codes
  42. public static string GetErrorString(int errorClass, int errorCode)
  43. {
  44. string result = string.Empty;
  45. switch (errorClass)
  46. {
  47. case Success:
  48. {
  49. result += "SUCCESS";
  50. break;
  51. }
  52. case ErrNamSrvc:
  53. {
  54. result += "ERR_NAM_SRVC/";
  55. switch (errorCode)
  56. {
  57. case FmtErr:
  58. {
  59. result += "FMT_ERR: Format Error";
  60. goto default;
  61. }
  62. default:
  63. {
  64. result += "Unknown error code: " + errorCode;
  65. break;
  66. }
  67. }
  68. break;
  69. }
  70. case ErrSsnSrvc:
  71. {
  72. result += "ERR_SSN_SRVC/";
  73. switch (errorCode)
  74. {
  75. case ConnectionRefused:
  76. {
  77. result += "Connection refused";
  78. break;
  79. }
  80. case NotListeningCalled:
  81. {
  82. result += "Not listening on called name";
  83. break;
  84. }
  85. case NotListeningCalling:
  86. {
  87. result += "Not listening for calling name";
  88. break;
  89. }
  90. case CalledNotPresent:
  91. {
  92. result += "Called name not present";
  93. break;
  94. }
  95. case NoResources:
  96. {
  97. result += "Called name present, but insufficient resources";
  98. break;
  99. }
  100. case Unspecified:
  101. {
  102. result += "Unspecified error";
  103. break;
  104. }
  105. default:
  106. {
  107. result += "Unknown error code: " + errorCode;
  108. break;
  109. }
  110. }
  111. break;
  112. }
  113. default:
  114. {
  115. result += "unknown error class: " + errorClass;
  116. break;
  117. }
  118. }
  119. return result;
  120. }
  121. public NbtException(int errorClass, int errorCode) : base(GetErrorString(errorClass
  122. , errorCode))
  123. {
  124. this.ErrorClass = errorClass;
  125. this.ErrorCode = errorCode;
  126. }
  127. public override string ToString()
  128. {
  129. return "errorClass=" + ErrorClass + ",errorCode=" + ErrorCode + ",errorString="
  130. + GetErrorString(ErrorClass, ErrorCode);
  131. }
  132. }
  133. }