Exemple #1
0
        /// <summary>
        ///   Ping the server to test the connection to the server and to
        ///   see if the server is still responding.
        /// </summary>
        /// <param name = "text">text to send</param>
        /// <returns>Text returned by server (must be the same as the input text)</returns>
        public string Echo(string text)
        {
            lock (this)
            {
                if (Debug.DebugOn)
                    Debug.WriteLine(Debug.Info, "ping (SMB_COM_ECHO)");


                // for now we only support 0 or 1
                int echos = 1;

                SetupSmbMessage(fMsg, SmbMessage.SMB_COM_ECHO);

                /*
                    UCHAR WordCount;	Count of parameter words = 1
                    USHORT EchoCount;	Number of times to echo data back
                    USHORT ByteCount;	Count of data bytes;    min = 1
                    UCHAR Buffer[1];	Data to echo
                */

                // Set WordCount
                fMsg.setWordCount(1);
                // Set echo count
                fMsg.setShortParameterAt(0, echos);

                var data = new MarshalBuffer(text.Length + 10);

                int pos = 0;
                pos += data.SetAsciiStringAt(pos, text);
                data.Size = pos;

                fMsg.setContent(data);

                fMsg.SendAndRecieve(fNBTSession, fMsg);

                int errorclass = fMsg.getErrorClass();

                if (errorclass != CifsIoException.SUCCESS)
                    throw new CifsIoException(errorclass, fMsg.getErrorCode());

                int size = fMsg.getContentSize();

                if (size == 0)
                    return "";

                pos = fMsg.getContentOffset();

                return fMsg.GetAsciiStringAt(pos, size);
            }
        }