version 1.1.1.1.2.6, 2010/04/20 12:16:52
|
version 1.1.1.1.2.7, 2010/04/24 10:02:33
|
Line 196 void cliNetInit(const char *csProg, int pty, struct te
|
Line 196 void cliNetInit(const char *csProg, int pty, struct te
|
|
|
if (term) { |
if (term) { |
t = *term; |
t = *term; |
t.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); | // t.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); |
t.c_iflag &= ~ICRNL; |
t.c_iflag &= ~ICRNL; |
t.c_iflag |= IGNBRK; |
t.c_iflag |= IGNBRK; |
t.c_cc[VMIN] = 1; |
t.c_cc[VMIN] = 1; |
Line 214 void cliNetInit(const char *csProg, int pty, struct te
|
Line 214 void cliNetInit(const char *csProg, int pty, struct te
|
|
|
rl_getc_function = cli_GetC; |
rl_getc_function = cli_GetC; |
|
|
|
} |
|
|
|
/* |
|
* cliNetExec() Execute net CLI main loop |
|
* @cmdList = Commands list |
|
* @csPrompt = Prompt text |
|
* @sock = client socket |
|
* @term = stdin termios |
|
* @win = window size of tty |
|
* return: -1 error, 0 = exit w/^+D, 1 done. |
|
*/ |
|
int cliNetExec(cliCommands_t *cmdList, const char *csPrompt, int sock, struct termios *term, struct winsize *win) |
|
{ |
|
int pty, ret = 0, r, s, alen; |
|
fd_set fds; |
|
struct timeval tv = { DEFAULT_SOCK_TIMEOUT, 0 }; |
|
u_char buf[BUFSIZ]; |
|
struct telnetAttrs *a, Attr[3]; |
|
|
|
switch (forkpty(&pty, NULL, term, win)) { |
|
case -1: |
|
LOGERR; |
|
return -1; |
|
case 0: |
|
close(sock); |
|
|
|
cliTTY(NULL, NULL, NULL, win); |
|
ret = cliExec(cmdList, csPrompt) < 0 ? 1 : 0; |
|
_exit(ret); |
|
default: |
|
cliNetInit(getprogname(), pty, term); |
|
|
|
telnet_SetCmd(Attr, DO, TELOPT_TTYPE); |
|
telnet_SetCmd(Attr + 1, DO, TELOPT_LINEMODE); |
|
telnet_SetCmd(Attr + 2, GA, 0); |
|
if ((ret = telnetSend(sock, Attr, 3, NULL, 0, 0)) == -1) { |
|
cli_Errno = telnet_GetErrno(); |
|
strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
|
return -1; |
|
} |
|
|
|
while (42) { |
|
FD_ZERO(&fds); |
|
FD_SET(sock, &fds); |
|
FD_SET(pty, &fds); |
|
if (select(FD_SETSIZE, &fds, NULL, NULL, &tv) < 1) |
|
break; |
|
|
|
r = FD_ISSET(sock, &fds) ? sock : pty; |
|
s = FD_ISSET(sock, &fds) ? pty : sock; |
|
|
|
if ((ret = telnetRecv(r, &a, &alen, buf, BUFSIZ)) < 0) { |
|
if (-2 == ret) |
|
continue; |
|
// EOF |
|
if (-3 == ret) |
|
shutdown(r, SHUT_RD); |
|
else { |
|
cli_Errno = telnet_GetErrno(); |
|
strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
|
} |
|
break; |
|
} |
|
if ((ret = telnetSend(s, NULL, 0, buf, ret, 0)) == -1) { |
|
cli_Errno = telnet_GetErrno(); |
|
strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
|
break; |
|
} |
|
|
|
/* |
|
if ((ret = read(r, &ch, 1)) < 1) { |
|
if (!ret) |
|
shutdown(r, SHUT_RD); |
|
break; |
|
} |
|
if (write(s, &ch, 1) == -1) |
|
break; |
|
*/ |
|
} |
|
|
|
close(pty); |
|
} |
|
|
|
return ret; |
} |
} |
|
|
/* |
/* |