diff --git a/.gitignore b/.gitignore index 5ac1006..475eec9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,24 @@ hping3 *.swp Makefile -byteorder -byteorder.h -systype.h + +*~ +.deps/ +aclocal.m4 +autom4te.cache/ +compile +config.guess +config.h +config.h.in +config.log +config.status +config.sub +configure +depcomp +install-sh +libtool +ltmain.sh +m4/ +missing +Makefile.in +stamp-h1 diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..88f815e --- /dev/null +++ b/Makefile.am @@ -0,0 +1,71 @@ +# Makefile.am for hping3 + +# Specify the program to build +bin_PROGRAMS = hping3 + +# Define CFLAGS, CPPFLAGS, and LDFLAGS +# AM_CPPFLAGS is for preprocessor flags (includes, defines) +# AM_CFLAGS is for compiler flags +# AM_LDFLAGS is for linker flags +AM_CFLAGS = -O3 -Wall $(DEBUG) # DEBUG variable is not defined anywhere, usually handled by configure.ac --enable-debug +AM_CPPFLAGS = $(USE_TCL_CPPFLAGS) +AM_LDFLAGS = +ACLOCAL_AMFLAGS= -I m4 + + +# Source files for hping3 +hping3_SOURCES = \ + main.c getifname.c getlhs.c \ + parseoptions.c datafiller.c \ + datahandler.c gethostname.c \ + binding.c getusec.c opensockraw.c \ + logicmp.c waitpacket.c resolve.c \ + sendip.c sendicmp.c sendudp.c \ + sendtcp.c cksum.c statistics.c \ + usage.c version.c antigetopt.c \ + sockopt.c listen.c \ + sendhcmp.c memstr.c rtt.c \ + relid.c sendip_handler.c \ + libpcap_stuff.c memlockall.c memunlockall.c \ + memlock.c memunlock.c ip_opt_build.c \ + display_ipopt.c sendrawip.c signal.c send.c \ + strlcpy.c arsglue.c random.c scan.c \ + hstring.c script.c interface.c \ + adbuf.c hex.c apdutils.c sbignum.c \ + sbignum-tables.c \ + ars.c apd.c split.c rapd.c + +# Linker libraries +# hping3_LDADD will include LIBS (from AC_CHECK_LIB), SOLARISLIB, and TCL_LIB +# Libtool handles adding -static or -dynamic based on configure options +hping3_LDADD = $(LIBS) $(SOLARISLIB) $(TCL_LIBS) + +# Man page installation +man8_MANS = docs/hping3.8 +# Extra distributions (these are files that are part of the distribution +# but not built by Automake itself) +EXTRA_DIST = \ + configure.ac \ + Makefile.am \ + docs/hping3.8 + + +distclean-local: + rm -f configure aclocal.m4 Makefile.in config.h.in config.h.in~ autoreconf.log + rm -f config.guess config.sub ltmain.sh missing install-sh depcomp configure~ compile + rm -rf autom4te.cache m4 + + + +# Special target to make a purely static hping3 (if desired, though `configure --enable-static` should handle this) +# This is typically not needed if LT_INIT is used and configure --enable-static is passed. +# However, if you wanted a separate `make hping3-static` rule, it'd look something like this: +# (Note: This might conflict with Libtool's default behavior, usually configure --enable-static is enough) +# hping3-static: $(hping3_OBJECTS) +# $(LIBTOOL) --tag=CC --mode=link $(CC) $(AM_CFLAGS) $(hping3_OBJECTS) -static -o $@ $(hping3_LDADD) + +# Clean rules are handled by Automake +# distclean is also handled by Automake + +# include .depend is no longer needed, Automake handles dependencies + diff --git a/Makefile.in b/Makefile.in deleted file mode 100644 index 5cccbdd..0000000 --- a/Makefile.in +++ /dev/null @@ -1,92 +0,0 @@ -# $smu-mark$ -# $name: Makefile.in$ -# $author: Salvatore Sanfilippo 'antirez'$ -# $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$ -# $license: This software is under GPL version 2 of license$ -# $date: Sun Jul 25 17:56:15 MET DST 1999$ -# $rev: 3$ - -CC= gcc -AR=/usr/bin/ar -RANLIB=/usr/bin/ranlib -CCOPT= -O2 -Wall @PCAP_INCLUDE@ @TCL_INC@ @USE_TCL@ -DEBUG= -g -#uncomment the following if you need libpcap based build under linux -#(not raccomanded) -COMPILE_TIME= -INSTALL_MANPATH=@MANPATH@ -@PCAP@ - -ARSOBJ = ars.o apd.o split.o rapd.o - -OBJ= main.o getifname.o getlhs.o \ - parseoptions.o datafiller.o \ - datahandler.o gethostname.o \ - binding.o getusec.o opensockraw.o \ - logicmp.o waitpacket.o resolve.o \ - sendip.o sendicmp.o sendudp.o \ - sendtcp.o cksum.o statistics.o \ - usage.o version.o antigetopt.o \ - sockopt.o listen.o \ - sendhcmp.o memstr.o rtt.o \ - relid.o sendip_handler.o \ - libpcap_stuff.o memlockall.o memunlockall.o \ - memlock.o memunlock.o ip_opt_build.o \ - display_ipopt.o sendrawip.o signal.o send.o \ - strlcpy.o arsglue.o random.o scan.o \ - hstring.o script.o interface.o \ - adbuf.o hex.o apdutils.o sbignum.o \ - sbignum-tables.o $(ARSOBJ) - -all: .depend hping3 - -dep: .depend -.depend: - @echo Making dependences - @$(CC) -MM *.c > .depend - -libars.a: $(ARSOBJ) - $(AR) rc $@ $^ - $(RANLIB) $@ - -hping3: byteorder.h $(OBJ) - $(CC) -o hping3 $(CCOPT) $(DEBUG) $(OBJ) -L/usr/local/lib $(PCAP) @SOLARISLIB@ @TCL_LIB@ - @echo - ./hping3 -v - @echo "use \`make strip' to strip hping3 binary" - @echo "use \`make install' to install hping3" - -hping3-static: byteorder.h $(OBJ) - $(CC) -static -o hping3-static $(CCOPT) $(DEBUG) $(OBJ) -L/usr/local/lib $(PCAP) @SOLARISLIB@ @TCL_LIB@ -ldl - -byteorder.h: - ./configure - -.c.o: - $(CC) -c $(CCOPT) $(DEBUG) $(COMPILE_TIME) $< - -clean: - rm -rf hping3 *.o libars.a - -distclean: - rm -rf hping3 *.o byteorder byteorder.h systype.h Makefile libars.a .depend - -install: hping3 - cp -f hping3 /usr/sbin/ - chmod 755 /usr/sbin/hping3 - ln -s /usr/sbin/hping3 /usr/sbin/hping - ln -s /usr/sbin/hping3 /usr/sbin/hping2 - @if [ -d ${INSTALL_MANPATH}/man8 ]; then \ - cp ./docs/hping3.8 ${INSTALL_MANPATH}/man8; \ - chmod 644 ${INSTALL_MANPATH}/man8/hping3.8; \ - else \ - echo "@@@@@@ WARNING @@@@@@"; \ - echo "Can't install the man page: ${INSTALL_MANPATH}/man8 does not exist"; \ - fi - -strip: hping3 - @ls -l ./hping3 - strip hping3 - @ls -l ./hping3 - -include .depend diff --git a/ars.h b/ars.h index ba460fe..d09bd8d 100644 --- a/ars.h +++ b/ars.h @@ -6,6 +6,10 @@ #ifndef _ARS_H #define _ARS_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + /* define before including sys/socket.h */ #if defined(__APPLE__) && !defined(_BSD_SOCKLEN_T_) #define _BSD_SOCKLEN_T_ int @@ -15,9 +19,7 @@ #include #include #include -#include "systype.h" #include "in.h" -#include "byteorder.h" #include "adbuf.h" #include "fixtypes.h" diff --git a/byteorder.c b/byteorder.c deleted file mode 100644 index 06f9d06..0000000 --- a/byteorder.c +++ /dev/null @@ -1,80 +0,0 @@ -#if 0 -# -# Compile with: -# $sh byteorder.c -# -cc byteorder.c -o byteorder || exit 1 -echo successfully compiled -exit -#endif /* 0 */ - -/* Coypright (C) 1999-2003 Salvatore Sanfilippo */ - -/* - * 0.1 first version - * 0.2 add Strchr, so it's possibile remove string.h - * 0.3 more portable thx to Pancrazio De Mauro 'TrantIT'!!! - * 0.4 better debug output - */ - -/* $Id: byteorder.c,v 1.2 2003/09/01 00:22:06 antirez Exp $ */ - -#include - -char *Strchr(char *s, char c) -{ - while(*s) - if (*s++ == c) - return s; - - return (char*) 0; -} - -int main(int argc, char **argv) -{ - unsigned int test = 1; - unsigned char *x; - int macro = 0, debug = 0, help = 0, j; - - for (j = 1; j < argc; j++) { - if (Strchr(argv[j], 'm')) macro = 1; - if (Strchr(argv[j], 'd')) debug = 1; - if (Strchr(argv[j], 'h')) help = 1; - } - - if (help) { - printf( "-m macro output\n" - "-d debug\n" - "-h help\n"); - return 0; - } - - x = (unsigned char*) &test; - - if (*x == 0x00) { - if (macro) - printf("__BIG_ENDIAN_BITFIELD\n"); - else - printf("big endian\n"); - } - else if (*x == 0x01) { - if (macro) - printf("__LITTLE_ENDIAN_BITFIELD\n"); - else - printf("little endian\n"); - } else { - printf("\nWARNING!!! byteorder exception\n\n"); - debug = 1; - } - - if (debug) { - printf("sizeof(unsigned int) = %d\n", - (int)sizeof(unsigned int)); - printf("unsigned int test = 1;\n"); - printf("in memory as: "); - for (j = 0; j < sizeof(unsigned int); j++) - printf("%02x ", x[j]); - printf("\n"); - } - return 0; -} diff --git a/configure b/configure deleted file mode 100755 index dab04ab..0000000 --- a/configure +++ /dev/null @@ -1,166 +0,0 @@ -#!/bin/sh - -show_help() -{ - echo configure help: - echo "--help show this help" - echo "--no-tcl disable TCL scripting support" - echo " even if uid != euid" -} - -if [ "$1" = "--help" ]; then - show_help - exit 0 -fi - -CC=${CC:=cc} - -echo build byteorder.c... -$CC byteorder.c -o byteorder || exit 1 - -INSTALL_MANPATH=`echo $MANPATH|cut -f1 -d:` -if [ "$INSTALL_MANPATH" = "" ]; then - INSTALL_MANPATH="/usr/local/man" -fi -BYTEORDER=`./byteorder -m` - -echo create byteorder.h... -cat > byteorder.h <> byteorder.h -echo \#define $BYTEORDER >> byteorder.h -echo \#endif /\* $BYTEORDER \*/ >> byteorder.h -cat >> byteorder.h < Found Tclsh in: $TCLSH" - fi - fi - done -done -if [ -f $TCLSH ] -then - TCL_VER=`echo puts \\$tcl_version | $TCLSH -` - USE_TCL='-DUSE_TCL' - TCL_LIB="-ltcl${TCL_VER}" - if [ -e /usr/include/tcl${TCL_VER} ] - then - TCL_INC="-I/usr/include/tcl${TCL_VER}" - elif [ -e /usr/include/tcl.h ] - then - TCL_INC="" - elif [ -e /usr/local/include/tcl${TCL_VER} ] - then - TCL_INC="-I/usr/local/include/tcl${TCL_VER}" - else - USE_TCL="" - TCL_LIB="" - echo "==> WARNING: no Tcl header files found!" - fi -fi -if [ -n $USE_TCL ] -then - LIBPOSTFIX=`ls -1 /usr/local/lib/ /usr/lib | grep 'libtcl[0-9]' | grep so | sed -e 's/\.so.*//g' -e 's/libtcl//g' | sort -r | head -1` - TCL_LIB="-ltcl${LIBPOSTFIX} -lm -lpthread" -fi - -# -# configurable stuff -# -PCAP="PCAP=-lpcap" -PCAP_INCLUDE="" - -for ARG in $*; do - case "$ARG" in - *"--no-tcl") - USE_TCL="" - TCL_VER="" - TCL_INC="" - TCL_LIB="" - ;; - esac -done - -echo -------------------------------------- -echo system type: $CONFIGOSTYPE -echo -echo "LIBPCAP : $PCAP" -echo "PCAP_INCLUDE : $PCAP_INCLUDE" -echo "MANPATH : $INSTALL_MANPATH" -echo "USE_TCL : $USE_TCL" -echo "TCL_VER : $TCL_VER" -echo "TCL_INC : $TCL_INC" -echo "LIBTCL : $TCL_LIB" -echo "TCLSH : $TCLSH" -echo -echo "(to modify try configure --help)" -echo -------------------------------------- - -echo creating Makefile... -sed -e "s^@PCAP@^$PCAP^g" \ - -e "s^@PCAP_INCLUDE@^$PCAP_INCLUDE^g" \ - -e "s^@MANPATH@^$INSTALL_MANPATH^g" \ - -e "s^@SOLARISLIB@^$SOLARISLIB^g" \ - -e "s^@USE_TCL@^$USE_TCL^g" \ - -e "s^@TCL_INC@^$TCL_INC^g" \ - -e "s^@TCL_VER@^$TCL_VER^g" \ - -e "s^@TCL_LIB@^$TCL_LIB^g" \ - Makefile - -# -# -# - -cat > systype.h <> systype.h -cat >> systype.h < .depend - -echo now you can try \`make\' diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..d2847b1 --- /dev/null +++ b/configure.ac @@ -0,0 +1,157 @@ +# -*- Autoconf -*- +AC_INIT([hping3], [3.0.0], [antirez@invece.org]) +AM_INIT_AUTOMAKE([-Wall -Werror foreign]) +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_FILES([Makefile]) +AC_CONFIG_MACRO_DIRS([m4]) + + +# Tools +AC_PROG_CC +AC_PROG_INSTALL +AC_PROG_AR +LT_INIT + +# ----------- libpcap support ----------- + +AC_ARG_WITH([libpcap], + [AS_HELP_STRING([--with-libpcap=PATH], [Specify root path to libpcap (contains include/ and lib/)])], + [libpcap_path="$withval"], + [libpcap_path=""] +) + +AS_IF([test -z "$libpcap_path"], [ + AC_MSG_ERROR([--with-libpcap=PATH is required when compiling.]) +]) + +AC_MSG_NOTICE([Checking for libpcap...]) +pcap_inc_dir="$libpcap_path/include" +pcap_lib_dir="$libpcap_path/lib" +pcap_static="$pcap_lib_dir/libpcap.a" + +CPPFLAGS="$CPPFLAGS -I$pcap_inc_dir" +LDFLAGS="$LDFLAGS -L$pcap_lib_dir" + +AS_IF([test "x$enable_static" = "xyes" && test -f "$pcap_static"], [ + AC_MSG_NOTICE([Using static libpcap from $pcap_lib_dir]) + LIBS="$pcap_static -ldl" +], [ + AC_CHECK_LIB([pcap], [pcap_open_live], [], [ + AC_MSG_ERROR([libpcap not found in $libpcap_path]) + ]) +]) + +# ----------- Tcl scripting support ----------- + +AC_ARG_ENABLE([tcl], + [AS_HELP_STRING([--disable-tcl], [Disable Tcl scripting support])], + [], + [enable_tcl=yes] +) + +AC_ARG_WITH([libtcl], + [AS_HELP_STRING([--with-libtcl=PATH], [Specify root path to Tcl (contains include/ and lib/)])], + [libtcl_path="$withval"], + [libtcl_path=""] +) + +AS_IF([test "x$enable_tcl" = "xyes"], [ + AS_IF([test -z "$libtcl_path"], [ + AC_MSG_ERROR([--with-libtcl=PATH is required when Tcl scripting is enabled and compiling.]) + ]) +]) + +tcl_inc_dir="$libtcl_path/include" +tcl_lib_dir="$libtcl_path/lib" +CPPFLAGS="$CPPFLAGS -I$tcl_inc_dir" +LDFLAGS="$LDFLAGS -L$tcl_lib_dir" + +AS_IF([test "x$enable_tcl" = "xyes"], [ + AC_MSG_NOTICE([Checking for Tcl (8.0–8.6)...]) + have_tcl_lib=no + have_tcl_hdr=no + TCL_VERSIONS="8.6 8.5 8.4 8.3 8.2 8.1 8.0" + + if test "x$enable_static" = "xyes"; then + for ver in $TCL_VERSIONS; do + tcl_static="$tcl_lib_dir/libtcl${ver}.a" + if test -f "$tcl_static"; then + have_tcl_lib=yes + TCL_LIBS="$tcl_static -lm -lpthread" + TCL_VERSION_DETECTED="$ver" + break + fi + done + fi + + if test "x$have_tcl_lib" = "xno"; then + for ver in $TCL_VERSIONS; do + AC_CHECK_LIB([tcl$ver], [Tcl_Init], [ + have_tcl_lib=yes + TCL_LIBS="-ltcl$ver -lm -lpthread" + TCL_VERSION_DETECTED="$ver" + break + ]) + done + fi + + AC_CHECK_HEADER([tcl.h], [have_tcl_hdr=yes], [ + AC_MSG_WARN([tcl.h not found; Tcl scripting disabled]) + ]) + + AS_IF([test "x$have_tcl_lib" = "xyes" -a "x$have_tcl_hdr" = "xyes"], [ + AC_DEFINE([USE_TCL], [1], [Define if using Tcl scripting]) + USE_TCL_CPPFLAGS="-DUSE_TCL" + ], [ + enable_tcl=no + TCL_LIBS="" + USE_TCL_CPPFLAGS="" + TCL_VERSION_DETECTED="" + ]) +]) + +AC_SUBST([TCL_LIBS]) +AC_SUBST([USE_TCL_CPPFLAGS]) +AC_SUBST([TCL_VERSION_DETECTED]) + + + + + + +# Endianness +# Endianness +AC_C_BIGENDIAN( + [AC_DEFINE([__BIG_ENDIAN_BITFIELD], [1], [Define if target is big endian])], + [AC_DEFINE([__LITTLE_ENDIAN_BITFIELD], [1], [Define if target is little endian])] +) + +# OS type macros +case "$host_os" in + linux*) AC_DEFINE([OSTYPE_LINUX], [1], [Define if OS is Linux]) ;; + solaris*) AC_DEFINE([OSTYPE_SUNOS], [1], [Define if OS is Solaris]) + SOLARISLIB="-lsocket -lresolv -lnsl" + AC_DEFINE([STUPID_SOLARIS_CHECKSUM_BUG], [1], [Define if workaround needed for Solaris checksum bug]) ;; + freebsd*) AC_DEFINE([OSTYPE_FREEBSD], [1], [Define if OS is FreeBSD]) ;; + openbsd*) AC_DEFINE([OSTYPE_OPENBSD], [1], [Define if OS is OpenBSD]) ;; + netbsd*) AC_DEFINE([OSTYPE_NETBSD], [1], [Define if OS is NetBSD]) ;; + darwin*) AC_DEFINE([OSTYPE_DARWIN], [1], [Define if OS is Darwin/macOS]) ;; + cygwin*) AC_DEFINE([OSTYPE_CYGWIN], [1], [Define if OS is Cygwin]) ;; + *) AC_DEFINE([OSTYPE_UNKNOWN], [1], [Define if OS is unknown]) ;; +esac +AC_SUBST([SOLARISLIB]) + +# Output summary +AC_MSG_NOTICE([]) +AC_MSG_NOTICE([------ Configuration Summary ------]) +AC_MSG_NOTICE([OS : ${host_os}]) +AC_MSG_NOTICE([libpcap : yes]) +AC_MSG_NOTICE([Tcl support : ${enable_tcl}]) +AC_MSG_NOTICE([Tcl version : ${TCL_VERSION_DETECTED}]) +AC_MSG_NOTICE([Static build : ${enable_static:-no}]) +AC_MSG_NOTICE([Cross-compiler : ${host}]) +AC_MSG_NOTICE([------------------------------------]) +AC_MSG_NOTICE([Run 'make' to build hping3]) +AC_MSG_NOTICE([]) +AC_OUTPUT + diff --git a/hping2.h b/hping2.h index 27cb0ff..a165ef3 100644 --- a/hping2.h +++ b/hping2.h @@ -13,12 +13,14 @@ #ifndef _HPING2_H #define _HPING2_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include #include -#include "byteorder.h" -#include "systype.h" #include "fixtypes.h" /* types */ @@ -357,7 +359,7 @@ struct delaytable_element { int status; }; -volatile struct delaytable_element delaytable[TABLESIZE]; +extern volatile struct delaytable_element delaytable[TABLESIZE]; /* protos */ void nop(void); /* nop */ diff --git a/libpcap_stuff.c b/libpcap_stuff.c index 26f9993..51dd367 100644 --- a/libpcap_stuff.c +++ b/libpcap_stuff.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include "globals.h" diff --git a/script.c b/script.c index 124370c..902654c 100644 --- a/script.c +++ b/script.c @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include "release.h"