/// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbTreeConnectRequestPacket(SmbTreeConnectRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;

            this.smbData.ByteCount     = packet.SmbData.ByteCount;
            this.smbData.BufferFormat1 = packet.SmbData.BufferFormat1;
            if (packet.smbData.Path != null)
            {
                this.smbData.Path = new byte[packet.smbData.Path.Length];
                Array.Copy(packet.smbData.Path, this.smbData.Path, packet.smbData.Path.Length);
            }
            else
            {
                this.smbData.Path = new byte[0];
            }

            this.smbData.BufferFormat2 = packet.SmbData.BufferFormat2;
            if (packet.smbData.Password != null)
            {
                this.smbData.Password = new byte[packet.smbData.Password.Length];
                Array.Copy(packet.smbData.Password, this.smbData.Password, packet.smbData.Password.Length);
            }
            else
            {
                this.smbData.Password = new byte[0];
            }

            this.smbData.BufferFormat3 = packet.SmbData.BufferFormat3;
            if (packet.smbData.Service != null)
            {
                this.smbData.Service = new byte[packet.smbData.Service.Length];
                Array.Copy(packet.smbData.Service, this.smbData.Service, packet.smbData.Service.Length);
            }
            else
            {
                this.smbData.Service = new byte[0];
            }
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbTreeConnectRequestPacket(SmbTreeConnectRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
            this.smbData.BufferFormat1 = packet.SmbData.BufferFormat1;
            if (packet.smbData.Path != null)
            {
                this.smbData.Path = new byte[packet.smbData.Path.Length];
                Array.Copy(packet.smbData.Path, this.smbData.Path, packet.smbData.Path.Length);
            }
            else
            {
                this.smbData.Path = new byte[0];
            }

            this.smbData.BufferFormat2 = packet.SmbData.BufferFormat2;
            if (packet.smbData.Password != null)
            {
                this.smbData.Password = new byte[packet.smbData.Password.Length];
                Array.Copy(packet.smbData.Password, this.smbData.Password, packet.smbData.Password.Length);
            }
            else
            {
                this.smbData.Password = new byte[0];
            }

            this.smbData.BufferFormat3 = packet.SmbData.BufferFormat3;
            if (packet.smbData.Service != null)
            {
                this.smbData.Service = new byte[packet.smbData.Service.Length];
                Array.Copy(packet.smbData.Service, this.smbData.Service, packet.smbData.Service.Length);
            }
            else
            {
                this.smbData.Service = new byte[0];
            }
        }
        /// <summary>
        /// to create a TreeConnect request packet.
        /// </summary>
        /// <param name="messageId">This field SHOULD be the multiplex ID that is used to associate a response with a
        /// request.</param>
        /// <param name="uid">This field SHOULD identify the authenticated instance of the user.</param>
        /// <param name="flags">An 8-bit field of 1-bit flags describing various features in effect for the
        /// message</param>
        /// <param name="flags2">A 16-bit field of 1-bit flags that represent various features in effect for the
        /// message. Unspecified bits are reserved and MUST be zero.</param>
        /// <param name="path">A null-terminated string that represents the server and share name of the resource to
        /// which the client is attempting to connect</param>
        /// <param name="password">A null-terminated string that represents a share password in plaintext form</param>
        /// <param name="service">A null-terminated string representing the type of resource the client intends to
        /// access</param>
        /// <returns>a TreeConnect request packet</returns>
        public SmbTreeConnectRequestPacket CreateTreeConnectRequest(
            ushort messageId,
            ushort uid,
            SmbFlags flags,
            SmbFlags2 flags2,
            string path,
            string password,
            string service)
        {
            if (path == null)
            {
                path = string.Empty;
            }
            if (password == null)
            {
                password = string.Empty;
            }
            if (service == null)
            {
                service = string.Empty;
            }

            SmbTreeConnectRequestPacket packet = new SmbTreeConnectRequestPacket();

            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_TREE_CONNECT,
                messageId, uid, 0, flags, flags2);

            SMB_COM_TREE_CONNECT_Request_SMB_Parameters smbParameters =
                new SMB_COM_TREE_CONNECT_Request_SMB_Parameters();
            smbParameters.WordCount = 0;

            SMB_COM_TREE_CONNECT_Request_SMB_Data smbData = new SMB_COM_TREE_CONNECT_Request_SMB_Data();
            smbData.BufferFormat1 = (byte)DataBufferFormat.SmbString;
            smbData.BufferFormat2 = (byte)DataBufferFormat.SmbString;
            smbData.BufferFormat3 = (byte)DataBufferFormat.SmbString;
            smbData.Path = CifsMessageUtils.ToSmbStringBytes(path, false);
            smbData.Password = CifsMessageUtils.ToSmbStringBytes(password, false);
            smbData.Service = CifsMessageUtils.ToSmbStringBytes(service, false);

            smbData.ByteCount = (ushort)(Marshal.SizeOf(smbData.BufferFormat1) + smbData.Path.Length
                + Marshal.SizeOf(smbData.BufferFormat2) + smbData.Password.Length
                + Marshal.SizeOf(smbData.BufferFormat3) + smbData.Service.Length);

            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;

            return packet;
        }
        public SmbTreeConnectResponsePacket CreateTreeConnectResponse(
            CifsServerPerConnection connection,
            SmbTreeConnectRequestPacket request)
        {
            SmbTreeConnectResponsePacket response = new SmbTreeConnectResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_TREE_CONNECT_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.MaxBufferSize = (ushort)this.context.MaxBufferSize;
            smbParameters.TID = (ushort)connection.GenerateTID();
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            return response;
        }