version 1.1.1.1.2.9, 2010/04/24 10:56:08
|
version 1.1.1.1.2.10, 2010/04/28 11:23:56
|
Line 31 static void cli_Null_Prep_Term(int meta)
|
Line 31 static void cli_Null_Prep_Term(int meta)
|
{ |
{ |
} |
} |
|
|
static void cli_Null_Deprep_Term() |
|
{ |
|
} |
|
|
|
static int cli_Pre_Input_Change_Mode() |
|
{ |
|
return 0; |
|
} |
|
|
|
static int cli_GetC(FILE *dummy) |
|
{ |
|
int ch = rl_getc(stdin); |
|
|
|
/* |
|
if (is_special_char(ch)) { |
|
pending_special_char = ch; |
|
return '\r'; |
|
} |
|
*/ |
|
|
|
return ch; |
|
} |
|
|
|
|
|
// cli_GetErrno() Get error code of last operation |
// cli_GetErrno() Get error code of last operation |
inline int cli_GetErrno() |
inline int cli_GetErrno() |
{ |
{ |
Line 193 inline void cliInit(const char *csProg)
|
Line 170 inline void cliInit(const char *csProg)
|
void cliNetInit(const char *csProg, int pty, struct termios *term) |
void cliNetInit(const char *csProg, int pty, struct termios *term) |
{ |
{ |
struct termios t; |
struct termios t; |
|
int on = 1; |
|
|
if (term) { | memset(&t, 0, sizeof t); |
| if (term) |
t = *term; |
t = *term; |
t.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); | else { |
t.c_iflag &= ~ICRNL; | t.c_lflag = TTYDEF_LFLAG; |
t.c_iflag |= IGNBRK; | t.c_iflag = TTYDEF_IFLAG; |
t.c_cc[VMIN] = 1; | t.c_oflag = TTYDEF_OFLAG; |
t.c_cc[VTIME] = 0; | cfsetspeed(&t, B9600); |
tcsetattr(pty, TCSANOW, &t); | |
} |
} |
|
|
cliInit(csProg); | t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); |
| t.c_iflag &= ~(ICRNL | BRKINT | INPCK | ISTRIP | IXON); |
| t.c_oflag &= ~OPOST; |
| t.c_cflag &= ~PARENB; |
| t.c_cc[VMIN] = 1; |
| t.c_cc[VTIME] = 0; |
| tcsetattr(pty, TCSANOW, &t); |
|
|
rl_instream = fdopen(pty, "r"); | ioctl(pty, TIOCPKT, &on); |
|
|
rl_prep_term_function = cli_Null_Prep_Term; | cliInit(csProg); |
rl_deprep_term_function = cli_Null_Deprep_Term; | rl_instream = fdopen(pty, "r"); |
rl_pre_input_hook = cli_Pre_Input_Change_Mode; | |
| |
rl_getc_function = cli_GetC; | |
| |
} |
} |
|
|
/* |
/* |
Line 227 void cliNetInit(const char *csProg, int pty, struct te
|
Line 207 void cliNetInit(const char *csProg, int pty, struct te
|
*/ |
*/ |
int cliNetExec(cliCommands_t *cmdList, const char *csPrompt, int sock, struct termios *term, struct winsize *win) |
int cliNetExec(cliCommands_t *cmdList, const char *csPrompt, int sock, struct termios *term, struct winsize *win) |
{ |
{ |
int pty, ret = 0, r, s, alen; | int pty, ret = 0, r, s, alen, attrlen; |
fd_set fds; |
fd_set fds; |
struct timeval tv = { DEFAULT_SOCK_TIMEOUT, 0 }; |
struct timeval tv = { DEFAULT_SOCK_TIMEOUT, 0 }; |
u_char buf[BUFSIZ]; |
u_char buf[BUFSIZ]; |
struct telnetAttrs *a, Attr[3]; | struct telnetAttrs *a, Attr[5]; |
| register int i; |
|
|
switch (forkpty(&pty, NULL, term, win)) { |
switch (forkpty(&pty, NULL, term, win)) { |
case -1: |
case -1: |
Line 240 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
Line 221 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
case 0: |
case 0: |
close(sock); |
close(sock); |
|
|
|
// rl_prep_term_function = cli_Null_Prep_Term; |
|
|
|
cliNetInit(getprogname(), STDIN_FILENO, term); |
|
// cliInit(getprogname()); |
cliTTY(NULL, NULL, NULL, win); |
cliTTY(NULL, NULL, NULL, win); |
ret = cliExec(cmdList, csPrompt) < 0 ? 1 : 0; | // ret = cliExec(cmdList, csPrompt) < 0 ? 1 : 0; |
| execl("/bin/tcsh", "tcsh", NULL); |
_exit(ret); |
_exit(ret); |
default: |
default: |
cliNetInit(getprogname(), pty, term); |
cliNetInit(getprogname(), pty, term); |
|
|
telnet_SetCmd(Attr, DO, TELOPT_TTYPE); |
telnet_SetCmd(Attr, DO, TELOPT_TTYPE); |
telnet_SetCmd(Attr + 1, DO, TELOPT_LINEMODE); | telnet_SetCmd(Attr + 1, WILL, TELOPT_SGA); |
telnet_SetCmd(Attr + 2, GA, 0); | telnet_SetCmd(Attr + 2, DO, TELOPT_LINEMODE); |
if ((ret = telnetSend(sock, Attr, 3, NULL, 0, 0)) == -1) { | telnet_Set_SubOpt(Attr + 3, TELOPT_LINEMODE, LM_MODE, "\x0", 1); |
| if ((ret = telnetSend(sock, Attr, 4, NULL, 0, 0)) == -1) { |
cli_Errno = telnet_GetErrno(); |
cli_Errno = telnet_GetErrno(); |
strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
return -1; |
return -1; |
Line 259 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
Line 246 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
FD_ZERO(&fds); |
FD_ZERO(&fds); |
FD_SET(sock, &fds); |
FD_SET(sock, &fds); |
FD_SET(pty, &fds); |
FD_SET(pty, &fds); |
if (select(FD_SETSIZE, &fds, NULL, NULL, &tv) < 1) | if ((ret = select(FD_SETSIZE, &fds, NULL, NULL, &tv)) < 1) { |
| if (!ret) |
| cli_SetErr(ETIMEDOUT, "Client session timeout ..."); |
| |
break; |
break; |
|
} |
|
|
r = FD_ISSET(sock, &fds) ? sock : pty; |
r = FD_ISSET(sock, &fds) ? sock : pty; |
s = FD_ISSET(sock, &fds) ? pty : sock; |
s = FD_ISSET(sock, &fds) ? pty : sock; |
|
|
if ((ret = telnetRecv(r, &a, &alen, buf, BUFSIZ)) < 0) { |
if ((ret = telnetRecv(r, &a, &alen, buf, BUFSIZ)) < 0) { |
|
if (a) |
|
free(a); |
|
|
if (-2 == ret) |
if (-2 == ret) |
continue; |
continue; |
// EOF |
// EOF |
Line 277 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
Line 271 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
} |
} |
break; |
break; |
} |
} |
if ((ret = telnetSend(s, NULL, 0, buf, ret, 0)) == -1) { | for (attrlen = i = 0; i < alen; i++) { |
| if (TELOPT_TTYPE == a[i].ta_opt && WILL == a[i].ta_cmd) |
| telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_TTYPE, TELQUAL_SEND, NULL, 0); |
| if (TELOPT_LINEMODE == a[i].ta_cmd && SB == a[i].ta_cmd) { |
| telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LINEMODE, LM_SLC, |
| "\x1\x0\x0\x3\xe2\x3\x4\x0\x0\x5\x0\x0\x7\xe2\x1c" |
| "\x8\x82\x4\x9\x0\x0\xa\x82\x7f\xb\x82\x15\xc\x82\x17" |
| "\xd\x82\x12\xe\x82\x16\xf\x82\x11\x10\x82\x13", 42); |
| } |
| } |
| if (a) |
| free(a); |
| #include "syslog.h" |
| int j; |
| for (j = 0; j < ret; j++) |
| syslog(LOG_CRIT, "prepare to send %d = %X", j, buf[j]); |
| syslog(LOG_CRIT, "send packet %d ===========", ret); |
| if ((ret = telnetSend(s, Attr, attrlen, buf, ret, 0)) == -1) { |
cli_Errno = telnet_GetErrno(); |
cli_Errno = telnet_GetErrno(); |
strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
break; |
break; |