--- ansh/src/client3.c 2011/10/04 22:37:46 1.1.1.1 +++ ansh/src/client3.c 2011/10/05 23:57:24 1.1.1.1.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: client3.c,v 1.1.1.1 2011/10/04 22:37:46 misho Exp $ + * $Id: client3.c,v 1.1.1.1.2.1 2011/10/05 23:57:24 misho Exp $ * *************************************************************************/ #include "global.h" @@ -42,7 +42,7 @@ ConnectL3(int h, u_short id, struct sockaddr *sa, int int rlen, ret = 0; u_short aid; struct sockaddr s; - char flg; + char flg, nl = 0; u_char *buf; socklen_t sl; @@ -76,6 +76,37 @@ ConnectL3(int h, u_short id, struct sockaddr *sa, int ret = -1; break; } + + /* local command handling */ + if (rlen) { + /* execute local command */ + if (nl == 2) { + switch (*buf) { + case '.': + Kill++; + printf("\n"); + VERB(1) LOG("Exit from client\n"); + continue; + case '~': + default: + nl ^= nl; + /* send buffer, unknown command */ + break; + } + } + /* skip buffer and wait for local command */ + if (nl == 1 && *buf == '~') { + nl++; + continue; + } + /* send buffer if detect NL */ + if (*buf == 0xa || *buf == 0xd) + nl = 1; + else + nl ^= nl; + } else + nl ^= nl; + rlen = icmpSend(h, id, ANSH_FLG_CPOUT, buf, rlen, sa, sizeof(struct sockaddr)); if (rlen == ANSH_FLG_ERR) { ret = -1;