|
version 1.1.1.1.2.16, 2010/06/04 11:25:45
|
version 1.2, 2010/06/04 11:32:47
|
|
Line 275 void cliNetInit(const char *csProg, int pty, struct te
|
Line 275 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, alen, attrlen, flg; | int pty, ret = 0, r, s, alen, attrlen, flg; |
| 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]; |
|
Line 288 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
Line 288 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
| case 0: |
case 0: |
| close(sock); |
close(sock); |
| |
|
| rl_prep_term_function = cli_Null_Prep_Term; | // rl_prep_term_function = cli_Null_Prep_Term; |
| rl_getc_function = cli_Net_rl_GetCh; |
rl_getc_function = cli_Net_rl_GetCh; |
| |
|
| cliNetInit(getprogname(), STDIN_FILENO, term); |
cliNetInit(getprogname(), STDIN_FILENO, term); |
|
Line 299 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
Line 299 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
| */ |
*/ |
| _exit(ret); |
_exit(ret); |
| default: |
default: |
| |
rl_prep_term_function = cli_Null_Prep_Term; |
| |
|
| cliNetInit(getprogname(), pty, term); |
cliNetInit(getprogname(), pty, term); |
| |
|
| /* spawn Shell mode */ |
/* spawn Shell mode */ |
|
Line 332 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
Line 334 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
| break; |
break; |
| } |
} |
| |
|
| if (FD_ISSET(sock, &fds)) { | r = FD_ISSET(sock, &fds) ? sock : pty; |
| memset(buf, 0, BUFSIZ); | s = FD_ISSET(sock, &fds) ? pty : sock; |
| if ((ret = telnetRecv(sock, &a, &alen, buf, BUFSIZ)) < 0) { | |
| if (a) | |
| free(a); | |
| |
|
| if (-2 == ret) | if ((ret = telnetRecv(r, &a, &alen, buf, BUFSIZ)) < 0) { |
| continue; | |
| // EOF | |
| if (-3 == ret) | |
| shutdown(sock, SHUT_RD); | |
| else { | |
| cli_Errno = telnet_GetErrno(); | |
| strlcpy(cli_Error, telnet_GetError(), STRSIZ); | |
| } | |
| break; | |
| } | |
| if (a) |
if (a) |
| free(a); |
free(a); |
| if (alen) { |
|
| attrlen = 0; |
|
| if (1 == flg && alen) { |
|
| telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_SGA); |
|
| telnet_SetCmd(&Attr[attrlen++], DO, TELOPT_ECHO); |
|
| } |
|
| if (2 == flg && alen) { |
|
| telnet_SetCmd(&Attr[attrlen++], WILL, TELOPT_ECHO); |
|
| telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, |
|
| LFLOW_OFF, NULL, 0); |
|
| telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, |
|
| LFLOW_RESTART_XON, NULL, 0); |
|
| telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_LINEMODE); |
|
| } |
|
| if ((ret = telnetSend(sock, Attr, attrlen, buf, ret, 0)) == -1) { |
|
| cli_Errno = telnet_GetErrno(); |
|
| strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
|
| break; |
|
| } |
|
| } |
|
| syslog(LOG_CRIT, "alen=%d ret=%d b0=%x b1=%x b2=%x\n", alen, ret, buf[0], buf[1], buf[2]); |
|
| |
|
| if ((ret = write(pty, buf, ret)) == -1) { | if (-2 == ret) |
| LOGERR; | continue; |
| break; | // EOF |
| } | if (-3 == ret) |
| } | shutdown(r, SHUT_RD); |
| else { |
| if (FD_ISSET(pty, &fds)) { | |
| memset(buf, 0, BUFSIZ); | |
| if ((ret = read(pty, buf, BUFSIZ)) < 1) { | |
| if (!ret) | |
| shutdown(sock, SHUT_WR); | |
| else | |
| LOGERR; | |
| break; | |
| } | |
| syslog(LOG_CRIT, "ret=%d b0=%x b1=%x b2=%x\n", ret, buf[0], buf[1], buf[2]); | |
| attrlen = 0; | |
| if (1 == flg && alen) { | |
| telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_SGA); | |
| telnet_SetCmd(&Attr[attrlen++], DO, TELOPT_ECHO); | |
| } | |
| if (2 == flg && alen) { | |
| telnet_SetCmd(&Attr[attrlen++], WILL, TELOPT_ECHO); | |
| telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, | |
| LFLOW_OFF, NULL, 0); | |
| telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, | |
| LFLOW_RESTART_XON, NULL, 0); | |
| telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_LINEMODE); | |
| } | |
| if ((ret = telnetSend(sock, 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; |
| } |
} |
| |
attrlen = 0; |
| |
if (1 == flg && alen) { |
| |
telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_SGA); |
| |
telnet_SetCmd(&Attr[attrlen++], DO, TELOPT_ECHO); |
| |
} |
| |
if (2 == flg && alen) { |
| |
telnet_SetCmd(&Attr[attrlen++], WILL, TELOPT_ECHO); |
| |
telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, |
| |
LFLOW_OFF, NULL, 0); |
| |
telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, |
| |
LFLOW_RESTART_XON, NULL, 0); |
| |
telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_LINEMODE); |
| |
} |
| |
if (a) |
| |
free(a); |
| |
|
| |
if ((ret = telnetSend(s, Attr, pty == s ? 0 : attrlen, buf, ret, 0)) == -1) { |
| |
cli_Errno = telnet_GetErrno(); |
| |
strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
| |
break; |
| |
} else |
| |
flg++; |
| } |
} |
| |
|
| close(pty); |
close(pty); |