diff --git a/ncat/ChangeLog b/ncat/ChangeLog index 7475530..cde93fe 100644 --- a/ncat/ChangeLog +++ b/ncat/ChangeLog @@ -1,5 +1,8 @@ # Ncat Changelog ($Id$); -*-text-*- +o Added --color-input that colors the incoming network input to make it easily + distinguishable from the user wrote to the terminal. [Jacek Wielemborek] + o Reworked the test program test/test-cmdline-split slightly and added additional test cases. Rewrote cmdline_split in ncat_posix.c [Josh Marlow] diff --git a/ncat/docs/ncat.xml b/ncat/docs/ncat.xml index 9cfabf1..b8d6964 100644 --- a/ncat/docs/ncat.xml +++ b/ncat/docs/ncat.xml @@ -684,6 +684,19 @@ + (Color input) + (Ncat option) + + + Issue Ncat with and it will mark + all the network using red color. Note that this has no effect if Ncat's + standard output is redirected to a file. + + + + + + , (Be verbose) (Ncat option) diff --git a/ncat/ncat_connect.c b/ncat/ncat_connect.c index 0289882..8064381 100644 --- a/ncat/ncat_connect.c +++ b/ncat/ncat_connect.c @@ -496,7 +496,7 @@ static int do_proxy_http(void) } remainder = socket_buffer_remainder(&sockbuf, &len); - Write(STDOUT_FILENO, remainder, len); + write_colored(STDOUT_FILENO, remainder, len); return sd; @@ -696,7 +696,7 @@ int ncat_connect(void) already sent by proxy server along with http response headers. */ line = socket_buffer_remainder(&stateful_buf, &n); /* Write the leftover data to stdout. */ - Write(STDOUT_FILENO, line, n); + write_colored(STDOUT_FILENO, line, n); } /* Once the proxy negotiation is done, Nsock takes control of the @@ -890,7 +890,7 @@ static void read_socket_handler(nsock_pool nsp, nsock_event evt, void *data) dotelnet(nsi_getsd(nse_iod(evt)), (unsigned char *) buf, nbytes); /* Write socket data to stdout */ - Write(STDOUT_FILENO, buf, nbytes); + write_colored(STDOUT_FILENO, buf, nbytes); ncat_log_recv(buf, nbytes); nsock_readbytes(nsp, cs.sock_nsi, read_socket_handler, -1, NULL, 0); diff --git a/ncat/ncat_core.c b/ncat/ncat_core.c index e2b7168..b1c4cc8 100644 --- a/ncat/ncat_core.c +++ b/ncat/ncat_core.c @@ -181,6 +181,7 @@ void options_init(void) o.normlogfd = -1; o.hexlogfd = -1; o.append = 0; + o.color = 0; o.idletimeout = 0; o.crlf = 0; o.allow = 0; diff --git a/ncat/ncat_core.h b/ncat/ncat_core.h index b19e436..3f90457 100644 --- a/ncat/ncat_core.h +++ b/ncat/ncat_core.h @@ -171,6 +171,7 @@ struct options { int normlogfd; int hexlogfd; int append; + int color; int idletimeout; int crlf; /* Were any hosts specifically allowed? If so, deny all others. */ @@ -259,6 +260,8 @@ extern void ncat_log_send(const char *data, size_t len); extern void ncat_log_recv(const char *data, size_t len); +extern int write_colored(int fildes, const void *buf, size_t nbyte); + extern int ncat_hostaccess(char *matchaddr, char *filename, char *remoteip); /* Make it so that line endings read from a console are always \n (not \r\n). diff --git a/ncat/ncat_listen.c b/ncat/ncat_listen.c index 6568a61..bb789d6 100644 --- a/ncat/ncat_listen.c +++ b/ncat/ncat_listen.c @@ -623,7 +623,7 @@ int read_socket(int recv_fd) return n; } - Write(STDOUT_FILENO, buf, n); + write_colored(STDOUT_FILENO, buf, n); nbytes += n; } while (pending); @@ -890,7 +890,7 @@ static int ncat_listen_dgram(int proto) } ncat_log_recv(buf, nbytes); if (!o.sendonly) - Write(STDOUT_FILENO, buf, nbytes); + write_colored(STDOUT_FILENO, buf, nbytes); } zmem(buf, sizeof(buf)); diff --git a/ncat/ncat_main.c b/ncat/ncat_main.c index 3562d85..1347d22 100644 --- a/ncat/ncat_main.c +++ b/ncat/ncat_main.c @@ -285,6 +285,7 @@ int main(int argc, char *argv[]) {"output", required_argument, NULL, 'o'}, {"hex-dump", required_argument, NULL, 'x'}, {"append-output", no_argument, NULL, 0}, + {"color-input", no_argument, NULL, 0}, {"idle-timeout", required_argument, NULL, 'i'}, {"keep-open", no_argument, NULL, 'k'}, {"recv-only", no_argument, &o.recvonly, 1}, @@ -496,6 +497,8 @@ int main(int argc, char *argv[]) host_list_add_filename(&deny_host_list, optarg); } else if (strcmp(long_options[option_index].name, "append-output") == 0) { o.append = 1; + } else if (strcmp(long_options[option_index].name, "color-input") == 0) { + o.color = 1; } else if (strcmp(long_options[option_index].name, "sctp") == 0) { o.proto = IPPROTO_SCTP; } @@ -586,6 +589,7 @@ int main(int argc, char *argv[]) " -v, --verbose Set verbosity level (can be used several times)\n" " -w, --wait