/// <summary>
        /// to create a WriteAndClose 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 16-bit signed integer indicating the file to which the data
        /// SHOULD be written.</param>
        /// <param name="writeOffsetInBytes">This field is a 16-bit unsigned integer indicating the number of bytes to
        /// be written to the file</param>
        /// <param name="lastWriteTime">This field is a 32-bit unsigned integer indicating  the number of seconds since
        /// Jan 1, 1970, 00:00:00.0. The server SHOULD set the last write time of the file represented by the FID to
        /// this value. If the value is zero (0), the server SHOULD use the current local time of the server to set the
        /// value. Failure to set the time MUST not result in an error response from the server.</param>
        /// <param name="data">The raw bytes to be written to the file</param>
        /// <returns>a WriteAndClose request packet</returns>
        public SmbWriteAndCloseRequestPacket CreateWriteAndCloseRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort fid,
            uint writeOffsetInBytes,
            UTime lastWriteTime,
            byte[] data)
        {
            if (data == null)
            {
                data = new byte[0];
            }

            SmbWriteAndCloseRequestPacket packet = new SmbWriteAndCloseRequestPacket();

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

            SMB_COM_WRITE_AND_CLOSE_Request_SMB_Parameters smbParameters =
                new SMB_COM_WRITE_AND_CLOSE_Request_SMB_Parameters();
            smbParameters.FID = fid;
            smbParameters.CountOfBytesToWrite = (ushort)data.Length;
            smbParameters.WriteOffsetInBytes = writeOffsetInBytes;
            smbParameters.LastWriteTime = lastWriteTime;
            smbParameters.Reserved = new uint[3]; // the correct length of Reserved word is always 3.
            smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_WRITE_AND_CLOSE_Request_SMB_Parameters>(
                smbParameters) / NumBytesOfWord);

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

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

            return packet;
        }
 /// <summary>
 /// to create a WriteAndClose request packet.
 /// </summary>
 /// <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="fid">This field MUST be a valid 16-bit signed integer indicating the file to which the data
 /// SHOULD be written.</param>
 /// <param name="writeOffsetInBytes">This field is a 16-bit unsigned integer indicating the number of bytes to
 /// be written to the file</param>
 /// <param name="lastWriteTime">This field is a 32-bit unsigned integer indicating  the number of seconds since
 /// Jan 1, 1970, 00:00:00.0. The server SHOULD set the last write time of the file represented by the FID to
 /// this value. If the value is zero (0), the server SHOULD use the current local time of the server to set the
 /// value. Failure to set the time MUST not result in an error response from the server.</param>
 /// <param name="data">The raw bytes to be written to the file</param>
 /// <returns>a WriteAndClose request packet</returns>
 /// <exception cref="System.NullReferenceException">There is no connection in context. </exception>
 public SmbWriteAndCloseRequestPacket CreateWriteAndCloseRequest(
     ushort uid,
     ushort treeId,
     ushort fid,
     uint writeOffsetInBytes,
     UTime lastWriteTime,
     byte[] data)
 {
     return this.CreateWriteAndCloseRequest(this.Context.GetMessageId(this.connectionId),
         uid, treeId, this.defaultParameters.Flag, this.defaultParameters.Flag2, fid, writeOffsetInBytes, lastWriteTime, data);
 }
        /// <summary>
        /// to create a CreateTemporary 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="creationTime">The time the file was created on the client represented as the number of seconds
        /// since Jan 1, 1970, 00:00:00.0. Server support of this field is OPTIONAL</param>
        /// <param name="directoryName">A null-terminated string that represents the fully qualified name of the
        /// directory relative to the supplied TID in which to create the temporary file.</param>
        /// <returns>a CreateTemporary request packet</returns>
        public SmbCreateTemporaryRequestPacket CreateCreateTemporaryRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            UTime creationTime,
            string directoryName)
        {
            if (directoryName == null)
            {
                directoryName = string.Empty;
            }

            SmbCreateTemporaryRequestPacket packet = new SmbCreateTemporaryRequestPacket();

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

            SMB_COM_CREATE_TEMPORARY_Request_SMB_Parameters smbParameters =
                new SMB_COM_CREATE_TEMPORARY_Request_SMB_Parameters();
            smbParameters.FileAttributes = SmbFileAttributes.SMB_FILE_ATTRIBUTE_NORMAL;
            smbParameters.CreationTime = creationTime;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_CREATE_TEMPORARY_Request_SMB_Data smbData = new SMB_COM_CREATE_TEMPORARY_Request_SMB_Data();
            smbData.BufferFormat = (byte)DataBufferFormat.SmbString;
            smbData.DirectoryName = CifsMessageUtils.ToSmbStringBytes(directoryName,
                (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE);
            smbData.ByteCount = (ushort)(Marshal.SizeOf(smbData.BufferFormat) + smbData.DirectoryName.Length);

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

            return packet;
        }
 /// <summary>
 /// to create a CreateTemporary request packet.
 /// </summary>
 /// <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="creationTime">The time the file was created on the client represented as the number of seconds
 /// since Jan 1, 1970, 00:00:00.0. Server support of this field is OPTIONAL</param>
 /// <param name="directoryName">A null-terminated string that represents the fully qualified name of the
 /// directory relative to the supplied TID in which to create the temporary file.</param>
 /// <returns>a CreateTemporary request packet</returns>
 /// <exception cref="System.NullReferenceException">There is no connection in context. </exception>
 public SmbCreateTemporaryRequestPacket CreateCreateTemporaryRequest(
     ushort uid,
     ushort treeId,
     UTime creationTime,
     string directoryName)
 {
     return this.CreateCreateTemporaryRequest(this.Context.GetMessageId(this.connectionId),
         uid, treeId, this.defaultParameters.Flag, this.defaultParameters.Flag2, creationTime, directoryName);
 }
        /// <summary>
        /// to create a SetInformation 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="fileAttributes">This field is a 16 bit unsigned bit field encoded as 
        /// SMB_FILE_ATTRIBUTES</param>
        /// <param name="lastWriteTime">The time of the last write to the file</param>
        /// <param name="fileName">A null-terminated string that represents the fully qualified name of the file 
        /// relative to the supplied TID. This is the file for which attributes are set.</param>
        /// <returns>a SetInformation request packet</returns>
        public SmbSetInformationRequestPacket CreateSetInformationRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            SmbFileAttributes fileAttributes,
            UTime lastWriteTime,
            string fileName)
        {
            if (fileName == null)
            {
                fileName = string.Empty;
            }

            SmbSetInformationRequestPacket packet = new SmbSetInformationRequestPacket();

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

            SMB_COM_SET_INFORMATION_Request_SMB_Parameters smbParameters;
            smbParameters = new SMB_COM_SET_INFORMATION_Request_SMB_Parameters();
            smbParameters.FileAttributes = fileAttributes;
            smbParameters.LastWriteTime = lastWriteTime;
            smbParameters.Reserved = new ushort[5]; // the correct length of Reserved word is always 5.
            smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_SET_INFORMATION_Request_SMB_Parameters>(
                smbParameters) / NumBytesOfWord);

            SMB_COM_SET_INFORMATION_Request_SMB_Data smbData = new SMB_COM_SET_INFORMATION_Request_SMB_Data();
            smbData.BufferFormat = (byte)DataBufferFormat.SmbString;
            smbData.FileName = CifsMessageUtils.ToSmbStringBytes(fileName,
                (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE);
            smbData.ByteCount = (ushort)(Marshal.SizeOf(smbData.BufferFormat) + smbData.FileName.Length);

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

            return packet;
        }
 /// <summary>
 /// to create a Create request packet.
 /// </summary>
 /// <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="fileAttributes">A 16-bit field of 1-bit flags that represent the file attributes to assign to
 /// the file if it is created successfully.</param>
 /// <param name="creationTime">UTIME The time the file was created on the client represented as the number of
 /// seconds since Jan 1, 1970, 00:00:00.0. Server support of this field is OPTIONAL</param>
 /// <param name="fileName">A null-terminated string that represents the fully qualified name of the file
 /// relative to the supplied TID to create or truncate on the server.</param>
 /// <returns>a Create Request Packet</returns>
 /// <exception cref="System.NullReferenceException">There is no connection in context. </exception>
 public SmbCreateRequestPacket CreateCreateRequest(
     ushort uid,
     ushort treeId,
     SmbFileAttributes fileAttributes,
     UTime creationTime,
     string fileName)
 {
     return this.CreateCreateRequest(this.Context.GetMessageId(this.connectionId),
         uid, treeId, this.defaultParameters.Flag, this.defaultParameters.Flag2, fileAttributes, creationTime, fileName);
 }
        /// <summary>
        /// to create a Close 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">The FID of the object to be closed</param>
        /// <param name="lastTimeModified">A time value encoded as the number of seconds since January 1, 
        /// 1970 00:00:00.0. The client MAY request that the last modification time for the file be updated to this
        /// time value. A value of 0 or 0xFFFFFF results in the server using the default value. The server is NOT 
        /// REQUIRED to support this request</param>
        /// <returns>a Close request packet</returns>
        public SmbCloseRequestPacket CreateCloseRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort fid,
            UTime lastTimeModified)
        {
            SmbCloseRequestPacket packet = new SmbCloseRequestPacket();

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

            SMB_COM_CLOSE_Request_SMB_Parameters smbParameters = new SMB_COM_CLOSE_Request_SMB_Parameters();
            smbParameters.FID = fid;
            smbParameters.LastTimeModified = lastTimeModified;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_CLOSE_Request_SMB_Data smbData = new SMB_COM_CLOSE_Request_SMB_Data();
            smbData.ByteCount = 0;

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

            return packet;
        }
 /// <summary>
 /// to create a Close request packet.
 /// </summary>
 /// <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="fid">The FID of the object to be closed</param>
 /// <param name="lastTimeModified">A time value encoded as the number of seconds since January 1, 1970
 /// 00:00:00.0. The client MAY request that the last modification time for the file be updated to this time
 /// value. A value of 0 or 0xFFFFFF results in the server using the default value. The server is NOT REQUIRED to
 /// support this request</param>
 /// <returns>a Close request packet</returns>
 /// <exception cref="System.NullReferenceException">There is no connection in context. </exception>
 public SmbCloseRequestPacket CreateCloseRequest(
     ushort uid,
     ushort treeId,
     ushort fid,
     UTime lastTimeModified)
 {
     return this.CreateCloseRequest(this.Context.GetMessageId(this.connectionId),
         uid, treeId, this.defaultParameters.Flag, this.defaultParameters.Flag2, fid, lastTimeModified);
 }
 /// <summary>
 /// to create a OpenAndx request packet.
 /// </summary>
 /// <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="smbParametersFlags">A 16-bit field of flags for requesting attribute data and locking</param>
 /// <param name="accessMode">A 16-bit field for encoding the requested access mode. See section 3.2.4.5.1 for a
 /// discussion on sharing modes</param>
 /// <param name="searchAttrs">ATTRIBUTES The set of attributes that the file MUST have in order to be found
 /// while searching to see if it exists. If none of the attribute bytes are set, the file attributes MUST refer
 /// to a regular file.</param>
 /// <param name="fileAttrs">The set of attributes that the file is to have if the file needs to be created. If
 /// none of the attribute bytes are set, the file attributes MUST refer to a regular file.</param>
 /// <param name="creationTime">32-bit integer time value to be assigned to the file as a time of creation if
 /// the file is to be created. </param>
 /// <param name="openMode">A 16-bit field that controls the way a file SHOULD be treated when it is opened for
 /// use by certain extended SMB requests</param>
 /// <param name="allocationSize">The number of bytes to reserve on file creation or truncation. This field MAY
 /// be ignored by the server</param>
 /// <param name="timeout">This field is a 32-bit unsigned integer value containing the number of milliseconds
 /// to wait on a blocked open request before returning without successfully opening the file.</param>
 /// <param name="fileName">A buffer containing the name of the file to be opened. </param>
 /// <param name="andxPacket">the andx packet.</param>
 /// <returns>a OpenAndx request packet</returns>
 /// <exception cref="System.NullReferenceException">There is no connection in context. </exception>
 public SmbOpenAndxRequestPacket CreateOpenAndxRequest(
     ushort uid,
     ushort treeId,
     Flags smbParametersFlags,
     AccessMode accessMode,
     SmbFileAttributes searchAttrs,
     SmbFileAttributes fileAttrs,
     UTime creationTime,
     OpenMode openMode,
     uint allocationSize,
     uint timeout,
     string fileName,
     SmbPacket andxPacket)
 {
     return this.CreateOpenAndxRequest(this.Context.GetMessageId(this.connectionId),
         uid, treeId, this.defaultParameters.Flag, this.defaultParameters.Flag2, smbParametersFlags, accessMode,
         searchAttrs, fileAttrs, creationTime, openMode, allocationSize, timeout, fileName, andxPacket);
 }
        /// <summary>
        /// to create a OpenAndx 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="smbParametersFlags">A 16-bit field of flags for requesting attribute data and locking</param>
        /// <param name="accessMode">A 16-bit field for encoding the requested access mode. See section 3.2.4.5.1 for a
        /// discussion on sharing modes</param>
        /// <param name="searchAttrs">ATTRIBUTES The set of attributes that the file MUST have in order to be found
        /// while searching to see if it exists. If none of the attribute bytes are set, the file attributes MUST refer
        /// to a regular file.</param>
        /// <param name="fileAttrs">The set of attributes that the file is to have if the file needs to be created. If
        /// none of the attribute bytes are set, the file attributes MUST refer to a regular file.</param>
        /// <param name="creationTime">32-bit integer time value to be assigned to the file as a time of creation if
        /// the file is to be created. </param>
        /// <param name="openMode">A 16-bit field that controls the way a file SHOULD be treated when it is opened for
        /// use by certain extended SMB requests</param>
        /// <param name="allocationSize">The number of bytes to reserve on file creation or truncation. This field MAY
        /// be ignored by the server</param>
        /// <param name="timeout">This field is a 32-bit unsigned integer value containing the number of milliseconds
        /// to wait on a blocked open request before returning without successfully opening the file.</param>
        /// <param name="fileName">A buffer containing the name of the file to be opened. </param>
        /// <param name="andxPacket">the andx packet.</param>
        /// <returns>a OpenAndx request packet</returns>
        public SmbOpenAndxRequestPacket CreateOpenAndxRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            Flags smbParametersFlags,
            AccessMode accessMode,
            SmbFileAttributes searchAttrs,
            SmbFileAttributes fileAttrs,
            UTime creationTime,
            OpenMode openMode,
            uint allocationSize,
            uint timeout,
            string fileName,
            SmbPacket andxPacket)
        {
            if (fileName == null)
            {
                fileName = string.Empty;
            }

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

            SMB_COM_OPEN_ANDX_Request_SMB_Parameters smbParameters = new SMB_COM_OPEN_ANDX_Request_SMB_Parameters();
            smbParameters.AndXReserved = 0;
            smbParameters.Reserved = new ushort[2]; // the correct length of Reserved word is always 2.
            if (andxPacket == null)
            {
                smbParameters.AndXCommand = SmbCommand.SMB_COM_NO_ANDX_COMMAND;
            }
            else
            {
                smbParameters.AndXCommand = andxPacket.SmbHeader.Command;
            }
            smbParameters.Flags = smbParametersFlags;
            smbParameters.AccessMode = accessMode;
            smbParameters.SearchAttrs = searchAttrs;
            smbParameters.FileAttrs = fileAttrs;
            smbParameters.CreationTime = creationTime;
            smbParameters.OpenMode = openMode;
            smbParameters.AllocationSize = allocationSize;
            smbParameters.Timeout = timeout;
            smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_OPEN_ANDX_Request_SMB_Parameters>(
                smbParameters) / NumBytesOfWord);

            SMB_COM_OPEN_ANDX_Request_SMB_Data smbData = new SMB_COM_OPEN_ANDX_Request_SMB_Data();
            if ((flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE)
            {
                // if Unicode, add 1 byte pad for align on 16-bits.
                smbData.FileName = new byte[1 + (fileName.Length + 1) * 2];
                Array.Copy(CifsMessageUtils.ToSmbStringBytes(fileName, true), 0, smbData.FileName, 1,
                    (fileName.Length + 1) * 2);
            }
            else
            {
                smbData.FileName = CifsMessageUtils.ToSmbStringBytes(fileName, false);
            }
            smbData.ByteCount = (ushort)smbData.FileName.Length;

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

            return packet;
        }
        public SmbQueryInformationResponsePacket CreateQueryInformationResponse(
            CifsServerPerConnection connection,
            SmbQueryInformationRequestPacket request,
            SmbFileAttributes fileAttributes,
            UTime lastWriteTime,
            uint fileSize)
        {
            SmbQueryInformationResponsePacket response = new SmbQueryInformationResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_QUERY_INFORMATION_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.FileAttributes = fileAttributes;
            smbParameters.FileSize = fileSize;
            smbParameters.LastWriteTime = lastWriteTime;
            smbParameters.Reserved = new ushort[5];
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            return response;
        }
        public SmbOpenResponsePacket CreateOpenResponse(
            CifsServerPerConnection connection,
            SmbOpenRequestPacket request,
            uint fileSize,
            UTime lastModified)
        {
            SmbOpenResponsePacket response = new SmbOpenResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_OPEN_Response_SMB_Parameters smbParameters = response.SmbParameters;

            smbParameters.AccessMode = request.SmbParameters.AccessMode;
            smbParameters.FID = (ushort)connection.GenerateFID();
            smbParameters.FileAttrs = request.SmbParameters.SearchAttributes;
            smbParameters.FileSize = fileSize;
            smbParameters.LastModified = lastModified;

            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            return response;
        }
        public SmbOpenAndxResponsePacket CreateOpenAndxResponse(
            CifsServerPerConnection connection,
            SmbOpenAndxRequestPacket request,
            UTime lastWriteTime,
            uint fileDataSize,
            AccessRightsValue accessRights,
            ResourceTypeValue resourceType,
            SMB_NMPIPE_STATUS nmPipeStatus,
            OpenResultsValues openResults,
            SmbPacket andxPacket)
        {
            SmbOpenAndxResponsePacket response = new SmbOpenAndxResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_OPEN_ANDX_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.AndXCommand =
                andxPacket != null ? andxPacket.SmbHeader.Command : SmbCommand.SMB_COM_NO_ANDX_COMMAND;
            smbParameters.AndXReserved = 0x00;
            smbParameters.FID = (ushort)(connection.GenerateFID());
            smbParameters.FileAttrs = request.SmbParameters.FileAttrs;
            smbParameters.LastWriteTime = lastWriteTime;
            smbParameters.FileDataSize = fileDataSize;
            smbParameters.AccessRights = accessRights;
            smbParameters.ResourceType = resourceType;
            smbParameters.NMPipeStatus = nmPipeStatus;
            smbParameters.OpenResults = openResults;
            smbParameters.Reserved = new ushort[3];
            smbParameters.AndXOffset = (ushort)(response.HeaderSize + Marshal.SizeOf(response.SmbParameters)
                    + Marshal.SizeOf(response.SmbData));
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

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

            return response;
        }