From: Marko O. <d0...@us...> - 2009-10-28 12:24:58
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "UNNAMED PROJECT". The branch, master has been updated via 00d7530dbb8e59541120635b9a349954c1c0484e (commit) from 8b361814e9b8a1a41b3fbddaf91b4cdea4115220 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 00d7530dbb8e59541120635b9a349954c1c0484e Author: Marko Obrovac <mar...@in...> Date: Wed Oct 28 12:20:56 2009 +0000 Added netclient.c to the tools directory diff --git a/scripts/Makefile.in b/scripts/Makefile.in index 36284b0..b55c34b 100644 --- a/scripts/Makefile.in +++ b/scripts/Makefile.in @@ -1,8 +1,9 @@ -# Makefile.in generated by automake 1.10.1 from Makefile.am. +# Makefile.in generated by automake 1.11 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -15,8 +16,9 @@ @SET_MAKE@ VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c @@ -41,6 +43,7 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = SOURCES = DIST_SOURCES = DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -56,45 +59,47 @@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DIST_ID = @DIST_ID@ DIST_RELEASE = @DIST_RELEASE@ DSYMUTIL = @DSYMUTIL@ -ECHO = @ECHO@ +DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ -F77 = @F77@ -FFLAGS = @FFLAGS@ +FGREP = @FGREP@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ +NM = @NM@ NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ RANLIB = @RANLIB@ @@ -108,8 +113,7 @@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_F77 = @ac_ct_F77@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ @@ -147,6 +151,7 @@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ lsb = @lsb@ +lt_ECHO = @lt_ECHO@ ltpbase = @ltpbase@ mandir = @mandir@ mkdir_p = @mkdir_p@ @@ -165,6 +170,7 @@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ vanilla_linux_version = @vanilla_linux_version@ @@ -203,14 +209,14 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu scripts/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu scripts/Makefile + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu scripts/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu scripts/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ @@ -228,6 +234,7 @@ $(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): mostlyclean-libtool: -rm -f *.lo @@ -257,13 +264,17 @@ distdir: $(DISTFILES) if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done @@ -294,6 +305,7 @@ clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @@ -312,6 +324,8 @@ dvi-am: html: html-am +html-am: + info: info-am info-am: @@ -320,18 +334,28 @@ install-data-am: install-data-local install-dvi: install-dvi-am +install-dvi-am: + install-exec-am: install-html: install-html-am +install-html-am: + install-info: install-info-am +install-info-am: + install-man: install-pdf: install-pdf-am +install-pdf-am: + install-ps: install-ps-am +install-ps-am: + installcheck-am: maintainer-clean: maintainer-clean-am @@ -381,6 +405,7 @@ uninstall-local: dist-hook: rm -rf $(find $(distdir) -name '*~') + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/tools/netclient.c b/tools/netclient.c new file mode 100644 index 0000000..1a64130 --- /dev/null +++ b/tools/netclient.c @@ -0,0 +1,194 @@ +/* + * A network client for interacting with KDB. + * + * Dan Aloni <da...@xi...>, 2006 (c) + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + */ +/* + * Changelog: + * - 2007: added rough arguments to configure the listening port and not + * deactivate character echoing - Louis Riling <lou...@ke...> + * - 2007: fix newline over ssh - Matthieu Fertre <mf...@ir...> + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/poll.h> +#include <netinet/in.h> +#include <termios.h> +#include <unistd.h> +#include <arpa/inet.h> +#include <signal.h> + +struct termios orig_tty; +int enable_echo = 0; + +void sigint(int s) +{ + tcsetattr(STDIN_FILENO, TCSANOW, &orig_tty); +} + +void disable_icanon(void) +{ + struct termios tty; + + tcgetattr(STDIN_FILENO, &tty); + orig_tty = tty; + + tty.c_lflag &= ~ICANON; + if (!enable_echo) + tty.c_lflag &= ~ECHO; + + tty.c_iflag &= ~ICRNL; + + tcsetattr(STDIN_FILENO, TCSANOW, &tty); + + signal(SIGINT, sigint); +} + + +int main(int argc, char *argv[]) +{ + int sock_fd; + int ret; + int flag; + int stdin_fd = STDIN_FILENO; + char in_char; + struct sockaddr_in listening_address = { + .sin_family = AF_INET, + .sin_addr.s_addr = INADDR_ANY, + .sin_port = htons(6666), + }; + struct sockaddr_in remote_address = { + .sin_family = AF_INET, + .sin_addr.s_addr = INADDR_ANY, + .sin_port = htons(6665), + }; + struct pollfd ufds[2]; + int enable_recv = 1; + int nr_pollfd = 2; + + if (argc < 2) + return -1; + + remote_address.sin_addr.s_addr = inet_addr(argv[1]); + if (argc > 2) + listening_address.sin_port = htons(atoi(argv[2])); + + if (argc > 3) + enable_echo = 1; + + if (!listening_address.sin_port) { + printf("netkdb sending to %s:%d, SIGINT will exit\n", inet_ntoa(remote_address.sin_addr), ntohs(remote_address.sin_port)); + enable_recv = 0; + nr_pollfd = 1; + } else { + printf("netkdb listening and sending on port %d to %s:%d, SIGINT will exit\n", ntohs(listening_address.sin_port), inet_ntoa(remote_address.sin_addr), ntohs(remote_address.sin_port)); + } + if (enable_echo) + printf("echo enabled\n"); + + sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (sock_fd < 0) { + printf("socket creation failed\n"); + return -1; + } + + flag = 1; + ret = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)); + if (ret <0) { + return -1; + } + + ret = bind(sock_fd, (struct sockaddr *)&listening_address, + sizeof(listening_address)); + + if (ret < 0) { + printf("bind failed\n"); + return -1; + } + + ufds[0].fd = stdin_fd; + ufds[0].events = POLLIN; + if (enable_recv) { + ufds[1].fd = sock_fd; + ufds[1].events = POLLIN; + } else + shutdown(sock_fd, SHUT_RD); + + disable_icanon(); + + while (1) { + ufds[0].revents = 0; + if (enable_recv) + ufds[1].revents = 0; + + ret = poll(ufds, nr_pollfd, 1000); + if (ret < 0) + break; + + if (ufds[0].revents & POLLIN) { + ret = read(stdin_fd, &in_char, 1); + if (ret == 0) + break; + + /* translate backspace to what kdb is expecting */ + if (in_char == 127) { + in_char = 8; + } + /* translate enter to what kdb is expecting + * (\n -> \r) */ + if (in_char == 10) { + in_char = 13; + } + + ret = sendto(sock_fd, &in_char, 1, 0, (struct sockaddr *)&remote_address, + sizeof(remote_address)); + + if (ret < 0) { + fprintf(stderr, "sendto() failed\n"); + break; + } + } + + if (enable_recv && (ufds[1].revents & POLLIN)) { + struct sockaddr_in source; + socklen_t socklen = sizeof(remote_address); + char buf[0x1000]; + + ret = recvfrom(sock_fd, buf, sizeof(buf), 0, (struct sockaddr *)&source, + &socklen); + + if (ret < 0) { + fprintf(stderr, "recvfrom() failed\n"); + break; + } + + if (source.sin_addr.s_addr == remote_address.sin_addr.s_addr) { + write(STDOUT_FILENO, buf, ret); + } + } + } + + tcsetattr(STDIN_FILENO, TCSANOW, &orig_tty); + + return 0; +} + ----------------------------------------------------------------------- Summary of changes: scripts/Makefile.in | 67 ++++++++++++------ tools/netclient.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+), 21 deletions(-) create mode 100644 tools/netclient.c hooks/post-receive -- UNNAMED PROJECT |