NameFlags.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Copyright (C) 2014-2020 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. public enum OwnerNodeType : byte
  14. {
  15. BNode = 0x00,
  16. PNode = 0x01,
  17. MNode = 0x10,
  18. }
  19. public struct NameFlags // ushort
  20. {
  21. public const int Length = 2;
  22. public OwnerNodeType NodeType;
  23. public bool WorkGroup;
  24. public static explicit operator ushort(NameFlags nameFlags)
  25. {
  26. ushort value = (ushort)(((byte)nameFlags.NodeType) << 13);
  27. if (nameFlags.WorkGroup)
  28. {
  29. value |= 0x8000;
  30. }
  31. return value;
  32. }
  33. public static explicit operator NameFlags(ushort value)
  34. {
  35. NameFlags result = new NameFlags();
  36. result.NodeType = (OwnerNodeType)((value >> 13) & 0x3);
  37. result.WorkGroup = (value & 0x8000) > 0;
  38. return result;
  39. }
  40. }
  41. }