From 15b03895fdbaec82fa0ea47b6c3fc57b788583f1 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Tue, 1 Jan 2013 11:55:30 +0800 Subject: [PATCH] update to the latest libev --- Makefile.am | 5 +- Makefile.in | 145 ++++--- aclocal.m4 | 339 ++++++++--------- config.h.in | 6 + configure | 365 ++++++++++-------- configure.ac | 17 + depcomp | 2 +- encrypt.c | 260 +++++++++---- encrypt.h | 46 ++- install-sh | 2 +- local.c | 1023 +++++++++++++++++++++++++++++--------------------- local.h | 41 +- missing | 2 +- socks5.h | 85 ++--- 14 files changed, 1376 insertions(+), 962 deletions(-) mode change 100755 => 100644 socks5.h diff --git a/Makefile.am b/Makefile.am index 57a50de6..69ed0370 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,2 +1,3 @@ -bin_PROGRAMS = local -local_SOURCES = encrypt.c encrypt.h local.c local.h socks5.h +bin_PROGRAMS = ss +ss_SOURCES = encrypt.c encrypt.h local.c local.h socks5.h +AM_CFLAGS = -Wall -std=c99 diff --git a/Makefile.in b/Makefile.in index 560e4bb1..792f1867 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,9 +1,8 @@ -# Makefile.in generated by automake 1.11.3 from Makefile.am. +# Makefile.in generated by automake 1.12.5 from Makefile.am. # @configure_input@ -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software -# Foundation, Inc. +# Copyright (C) 1994-2012 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. @@ -16,6 +15,23 @@ @SET_MAKE@ VPATH = @srcdir@ +am__make_dryrun = \ + { \ + am__dry=no; \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ + | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ + *) \ + for am__flg in $$MAKEFLAGS; do \ + case $$am__flg in \ + *=*|--*) ;; \ + *n*) am__dry=yes; break;; \ + esac; \ + done;; \ + esac; \ + test $$am__dry = yes; \ + } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -32,7 +48,7 @@ POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : -bin_PROGRAMS = local$(EXEEXT) +bin_PROGRAMS = ss$(EXEEXT) subdir = . DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in $(srcdir)/config.h.in \ @@ -49,9 +65,9 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) -am_local_OBJECTS = encrypt.$(OBJEXT) local.$(OBJEXT) -local_OBJECTS = $(am_local_OBJECTS) -local_LDADD = $(LDADD) +am_ss_OBJECTS = encrypt.$(OBJEXT) local.$(OBJEXT) +ss_OBJECTS = $(am_ss_OBJECTS) +ss_LDADD = $(LDADD) DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -60,10 +76,17 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = $(local_SOURCES) -DIST_SOURCES = $(local_SOURCES) +SOURCES = $(ss_SOURCES) +DIST_SOURCES = $(ss_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac ETAGS = etags CTAGS = ctags +CSCOPE = cscope +AM_RECURSIVE_TARGETS = cscope DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) @@ -73,8 +96,10 @@ am__remove_distdir = \ && rm -rf "$(distdir)" \ || { sleep 5 && rm -rf "$(distdir)"; }; \ else :; fi +am__post_remove_distdir = $(am__remove_distdir) DIST_ARCHIVES = $(distdir).tar.gz GZIP_ENV = --best +DIST_TARGETS = dist-gzip distuninstallcheck_listfiles = find . -type f -print am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' @@ -165,7 +190,8 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -local_SOURCES = encrypt.c encrypt.h local.c local.h socks5.h +ss_SOURCES = encrypt.c encrypt.h local.c local.h socks5.h +AM_CFLAGS = -Wall -std=c99 all: config.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -222,8 +248,11 @@ distclean-hdr: -rm -f config.h stamp-h1 install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) - test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ + fi; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p; \ @@ -257,9 +286,9 @@ uninstall-binPROGRAMS: clean-binPROGRAMS: -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) -local$(EXEEXT): $(local_OBJECTS) $(local_DEPENDENCIES) $(EXTRA_local_DEPENDENCIES) - @rm -f local$(EXEEXT) - $(LINK) $(local_OBJECTS) $(local_LDADD) $(LIBS) +ss$(EXEEXT): $(ss_OBJECTS) $(ss_DEPENDENCIES) $(EXTRA_ss_DEPENDENCIES) + @rm -f ss$(EXEEXT) + $(LINK) $(ss_OBJECTS) $(ss_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -333,8 +362,32 @@ GTAGS: && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" +cscope: cscope.files + test ! -s cscope.files \ + || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS) + +clean-cscope: + -rm -f cscope.files + +cscope.files: clean-cscope cscopelist + +cscopelist: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + -rm -f cscope.out cscope.in.out cscope.po.out cscope.files distdir: $(DISTFILES) $(am__remove_distdir) @@ -377,40 +430,36 @@ distdir: $(DISTFILES) || chmod -R a+r "$(distdir)" dist-gzip: distdir tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz - $(am__remove_distdir) + $(am__post_remove_distdir) dist-bzip2: distdir tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2 - $(am__remove_distdir) + $(am__post_remove_distdir) dist-lzip: distdir tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz - $(am__remove_distdir) - -dist-lzma: distdir - tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma - $(am__remove_distdir) + $(am__post_remove_distdir) dist-xz: distdir tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz - $(am__remove_distdir) + $(am__post_remove_distdir) dist-tarZ: distdir tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z - $(am__remove_distdir) + $(am__post_remove_distdir) dist-shar: distdir shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz - $(am__remove_distdir) + $(am__post_remove_distdir) dist-zip: distdir -rm -f $(distdir).zip zip -rq $(distdir).zip $(distdir) - $(am__remove_distdir) + $(am__post_remove_distdir) -dist dist-all: distdir - tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz - $(am__remove_distdir) +dist dist-all: + $(MAKE) $(AM_MAKEFLAGS) $(DIST_TARGETS) am__post_remove_distdir='@:' + $(am__post_remove_distdir) # This target untars the dist file and tries a VPATH configuration. Then # it guarantees that the distribution is self-contained by making another @@ -421,8 +470,6 @@ distcheck: dist GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ - *.tar.lzma*) \ - lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\ *.tar.lz*) \ lzip -dc $(distdir).tar.lz | $(am__untar) ;;\ *.tar.xz*) \ @@ -434,9 +481,9 @@ distcheck: dist *.zip*) \ unzip $(distdir).zip ;;\ esac - chmod -R a-w $(distdir); chmod a+w $(distdir) - mkdir $(distdir)/_build - mkdir $(distdir)/_inst + chmod -R a-w $(distdir) + chmod u+w $(distdir) + mkdir $(distdir)/_build $(distdir)/_inst chmod a-w $(distdir) test -d $(distdir)/_build || exit 0; \ dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ @@ -468,7 +515,7 @@ distcheck: dist && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ && cd "$$am__cwd" \ || exit 1 - $(am__remove_distdir) + $(am__post_remove_distdir) @(echo "$(distdir) archives ready for distribution: "; \ list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' @@ -610,20 +657,20 @@ uninstall-am: uninstall-binPROGRAMS .MAKE: all install-am install-strip .PHONY: CTAGS GTAGS all all-am am--refresh check check-am clean \ - clean-binPROGRAMS clean-generic ctags dist dist-all dist-bzip2 \ - dist-gzip dist-lzip dist-lzma dist-shar dist-tarZ dist-xz \ - dist-zip distcheck distclean distclean-compile \ - distclean-generic distclean-hdr distclean-tags distcleancheck \ - distdir distuninstallcheck dvi dvi-am html html-am info \ - info-am install install-am install-binPROGRAMS install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-pdf install-pdf-am \ - install-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ - uninstall-am uninstall-binPROGRAMS + clean-binPROGRAMS clean-cscope clean-generic cscope cscopelist \ + ctags dist dist-all dist-bzip2 dist-gzip dist-lzip dist-shar \ + dist-tarZ dist-xz dist-zip distcheck distclean \ + distclean-compile distclean-generic distclean-hdr \ + distclean-tags distcleancheck distdir distuninstallcheck dvi \ + dvi-am html html-am info info-am install install-am \ + install-binPROGRAMS install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-binPROGRAMS # Tell versions [3.59,3.63) of GNU make to not export all variables. diff --git a/aclocal.m4 b/aclocal.m4 index da06da5f..5e9cd55d 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,8 +1,7 @@ -# generated automatically by aclocal 1.11.3 -*- Autoconf -*- +# generated automatically by aclocal 1.12.5 -*- Autoconf -*- + +# Copyright (C) 1996-2012 Free Software Foundation, Inc. -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, -# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, -# Inc. # This file 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. @@ -14,31 +13,28 @@ m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl -m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.68],, -[m4_warning([this file was generated for autoconf 2.68. +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],, +[m4_warning([this file was generated for autoconf 2.69. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. -To do so, use the procedure documented by the package, typically `autoreconf'.])]) +To do so, use the procedure documented by the package, typically 'autoreconf'.])]) -# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2011 Free Software -# Foundation, Inc. +# Copyright (C) 2002-2012 Free Software Foundation, Inc. # # This file 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. -# serial 1 - # AM_AUTOMAKE_VERSION(VERSION) # ---------------------------- # Automake X.Y traces this macro to ensure aclocal.m4 has been # generated from the m4 files accompanying Automake X.Y. # (This private macro should not be called outside this file.) AC_DEFUN([AM_AUTOMAKE_VERSION], -[am__api_version='1.11' +[am__api_version='1.12' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.11.3], [], +m4_if([$1], [1.12.5], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -54,24 +50,22 @@ m4_define([_AM_AUTOCONF_VERSION], []) # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.11.3])dnl +[AM_AUTOMAKE_VERSION([1.12.5])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # AM_AUX_DIR_EXPAND -*- Autoconf -*- -# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc. +# Copyright (C) 2001-2012 Free Software Foundation, Inc. # # This file 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. -# serial 1 - # For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets -# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to -# `$srcdir', `$srcdir/..', or `$srcdir/../..'. +# $ac_aux_dir to '$srcdir/foo'. In other projects, it is set to +# '$srcdir', '$srcdir/..', or '$srcdir/../..'. # # Of course, Automake must honor this variable whenever it calls a # tool from the auxiliary directory. The problem is that $srcdir (and @@ -90,7 +84,7 @@ _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # # The reason of the latter failure is that $top_srcdir and $ac_aux_dir # are both prefixed by $srcdir. In an in-source build this is usually -# harmless because $srcdir is `.', but things will broke when you +# harmless because $srcdir is '.', but things will broke when you # start a VPATH build or use an absolute $srcdir. # # So we could use something similar to $top_srcdir/$ac_aux_dir/missing, @@ -116,22 +110,19 @@ am_aux_dir=`cd $ac_aux_dir && pwd` # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008 -# Free Software Foundation, Inc. +# Copyright (C) 1997-2012 Free Software Foundation, Inc. # # This file 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. -# serial 9 - # AM_CONDITIONAL(NAME, SHELL-CONDITION) # ------------------------------------- # Define a conditional. AC_DEFUN([AM_CONDITIONAL], -[AC_PREREQ(2.52)dnl - ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], - [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl +[AC_PREREQ([2.52])dnl + m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], + [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl AC_SUBST([$1_TRUE])dnl AC_SUBST([$1_FALSE])dnl _AM_SUBST_NOTMAKE([$1_TRUE])dnl @@ -150,16 +141,14 @@ AC_CONFIG_COMMANDS_PRE( Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, -# 2010, 2011 Free Software Foundation, Inc. +# Copyright (C) 1999-2012 Free Software Foundation, Inc. # # This file 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. -# serial 12 -# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be +# There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be # written in clear, in which case automake, when reading aclocal.m4, # will think it sees a *use*, and therefore will trigger all it's # C support machinery. Also note that it means that autoscan, seeing @@ -169,7 +158,7 @@ fi])]) # _AM_DEPENDENCIES(NAME) # ---------------------- # See how the compiler implements dependency checking. -# NAME is "CC", "CXX", "GCJ", or "OBJC". +# NAME is "CC", "CXX", "OBJC", "OBJCXX", "UPC", or "GJC". # We try a few techniques and use that to set a single cache variable. # # We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was @@ -182,12 +171,13 @@ AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl AC_REQUIRE([AM_MAKE_INCLUDE])dnl AC_REQUIRE([AM_DEP_TRACK])dnl -ifelse([$1], CC, [depcc="$CC" am_compiler_list=], - [$1], CXX, [depcc="$CXX" am_compiler_list=], - [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], - [$1], UPC, [depcc="$UPC" am_compiler_list=], - [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], - [depcc="$$1" am_compiler_list=]) +m4_if([$1], [CC], [depcc="$CC" am_compiler_list=], + [$1], [CXX], [depcc="$CXX" am_compiler_list=], + [$1], [OBJC], [depcc="$OBJC" am_compiler_list='gcc3 gcc'], + [$1], [OBJCXX], [depcc="$OBJCXX" am_compiler_list='gcc3 gcc'], + [$1], [UPC], [depcc="$UPC" am_compiler_list=], + [$1], [GCJ], [depcc="$GCJ" am_compiler_list='gcc3 gcc'], + [depcc="$$1" am_compiler_list=]) AC_CACHE_CHECK([dependency style of $depcc], [am_cv_$1_dependencies_compiler_type], @@ -195,8 +185,8 @@ AC_CACHE_CHECK([dependency style of $depcc], # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up - # making a dummy file named `D' -- because `-MD' means `put the output - # in D'. + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're @@ -236,16 +226,16 @@ AC_CACHE_CHECK([dependency style of $depcc], : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c - # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with - # Solaris 8's {/usr,}/bin/sh. - touch sub/conftst$i.h + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf - # We check with `-c' and `-o' for the sake of the "dashmstdout" + # We check with '-c' and '-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly - # handle `-M -o', and we need to detect this. Also, some Intel - # versions had trouble with output in subdirs + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in @@ -254,8 +244,8 @@ AC_CACHE_CHECK([dependency style of $depcc], test "$am__universal" = false || continue ;; nosideeffect) - # after this tag, mechanisms are not by side-effect, so they'll - # only be used when explicitly requested + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. if test "x$enable_dependency_tracking" = xyes; then continue else @@ -263,7 +253,7 @@ AC_CACHE_CHECK([dependency style of $depcc], fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) - # This compiler won't grok `-c -o', but also, the minuso test has + # This compiler won't grok '-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} @@ -311,7 +301,7 @@ AM_CONDITIONAL([am__fastdep$1], [ # AM_SET_DEPDIR # ------------- # Choose a directory name for dependency files. -# This macro is AC_REQUIREd in _AM_DEPENDENCIES +# This macro is AC_REQUIREd in _AM_DEPENDENCIES. AC_DEFUN([AM_SET_DEPDIR], [AC_REQUIRE([AM_SET_LEADING_DOT])dnl AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl @@ -321,9 +311,13 @@ AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl # AM_DEP_TRACK # ------------ AC_DEFUN([AM_DEP_TRACK], -[AC_ARG_ENABLE(dependency-tracking, -[ --disable-dependency-tracking speeds up one-time build - --enable-dependency-tracking do not reject slow dependency extractors]) +[AC_ARG_ENABLE([dependency-tracking], [dnl +AS_HELP_STRING( + [--enable-dependency-tracking], + [do not reject slow dependency extractors]) +AS_HELP_STRING( + [--disable-dependency-tracking], + [speeds up one-time build])]) if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\' @@ -338,14 +332,12 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008 -# Free Software Foundation, Inc. +# Copyright (C) 1999-2012 Free Software Foundation, Inc. # # This file 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. -#serial 5 # _AM_OUTPUT_DEPENDENCY_COMMANDS # ------------------------------ @@ -364,7 +356,7 @@ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], # Strip MF so we end up with the name of the file. mf=`echo "$mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile or not. - # We used to match only the files named `Makefile.in', but + # We used to match only the files named 'Makefile.in', but # some people rename them; so instead we look at the file content. # Grep'ing the first line is not enough: some people post-process # each Makefile.in and add a new line on top of each file to say so. @@ -376,21 +368,19 @@ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], continue fi # Extract the definition of DEPDIR, am__include, and am__quote - # from the Makefile without running `make'. + # from the Makefile without running 'make'. DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` test -z "$DEPDIR" && continue am__include=`sed -n 's/^am__include = //p' < "$mf"` test -z "am__include" && continue am__quote=`sed -n 's/^am__quote = //p' < "$mf"` - # When using ansi2knr, U may be empty or an underscore; expand it - U=`sed -n 's/^U = //p' < "$mf"` # Find all dependency output files, they are included files with # $(DEPDIR) in their names. We invoke sed twice because it is the # simplest approach to changing $(DEPDIR) to its actual value in the # expansion. for file in `sed -n " s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ - sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do # Make sure the directory exists. test -f "$dirpart/$file" && continue fdir=`AS_DIRNAME(["$file"])` @@ -408,7 +398,7 @@ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], # This macro should only be invoked once -- use via AC_REQUIRE. # # This code is only required when automatic dependency tracking -# is enabled. FIXME. This creates each `.P' file that we will +# is enabled. FIXME. This creates each '.P' file that we will # need in order to bootstrap the dependency handling code. AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], [AC_CONFIG_COMMANDS([depfiles], @@ -418,15 +408,12 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, -# 2005, 2006, 2008, 2009 Free Software Foundation, Inc. +# Copyright (C) 1996-2012 Free Software Foundation, Inc. # # This file 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. -# serial 16 - # This macro actually does too much. Some checks are only needed if # your package does certain things. But this isn't really a big deal. @@ -471,31 +458,41 @@ AC_SUBST([CYGPATH_W]) # Define the identity of the package. dnl Distinguish between old-style and new-style calls. m4_ifval([$2], -[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl +[AC_DIAGNOSE([obsolete], +[$0: two- and three-arguments forms are deprecated. For more info, see: +http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_INIT_AUTOMAKE-invocation]) +m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl AC_SUBST([PACKAGE], [$1])dnl AC_SUBST([VERSION], [$2])], [_AM_SET_OPTIONS([$1])dnl dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. -m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,, +m4_if( + m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]), + [ok:ok],, [m4_fatal([AC_INIT should be called with package and version arguments])])dnl AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl _AM_IF_OPTION([no-define],, -[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) - AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl +[AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package]) + AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])])dnl # Some tools Automake needs. AC_REQUIRE([AM_SANITY_CHECK])dnl AC_REQUIRE([AC_ARG_PROGRAM])dnl -AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}) -AM_MISSING_PROG(AUTOCONF, autoconf) -AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) -AM_MISSING_PROG(AUTOHEADER, autoheader) -AM_MISSING_PROG(MAKEINFO, makeinfo) +AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}]) +AM_MISSING_PROG([AUTOCONF], [autoconf]) +AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}]) +AM_MISSING_PROG([AUTOHEADER], [autoheader]) +AM_MISSING_PROG([MAKEINFO], [makeinfo]) AC_REQUIRE([AM_PROG_INSTALL_SH])dnl AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl -AC_REQUIRE([AM_PROG_MKDIR_P])dnl +AC_REQUIRE([AC_PROG_MKDIR_P])dnl +# For better backward compatibility. To be removed once Automake 1.9.x +# dies out for good. For more background, see: +# +# +AC_SUBST([mkdir_p], ['$(MKDIR_P)']) # We need awk for the "check" target. The system "awk" is bad on # some platforms. AC_REQUIRE([AC_PROG_AWK])dnl @@ -506,28 +503,35 @@ _AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], [_AM_PROG_TAR([v7])])]) _AM_IF_OPTION([no-dependencies],, [AC_PROVIDE_IFELSE([AC_PROG_CC], - [_AM_DEPENDENCIES(CC)], - [define([AC_PROG_CC], - defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl + [_AM_DEPENDENCIES([CC])], + [m4_define([AC_PROG_CC], + m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl AC_PROVIDE_IFELSE([AC_PROG_CXX], - [_AM_DEPENDENCIES(CXX)], - [define([AC_PROG_CXX], - defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl + [_AM_DEPENDENCIES([CXX])], + [m4_define([AC_PROG_CXX], + m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl AC_PROVIDE_IFELSE([AC_PROG_OBJC], - [_AM_DEPENDENCIES(OBJC)], - [define([AC_PROG_OBJC], - defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl + [_AM_DEPENDENCIES([OBJC])], + [m4_define([AC_PROG_OBJC], + m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl +dnl Support for Objective C++ was only introduced in Autoconf 2.65, +dnl but we still cater to Autoconf 2.62. +m4_ifdef([AC_PROG_OBJCXX], +[AC_PROVIDE_IFELSE([AC_PROG_OBJCXX], + [_AM_DEPENDENCIES([OBJCXX])], + [m4_define([AC_PROG_OBJCXX], + m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])])dnl ]) _AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl -dnl The `parallel-tests' driver may need to know about EXEEXT, so add the -dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro +dnl The 'parallel-tests' driver may need to know about EXEEXT, so add the +dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro dnl is hooked onto _AC_COMPILER_EXEEXT early, see below. AC_CONFIG_COMMANDS_PRE(dnl [m4_provide_if([_AM_COMPILER_EXEEXT], [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl ]) -dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion. Do not +dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further dnl mangled by Autoconf and run in a shell conditional statement. m4_define([_AC_COMPILER_EXEEXT], @@ -555,15 +559,12 @@ for _am_header in $config_headers :; do done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001, 2003, 2005, 2008, 2011 Free Software Foundation, -# Inc. +# Copyright (C) 2001-2012 Free Software Foundation, Inc. # # This file 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. -# serial 1 - # AM_PROG_INSTALL_SH # ------------------ # Define $install_sh. @@ -577,16 +578,14 @@ if test x"${install_sh}" != xset; then install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi -AC_SUBST(install_sh)]) +AC_SUBST([install_sh])]) -# Copyright (C) 2003, 2005 Free Software Foundation, Inc. +# Copyright (C) 2003-2012 Free Software Foundation, Inc. # # This file 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. -# serial 2 - # Check whether the underlying file-system supports filenames # with a leading dot. For instance MS-DOS doesn't. AC_DEFUN([AM_SET_LEADING_DOT], @@ -602,14 +601,12 @@ AC_SUBST([am__leading_dot])]) # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +# Copyright (C) 2001-2012 Free Software Foundation, Inc. # # This file 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. -# serial 4 - # AM_MAKE_INCLUDE() # ----------------- # Check to see how make treats includes. @@ -627,7 +624,7 @@ am__quote= _am_result=none # First try GNU make style include. echo "include confinc" > confmf -# Ignore all kinds of additional output from `make'. +# Ignore all kinds of additional output from 'make'. case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=include @@ -654,15 +651,12 @@ rm -f confinc confmf # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008 -# Free Software Foundation, Inc. +# Copyright (C) 1997-2012 Free Software Foundation, Inc. # # This file 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. -# serial 6 - # AM_MISSING_PROG(NAME, PROGRAM) # ------------------------------ AC_DEFUN([AM_MISSING_PROG], @@ -670,7 +664,6 @@ AC_DEFUN([AM_MISSING_PROG], $1=${$1-"${am_missing_run}$2"} AC_SUBST($1)]) - # AM_MISSING_HAS_RUN # ------------------ # Define MISSING if not defined so far and test if it supports --run. @@ -691,50 +684,18 @@ if eval "$MISSING --run true"; then am_missing_run="$MISSING --run " else am_missing_run= - AC_MSG_WARN([`missing' script is too old or missing]) + AC_MSG_WARN(['missing' script is too old or missing]) fi ]) -# Copyright (C) 2003, 2004, 2005, 2006, 2011 Free Software Foundation, -# Inc. -# -# This file 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. - -# serial 1 - -# AM_PROG_MKDIR_P -# --------------- -# Check for `mkdir -p'. -AC_DEFUN([AM_PROG_MKDIR_P], -[AC_PREREQ([2.60])dnl -AC_REQUIRE([AC_PROG_MKDIR_P])dnl -dnl Automake 1.8 to 1.9.6 used to define mkdir_p. We now use MKDIR_P, -dnl while keeping a definition of mkdir_p for backward compatibility. -dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile. -dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of -dnl Makefile.ins that do not define MKDIR_P, so we do our own -dnl adjustment using top_builddir (which is defined more often than -dnl MKDIR_P). -AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl -case $mkdir_p in - [[\\/$]]* | ?:[[\\/]]*) ;; - */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; -esac -]) - # Helper functions for option handling. -*- Autoconf -*- -# Copyright (C) 2001, 2002, 2003, 2005, 2008, 2010 Free Software -# Foundation, Inc. +# Copyright (C) 2001-2012 Free Software Foundation, Inc. # # This file 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. -# serial 5 - # _AM_MANGLE_OPTION(NAME) # ----------------------- AC_DEFUN([_AM_MANGLE_OPTION], @@ -744,7 +705,7 @@ AC_DEFUN([_AM_MANGLE_OPTION], # -------------------- # Set option NAME. Presently that only means defining a flag for this option. AC_DEFUN([_AM_SET_OPTION], -[m4_define(_AM_MANGLE_OPTION([$1]), 1)]) +[m4_define(_AM_MANGLE_OPTION([$1]), [1])]) # _AM_SET_OPTIONS(OPTIONS) # ------------------------ @@ -760,22 +721,16 @@ AC_DEFUN([_AM_IF_OPTION], # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008 -# Free Software Foundation, Inc. +# Copyright (C) 1996-2012 Free Software Foundation, Inc. # # This file 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. -# serial 5 - # AM_SANITY_CHECK # --------------- AC_DEFUN([AM_SANITY_CHECK], [AC_MSG_CHECKING([whether build environment is sane]) -# Just in case -sleep 1 -echo timestamp > conftest.file # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' @@ -786,32 +741,40 @@ case `pwd` in esac case $srcdir in *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) - AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);; + AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);; esac -# Do `set' in a subshell so we don't clobber the current shell's +# Do 'set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( - set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` - if test "$[*]" = "X"; then - # -L didn't work. - set X `ls -t "$srcdir/configure" conftest.file` - fi - rm -f conftest.file - if test "$[*]" != "X $srcdir/configure conftest.file" \ - && test "$[*]" != "X conftest.file $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken -alias in your environment]) - fi + am_has_slept=no + for am_try in 1 2; do + echo "timestamp, slept: $am_has_slept" > conftest.file + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$[*]" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + if test "$[*]" != "X $srcdir/configure conftest.file" \ + && test "$[*]" != "X conftest.file $srcdir/configure"; then + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken + alias in your environment]) + fi + if test "$[2]" = conftest.file || test $am_try -eq 2; then + break + fi + # Just in case. + sleep 1 + am_has_slept=yes + done test "$[2]" = conftest.file ) then @@ -821,46 +784,58 @@ else AC_MSG_ERROR([newly created file is older than distributed files! Check your system clock]) fi -AC_MSG_RESULT(yes)]) +AC_MSG_RESULT([yes]) +# If we didn't sleep, we still need to ensure time stamps of config.status and +# generated files are strictly newer. +am_sleep_pid= +if grep 'slept: no' conftest.file >/dev/null 2>&1; then + ( sleep 1 ) & + am_sleep_pid=$! +fi +AC_CONFIG_COMMANDS_PRE( + [AC_MSG_CHECKING([that generated files are newer than configure]) + if test -n "$am_sleep_pid"; then + # Hide warnings about reused PIDs. + wait $am_sleep_pid 2>/dev/null + fi + AC_MSG_RESULT([done])]) +rm -f conftest.file +]) -# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc. +# Copyright (C) 2001-2012 Free Software Foundation, Inc. # # This file 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. -# serial 1 - # AM_PROG_INSTALL_STRIP # --------------------- -# One issue with vendor `install' (even GNU) is that you can't +# One issue with vendor 'install' (even GNU) is that you can't # specify the program used to strip binaries. This is especially # annoying in cross-compiling environments, where the build's strip # is unlikely to handle the host's binaries. # Fortunately install-sh will honor a STRIPPROG variable, so we -# always use install-sh in `make install-strip', and initialize +# always use install-sh in "make install-strip", and initialize # STRIPPROG with the value of the STRIP variable (set by the user). AC_DEFUN([AM_PROG_INSTALL_STRIP], [AC_REQUIRE([AM_PROG_INSTALL_SH])dnl -# Installed binaries are usually stripped using `strip' when the user -# run `make install-strip'. However `strip' might not be the right +# Installed binaries are usually stripped using 'strip' when the user +# run "make install-strip". However 'strip' might not be the right # tool to use in cross-compilation environments, therefore Automake -# will honor the `STRIP' environment variable to overrule this program. -dnl Don't test for $cross_compiling = yes, because it might be `maybe'. +# will honor the 'STRIP' environment variable to overrule this program. +dnl Don't test for $cross_compiling = yes, because it might be 'maybe'. if test "$cross_compiling" != no; then AC_CHECK_TOOL([STRIP], [strip], :) fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006, 2008, 2010 Free Software Foundation, Inc. +# Copyright (C) 2006-2012 Free Software Foundation, Inc. # # This file 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. -# serial 3 - # _AM_SUBST_NOTMAKE(VARIABLE) # --------------------------- # Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. @@ -874,18 +849,16 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004, 2005, 2012 Free Software Foundation, Inc. +# Copyright (C) 2004-2012 Free Software Foundation, Inc. # # This file 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. -# serial 2 - # _AM_PROG_TAR(FORMAT) # -------------------- # Check how to create a tarball in format FORMAT. -# FORMAT should be one of `v7', `ustar', or `pax'. +# FORMAT should be one of 'v7', 'ustar', or 'pax'. # # Substitute a variable $(am__tar) that is a command # writing to stdout a FORMAT-tarball containing the directory @@ -908,7 +881,7 @@ AC_MSG_CHECKING([how to create a $1 tar archive]) _am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' _am_tools=${am_cv_prog_tar_$1-$_am_tools} # Do not fold the above two line into one, because Tru64 sh and -# Solaris sh will not grok spaces in the rhs of `-'. +# Solaris sh will not grok spaces in the rhs of '-'. for _am_tool in $_am_tools do case $_am_tool in diff --git a/config.h.in b/config.h.in index 015ed267..16b1e163 100644 --- a/config.h.in +++ b/config.h.in @@ -1,5 +1,8 @@ /* config.h.in. Generated from configure.ac by autoheader. */ +/* Define to 1 if system is big endian */ +#undef BIGENDIAN + /* Define to 1 if you have the header file. */ #undef HAVE_ARPA_INET_H @@ -58,6 +61,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H +/* Define to 1 if system is little endian */ +#undef LITTLEENDIAN + /* Name of package */ #undef PACKAGE diff --git a/configure b/configure index 16daa96f..31c8352e 100755 --- a/configure +++ b/configure @@ -1,13 +1,11 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.68 for libev-hello 0.1. +# Generated by GNU Autoconf 2.69 for libev-hello 0.1. # # Report bugs to . # # -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, -# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software -# Foundation, Inc. +# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation @@ -136,6 +134,31 @@ export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH +# Use a proper internal environment variable to ensure we don't fall + # into an infinite loop, continuously re-executing ourselves. + if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then + _as_can_reexec=no; export _as_can_reexec; + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +as_fn_exit 255 + fi + # We don't want this to propagate to other subprocesses. + { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh @@ -169,7 +192,8 @@ if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi -test x\$exitcode = x0 || exit 1" +test x\$exitcode = x0 || exit 1 +test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && @@ -214,21 +238,25 @@ IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : - # We cannot yet assume a decent shell, so we have to provide a - # neutralization value for shells without unset; and this also - # works around shells that cannot unset nonexistent variables. - # Preserve -v and -x to the replacement shell. - BASH_ENV=/dev/null - ENV=/dev/null - (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV - export CONFIG_SHELL - case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; - esac - exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} + export CONFIG_SHELL + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +exit 255 fi if test x$as_have_required = xno; then : @@ -331,6 +359,14 @@ $as_echo X"$as_dir" | } # as_fn_mkdir_p + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take @@ -452,6 +488,10 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + # If we had to re-execute with $CONFIG_SHELL, we're ensured to have + # already done that, so ensure we don't try to do so again and fall + # in an infinite loop. This has already happened in practice. + _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). @@ -486,16 +526,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -p'. + # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -p' + as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -p' + as_ln_s='cp -pR' fi else - as_ln_s='cp -p' + as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -507,28 +547,8 @@ else as_mkdir_p=false fi -if test -x / >/dev/null 2>&1; then - as_test_x='test -x' -else - if ls -dL / >/dev/null 2>&1; then - as_ls_L_option=L - else - as_ls_L_option= - fi - as_test_x=' - eval sh -c '\'' - if test -d "$1"; then - test -d "$1/."; - else - case $1 in #( - -*)set "./$1";; - esac; - case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( - ???[sx]*):;;*)false;;esac;fi - '\'' sh - ' -fi -as_executable_p=$as_test_x +as_test_x='test -x' +as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -1156,8 +1176,6 @@ target=$target_alias if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe - $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. - If a cross compiler is detected then cross compile mode will be used" >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi @@ -1317,8 +1335,10 @@ Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --disable-dependency-tracking speeds up one-time build - --enable-dependency-tracking do not reject slow dependency extractors + --enable-dependency-tracking + do not reject slow dependency extractors + --disable-dependency-tracking + speeds up one-time build Some influential environment variables: CC C compiler command @@ -1397,9 +1417,9 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF libev-hello configure 0.1 -generated by GNU Autoconf 2.68 +generated by GNU Autoconf 2.69 -Copyright (C) 2010 Free Software Foundation, Inc. +Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1475,7 +1495,7 @@ $as_echo "$ac_try_echo"; } >&5 test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext + test -x conftest$ac_exeext }; then : ac_retval=0 else @@ -1820,7 +1840,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by libev-hello $as_me 0.1, which was -generated by GNU Autoconf 2.68. Invocation command line was +generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2171,7 +2191,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_config_headers="$ac_config_headers config.h" -am__api_version='1.11' +am__api_version='1.12' ac_aux_dir= for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do @@ -2239,7 +2259,7 @@ case $as_dir/ in #(( # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. @@ -2297,9 +2317,6 @@ test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 $as_echo_n "checking whether build environment is sane... " >&6; } -# Just in case -sleep 1 -echo timestamp > conftest.file # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' @@ -2310,32 +2327,40 @@ case `pwd` in esac case $srcdir in *[\\\"\#\$\&\'\`$am_lf\ \ ]*) - as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5;; + as_fn_error $? "unsafe srcdir value: '$srcdir'" "$LINENO" 5;; esac -# Do `set' in a subshell so we don't clobber the current shell's +# Do 'set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( - set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` - if test "$*" = "X"; then - # -L didn't work. - set X `ls -t "$srcdir/configure" conftest.file` - fi - rm -f conftest.file - if test "$*" != "X $srcdir/configure conftest.file" \ - && test "$*" != "X conftest.file $srcdir/configure"; then - - # If neither matched, then we have a broken ls. This can happen - # if, for instance, CONFIG_SHELL is bash and it inherits a - # broken ls alias from the environment. This has actually - # happened. Such a system could not be considered "sane". - as_fn_error $? "ls -t appears to fail. Make sure there is not a broken -alias in your environment" "$LINENO" 5 - fi + am_has_slept=no + for am_try in 1 2; do + echo "timestamp, slept: $am_has_slept" > conftest.file + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$*" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + if test "$*" != "X $srcdir/configure conftest.file" \ + && test "$*" != "X conftest.file $srcdir/configure"; then + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + as_fn_error $? "ls -t appears to fail. Make sure there is not a broken + alias in your environment" "$LINENO" 5 + fi + if test "$2" = conftest.file || test $am_try -eq 2; then + break + fi + # Just in case. + sleep 1 + am_has_slept=yes + done test "$2" = conftest.file ) then @@ -2347,6 +2372,16 @@ Check your system clock" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } +# If we didn't sleep, we still need to ensure time stamps of config.status and +# generated files are strictly newer. +am_sleep_pid= +if grep 'slept: no' conftest.file >/dev/null 2>&1; then + ( sleep 1 ) & + am_sleep_pid=$! +fi + +rm -f conftest.file + test "$program_prefix" != NONE && program_transform_name="s&^&$program_prefix&;$program_transform_name" # Use a double $ so make ignores it. @@ -2373,8 +2408,8 @@ if eval "$MISSING --run true"; then am_missing_run="$MISSING --run " else am_missing_run= - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`missing' script is too old or missing" >&5 -$as_echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 +$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} fi if test x"${install_sh}" != xset; then @@ -2386,10 +2421,10 @@ if test x"${install_sh}" != xset; then esac fi -# Installed binaries are usually stripped using `strip' when the user -# run `make install-strip'. However `strip' might not be the right +# Installed binaries are usually stripped using 'strip' when the user +# run "make install-strip". However 'strip' might not be the right # tool to use in cross-compilation environments, therefore Automake -# will honor the `STRIP' environment variable to overrule this program. +# will honor the 'STRIP' environment variable to overrule this program. if test "$cross_compiling" != no; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. @@ -2408,7 +2443,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2448,7 +2483,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_STRIP="strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2499,7 +2534,7 @@ do test -z "$as_dir" && as_dir=. for ac_prog in mkdir gmkdir; do for ac_exec_ext in '' $ac_executable_extensions; do - { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue + as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( 'mkdir (GNU coreutils) '* | \ 'mkdir (coreutils) '* | \ @@ -2528,12 +2563,6 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 $as_echo "$MKDIR_P" >&6; } -mkdir_p="$MKDIR_P" -case $mkdir_p in - [\\/$]* | ?:[\\/]*) ;; - */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; -esac - for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. @@ -2552,7 +2581,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_AWK="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2666,6 +2695,12 @@ AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} +# For better backward compatibility. To be removed once Automake 1.9.x +# dies out for good. For more background, see: +# +# +mkdir_p='$(MKDIR_P)' + # We need awk for the "check" target. The system "awk" is bad on # some platforms. # Always define AMTAR for backward compatibility. Yes, it's still used @@ -2702,7 +2737,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2742,7 +2777,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2795,7 +2830,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2836,7 +2871,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue @@ -2894,7 +2929,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2938,7 +2973,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3384,8 +3419,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include -#include -#include +struct stat; /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); @@ -3488,7 +3522,7 @@ am__quote= _am_result=none # First try GNU make style include. echo "include confinc" > confmf -# Ignore all kinds of additional output from `make'. +# Ignore all kinds of additional output from 'make'. case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=include @@ -3544,8 +3578,8 @@ else # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up - # making a dummy file named `D' -- because `-MD' means `put the output - # in D'. + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're @@ -3580,16 +3614,16 @@ else : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c - # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with - # Solaris 8's {/usr,}/bin/sh. - touch sub/conftst$i.h + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf - # We check with `-c' and `-o' for the sake of the "dashmstdout" + # We check with '-c' and '-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly - # handle `-M -o', and we need to detect this. Also, some Intel - # versions had trouble with output in subdirs + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in @@ -3598,8 +3632,8 @@ else test "$am__universal" = false || continue ;; nosideeffect) - # after this tag, mechanisms are not by side-effect, so they'll - # only be used when explicitly requested + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. if test "x$enable_dependency_tracking" = xyes; then continue else @@ -3607,7 +3641,7 @@ else fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) - # This compiler won't grok `-c -o', but also, the minuso test has + # This compiler won't grok '-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} @@ -3936,7 +3970,7 @@ do for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" - { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue + as_fn_executable_p "$ac_path_GREP" || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in @@ -4002,7 +4036,7 @@ do for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" - { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue + as_fn_executable_p "$ac_path_EGREP" || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in @@ -4193,6 +4227,45 @@ fi done +echo -n "checking for little or big endian... " +if test "$cross_compiling" = yes; then : + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run test program while cross compiling +See \`config.log' for more details" "$LINENO" 5; } +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +int main() +{ + uint16_t s = 1; + uint16_t* ptr = &s; + uint8_t n = *((uint8_t*)ptr); + return n; +} + + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +$as_echo "#define BIGENDIAN 1" >>confdefs.h + + echo "big" + +else + +$as_echo "#define LITTLEENDIAN 1" >>confdefs.h + + echo "little" + +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + # Checks for typedefs, structures, and compiler characteristics. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 $as_echo_n "checking for inline... " >&6; } @@ -4440,6 +4513,14 @@ LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 +$as_echo_n "checking that generated files are newer than configure... " >&6; } + if test -n "$am_sleep_pid"; then + # Hide warnings about reused PIDs. + wait $am_sleep_pid 2>/dev/null + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5 +$as_echo "done" >&6; } if test -n "$EXEEXT"; then am__EXEEXT_TRUE= am__EXEEXT_FALSE='#' @@ -4754,16 +4835,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -p'. + # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -p' + as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -p' + as_ln_s='cp -pR' fi else - as_ln_s='cp -p' + as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -4823,28 +4904,16 @@ else as_mkdir_p=false fi -if test -x / >/dev/null 2>&1; then - as_test_x='test -x' -else - if ls -dL / >/dev/null 2>&1; then - as_ls_L_option=L - else - as_ls_L_option= - fi - as_test_x=' - eval sh -c '\'' - if test -d "$1"; then - test -d "$1/."; - else - case $1 in #( - -*)set "./$1";; - esac; - case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( - ???[sx]*):;;*)false;;esac;fi - '\'' sh - ' -fi -as_executable_p=$as_test_x + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p +as_test_x='test -x' +as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -4866,7 +4935,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # values after options handling. ac_log=" This file was extended by libev-hello $as_me 0.1, which was -generated by GNU Autoconf 2.68. Invocation command line was +generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -4932,10 +5001,10 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ libev-hello config.status 0.1 -configured by $0, generated by GNU Autoconf 2.68, +configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" -Copyright (C) 2010 Free Software Foundation, Inc. +Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -5026,7 +5095,7 @@ fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then - set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' @@ -5672,7 +5741,7 @@ $as_echo "$as_me: executing $ac_file commands" >&6;} # Strip MF so we end up with the name of the file. mf=`echo "$mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile or not. - # We used to match only the files named `Makefile.in', but + # We used to match only the files named 'Makefile.in', but # some people rename them; so instead we look at the file content. # Grep'ing the first line is not enough: some people post-process # each Makefile.in and add a new line on top of each file to say so. @@ -5706,21 +5775,19 @@ $as_echo X"$mf" | continue fi # Extract the definition of DEPDIR, am__include, and am__quote - # from the Makefile without running `make'. + # from the Makefile without running 'make'. DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` test -z "$DEPDIR" && continue am__include=`sed -n 's/^am__include = //p' < "$mf"` test -z "am__include" && continue am__quote=`sed -n 's/^am__quote = //p' < "$mf"` - # When using ansi2knr, U may be empty or an underscore; expand it - U=`sed -n 's/^U = //p' < "$mf"` # Find all dependency output files, they are included files with # $(DEPDIR) in their names. We invoke sed twice because it is the # simplest approach to changing $(DEPDIR) to its actual value in the # expansion. for file in `sed -n " s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ - sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do # Make sure the directory exists. test -f "$dirpart/$file" && continue fdir=`$as_dirname -- "$file" || diff --git a/configure.ac b/configure.ac index 04864eb7..05c46e21 100644 --- a/configure.ac +++ b/configure.ac @@ -18,6 +18,23 @@ AC_SEARCH_LIBS([ev_io_start], [ev], [ ], AC_MSG_ERROR([libev not found.])) # Checks for header files. AC_CHECK_HEADERS([arpa/inet.h fcntl.h langinfo.h locale.h netdb.h netinet/in.h stdlib.h string.h strings.h sys/socket.h unistd.h]) +[echo -n "checking for little or big endian... " ] +AC_TRY_RUN([ +#include +int main() +{ + uint16_t s = 1; + uint16_t* ptr = &s; + uint8_t n = *((uint8_t*)ptr); + return n; +} +] +, AC_DEFINE([BIGENDIAN], [1], [Define to 1 if system is big endian]) + [echo "big"] +, AC_DEFINE([LITTLEENDIAN], [1], [Define to 1 if system is little endian]) + [echo "little"] +) + # Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE AC_TYPE_SSIZE_T diff --git a/depcomp b/depcomp index b0ad20c0..aec44f0e 120000 --- a/depcomp +++ b/depcomp @@ -1 +1 @@ -/usr/share/automake-1.11/depcomp \ No newline at end of file +/usr/local/Cellar/automake/1.12.5/share/automake-1.12/depcomp \ No newline at end of file diff --git a/encrypt.c b/encrypt.c index e82b971f..f7d0c122 100755 --- a/encrypt.c +++ b/encrypt.c @@ -1,73 +1,187 @@ -#include "encrypt.h" -#include -#include - -void encrypt(char *buf, int len) { - char *end = buf + len; - while (buf < end) { - *buf = (char)encrypt_table[(unsigned char)*buf]; - buf++; - } -} - -void decrypt(char *buf, int len) { - char *end = buf + len; - while (buf < end) { - *buf = (char)decrypt_table[(unsigned char)*buf]; - buf++; - } -} - -int send_encrypt(int sock, char *buf, int len, int flags) { - char mybuf[4096]; - memcpy(mybuf, buf, len); - encrypt(mybuf, len); - return send(sock, mybuf, len, flags); -} - -int recv_decrypt(int sock, char *buf, int len, int flags) { - char mybuf[4096]; - int result = recv(sock, mybuf, len, flags); - memcpy(buf, mybuf, len); - decrypt(buf, len); - return result; -} - -inline int random_compare(unsigned char x, unsigned char y, unsigned int i, unsigned long long a) { - return (a % (x + i) - a % (y + i)); -} - -void get_table(const unsigned char* key) { - unsigned char *table = encrypt_table; - unsigned char *tmp_hash; - tmp_hash = MD5((const unsigned char*)key, strlen((const char*)key), NULL); - unsigned long long a; - a = *(unsigned long long *)tmp_hash; - a = htole64(a); - unsigned int i; - - for(i = 0; i < 256; ++i) { - table[i] = i; - } - for(i = 1; i < 1024; ++i) { - // use bubble sort in order to keep the array stable as in Python - int k,j; - unsigned char t; - for(k = 256 - 2; k >= 0; --k) - { - for(j = 0;j <= k; ++j) - { - if(random_compare(table[j], table[j + 1], i, a) > 0) - { - t=table[j]; - table[j]=table[j + 1]; - table[j + 1]=t; - } - } - } - } - for(i = 0; i < 256; ++i) { - // gen decrypt table from encrypt table - decrypt_table[encrypt_table[i]] = i; - } -} +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "encrypt.h" + +#ifdef BIGENDIAN +#include +#elif LITTLEENDIAN +#define htole64(x) (x) +#endif + +static int random_compare(const void *_x, const void *_y) { + uint32_t i = _i; + uint64_t a = _a; + uint8_t x = *((uint8_t *) _x); + uint8_t y = *((uint8_t*) _y); + return (a % (x + i) - a % (y + i)); +} + + +static void merge(uint8_t *left, int llength, uint8_t *right, int rlength) +{ + /* Temporary memory locations for the 2 segments of the array to merge. */ + uint8_t *ltmp = (uint8_t *) malloc(llength * sizeof(uint8_t)); + uint8_t *rtmp = (uint8_t *) malloc(rlength * sizeof(uint8_t)); + + /* + * Pointers to the elements being sorted in the temporary memory locations. + */ + uint8_t *ll = ltmp; + uint8_t *rr = rtmp; + + uint8_t *result = left; + + /* + * Copy the segment of the array to be merged into the temporary memory + * locations. + */ + memcpy(ltmp, left, llength * sizeof(uint8_t)); + memcpy(rtmp, right, rlength * sizeof(uint8_t)); + + while (llength > 0 && rlength > 0) { + if (random_compare(ll, rr) <= 0) { + /* + * Merge the first element from the left back into the main array + * if it is smaller or equal to the one on the right. + */ + *result = *ll; + ++ll; + --llength; + } else { + /* + * Merge the first element from the right back into the main array + * if it is smaller than the one on the left. + */ + *result = *rr; + ++rr; + --rlength; + } + ++result; + } + /* + * All the elements from either the left or the right temporary array + * segment have been merged back into the main array. Append the remaining + * elements from the other temporary array back into the main array. + */ + if (llength > 0) + while (llength > 0) { + /* Appending the rest of the left temporary array. */ + *result = *ll; + ++result; + ++ll; + --llength; + } + else + while (rlength > 0) { + /* Appending the rest of the right temporary array. */ + *result = *rr; + ++result; + ++rr; + --rlength; + } + + /* Release the memory used for the temporary arrays. */ + free(ltmp); + free(rtmp); +} + +static void merge_sort(uint8_t array[], int length) +{ + /* This is the middle index and also the length of the right array. */ + uint8_t middle; + + /* + * Pointers to the beginning of the left and right segment of the array + * to be merged. + */ + uint8_t *left, *right; + + /* Length of the left segment of the array to be merged. */ + int llength; + + if (length <= 1) + return; + + /* Let integer division truncate the value. */ + middle = length / 2; + + llength = length - middle; + + /* + * Set the pointers to the appropriate segments of the array to be merged. + */ + left = array; + right = array + llength; + + merge_sort(left, llength); + merge_sort(right, middle); + merge(left, llength, right, middle); +} + +void encrypt_ctx(char *buf, int len, EVP_CIPHER_CTX *ctx) { + if (ctx != NULL) { + int outlen; + unsigned char mybuf[BUF_SIZE]; + EVP_CipherUpdate(ctx, mybuf, &outlen, (unsigned char*)buf, len); + memcpy(buf, mybuf, len); + } else { + char *end = buf + len; + while (buf < end) { + *buf = (char)encrypt_table[(uint8_t)*buf]; + buf++; + } + } +} + +void decrypt_ctx(char *buf, int len, EVP_CIPHER_CTX *ctx) { + if (ctx != NULL) { + int outlen; + unsigned char mybuf[BUF_SIZE]; + EVP_CipherUpdate(ctx, mybuf, &outlen, (unsigned char*) buf, len); + memcpy(buf, mybuf, len); + } else { + char *end = buf + len; + while (buf < end) { + *buf = (char)decrypt_table[(uint8_t)*buf]; + buf++; + } + } +} + +void enc_ctx_init(EVP_CIPHER_CTX *ctx, const char *pass, int enc) { + unsigned char key[EVP_MAX_KEY_LENGTH]; + unsigned char iv[EVP_MAX_IV_LENGTH]; + int key_len = EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, (unsigned char*) pass, + strlen(pass), 1, key, iv); + EVP_CIPHER_CTX_init(ctx); + EVP_CipherInit_ex(ctx, EVP_rc4(), NULL, NULL, NULL, enc); + if (!EVP_CIPHER_CTX_set_key_length(ctx, key_len)) { + LOGE("Invalid key length: %d", key_len); + EVP_CIPHER_CTX_cleanup(ctx); + exit(EXIT_FAILURE); + } + EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, enc); +} + +void get_table(const char *pass) { + uint8_t *table = encrypt_table; + uint8_t *tmp_hash = MD5((unsigned char *) pass, strlen(pass), NULL); + _a = htole64(*(uint64_t *) tmp_hash); + uint32_t i; + + for(i = 0; i < 256; ++i) { + table[i] = i; + } + for(i = 1; i < 1024; ++i) { + _i = i; + merge_sort(table, 256); + } + for(i = 0; i < 256; ++i) { + // gen decrypt table from encrypt table + decrypt_table[encrypt_table[i]] = i; + } +} diff --git a/encrypt.h b/encrypt.h index 20ad3ede..4138af1f 100755 --- a/encrypt.h +++ b/encrypt.h @@ -1,15 +1,31 @@ -#pragma once - -#include -#include -#include -#include - -unsigned char encrypt_table[256]; -unsigned char decrypt_table[256]; -void get_table(const unsigned char* key); -void encrypt(char *buf, int len); -void decrypt(char *buf, int len); -int send_encrypt(int sock, char *buf, int len, int flags); -int recv_decrypt(int sock, char *buf, int len, int flags); - +#ifndef _ENCRYPT_H +#define _ENCRYPT_H + +#include +#include +#include +#include +#include +#include + +#define BUF_SIZE 4096 + +#define TABLE 0 +#define RC4 1 + +unsigned char encrypt_table[256]; +unsigned char decrypt_table[256]; + +void get_table(const char* key); +void encrypt_ctx(char *buf, int len, EVP_CIPHER_CTX *ctx); +void decrypt_ctx(char *buf, int len, EVP_CIPHER_CTX *ctx); +void enc_ctx_init(EVP_CIPHER_CTX *ctx, const char *pass, int enc); + +unsigned int _i; +unsigned long long _a; +int _method; + +#define LOGD(...) ((void)fprintf(stdout, __VA_ARGS__)) +#define LOGE(...) ((void)fprintf(stderr, __VA_ARGS__)) + +#endif // _ENCRYPT_H diff --git a/install-sh b/install-sh index 205f21c6..be8ebb45 120000 --- a/install-sh +++ b/install-sh @@ -1 +1 @@ -/usr/share/automake-1.11/install-sh \ No newline at end of file +/usr/local/Cellar/automake/1.12.5/share/automake-1.12/install-sh \ No newline at end of file diff --git a/local.c b/local.c index a547bcdd..2982394b 100644 --- a/local.c +++ b/local.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -21,544 +20,710 @@ #include "local.h" #include "socks5.h" -#include "encrypt.h" -#define SERVER "127.0.0.1" -#define REMOTE_PORT "8388" -#define PORT "1080" -#define KEY "barfoo!" +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#define REPLY "HTTP/1.1 200 OK\n\nhello" +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL MSG_HAVEMORE +#endif -#define min(a,b) \ - ({ typeof (a) _a = (a); \ - typeof (b) _b = (b); \ - _a < _b ? _a : _b; }) +#define min(a,b) (((a)<(b))?(a):(b)) -// every watcher type has its own typedef'd struct -// with the name ev_TYPE -ev_io stdin_watcher; - - -struct client_ctx { - ev_io io; - int fd; -}; +static char *_server; +static char *_remote_port; +static int _timeout; +static char *_key; int setnonblocking(int fd) { - int flags; - if (-1 ==(flags = fcntl(fd, F_GETFL, 0))) - flags = 0; - return fcntl(fd, F_SETFL, flags | O_NONBLOCK); + int flags; + if (-1 ==(flags = fcntl(fd, F_GETFL, 0))) + flags = 0; + return fcntl(fd, F_SETFL, flags | O_NONBLOCK); } -int create_and_bind(char *port) { - struct addrinfo hints; - struct addrinfo *result, *rp; - int s, listen_sock; +int create_and_bind(const char *port) { + struct addrinfo hints; + struct addrinfo *result, *rp; + int s, listen_sock; - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; /* Return IPv4 and IPv6 choices */ - hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */ + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; /* Return IPv4 and IPv6 choices */ + hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */ - s = getaddrinfo("0.0.0.0", port, &hints, &result); - if (s != 0) { - fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s)); - return -1; - } + s = getaddrinfo("0.0.0.0", port, &hints, &result); + if (s != 0) { + LOGD("getaddrinfo: %s", gai_strerror(s)); + return -1; + } - for (rp = result; rp != NULL; rp = rp->ai_next) { - listen_sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - int opt = 1; - setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); - if (listen_sock == -1) - continue; + for (rp = result; rp != NULL; rp = rp->ai_next) { + listen_sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if (listen_sock == -1) + continue; - s = bind(listen_sock, rp->ai_addr, rp->ai_addrlen); - if (s == 0) { - /* We managed to bind successfully! */ - break; - } else { - perror("bind"); - } + int opt = 1; + int err = setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + if (err) { + perror("setsocket"); + } - close(listen_sock); - } + s = bind(listen_sock, rp->ai_addr, rp->ai_addrlen); + if (s == 0) { + /* We managed to bind successfully! */ + break; + } else { + perror("bind"); + } - if (rp == NULL) { - fprintf(stderr, "Could not bind\n"); - return -1; - } + close(listen_sock); + } - freeaddrinfo(result); + if (rp == NULL) { + LOGE("Could not bind"); + return -1; + } - return listen_sock; + freeaddrinfo(result); + + return listen_sock; } static void server_recv_cb (EV_P_ ev_io *w, int revents) { - struct server_ctx *server_recv_ctx = (struct server_ctx *)w; - struct server *server = server_recv_ctx->server; - struct remote *remote = server->remote; + struct server_ctx *server_recv_ctx = (struct server_ctx *)w; + struct server *server = server_recv_ctx->server; + struct remote *remote = server->remote; if (remote == NULL) { close_and_free_server(EV_A_ server); return; } + while (1) { + char *buf = remote->buf; + int *buf_len = &remote->buf_len; + if (server->stage != 5) { + buf = server->buf; + buf_len = &server->buf_len; + } - char *buf = remote->buf; - int *buf_len = &remote->buf_len; - if (server->stage != 5) { - buf = server->buf; - buf_len = &server->buf_len; - } + ssize_t r = recv(server->fd, buf, BUF_SIZE, 0); - while (1) { - ssize_t r = recv(server->fd, buf, BUF_SIZE, 0); - - if (r == 0) { - // connection closed + if (r == 0) { + // connection closed *buf_len = 0; - close_and_free_server(EV_A_ server); - if (remote != NULL) { - ev_io_start(EV_A_ &remote->send_ctx->io); - } - return; - } else if(r < 0) { - if (errno == EAGAIN) { - // no data - // continue to wait for recv - break; - } else { + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } else if(r < 0) { + if (errno == EAGAIN) { + // no data + // continue to wait for recv + break; + } else { perror("server recv"); - close_and_free_server(EV_A_ server); - close_and_free_remote(EV_A_ remote); - return; - } - } + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } + } // local socks5 server - if (server->stage == 5) { - encrypt(remote->buf, r); - int w = send(remote->fd, remote->buf, r, 0); - if(w == -1) { - if (errno == EAGAIN) { - // no data, wait for send - ev_io_stop(EV_A_ &server_recv_ctx->io); - ev_io_start(EV_A_ &remote->send_ctx->io); - break; - } else { + if (server->stage == 5) { + encrypt_ctx(remote->buf, r, server->e_ctx); + int w = send(remote->fd, remote->buf, r, 0); + if(w == -1) { + if (errno == EAGAIN) { + // no data, wait for send + ev_io_stop(EV_A_ &server_recv_ctx->io); + ev_io_start(EV_A_ &remote->send_ctx->io); + break; + } else { perror("send"); - close_and_free_server(EV_A_ server); - close_and_free_remote(EV_A_ remote); - return; - } - } else if(w < r) { + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } + } else if(w < r) { char *pt = remote->buf; - char *et = pt + min(w, BUF_SIZE); - while (pt < et) { + char *et = pt + r; + while (pt + w < et) { *pt = *(pt + w); pt++; } - remote->buf_len = r - w; - ev_io_stop(EV_A_ &server_recv_ctx->io); - ev_io_start(EV_A_ &remote->send_ctx->io); - break; + remote->buf_len = r - w; + assert(remote->buf_len >= 0); + ev_io_stop(EV_A_ &server_recv_ctx->io); + ev_io_start(EV_A_ &remote->send_ctx->io); + break; } - } else if (server->stage == 0) { - struct method_select_response response; - response.ver = VERSION; - response.method = 0; - char *send_buf = (char *)&response; - send(server->fd, send_buf, sizeof(response), MSG_NOSIGNAL); - server->stage = 1; - return; - } else if (server->stage == 1) { - struct socks5_request *request = (struct socks5_request *)server->buf; + } else if (server->stage == 0) { + struct method_select_response response; + response.ver = SVERSION; + response.method = 0; + char *send_buf = (char *)&response; + send(server->fd, send_buf, sizeof(response), MSG_NOSIGNAL); + server->stage = 1; + return; + } else if (server->stage == 1) { + struct socks5_request *request = (struct socks5_request *)server->buf; - if (request->cmd != 1) { - fprintf(stderr, "unsupported cmd: %d\n", request->cmd); - struct socks5_response response; - response.ver = VERSION; - response.rep = CMD_NOT_SUPPORTED; - response.rsv = 0; - response.atyp = 1; - char *send_buf = (char *)&response; - send(server->fd, send_buf, 4, MSG_NOSIGNAL); - close_and_free_server(EV_A_ server); + if (request->cmd != 1) { + LOGE("unsupported cmd: %d\n", request->cmd); + struct socks5_response response; + response.ver = SVERSION; + response.rep = CMD_NOT_SUPPORTED; + response.rsv = 0; + response.atyp = 1; + char *send_buf = (char *)&response; + send(server->fd, send_buf, 4, MSG_NOSIGNAL); close_and_free_remote(EV_A_ remote); - return; - } + close_and_free_server(EV_A_ server); + return; + } char addr_to_send[256]; unsigned char addr_len = 0; addr_to_send[addr_len++] = request->atyp; - // get remote addr and port - if (request->atyp == 1) { + // get remote addr and port + if (request->atyp == 1) { - // IP V4 + // IP V4 size_t in_addr_len = sizeof(struct in_addr); memcpy(addr_to_send + addr_len, server->buf + 4, in_addr_len + 2); addr_len += in_addr_len + 2; - addr_to_send[addr_len] = 0; - } else if (request->atyp == 3) { + } else if (request->atyp == 3) { // Domain name - unsigned char name_len = *(unsigned char *)(server->buf + 4); + unsigned char name_len = *(unsigned char *)(server->buf + 4); addr_to_send[addr_len++] = name_len; - memcpy(addr_to_send + addr_len, server->buf + 4 + 1, name_len); + memcpy(addr_to_send + addr_len, server->buf + 4 + 1, name_len); addr_len += name_len; - // get port + // get port addr_to_send[addr_len++] = *(unsigned char *)(server->buf + 4 + 1 + name_len); addr_to_send[addr_len++] = *(unsigned char *)(server->buf + 4 + 1 + name_len + 1); - addr_to_send[addr_len] = 0; - } else { - fprintf(stderr, "unsupported addrtype: %d\n", request->atyp); - close_and_free_server(EV_A_ server); + } else { + LOGE("unsupported addrtype: %d\n", request->atyp); close_and_free_remote(EV_A_ remote); - return; - } + close_and_free_server(EV_A_ server); + return; + } - assert(addr_len < 256); + encrypt_ctx(addr_to_send, addr_len, server->e_ctx); + send(remote->fd, addr_to_send, addr_len, 0); - send_encrypt(remote->fd, addr_to_send, addr_len, 0); - - // Fake reply - struct socks5_response response; - response.ver = VERSION; - response.rep = 0; - response.rsv = 0; - response.atyp = 1; + // Fake reply + struct socks5_response response; + response.ver = SVERSION; + response.rep = 0; + response.rsv = 0; + response.atyp = 1; struct in_addr sin_addr; inet_aton("0.0.0.0", &sin_addr); - memcpy(server->buf, &response, 4); - memcpy(server->buf + 4, &sin_addr, sizeof(struct in_addr)); - *((unsigned short *)(server->buf + 4 + sizeof(struct in_addr))) = (unsigned short) htons(atoi(PORT)); + memcpy(server->buf, &response, 4); + memcpy(server->buf + 4, &sin_addr, sizeof(struct in_addr)); + *((unsigned short *)(server->buf + 4 + sizeof(struct in_addr))) + = (unsigned short) htons(atoi(_remote_port)); int reply_size = 4 + sizeof(struct in_addr) + sizeof(unsigned short); - int r = send(server->fd, server->buf, reply_size, MSG_NOSIGNAL); - if (r < reply_size) { - fprintf(stderr, "header not complete sent\n"); - close_and_free_remote(EV_A_ remote); - close_and_free_server(EV_A_ server); + int r = send(server->fd, server->buf, reply_size, MSG_NOSIGNAL); + if (r < reply_size) { + LOGE("header not complete sent\n"); + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); return; - } - - server->stage = 5; + } + server->stage = 5; } - } + } } static void server_send_cb (EV_P_ ev_io *w, int revents) { - struct server_ctx *server_send_ctx = (struct server_ctx *)w; - struct server *server = server_send_ctx->server; - struct remote *remote = server->remote; - if (server->buf_len == 0) { - // close and free - close_and_free_server(EV_A_ server); - close_and_free_remote(EV_A_ remote); - return; - } else { - // has data to send - ssize_t r = send(server->fd, server->buf, - server->buf_len, 0); - if (r < 0) { - if (errno != EAGAIN) { + struct server_ctx *server_send_ctx = (struct server_ctx *)w; + struct server *server = server_send_ctx->server; + struct remote *remote = server->remote; + if (server->buf_len == 0) { + // close and free + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } else { + // has data to send + ssize_t r = send(server->fd, server->buf, + server->buf_len, 0); + if (r < 0) { + if (errno != EAGAIN) { perror("send"); - close_and_free_server(EV_A_ server); - close_and_free_remote(EV_A_ remote); - return; - } - return; - } - if (r < server->buf_len) { - // printf("r=%d\n", r); - // printf("server->buf_len=%d\n", server->buf_len); - // partly sent, move memory, wait for the next time to send - char *pt = server->buf; - char *et = pt + min(r, BUF_SIZE); - while (pt < et) { - *pt = *(pt + r); + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } + return; + } + if (r < server->buf_len) { + // partly sent, move memory, wait for the next time to send + char *pt = server->buf; + char *et = pt + server->buf_len; + while (pt + r < et) { + *pt = *(pt + r); pt++; - } - server->buf_len -= r; - return; - } else { - // all sent out, wait for reading - ev_io_stop(EV_A_ &server_send_ctx->io); - if (remote != NULL) { - ev_io_start(EV_A_ &remote->recv_ctx->io); - } else { - close_and_free_server(EV_A_ server); - close_and_free_remote(EV_A_ remote); - return; - } - } - } + } + server->buf_len -= r; + assert(server->buf_len >= 0); + return; + } else { + // all sent out, wait for reading + ev_io_stop(EV_A_ &server_send_ctx->io); + if (remote != NULL) { + ev_io_start(EV_A_ &remote->recv_ctx->io); + } else { + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } + } + } } +static void remote_timeout_cb(EV_P_ ev_timer *watcher, int revents) { + struct remote_ctx *remote_ctx = (struct remote_ctx *) (((void*)watcher) + - sizeof(ev_io)); + struct remote *remote = remote_ctx->remote; + struct server *server = remote->server; + + LOGD("remote timeout"); + + ev_timer_stop(EV_A_ watcher); + + if (server == NULL) { + close_and_free_remote(EV_A_ remote); + return; + } + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); +} + static void remote_recv_cb (EV_P_ ev_io *w, int revents) { - struct remote_ctx *remote_recv_ctx = (struct remote_ctx *)w; - struct remote *remote = remote_recv_ctx->remote; - struct server *server = remote->server; - if (server == NULL) { - close_and_free_remote(EV_A_ remote); - return; - } - while (1) { - ssize_t r = recv(remote->fd, server->buf, BUF_SIZE, 0); - /*printf("after recv: r=%d\n", r);*/ + struct remote_ctx *remote_recv_ctx = (struct remote_ctx *)w; + struct remote *remote = remote_recv_ctx->remote; + struct server *server = remote->server; + if (server == NULL) { + close_and_free_remote(EV_A_ remote); + return; + } + while (1) { + ssize_t r = recv(remote->fd, server->buf, BUF_SIZE, 0); - if (r == 0) { - // connection closed - server->buf_len = 0; - close_and_free_remote(EV_A_ remote); - if (server != NULL) { - ev_io_start(EV_A_ &server->send_ctx->io); - } - return; - } else if(r < 0) { - if (errno == EAGAIN) { - // no data - // continue to wait for recv - break; - } else { + if (r == 0) { + // connection closed + server->buf_len = 0; + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } else if(r < 0) { + if (errno == EAGAIN) { + // no data + // continue to wait for recv + break; + } else { perror("remote recv"); - close_and_free_server(EV_A_ server); - close_and_free_remote(EV_A_ remote); - return; - } - } - decrypt(server->buf, r); - int w = send(server->fd, server->buf, r, MSG_NOSIGNAL); - // printf("after send: w=%d\n", w); - if(w == -1) { - if (errno == EAGAIN) { - // no data, wait for send - ev_io_stop(EV_A_ &remote_recv_ctx->io); - ev_io_start(EV_A_ &server->send_ctx->io); - break; - } else { + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } + } + decrypt_ctx(server->buf, r, server->d_ctx); + int w = send(server->fd, server->buf, r, MSG_NOSIGNAL); + if(w == -1) { + if (errno == EAGAIN) { + // no data, wait for send + ev_io_stop(EV_A_ &remote_recv_ctx->io); + ev_io_start(EV_A_ &server->send_ctx->io); + break; + } else { perror("send"); - close_and_free_server(EV_A_ server); - close_and_free_remote(EV_A_ remote); - return; - } - } else if(w < r) { - char *pt = server->buf; - char *et = pt + min(w, BUF_SIZE); - while (pt < et) { - *pt = *(pt + w); + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } + } else if(w < r) { + char *pt = server->buf; + char *et = pt + r; + while (pt + w < et) { + *pt = *(pt + w); pt++; - } - server->buf_len = r - w; - ev_io_stop(EV_A_ &remote_recv_ctx->io); - ev_io_start(EV_A_ &server->send_ctx->io); - break; - } - } + } + server->buf_len = r - w; + assert(server->buf_len >= 0); + ev_io_stop(EV_A_ &remote_recv_ctx->io); + ev_io_start(EV_A_ &server->send_ctx->io); + break; + } + } } static void remote_send_cb (EV_P_ ev_io *w, int revents) { - struct remote_ctx *remote_send_ctx = (struct remote_ctx *)w; - struct remote *remote = remote_send_ctx->remote; - struct server *server = remote->server; + struct remote_ctx *remote_send_ctx = (struct remote_ctx *)w; + struct remote *remote = remote_send_ctx->remote; + struct server *server = remote->server; - if (!remote_send_ctx->connected) { + if (!remote_send_ctx->connected) { - socklen_t len; - struct sockaddr_storage addr; - char ipstr[INET6_ADDRSTRLEN]; - int port; - len = sizeof addr; - int r = getpeername(remote->fd, (struct sockaddr*)&addr, &len); - if (r == 0) { - remote_send_ctx->connected = 1; - ev_io_stop(EV_A_ &remote_send_ctx->io); - ev_io_start(EV_A_ &server->recv_ctx->io); - ev_io_start(EV_A_ &remote->recv_ctx->io); - } else { - perror("getpeername"); - // not connected - close_and_free_remote(EV_A_ remote); - close_and_free_server(EV_A_ server); - return; - } - } else { - if (remote->buf_len == 0) { - // close and free - close_and_free_remote(EV_A_ remote); - close_and_free_server(EV_A_ server); - return; - } else { - // has data to send - ssize_t r = send(remote->fd, remote->buf, - remote->buf_len, 0); - if (r < 0) { - if (errno != EAGAIN) { + struct sockaddr_storage addr; + socklen_t len = sizeof addr; + int r = getpeername(remote->fd, (struct sockaddr*)&addr, &len); + if (r == 0) { + remote_send_ctx->connected = 1; + ev_io_stop(EV_A_ &remote_send_ctx->io); + ev_timer_stop(EV_A_ &remote_send_ctx->watcher); + ev_io_start(EV_A_ &server->recv_ctx->io); + ev_io_start(EV_A_ &remote->recv_ctx->io); + return; + } else { + perror("getpeername"); + // not connected + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } + } else { + if (remote->buf_len == 0) { + // close and free + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } else { + // has data to send + ssize_t r = send(remote->fd, remote->buf, + remote->buf_len, 0); + if (r < 0) { + if (errno != EAGAIN) { perror("send"); - // close and free - close_and_free_remote(EV_A_ remote); - close_and_free_server(EV_A_ server); - return; - } - return; - } - if (r < remote->buf_len) { - // partly sent, move memory, wait for the next time to send + // close and free + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } + return; + } + if (r < remote->buf_len) { + // partly sent, move memory, wait for the next time to send char *pt = remote->buf; - char *et = pt + min(r, BUF_SIZE); - while (pt < et) { + char *et = pt + remote->buf_len; + while (pt + r < et) { *pt = *(pt + r); pt++; } - remote->buf_len -= r; - return; - } else { - // all sent out, wait for reading - ev_io_stop(EV_A_ &remote_send_ctx->io); - if (server != NULL) { - ev_io_start(EV_A_ &server->recv_ctx->io); - } else { - close_and_free_remote(EV_A_ remote); - close_and_free_server(EV_A_ server); - return; - } - } - } + remote->buf_len -= r; + assert(remote->buf_len >= 0); + return; + } else { + // all sent out, wait for reading + ev_io_stop(EV_A_ &remote_send_ctx->io); + if (server != NULL) { + ev_io_start(EV_A_ &server->recv_ctx->io); + } else { + close_and_free_remote(EV_A_ remote); + close_and_free_server(EV_A_ server); + return; + } + } + } - } + } } struct remote* new_remote(int fd) { - struct remote *remote; - remote = malloc(sizeof(struct remote)); - remote->fd = fd; - remote->recv_ctx = malloc(sizeof(struct remote_ctx)); - remote->send_ctx = malloc(sizeof(struct remote_ctx)); - ev_io_init(&remote->recv_ctx->io, remote_recv_cb, fd, EV_READ); - ev_io_init(&remote->send_ctx->io, remote_send_cb, fd, EV_WRITE); - remote->recv_ctx->remote = remote; - remote->recv_ctx->connected = 0; - remote->send_ctx->remote = remote; - remote->send_ctx->connected = 0; - return remote; + struct remote *remote; + remote = malloc(sizeof(struct remote)); + remote->recv_ctx = malloc(sizeof(struct remote_ctx)); + remote->send_ctx = malloc(sizeof(struct remote_ctx)); + remote->fd = fd; + ev_io_init(&remote->recv_ctx->io, remote_recv_cb, fd, EV_READ); + ev_io_init(&remote->send_ctx->io, remote_send_cb, fd, EV_WRITE); + ev_timer_init(&remote->send_ctx->watcher, remote_timeout_cb, _timeout, 0); + remote->recv_ctx->remote = remote; + remote->recv_ctx->connected = 0; + remote->send_ctx->remote = remote; + remote->send_ctx->connected = 0; + return remote; } + void free_remote(struct remote *remote) { - if (remote != NULL) { - if (remote->server != NULL) { - remote->server->remote = NULL; - } - free(remote->recv_ctx); - free(remote->send_ctx); - free(remote); - } + if (remote != NULL) { + if (remote->server != NULL) { + remote->server->remote = NULL; + } + free(remote->recv_ctx); + free(remote->send_ctx); + free(remote); + } } void close_and_free_remote(EV_P_ struct remote *remote) { - if (remote != NULL) { - ev_io_stop(EV_A_ &remote->send_ctx->io); - ev_io_stop(EV_A_ &remote->recv_ctx->io); - close(remote->fd); - free_remote(remote); - } + if (remote != NULL) { + ev_timer_stop(EV_A_ &remote->send_ctx->watcher); + ev_io_stop(EV_A_ &remote->send_ctx->io); + ev_io_stop(EV_A_ &remote->recv_ctx->io); + close(remote->fd); + free_remote(remote); + } } struct server* new_server(int fd) { - struct server *server; - server = malloc(sizeof(struct server)); - server->fd = fd; - server->recv_ctx = malloc(sizeof(struct server_ctx)); - server->send_ctx = malloc(sizeof(struct server_ctx)); - ev_io_init(&server->recv_ctx->io, server_recv_cb, fd, EV_READ); - ev_io_init(&server->send_ctx->io, server_send_cb, fd, EV_WRITE); - server->recv_ctx->server = server; - server->recv_ctx->connected = 0; - server->send_ctx->server = server; - server->send_ctx->connected = 0; + struct server *server; + server = malloc(sizeof(struct server)); + server->recv_ctx = malloc(sizeof(struct server_ctx)); + server->send_ctx = malloc(sizeof(struct server_ctx)); + server->fd = fd; + ev_io_init(&server->recv_ctx->io, server_recv_cb, fd, EV_READ); + ev_io_init(&server->send_ctx->io, server_send_cb, fd, EV_WRITE); + server->recv_ctx->server = server; + server->recv_ctx->connected = 0; + server->send_ctx->server = server; + server->send_ctx->connected = 0; server->stage = 0; - return server; + if (_method == RC4) { + server->e_ctx = malloc(sizeof(EVP_CIPHER_CTX)); + server->d_ctx = malloc(sizeof(EVP_CIPHER_CTX)); + enc_ctx_init(server->e_ctx, _key, 1); + enc_ctx_init(server->d_ctx, _key, 0); + } else { + server->e_ctx = NULL; + server->d_ctx = NULL; + } + return server; } void free_server(struct server *server) { - if (server != NULL) { - if (server->remote != NULL) { - server->remote->server = NULL; - } - free(server->recv_ctx); - free(server->send_ctx); - free(server); - } + if (server != NULL) { + if (server->remote != NULL) { + server->remote->server = NULL; + } + if (_method == RC4) { + EVP_CIPHER_CTX_cleanup(server->e_ctx); + EVP_CIPHER_CTX_cleanup(server->d_ctx); + free(server->e_ctx); + free(server->d_ctx); + } + free(server->recv_ctx); + free(server->send_ctx); + free(server); + } } void close_and_free_server(EV_P_ struct server *server) { - if (server != NULL) { - ev_io_stop(EV_A_ &server->send_ctx->io); - ev_io_stop(EV_A_ &server->recv_ctx->io); - close(server->fd); - free_server(server); - } + if (server != NULL) { + ev_io_stop(EV_A_ &server->send_ctx->io); + ev_io_stop(EV_A_ &server->recv_ctx->io); + close(server->fd); + free_server(server); + } } static void accept_cb (EV_P_ ev_io *w, int revents) { - struct listen_ctx *listener = (struct listen_ctx *)w; - int serverfd; - while (1) { - serverfd = accept(listener->fd, NULL, NULL); - if (serverfd == -1) { - perror("accept"); - break; - } - setnonblocking(serverfd); - struct server *server = new_server(serverfd); - struct addrinfo hints, *res; - int sockfd; - memset(&hints, 0, sizeof hints); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - getaddrinfo(SERVER, REMOTE_PORT, &hints, &res); - sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - if (sockfd < 0) { - perror("socket"); - close(sockfd); - free_server(server); - continue; - } - setnonblocking(sockfd); - struct remote *remote = new_remote(sockfd); - server->remote = remote; - remote->server = server; - connect(sockfd, res->ai_addr, res->ai_addrlen); - freeaddrinfo(res); - // listen to remote connected event - ev_io_start(EV_A_ &remote->send_ctx->io); - break; - } + struct listen_ctx *listener = (struct listen_ctx *)w; + int serverfd; + while (1) { + serverfd = accept(listener->fd, NULL, NULL); + if (serverfd == -1) { + perror("accept"); + break; + } + setnonblocking(serverfd); + struct server *server = new_server(serverfd); + struct addrinfo hints, *res; + int sockfd; + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + int err = getaddrinfo(_server, _remote_port, &hints, &res); + if (err) { + perror("getaddrinfo"); + close_and_free_server(EV_A_ server); + break; + } + + sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (sockfd < 0) { + perror("socket"); + close(sockfd); + close_and_free_server(EV_A_ server); + freeaddrinfo(res); + break; + } + + struct timeval timeout; + timeout.tv_sec = _timeout; + timeout.tv_usec = 0; + err = setsockopt(sockfd, SOL_SOCKET, + SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)); + if (err) perror("setsockopt"); + err = setsockopt(sockfd, SOL_SOCKET, + SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)); + if (err) perror("setsockopt"); + + setnonblocking(sockfd); + struct remote *remote = new_remote(sockfd); + server->remote = remote; + remote->server = server; + connect(sockfd, res->ai_addr, res->ai_addrlen); + freeaddrinfo(res); + // listen to remote connected event + ev_io_start(EV_A_ &remote->send_ctx->io); + ev_timer_start(EV_A_ &remote->send_ctx->watcher); + break; + } } -int main (void) +static void print_usage() { + printf("usage: ss -s server_host -p server_port -l local_port\n"); + printf(" -k password [-m encrypt_method] [-f pid_file]\n"); + printf("\n"); + printf("info:\n"); + printf(" encrypt_method: table, rc4\n"); + printf(" pid_file: valid path to the pid file\n"); +} + +int main (int argc, char **argv) { - fprintf(stderr, "calculating ciphers\n"); - get_table(KEY); - int listenfd; - listenfd = create_and_bind(PORT); - if (listenfd < 0) { - return 1; - } - if (listen(listenfd, SOMAXCONN) == -1) { - perror("listen() error."); - return 1; - } - fprintf(stderr, "server listening at port %s\n", PORT); - setnonblocking(listenfd); - struct listen_ctx listen_ctx; - listen_ctx.fd = listenfd; - struct ev_loop *loop = EV_DEFAULT; - ev_io_init (&listen_ctx.io, accept_cb, listenfd, EV_READ); - ev_io_start (loop, &listen_ctx.io); - ev_run (loop, 0); - return 0; + char *server = NULL; + char *remote_port = NULL; + char *port = NULL; + char *key = NULL; + char *timeout = "10"; + char *method = NULL; + int c; + int f_flags = 0; + char *f_path = NULL; + + opterr = 0; + + while ((c = getopt (argc, argv, "f:s:p:l:k:t:m:")) != -1) { + switch (c) { + case 's': + server = optarg; + break; + case 'p': + remote_port = optarg; + break; + case 'l': + port = optarg; + break; + case 'k': + key = optarg; + break; + case 'f': + f_flags = 1; + f_path = optarg; + break; + case 't': + timeout = optarg; + break; + case 'm': + method = optarg; + break; + } + } + + if (server == NULL || remote_port == NULL || + port == NULL || key == NULL) { + print_usage(); + exit(EXIT_FAILURE); + } + + if (f_flags) { + + if (f_path == NULL) { + print_usage(); + exit(EXIT_FAILURE); + } + + /* Our process ID and Session ID */ + pid_t pid, sid; + + /* Fork off the parent process */ + pid = fork(); + if (pid < 0) { + exit(EXIT_FAILURE); + } + /* If we got a good PID, then + we can exit the parent process. */ + if (pid > 0) { + FILE *file = fopen(f_path, "w"); + fprintf(file, "%d", pid); + fclose(file); + exit(EXIT_SUCCESS); + } + + /* Change the file mode mask */ + umask(0); + + /* Open any logs here */ + + /* Create a new SID for the child process */ + sid = setsid(); + if (sid < 0) { + /* Log the failure */ + exit(EXIT_FAILURE); + } + + + /* Change the current working directory */ + if ((chdir("/")) < 0) { + /* Log the failure */ + exit(EXIT_FAILURE); + } + + /* Close out the standard file descriptors */ + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); + } + + // init global variables + _server = strdup(server); + _remote_port = strdup(remote_port); + _timeout = atoi(timeout); + _key = key; + _method = TABLE; + if (method != NULL) { + if (strcmp(method, "rc4") == 0) { + _method = RC4; + } + } + + LOGD("calculating ciphers %d", _method); + if (_method != RC4) { + get_table(key); + } + + int listenfd; + listenfd = create_and_bind(port); + if (listenfd < 0) { + LOGE("bind() error.."); + return 1; + } + if (listen(listenfd, SOMAXCONN) == -1) { + LOGE("listen() error."); + return 1; + } + LOGD("server listening at port %s\n", port); + + setnonblocking(listenfd); + struct listen_ctx listen_ctx; + listen_ctx.fd = listenfd; + struct ev_loop *loop = ev_default_loop(0); + if (!loop) { + LOGE("no epoll found here, maybe it hides under your chair"); + return 1; + } + ev_io_init (&listen_ctx.io, accept_cb, listenfd, EV_READ); + ev_io_start (loop, &listen_ctx.io); + ev_run (loop, 0); + return 0; } diff --git a/local.h b/local.h index f6b96007..85758030 100644 --- a/local.h +++ b/local.h @@ -1,8 +1,8 @@ -#pragma once +#ifndef _LOCAL_H +#define _LOCAL_H #include - -#define BUF_SIZE 1024 +#include "encrypt.h" struct listen_ctx { ev_io io; @@ -10,20 +10,31 @@ struct listen_ctx { struct sockaddr sock; }; -struct server { - int fd; - char buf[BUF_SIZE]; // server send from, remote recv into - int buf_len; - char stage; - struct server_ctx *recv_ctx; - struct server_ctx *send_ctx; - struct remote *remote; -}; struct server_ctx { ev_io io; int connected; struct server *server; }; + +struct server { + int fd; + char buf[BUF_SIZE]; // server send from, remote recv into + char stage; + int buf_len; + EVP_CIPHER_CTX *e_ctx; + EVP_CIPHER_CTX *d_ctx; + struct server_ctx *recv_ctx; + struct server_ctx *send_ctx; + struct remote *remote; +}; + +struct remote_ctx { + ev_io io; + ev_timer watcher; + int connected; + struct remote *remote; +}; + struct remote { int fd; char buf[BUF_SIZE]; // remote send from, server recv into @@ -32,11 +43,6 @@ struct remote { struct remote_ctx *send_ctx; struct server *server; }; -struct remote_ctx { - ev_io io; - int connected; - struct remote *remote; -}; static void accept_cb (EV_P_ ev_io *w, int revents); @@ -51,3 +57,4 @@ struct server* new_server(int fd); void free_server(struct server *server); void close_and_free_server(EV_P_ struct server *server); +#endif // _LOCAL_H diff --git a/missing b/missing index 20bc5b0e..98ba2366 120000 --- a/missing +++ b/missing @@ -1 +1 @@ -/usr/share/automake-1.11/missing \ No newline at end of file +/usr/local/Cellar/automake/1.12.5/share/automake-1.12/missing \ No newline at end of file diff --git a/socks5.h b/socks5.h old mode 100755 new mode 100644 index 6fe7cd03..6fac3b0d --- a/socks5.h +++ b/socks5.h @@ -1,42 +1,43 @@ -#pragma once - -#define VERSION 0x05 -#define CONNECT 0x01 -#define IPV4 0x01 -#define DOMAIN 0x03 -#define IPV6 0x04 -#define CMD_NOT_SUPPORTED 0x07 - -#pragma pack(1) - -struct method_select_request -{ - char ver; - char nmethods; - char methods[255]; -}; - -struct method_select_response -{ - char ver; - char method; -}; - -struct socks5_request -{ - char ver; - char cmd; - char rsv; - char atyp; -}; - -struct socks5_response -{ - char ver; - char rep; - char rsv; - char atyp; -}; - -#pragma pack() - +#ifndef _SOCKS5_H +#define _SOCKS5_H + +#define SVERSION 0x05 +#define CONNECT 0x01 +#define IPV4 0x01 +#define DOMAIN 0x03 +#define IPV6 0x04 +#define CMD_NOT_SUPPORTED 0x07 + +#pragma pack(1) + +struct method_select_request +{ + char ver; + char nmethods; + char methods[255]; +}; + +struct method_select_response +{ + char ver; + char method; +}; + +struct socks5_request +{ + char ver; + char cmd; + char rsv; + char atyp; +}; + +struct socks5_response +{ + char ver; + char rep; + char rsv; + char atyp; +}; + +#endif //_SOCKS5_H +