Logo 
Search:

Networking Articles

Submit Article
Home » Articles » Networking » TCP/IPRSS Feeds

TCP/IP program to handle TELNET WILL/WON'T ECHO option

Posted By: Milind Mishra     Category: Networking     Views: 2773

TCP/IP program to handle TELNET WILL/WON'T ECHO option.

Code for TCP/IP program to handle TELNET WILL/WON'T ECHO option in Networking

#include <sys/types.h>

#include <termios.h>
#include <stdio.h>

#include "telnet.h"char        doecho;        /* nonzero, if remote ECHO    */extern u_char    option_cmd;

int
do_echo(FILE *rfp, FILE *tfp, int c)
{
        struct termios  tio;
    staticchar    savec[2];
    int        ok, tfd = fileno(tfp);

    if (doecho) {
        if (option_cmd == TCWILL)
            return 0;    /* already doing ECHO        */
    } elseif (option_cmd == TCWONT)
        return 0;        /* already NOT doing ECHO    */if (ok = tcgetattr(tfd, &tio) == 0) {
            if (option_cmd == TCWILL) {
                       tio.c_lflag &= ~(ECHO | ICANON);
            /* VMIN & VTIME are overloaded with other chars,             * so save and restore them later.             */
            savec[0] = tio.c_cc[VMIN];
            savec[1] = tio.c_cc[VTIME];
            tio.c_cc[VMIN] = 1;
            tio.c_cc[VTIME] = 0;
        } else {
            tio.c_lflag |= (ECHO | ICANON);
            tio.c_cc[VMIN] = savec[0];
            tio.c_cc[VTIME] = savec[1];
        }
        ok &= tcsetattr(tfd, TCSADRAIN, &tio) == 0;
        }
    if (ok)
        doecho = !doecho;
        (void) putc(TCIAC, rfp);
        if (doecho)
                (void) putc(TCDO, rfp);
        else
                (void) putc(TCDONT, rfp);
    (void) putc((char)c, rfp);
    return 0;
}
  
Share: 


Didn't find what you were looking for? Find more on TCP/IP program to handle TELNET WILL/WON'T ECHO option Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of TCP/IP program to handle TELNET WILL/WON'T ECHO option is from India.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!