the source file(the second half tel_cli.c and tel_cli.h)
case WONT:
break;
case SB:
printf("ch is SB\n");
sleep(5);
if (lcOption == TSPEED)
{
printf("RECV IAC SB TERMINAL SPEED SEND (32)\n");
printf("%d%d%d\n", rbuf[i], rbuf[i + 1], rbuf[i + 2]);
//i = i + 3;
sleep(5);
bzero(gsSendMsg, LINELEN);
sprintf(gsSendMsg, "%c%c%c%c%d%d%d%d%c%c\n", IAC, SB, TSPEED, IS, 38400 >> 8, (38400 & 0xFF), 38400 >> 8, (38400 & 0xFF), IAC,SE);
write(li_sock, gsSendMsg, strlen(gsSendMsg));
}
if (lcOption == NEW_ENVIRON)
{
printf("RECV IAC SB NEW-ENVIRON SEND (39)\n");
printf("%d%d%d\n", rbuf[i], rbuf[i + 1], rbuf[i + 2]);
//i = i + 3;
sleep(5);
bzero(gsSendMsg, LINELEN);
sprintf(gsSendMsg, "%c%c%c%c%c%c\n", IAC, SB, NEW_ENVIRON, IS, IAC, SE);
write(li_sock, gsSendMsg, strlen(gsSendMsg));
}
if (lcOption == TERMINAL)
{
printf("RECV IAC SB TERMINAL TYPE SEND (24)\n");
printf("%d%d%d\n", rbuf[i], rbuf[i + 1], rbuf[i + 2]);
//i = i + 3;
sleep(5);
bzero(gsSendMsg, LINELEN);
sprintf(gsSendMsg, "%c%c%c%c%s%c%c\n", IAC, SB, NEW_ENVIRON, IS,"ANSI", IAC, SE);
write(li_sock, gsSendMsg, strlen(gsSendMsg));
printf("okokok\n");
bzero(gsSendMsg, LINELEN);
sprintf(gsSendMsg, "%c%c%c\n", IAC, DODO,ECHO_ON);
write(li_sock, gsSendMsg, strlen(gsSendMsg));
printf("okokok\n");
}
i = i + 3;
break;
default:
printf("ch is other character\n");
break;
}
}
else
{
//printf("ch isn't IAC, there are maybe some errors occur!\n");
i++;
}
}
}
}
tel_cli.h:
//telnet command code
#define IAC 255
#define DODO 253
#define DONT 254
#define WILL 251
#define WONT 252
#define SB 250
#define SE 240
#define IS '0'
#define SEND '1'
#define INFO '2'
#define VAR '0'
#define VALUE '1'
#define ESC '2'
#define USERVAR '3'
//option name and id
#define ECHO_ON 1
#define GO_AHEAD 3
#define STATUS 5
#define TIMER 6
#define TERMINAL 24
#define NAWS 31
#define TSPEED 32
#define FLOW 33
#define LINEMODE 34
#define XDISPLOC 35 // X Display Location
#define OLD_ENVIRON 36 // Old - Environment variables
#define AUTH 37
#define NEW_ENVIRON 39