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

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.AndXCommand = packet.SmbParameters.AndXCommand;
            this.smbParameters.AndXReserved = packet.SmbParameters.AndXReserved;
            this.smbParameters.AndXOffset = packet.SmbParameters.AndXOffset;
            this.smbParameters.FID = packet.SmbParameters.FID;
            this.smbParameters.Offset = packet.SmbParameters.Offset;
            this.smbParameters.Timeout = packet.SmbParameters.Timeout;
            this.smbParameters.WriteMode = packet.SmbParameters.WriteMode;
            this.smbParameters.Remaining = packet.SmbParameters.Remaining;
            this.smbParameters.Reserved = packet.SmbParameters.Reserved;
            this.smbParameters.DataLength = packet.SmbParameters.DataLength;
            this.smbParameters.DataOffset = packet.SmbParameters.DataOffset;
            this.smbParameters.OffsetHigh = packet.SmbParameters.OffsetHigh;

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

            this.smbParameters.WordCount    = packet.SmbParameters.WordCount;
            this.smbParameters.AndXCommand  = packet.SmbParameters.AndXCommand;
            this.smbParameters.AndXReserved = packet.SmbParameters.AndXReserved;
            this.smbParameters.AndXOffset   = packet.SmbParameters.AndXOffset;
            this.smbParameters.FID          = packet.SmbParameters.FID;
            this.smbParameters.Offset       = packet.SmbParameters.Offset;
            this.smbParameters.Timeout      = packet.SmbParameters.Timeout;
            this.smbParameters.WriteMode    = packet.SmbParameters.WriteMode;
            this.smbParameters.Remaining    = packet.SmbParameters.Remaining;
            this.smbParameters.Reserved     = packet.SmbParameters.Reserved;
            this.smbParameters.DataLength   = packet.SmbParameters.DataLength;
            this.smbParameters.DataOffset   = packet.SmbParameters.DataOffset;
            this.smbParameters.OffsetHigh   = packet.SmbParameters.OffsetHigh;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
            if (packet.smbData.Data != null)
            {
                this.smbData.Data = new byte[packet.smbData.Data.Length];
                Array.Copy(packet.smbData.Data, this.smbData.Data, packet.smbData.Data.Length);
            }
            else
            {
                this.smbData.Data = new byte[0];
            }
        }
        /// <summary>
        /// to create a WriteAndx 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="treeId">This field identifies the subdirectory (or tree) on the server that the client is
        /// accessing.</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="fid">This field MUST be a valid FID indicating the file from which the data MUST be
        /// read.</param>
        /// <param name="offset">If WordCount is 10 this field represents a 32-bit offset, measured in bytes, of where
        /// the read MUST start relative to the beginning of the file. If WordCount is 12 this field represents the
        /// lower 32 bits of a 64-bit offset</param>
        /// <param name="timeout">This field represents the amount of time, in milliseconds, that a server MUST wait
        /// before sending a response</param>
        /// <param name="writeMode">A 16-bit field containing flags </param>
        /// <param name="offsetHigh">This field is optional. If WordCount is 12 this field is not included in the
        /// request. If WordCount is 14 this field represents the upper 32 bits of a 64-bit offset, measured in bytes,
        /// of where the write SHOULD start relative to the beginning of the file</param>
        /// <param name="data">The bytes to be written to the file</param>
        /// <param name="andxPacket">the andx packet.</param>
        /// <returns>a WriteAndx request packet</returns>
        public SmbWriteAndxRequestPacket CreateWriteAndxRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort fid,
            uint offset,
            uint timeout,
            WriteAndxWriteMode writeMode,
            uint offsetHigh,
            byte[] data,
            SmbPacket andxPacket)
        {
            if (data == null)
            {
                data = new byte[0];
            }

            SmbWriteAndxRequestPacket packet = new SmbWriteAndxRequestPacket();

            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_WRITE_ANDX,
                messageId, uid, treeId, flags, flags2);

            SMB_COM_WRITE_ANDX_Request_SMB_Parameters smbParameters = new SMB_COM_WRITE_ANDX_Request_SMB_Parameters();
            smbParameters.AndXReserved = 0;
            smbParameters.Remaining = 0;
            smbParameters.Reserved = 0;

            if (andxPacket == null)
            {
                smbParameters.AndXCommand = SmbCommand.SMB_COM_NO_ANDX_COMMAND;
            }
            else
            {
                smbParameters.AndXCommand = andxPacket.SmbHeader.Command;
            }
            smbParameters.FID = fid;
            smbParameters.Offset = offset;
            smbParameters.WriteMode = writeMode;
            smbParameters.Timeout = timeout;
            smbParameters.OffsetHigh = offsetHigh;
            smbParameters.Remaining = (ushort)data.Length;
            smbParameters.DataLength = (ushort)data.Length;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_WRITE_ANDX_Request_SMB_Data smbData = new SMB_COM_WRITE_ANDX_Request_SMB_Data();
            smbData.Pad = 0;
            smbData.Data = data;
            smbData.ByteCount = (ushort)(Marshal.SizeOf(smbData.Pad) + smbData.Data.Length);

            smbParameters.DataOffset = (ushort)(Marshal.SizeOf(packet.SmbHeader) + Marshal.SizeOf(smbParameters)
                + Marshal.SizeOf(smbData.ByteCount) + Marshal.SizeOf(smbData.Pad));

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

            return packet;
        }
        public SmbWriteAndxResponsePacket CreateWriteAndxResponse(
            CifsServerPerConnection connection,
            SmbWriteAndxRequestPacket request,
            ushort available,
            SmbPacket andxPacket)
        {
            SmbWriteAndxResponsePacket response = new SmbWriteAndxResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_WRITE_ANDX_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.AndXCommand =
                andxPacket != null ? andxPacket.SmbHeader.Command : SmbCommand.SMB_COM_NO_ANDX_COMMAND;
            smbParameters.AndXOffset = (ushort)(response.HeaderSize + Marshal.SizeOf(response.SmbParameters)
                    + Marshal.SizeOf(response.SmbData));
            smbParameters.Count = (ushort)request.SmbData.Data.Length;
            smbParameters.Available = available;
            smbParameters.AndXReserved = 0x00;
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            response.AndxPacket = andxPacket;
            response.UpdateHeader();

            return response;
        }