From: Ari Johnson Date: Tue, 19 Apr 2011 05:31:40 +0000 (-0400) Subject: Finish re-implementation of console mode with ./netmush --console X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=bcaaa97ef1e6b6b0c5d5c0eaa90cb1f5663d8f97;p=cobramush.git Finish re-implementation of console mode with ./netmush --console --- diff --git a/src/bsd.c b/src/bsd.c index a8315ed..337b50b 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -275,7 +275,7 @@ DESC *descriptor_list = NULL; /**< The linked list of descriptors */ intmap *descs_by_fd = NULL; /**< Map of ports to DESC* objects */ static bool console_mode = 0; -static int console_input, console_output; +static int console_input = -1, console_output = -1; static int sock = 0; #ifdef HAS_OPENSSL static int sslsock = 0; @@ -1831,9 +1831,9 @@ process_output(DESC *d) } #ifdef DEBUG do_rawlog(LT_TRACE, "Sending %d bytes in %d blocks to socket %d", - cnt, n, d->descriptor); + cnt, n, d->outdesc); #endif - cnt = writev(d->descriptor, lines, n); + cnt = writev(d->outdesc, lines, n); #ifdef DEBUG do_rawlog(LT_TRACE, "writev() returned %d", cnt); #endif @@ -1889,7 +1889,10 @@ process_output(DESC *d) } else #endif /* HAS_OPENSSL */ { - cnt = send(d->descriptor, cur->start, cur->nchars, 0); + if (d->outdesc == console_output) + cnt = write(d->outdesc, cur->start, cur->nchars); + else + cnt = send(d->outdesc, cur->start, cur->nchars, 0); if (cnt < 0) { #ifdef WIN32 if (cnt == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) @@ -2294,7 +2297,10 @@ process_input(DESC *d, int output_ready __attribute__ ((__unused__))) } else { #endif - got = recv(d->descriptor, tbuf1, sizeof tbuf1, 0); + if (d->descriptor == console_input) + got = read(d->descriptor, tbuf1, sizeof tbuf1); + else + got = recv(d->descriptor, tbuf1, sizeof tbuf1, 0); if (got <= 0) { /* At this point, select() says there's data waiting to be read from * the socket, but we shouldn't assume that read() will actually get it @@ -2838,8 +2844,13 @@ close_sockets(void) byebye[1].iov_len = 2; writev(d->outdesc, byebye, 2); #else - send(d->outdesc, shutmsg, shutlen, 0); - send(d->outdesc, (char *) "\r\n", 2, 0); + if (d->outdesc == console_outpt) { + write(d->outdesc, shutmsg, shutlen); + write(d->outdesc, (char *) "\r\n", 2); + } else { + send(d->outdesc, shutmsg, shutlen, 0); + send(d->outdesc, (char *) "\r\n", 2, 0); + } #endif #ifdef HAS_OPENSSL } else { diff --git a/src/info_master.c b/src/info_master.c index 5b4cadd..8bceeb7 100644 --- a/src/info_master.c +++ b/src/info_master.c @@ -69,7 +69,7 @@ bool info_slave_halted = false; /* From bsd.c */ extern int maxd; -DESC *initializesock(int s, char *addr, char *ip, int use_ssl); +DESC *initializesock(int s, int os, char *addr, char *ip, int use_ssl); /** Re-query lookups that have timed out */ void @@ -359,7 +359,7 @@ reap_info_slave(void) do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Connection opened."), resp.fd, hostname, resp.ipaddr); set_keepalive(resp.fd); - initializesock(resp.fd, hostname, resp.ipaddr, + initializesock(resp.fd, resp.fd, hostname, resp.ipaddr, (resp.connected_to == SSLPORT)); }