Browse Source

NetBIOS name service packets implementation refactoring

Tal Aloni 8 years ago
parent
commit
dd8e867693

+ 11 - 8
SMBLibrary/NetBios/NameServicePackets/EnumStructures/NameFlags.cs

@@ -1,3 +1,9 @@
+/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
 using System;
 using System.Collections.Generic;
 using System.Text;
@@ -19,17 +25,14 @@ namespace SMBLibrary.NetBios
         public OwnerNodeType NodeType;
         public bool WorkGroup;
 
-        public ushort Value
+        public static explicit operator ushort(NameFlags nameFlags)
         {
-            get
+            ushort value = (ushort)(((byte)nameFlags.NodeType) << 13);
+            if (nameFlags.WorkGroup)
             {
-                ushort value = (ushort)(((byte)NodeType) << 13);
-                if (WorkGroup)
-                {
-                    value |= 0x8000;
-                }
-                return value;
+                value |= 0x8000;
             }
+            return value;
         }
     }
 }

+ 2 - 2
SMBLibrary/NetBios/NameServicePackets/NameRegistrationRequest.cs

@@ -1,4 +1,4 @@
-/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  * 
  * You can redistribute this program and/or modify it under the terms of
  * the GNU Lesser Public License as published by the Free Software Foundation,
@@ -58,7 +58,7 @@ namespace SMBLibrary.NetBios
         public byte[] GetData()
         {
             byte[] data = new byte[DataLength];
-            BigEndianWriter.WriteUInt16(data, 0, NameFlags.Value);
+            BigEndianWriter.WriteUInt16(data, 0, (ushort)NameFlags);
             ByteWriter.WriteBytes(data, 2, Address, 4);
             return data;
         }

+ 6 - 1
SMBLibrary/NetBios/NameServicePackets/NameServicePacketHeader.cs

@@ -1,3 +1,9 @@
+/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
 using System;
 using System.Collections.Generic;
 using System.IO;
@@ -55,7 +61,6 @@ namespace SMBLibrary.NetBios
             BigEndianWriter.WriteUInt16(stream, ANCount);
             BigEndianWriter.WriteUInt16(stream, NSCount);
             BigEndianWriter.WriteUInt16(stream, ARCount);
-
         }
     }
 }

+ 2 - 4
SMBLibrary/NetBios/NameServicePackets/NodeStatusResponse.cs

@@ -1,4 +1,4 @@
-/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  * 
  * You can redistribute this program and/or modify it under the terms of
  * the GNU Lesser Public License as published by the Free Software Foundation,
@@ -51,9 +51,7 @@ namespace SMBLibrary.NetBios
             foreach (KeyValuePair<string, NameFlags> entry in Names)
             {
                 ByteWriter.WriteAnsiString(stream, entry.Key);
-                //byte[] encodedName = NetBiosUtils.EncodeName(entry.Key, String.Empty);
-                //ByteWriter.WriteBytes(stream, encodedName);
-                BigEndianWriter.WriteUInt16(stream, entry.Value.Value);
+                BigEndianWriter.WriteUInt16(stream, (ushort)entry.Value);
             }
 
             ByteWriter.WriteBytes(stream, Statistics.GetBytes());

+ 2 - 2
SMBLibrary/NetBios/NameServicePackets/PositiveNameQueryResponse.cs

@@ -1,4 +1,4 @@
-/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  * 
  * You can redistribute this program and/or modify it under the terms of
  * the GNU Lesser Public License as published by the Free Software Foundation,
@@ -48,7 +48,7 @@ namespace SMBLibrary.NetBios
             int offset = 0;
             foreach (KeyValuePair<byte[], NameFlags> entry in Addresses)
             {
-                BigEndianWriter.WriteUInt16(data, ref offset, entry.Value.Value);
+                BigEndianWriter.WriteUInt16(data, ref offset, (ushort)entry.Value);
                 ByteWriter.WriteBytes(data, ref offset, entry.Key, 4);
             }
             return data;