BindNakPDU.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using Utilities;
  10. namespace SMBLibrary.RPC
  11. {
  12. /// <summary>
  13. /// rpcconn_bind_nak_hdr_t
  14. /// </summary>
  15. public class BindNakPDU : RPCPDU
  16. {
  17. public const int BindNakFieldsFixedLength = 2;
  18. public RejectionReason RejectReason; // provider_reject_reason
  19. public VersionsSupported Versions; // versions
  20. public BindNakPDU() : base()
  21. {
  22. PacketType = PacketTypeName.BindNak;
  23. }
  24. public BindNakPDU(byte[] buffer, int offset) : base(buffer, offset)
  25. {
  26. int startOffset = offset;
  27. offset += CommonFieldsLength;
  28. RejectReason = (RejectionReason)LittleEndianReader.ReadUInt16(buffer, ref offset);
  29. Versions = new VersionsSupported(buffer, offset);
  30. }
  31. public override byte[] GetBytes()
  32. {
  33. byte[] buffer = new byte[Length];
  34. WriteCommonFieldsBytes(buffer);
  35. int offset = CommonFieldsLength;
  36. LittleEndianWriter.WriteUInt16(buffer, ref offset, (ushort)RejectReason);
  37. Versions.WriteBytes(buffer, offset);
  38. return buffer;
  39. }
  40. public override int Length
  41. {
  42. get
  43. {
  44. int length = CommonFieldsLength + BindNakFieldsFixedLength;
  45. if (Versions != null)
  46. {
  47. length += Versions.Length;
  48. }
  49. return length;
  50. }
  51. }
  52. }
  53. }