public SmbCreateResponsePacket CreateCreateResponse(
            CifsServerPerConnection connection,
            SmbCreateRequestPacket request)
        {
            SmbCreateResponsePacket response = new SmbCreateResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_CREATE_Response_SMB_Parameters smbParameters = response.SmbParameters;

            smbParameters.FID = (ushort)connection.GenerateFID();
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            return response;
        }
        public SmbCreateTemporaryResponsePacket CreateCreateTemporaryResponse(
            CifsServerPerConnection connection,
            SmbCreateTemporaryRequestPacket request,
            string temporaryFileName)
        {
            SmbCreateTemporaryResponsePacket response = new SmbCreateTemporaryResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_CREATE_TEMPORARY_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.WordCount = 0x01; // should be 0x1; But it reads 0x02 in TD.
            smbParameters.FID = (ushort)connection.GenerateFID();
            response.SmbParameters = smbParameters;

            SMB_COM_CREATE_TEMPORARY_Response_SMB_Data smbData = response.SmbData;
            smbData.BufferFormat = 0x04;
            smbData.TemporaryFileName = CifsMessageUtils.ToSmbStringBytes(temporaryFileName,
                    (response.SmbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE);
            smbData.ByteCount = (ushort)(smbData.TemporaryFileName.Length + Marshal.SizeOf(smbData.BufferFormat));
            response.SmbData = smbData;

            return response;
        }
        public SmbTrans2Open2FinalResponsePacket CreateTrans2Open2FinalResponse(
            CifsServerPerConnection connection,
            SmbTrans2Open2RequestPacket request,
            uint fileDataSize,
            FileTypeValue resourceType,
            SMB_NMPIPE_STATUS nmPipeStatus,
            OpenResultsValues actionTaken)
        {
            SmbTrans2Open2FinalResponsePacket response = new SmbTrans2Open2FinalResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            TRANS2_OPEN2_Response_Trans2_Parameters trans2Parameters = response.Trans2Parameters;
            trans2Parameters.Fid = (ushort)connection.GenerateFID();
            trans2Parameters.FileAttributes = request.Trans2Parameters.FileAttributes;
            trans2Parameters.CreationTime = (uint)DateTime.Now.Millisecond;
            trans2Parameters.FileDataSize = fileDataSize;
            trans2Parameters.AccessMode = request.Trans2Parameters.AccessMode;
            trans2Parameters.ResourceType = resourceType;
            trans2Parameters.NMPipeStatus = nmPipeStatus;
            trans2Parameters.OpenResults = actionTaken;
            trans2Parameters.Reserved = 0x00000000;
            trans2Parameters.ExtendedAttributeErrorOffset = 0;
            trans2Parameters.ExtendedAttributeLength = request.Trans2Data.ExtendedAttributeList.SizeOfListInBytes;
            response.Trans2Parameters = trans2Parameters;

            response.UpdateCountAndOffset();

            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;
        }
        public SmbNtTransactCreateResponsePacket CreateNtTransactCreateResponse(
            CifsServerPerConnection connection,
            SmbNtTransactCreateRequestPacket request,
            ulong allocationSize,
            ulong endOfFile,
            FileTypeValue resourceType,
            SMB_NMPIPE_STATUS nmPipeStatus,
            byte directory)
        {
            SmbNtTransactCreateResponsePacket response = new SmbNtTransactCreateResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            NT_TRANSACT_CREATE_Response_NT_Trans_Parameters ntTransParameters = response.NtTransParameters;
            ntTransParameters.OpLockLevel = OplockLevelValue.None;
            ntTransParameters.Reserved = 0x00;
            ntTransParameters.FID = (ushort)connection.GenerateFID();
            ntTransParameters.CreateAction = NtTransactCreateActionValues.FILE_CREATED;
            FileTime fileTime = new FileTime();
            fileTime.Time = (ulong)DateTime.Now.ToFileTime();
            ntTransParameters.CreationTime = fileTime;
            ntTransParameters.LastAccessTime = fileTime;
            ntTransParameters.LastWriteTime = fileTime;
            ntTransParameters.LastChangeTime = fileTime;
            ntTransParameters.ExtFileAttributes = request.NtTransParameters.ExtFileAttributes;
            ntTransParameters.AllocationSize = allocationSize;
            ntTransParameters.EndOfFile = endOfFile;
            ntTransParameters.ResourceType = resourceType;
            ntTransParameters.NMPipeStatus = nmPipeStatus;
            ntTransParameters.Directory = directory;
            response.NtTransParameters = ntTransParameters;

            response.UpdateCountAndOffset();

            return response;
        }
        public SmbNtCreateAndxResponsePacket CreateNtCreateAndxResponse(
            CifsServerPerConnection connection,
            SmbNtCreateAndxRequestPacket request,
            OplockLevelValue opLockLevel,
            ulong allocationSize,
            ulong endOfFile,
            FileTypeValue resourceType,
            SMB_NMPIPE_STATUS nmPipeStatus,
            byte directory,
            SmbPacket andxPacket)
        {
            SmbNtCreateAndxResponsePacket response = new SmbNtCreateAndxResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_NT_CREATE_ANDX_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.AndXCommand =
                andxPacket != null ? andxPacket.SmbHeader.Command : SmbCommand.SMB_COM_NO_ANDX_COMMAND;
            smbParameters.AndXReserved = 0x00;
            smbParameters.AndXOffset = (ushort)(response.HeaderSize + Marshal.SizeOf(response.SmbParameters)
                + Marshal.SizeOf(response.SmbData));
            smbParameters.OplockLevel = opLockLevel;
            smbParameters.FID = (ushort)connection.GenerateFID();
            smbParameters.CreateDisposition = NtTransactCreateDisposition.FILE_CREATE;
            FileTime fileTime = new FileTime();
            fileTime.Time = (ulong)DateTime.Now.ToFileTime();
            smbParameters.CreateTime = fileTime;
            smbParameters.LastAccessTime = fileTime;
            smbParameters.LastChangeTime = fileTime;
            smbParameters.ExtFileAttributes = (SMB_EXT_FILE_ATTR)request.SmbParameters.ExtFileAttributes;
            smbParameters.AllocationSize = allocationSize;
            smbParameters.EndOfFile = endOfFile;
            smbParameters.ResourceType = resourceType;
            smbParameters.NMPipeStatus = nmPipeStatus;
            smbParameters.Directory = directory;
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

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

            return response;
        }