SessionRequestPacket.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 System.Text;
  10. using Utilities;
  11. namespace SMBLibrary.NetBios
  12. {
  13. /// <summary>
  14. /// [RFC 1002] 4.3.2. SESSION REQUEST PACKET
  15. /// </summary>
  16. public class SessionRequestPacket : SessionPacket
  17. {
  18. public string CalledName;
  19. public string CallingName;
  20. public SessionRequestPacket()
  21. {
  22. this.Type = SessionPacketTypeName.SessionRequest;
  23. }
  24. public SessionRequestPacket(byte[] buffer, int offset) : base(buffer, offset)
  25. {
  26. CalledName = NetBiosUtils.DecodeName(this.Trailer, ref offset);
  27. CallingName = NetBiosUtils.DecodeName(this.Trailer, ref offset);
  28. }
  29. public override byte[] GetBytes()
  30. {
  31. byte[] part1 = NetBiosUtils.EncodeName(CalledName, String.Empty);
  32. byte[] part2 = NetBiosUtils.EncodeName(CallingName, String.Empty);
  33. this.Trailer = new byte[part1.Length + part2.Length];
  34. ByteWriter.WriteBytes(this.Trailer, 0, part1);
  35. ByteWriter.WriteBytes(this.Trailer, part1.Length, part2);
  36. return base.GetBytes();
  37. }
  38. }
  39. }