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

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.EchoCount = packet.SmbParameters.EchoCount;
            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];
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbEchoRequestPacket(SmbEchoRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.EchoCount = packet.SmbParameters.EchoCount;
            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 an Echo 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="echoCount">The number of times the server SHOULD echo the contents of the SMB_Data.Data
        /// field</param>
        /// <param name="data">Data to echo. The value does not matter</param>
        /// <returns>a Echo request packet</returns>
        public SmbEchoRequestPacket CreateEchoRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort echoCount,
            byte[] data)
        {
            if (data == null)
            {
                data = new byte[0];
            }

            SmbEchoRequestPacket packet = new SmbEchoRequestPacket();

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

            SMB_COM_ECHO_Request_SMB_Parameters smbParameters = new SMB_COM_ECHO_Request_SMB_Parameters();
            smbParameters.EchoCount = echoCount;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_ECHO_Request_SMB_Data smbData = new SMB_COM_ECHO_Request_SMB_Data();
            smbData.Data = data;
            smbData.ByteCount = (ushort)data.Length;

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

            return packet;
        }
        public SmbEchoResponsePacket CreateEchoResponse(
            CifsServerPerConnection connection,
            SmbEchoRequestPacket request)
        {
            SmbEchoResponsePacket response = new SmbEchoResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_ECHO_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.WordCount = 0x01;
            //The SMB_Parameters.Words.SequenceNumber field MUST be set to 1.(3.3.5.32)
            smbParameters.SequenceNumber = 0x01;
            response.SmbParameters = smbParameters;

            SMB_COM_ECHO_Response_SMB_Data smbData = response.SmbData;
            smbData.ByteCount = request.SmbData.ByteCount;
            smbData.Data = request.SmbData.Data;
            response.SmbData = smbData;

            return response;
        }