SessionRequestPacket.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Copyright (C) 2014-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.NetBios
  11. {
  12. /// <summary>
  13. /// [RFC 1002] 4.3.2. SESSION REQUEST PACKET
  14. /// </summary>
  15. public class SessionRequestPacket : SessionPacket
  16. {
  17. public string CalledName;
  18. public string CallingName;
  19. public SessionRequestPacket()
  20. {
  21. this.Type = SessionPacketTypeName.SessionRequest;
  22. }
  23. public SessionRequestPacket(byte[] buffer, int offset) : base(buffer, offset)
  24. {
  25. CalledName = NetBiosUtils.DecodeName(this.Trailer, ref offset);
  26. CallingName = NetBiosUtils.DecodeName(this.Trailer, ref offset);
  27. }
  28. public override byte[] GetBytes()
  29. {
  30. byte[] part1 = NetBiosUtils.EncodeName(CalledName, String.Empty);
  31. byte[] part2 = NetBiosUtils.EncodeName(CallingName, String.Empty);
  32. this.Trailer = new byte[part1.Length + part2.Length];
  33. ByteWriter.WriteBytes(this.Trailer, 0, part1);
  34. ByteWriter.WriteBytes(this.Trailer, part1.Length, part2);
  35. return base.GetBytes();
  36. }
  37. public override int Length
  38. {
  39. get
  40. {
  41. byte[] part1 = NetBiosUtils.EncodeName(CalledName, String.Empty);
  42. byte[] part2 = NetBiosUtils.EncodeName(CallingName, String.Empty);
  43. return HeaderLength + part1.Length + part2.Length;
  44. }
  45. }
  46. }
  47. }