QuestionSection.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Copyright (C) 2014 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.IO;
  10. using System.Text;
  11. using Utilities;
  12. namespace SMBLibrary.NetBios
  13. {
  14. /// <summary>
  15. /// [RFC 1002] 4.2.1.2. QUESTION SECTION
  16. /// </summary>
  17. public class QuestionSection
  18. {
  19. public string Name;
  20. public NameRecordType Type = NameRecordType.NB; // NB
  21. public ushort Class = 0x0001; // IN
  22. public QuestionSection()
  23. {
  24. }
  25. public QuestionSection(byte[] buffer, ref int offset)
  26. {
  27. Name = NetBiosUtils.DecodeName(buffer, ref offset);
  28. Type = (NameRecordType)BigEndianReader.ReadUInt16(buffer, ref offset);
  29. Class = BigEndianReader.ReadUInt16(buffer, ref offset);
  30. }
  31. public void WriteBytes(Stream stream)
  32. {
  33. byte[] encodedName = NetBiosUtils.EncodeName(Name, String.Empty);
  34. ByteWriter.WriteBytes(stream, encodedName);
  35. BigEndianWriter.WriteUInt16(stream, (ushort)Type);
  36. BigEndianWriter.WriteUInt16(stream, Class);
  37. }
  38. }
  39. }