How to use putty code for telnet server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omidrh
    New Member
    • May 2010
    • 5

    #1

    How to use putty code for telnet server

    I want use putty code for writing a C program in linux.
    My program is a small telnet server that user log into it and send command to server.
    How can I use putty source code? What files is needed?
    Last edited by Niheel; May 28 '10, 06:59 AM. Reason: punctuation grammar
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Given that putty is an ssh client I can see it being any help in writing telnet server.

    However the telnet protocol is a fairly simple one. It is transmitted over a simple tcp socket and uses 7bit ascii data for carrying text commands with control data flagged by have bit 7 in the data set.

    It isn't to hard to build a basic telnet server (one that refuses all options) have a read about it on Wikipedia http://en.wikipedia.org/wiki/Telnet and don't forget to read the external links.

    Comment

    • omidrh
      New Member
      • May 2010
      • 5

      #3
      I have written the telnet server, my problem is i can't send commands to the client using the send and write function,
      For example i want to send "IAC Dont Echo" to the client but this is displayed like any text message and isn't interpreted as a command.
      I wanted to use putty for this, could you help me?
      Thanks.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        "IAC Dont Echo" should not be sent as text because then it will just be interpreted as text for the telnet client.

        It should be sent as the string of bytes

        0xFF 0xFE 0X01

        Follow the link I posted and read the page and then follow the external links and read those pages too.

        Comment

        • omidrh
          New Member
          • May 2010
          • 5

          #5
          thanks Banfa for reply but i still have problem

          This is my c++ code for turn off echo but it doesnt work. Whats the problem?

          Code:
          #define IAC 255
          #define DONT 254
          #define ECHO 1
          
          ...
          
          char test[256];
          bzero(test, 256);
          
          sprintf(test, "%c%c%c\n", IAC, DONT, ECHO);
          int n = write(sockfd, test, strlen(test));
          
          n = recv(sockfd, test, 256, 0);

          Comment

          • omidrh
            New Member
            • May 2010
            • 5

            #6
            the dont echo problem is solved. the code was right, the problem was i was testing from localhost.
            Now the problem is I cant turn echo on. I write the same code with DO ECHO but it doesnt work. whats the problem now?

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              You need to check the reply from the server, it may have replied with a WONT in which case echo wont be on.

              All transmitted control codes have a handshake (a reply) you should be checking for codes sent by the server in the first place and handshaking them.

              You shouldn't really treat your array of control characters as a string because it will go wrong if you ever need to transmit a 0.

              Comment

              • omidrh
                New Member
                • May 2010
                • 5

                #8
                How can i check the reply from the server? can you show me a sample code because I'm a beginner and not very familiar with these thing. All the things I read just explain about echo, not how to write the code to enable or disable it.

                Comment

                • Banfa
                  Recognized Expert Expert
                  • Feb 2006
                  • 9067

                  #9
                  When you read data from the server using recv you should being checking that data to see if any of it is control codes.

                  Just check the value of the bytes, you can look for 255 since all control codes are prefixed with a 255 byte.

                  Comment

                  Working...