コード例 #1
0
ファイル: TelnetController.cs プロジェクト: rypl/naogui
        private bool SendSubNegotiation(int option, byte[] data)
        {
            byte[] SubNegotiationCommand;

            SubNegotiationCommand = TelnetHelper.GetSubNegotiationCommand(option, data);

            return(telnetClient.SendData(SubNegotiationCommand));
        }
コード例 #2
0
ファイル: TelnetController.cs プロジェクト: rypl/naogui
        private bool SendCommand(int negotiation, int option)
        {
            byte[] sendData;

            sendData = TelnetHelper.GetCommand(negotiation, option);

            return(telnetClient.SendData(sendData));
        }
コード例 #3
0
ファイル: TelnetController.cs プロジェクト: rypl/naogui
        // Possibly needs to be rewritten
        private void DisplayReceivedData(byte[] data, int dataLength)
        {
            for (int i = 0; i < dataLength; ++i)
            {
                byte dataByte = data[i];

                if (dataByte != 0)
                {
                    if (dataByte == TelnetHelper.SB)
                    {
                        Console.Write("SB:   ");
                    }
                    else if (dataByte == TelnetHelper.SE)
                    {
                        Console.Write("SE:    ");
                    }
                    else if (dataByte == TelnetHelper.WILL)
                    {
                        Console.Write("WILL:  ");
                    }
                    else if (dataByte == TelnetHelper.WONT)
                    {
                        Console.Write("WON'T: ");
                    }
                    else if (dataByte == TelnetHelper.DO)
                    {
                        Console.Write("DO:    ");
                    }
                    else if (dataByte == TelnetHelper.DONT)
                    {
                        Console.Write("DON'T: ");
                    }
                    else if (dataByte == TelnetHelper.IAC)
                    {
                        Console.Write("\nIAC  ");
                    }
                    else if (dataByte == TelnetHelper.ESC)
                    {
                        Console.Write("\nESC: ");
                    }
                    else // Get Option Description of Command
                    {
                        Console.Write(TelnetHelper.GetOptionDescription(dataByte) + " "); //dataByte.ToString("X")
                    }
                }
            }

            Console.WriteLine();
        }
コード例 #4
0
ファイル: TelnetController.cs プロジェクト: rypl/naogui
        // If you want to add additional IAC responses add it in this method
        private int ProcessIAC(byte[] dataBytes, int dataLength, int i)
        {
            // IAC Negotiation Option
            byte negotiation = dataBytes[i + 1];
            byte option      = dataBytes[i + 2];

            if (negotiation == TelnetHelper.DO)
            {
                Console.WriteLine("DO= " + dataBytes[i + 3].ToString("X"));

                if (TelnetHelper.GetOptionDescription(option) == "Echo")
                {
                    SendCommand(TelnetHelper.WILL, 0x01);
                }
                else if (TelnetHelper.GetOptionDescription(option) == "Suppress Go Ahead")
                {
                    SendCommand(TelnetHelper.WILL, 0x03);
                }
                else if (TelnetHelper.GetOptionDescription(option) == "Terminal Type")
                {
                    SendCommand(TelnetHelper.WILL, 0x18);
                }
                else if (TelnetHelper.GetOptionDescription(option) == "Terminal Speed")
                {
                    SendCommand(TelnetHelper.WILL, 0x20);
                }
                else if (TelnetHelper.GetOptionDescription(option) == "X Display Location")
                {
                    SendCommand(TelnetHelper.WONT, 0x23); // Won't display X Location
                }
                else if (TelnetHelper.GetOptionDescription(option) == "New Environment Option")
                {
                    SendCommand(TelnetHelper.WILL, 0x27);
                }
                else if (TelnetHelper.GetOptionDescription(option) == "Negotiate About Window Size")
                {
                    SendCommand(TelnetHelper.WILL, 0x1F);
                }

                i += 2;
            }

            else if (negotiation == TelnetHelper.SB)
            {
                Console.WriteLine("SB= " + dataBytes[i + 3].ToString("X"));

                if (TelnetHelper.GetOptionDescription(option) == "Terminal Type")
                {
                    SendSubNegotiation(option, encoder.GetBytes("\0XTERM"));
                }
                else if (TelnetHelper.GetOptionDescription(option) == "Terminal Speed")
                {
                    SendSubNegotiation(option, encoder.GetBytes("\038400,38400"));
                }
                else if (TelnetHelper.GetOptionDescription(option) == "New Environment Option")
                {
                    SendSubNegotiation(option, encoder.GetBytes("\0"));
                }

                i += 3;
            }

            return(i);
        }