Browse Source

Import upstream version 4.4.4

Fred Klassen 11 months ago
parent
commit
27a7598261
100 changed files with 4194 additions and 4149 deletions
  1. 27 13
      Makefile.in
  2. 92 112
      aclocal.m4
  3. 10 9
      config/ar-lib
  4. 9 8
      config/compile
  5. 371 312
      config/config.guess
  6. 148 154
      config/config.sub
  7. 5 5
      config/depcomp
  8. 107 67
      config/install-sh
  9. 177 73
      config/ltmain.sh
  10. 8 8
      config/missing
  11. 205 139
      configure
  12. 18 2
      configure.ac
  13. 8 0
      docs/CHANGELOG
  14. 4 1
      docs/CREDIT
  15. 10 5
      docs/Makefile.in
  16. 34 20
      lib/Makefile.in
  17. 20 21
      lib/strlcat.c
  18. 17 18
      lib/strlcpy.c
  19. 39 26
      libopts/Makefile.in
  20. 1 1
      libopts/autoopts.h
  21. 2 1
      libopts/enum.c
  22. 2 1
      libopts/save.c
  23. 42 17
      m4/libtool.m4
  24. 10 5
      scripts/Makefile.in
  25. 3 3
      src/Makefile.am
  26. 150 59
      src/Makefile.in
  27. 54 93
      src/bridge.c
  28. 10 14
      src/bridge.h
  29. 23 27
      src/common.h
  30. 104 42
      src/common/Makefile.in
  31. 62 76
      src/common/cache.c
  32. 3 4
      src/common/cache.h
  33. 63 164
      src/common/cidr.c
  34. 7 12
      src/common/cidr.h
  35. 14 19
      src/common/err.c
  36. 2 5
      src/common/err.h
  37. 6 9
      src/common/fakepcap.c
  38. 1 4
      src/common/fakepcap.h
  39. 14 18
      src/common/fakepcapnav.c
  40. 6 9
      src/common/fakepcapnav.h
  41. 10 11
      src/common/fakepoll.c
  42. 11 9
      src/common/fakepoll.h
  43. 4 2
      src/common/flows.c
  44. 16 16
      src/common/flows.h
  45. 111 164
      src/common/get.c
  46. 7 11
      src/common/get.h
  47. 1 1
      src/common/git_version.c
  48. 21 36
      src/common/interface.c
  49. 6 7
      src/common/interface.h
  50. 12 24
      src/common/list.c
  51. 4 7
      src/common/list.h
  52. 29 34
      src/common/mac.c
  53. 4 4
      src/common/mac.h
  54. 107 96
      src/common/netmap.c
  55. 37 40
      src/common/netmap.h
  56. 5 11
      src/common/pcap_dlt.h
  57. 354 360
      src/common/sendpacket.c
  58. 10 18
      src/common/sendpacket.h
  59. 1 2
      src/common/services.c
  60. 4 7
      src/common/services.h
  61. 55 86
      src/common/tcpdump.c
  62. 11 15
      src/common/tcpdump.h
  63. 10 58
      src/common/timer.c
  64. 62 85
      src/common/timer.h
  65. 55 59
      src/common/txring.c
  66. 13 17
      src/common/txring.h
  67. 115 80
      src/common/utils.c
  68. 46 47
      src/common/utils.h
  69. 56 82
      src/common/xX.c
  70. 1 5
      src/common/xX.h
  71. 128 142
      src/defines.h
  72. 128 142
      src/defines.h.in
  73. 119 41
      src/fragroute/Makefile.in
  74. 1 3
      src/fragroute/argv.c
  75. 1 4
      src/fragroute/argv.h
  76. 222 221
      src/fragroute/bget.c
  77. 2 0
      src/fragroute/bget.h
  78. 14 24
      src/fragroute/fragroute.c
  79. 16 25
      src/fragroute/fragroute.h
  80. 10 18
      src/fragroute/iputil.c
  81. 3 4
      src/fragroute/iputil.h
  82. 51 55
      src/fragroute/mod.c
  83. 1 4
      src/fragroute/mod.h
  84. 16 19
      src/fragroute/mod_delay.c
  85. 15 19
      src/fragroute/mod_drop.c
  86. 15 19
      src/fragroute/mod_dup.c
  87. 7 11
      src/fragroute/mod_echo.c
  88. 32 36
      src/fragroute/mod_ip6_opt.c
  89. 15 21
      src/fragroute/mod_ip6_qos.c
  90. 30 38
      src/fragroute/mod_ip_chaff.c
  91. 42 62
      src/fragroute/mod_ip_frag.c
  92. 24 23
      src/fragroute/mod_ip_opt.c
  93. 16 18
      src/fragroute/mod_ip_tos.c
  94. 18 19
      src/fragroute/mod_ip_ttl.c
  95. 10 12
      src/fragroute/mod_order.c
  96. 100 96
      src/fragroute/mod_print.c
  97. 39 49
      src/fragroute/mod_tcp_chaff.c
  98. 25 19
      src/fragroute/mod_tcp_opt.c
  99. 28 35
      src/fragroute/mod_tcp_seg.c
  100. 0 0
      src/fragroute/pkt.c

+ 27 - 13
Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.16.3 from Makefile.am.
 # @configure_input@
 # @configure_input@
 
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 
 # This Makefile.in is free software; the Free Software Foundation
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -140,7 +140,7 @@ am__recursive_targets = \
   $(RECURSIVE_CLEAN_TARGETS) \
   $(RECURSIVE_CLEAN_TARGETS) \
   $(am__extra_recursive_targets)
   $(am__extra_recursive_targets)
 AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
 AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
-	cscope distdir dist dist-all distcheck
+	cscope distdir distdir-am dist dist-all distcheck
 am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
 am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
 # Read a list of newline-separated strings from the standard input,
 # Read a list of newline-separated strings from the standard input,
 # and print each of them once, without duplicates.  Input order is
 # and print each of them once, without duplicates.  Input order is
@@ -168,7 +168,8 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/doxygen.cfg.in \
 	$(top_srcdir)/config/install-sh $(top_srcdir)/config/ltmain.sh \
 	$(top_srcdir)/config/install-sh $(top_srcdir)/config/ltmain.sh \
 	$(top_srcdir)/config/missing INSTALL config/ar-lib \
 	$(top_srcdir)/config/missing INSTALL config/ar-lib \
 	config/compile config/config.guess config/config.sub \
 	config/compile config/config.guess config/config.sub \
-	config/install-sh config/ltmain.sh config/missing
+	config/depcomp config/install-sh config/ltmain.sh \
+	config/missing
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 distdir = $(PACKAGE)-$(VERSION)
 distdir = $(PACKAGE)-$(VERSION)
 top_distdir = $(distdir)
 top_distdir = $(distdir)
@@ -207,6 +208,8 @@ am__relativize = \
 DIST_ARCHIVES = $(distdir).tar.gz
 DIST_ARCHIVES = $(distdir).tar.gz
 GZIP_ENV = --best
 GZIP_ENV = --best
 DIST_TARGETS = dist-gzip
 DIST_TARGETS = dist-gzip
+# Exists only to be overridden by the user if desired.
+AM_DISTCHECK_DVI_TARGET = dvi
 distuninstallcheck_listfiles = find . -type f -print
 distuninstallcheck_listfiles = find . -type f -print
 am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
 am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
   | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
   | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
@@ -326,6 +329,7 @@ build_alias = @build_alias@
 build_asan = @build_asan@
 build_asan = @build_asan@
 build_cpu = @build_cpu@
 build_cpu = @build_cpu@
 build_os = @build_os@
 build_os = @build_os@
+build_tsan = @build_tsan@
 build_vendor = @build_vendor@
 build_vendor = @build_vendor@
 builddir = @builddir@
 builddir = @builddir@
 datadir = @datadir@
 datadir = @datadir@
@@ -362,6 +366,7 @@ prefix = @prefix@
 program_transform_name = @program_transform_name@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
 psdir = @psdir@
 rmmod = @rmmod@
 rmmod = @rmmod@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
 srcdir = @srcdir@
@@ -415,8 +420,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	    echo ' $(SHELL) ./config.status'; \
 	    echo ' $(SHELL) ./config.status'; \
 	    $(SHELL) ./config.status;; \
 	    $(SHELL) ./config.status;; \
 	  *) \
 	  *) \
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
-	    cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles);; \
 	esac;
 	esac;
 
 
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
@@ -545,7 +550,10 @@ distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 	-rm -f cscope.out cscope.in.out cscope.po.out cscope.files
 	-rm -f cscope.out cscope.in.out cscope.po.out cscope.files
 
 
-distdir: $(DISTFILES)
+distdir: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
 	$(am__remove_distdir)
 	$(am__remove_distdir)
 	test -d "$(distdir)" || mkdir "$(distdir)"
 	test -d "$(distdir)" || mkdir "$(distdir)"
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
@@ -613,7 +621,7 @@ distdir: $(DISTFILES)
 	  ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
 	  ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
 	|| chmod -R a+r "$(distdir)"
 	|| chmod -R a+r "$(distdir)"
 dist-gzip: distdir
 dist-gzip: distdir
-	tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+	tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz
 	$(am__post_remove_distdir)
 	$(am__post_remove_distdir)
 
 
 dist-bzip2: distdir
 dist-bzip2: distdir
@@ -628,6 +636,10 @@ dist-xz: distdir
 	tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
 	tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
 	$(am__post_remove_distdir)
 	$(am__post_remove_distdir)
 
 
+dist-zstd: distdir
+	tardir=$(distdir) && $(am__tar) | zstd -c $${ZSTD_CLEVEL-$${ZSTD_OPT--19}} >$(distdir).tar.zst
+	$(am__post_remove_distdir)
+
 dist-tarZ: distdir
 dist-tarZ: distdir
 	@echo WARNING: "Support for distribution archives compressed with" \
 	@echo WARNING: "Support for distribution archives compressed with" \
 		       "legacy program 'compress' is deprecated." >&2
 		       "legacy program 'compress' is deprecated." >&2
@@ -639,7 +651,7 @@ dist-shar: distdir
 	@echo WARNING: "Support for shar distribution archives is" \
 	@echo WARNING: "Support for shar distribution archives is" \
 	               "deprecated." >&2
 	               "deprecated." >&2
 	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
 	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
-	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
+	shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz
 	$(am__post_remove_distdir)
 	$(am__post_remove_distdir)
 
 
 dist-zip: distdir
 dist-zip: distdir
@@ -657,7 +669,7 @@ dist dist-all:
 distcheck: dist
 distcheck: dist
 	case '$(DIST_ARCHIVES)' in \
 	case '$(DIST_ARCHIVES)' in \
 	*.tar.gz*) \
 	*.tar.gz*) \
-	  GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\
+	  eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\
 	*.tar.bz2*) \
 	*.tar.bz2*) \
 	  bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
 	  bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
 	*.tar.lz*) \
 	*.tar.lz*) \
@@ -667,9 +679,11 @@ distcheck: dist
 	*.tar.Z*) \
 	*.tar.Z*) \
 	  uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
 	  uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
 	*.shar.gz*) \
 	*.shar.gz*) \
-	  GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\
+	  eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\
 	*.zip*) \
 	*.zip*) \
 	  unzip $(distdir).zip ;;\
 	  unzip $(distdir).zip ;;\
+	*.tar.zst*) \
+	  zstd -dc $(distdir).tar.zst | $(am__untar) ;;\
 	esac
 	esac
 	chmod -R a-w $(distdir)
 	chmod -R a-w $(distdir)
 	chmod u+w $(distdir)
 	chmod u+w $(distdir)
@@ -685,7 +699,7 @@ distcheck: dist
 	    $(DISTCHECK_CONFIGURE_FLAGS) \
 	    $(DISTCHECK_CONFIGURE_FLAGS) \
 	    --srcdir=../.. --prefix="$$dc_install_base" \
 	    --srcdir=../.. --prefix="$$dc_install_base" \
 	  && $(MAKE) $(AM_MAKEFLAGS) \
 	  && $(MAKE) $(AM_MAKEFLAGS) \
-	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
+	  && $(MAKE) $(AM_MAKEFLAGS) $(AM_DISTCHECK_DVI_TARGET) \
 	  && $(MAKE) $(AM_MAKEFLAGS) check \
 	  && $(MAKE) $(AM_MAKEFLAGS) check \
 	  && $(MAKE) $(AM_MAKEFLAGS) install \
 	  && $(MAKE) $(AM_MAKEFLAGS) install \
 	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
 	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
@@ -850,7 +864,7 @@ uninstall-am:
 	am--refresh check check-am clean clean-cscope clean-generic \
 	am--refresh check check-am clean clean-cscope clean-generic \
 	clean-libtool cscope cscopelist-am ctags ctags-am dist \
 	clean-libtool cscope cscopelist-am ctags ctags-am dist \
 	dist-all dist-bzip2 dist-gzip dist-hook dist-lzip dist-shar \
 	dist-all dist-bzip2 dist-gzip dist-hook dist-lzip dist-shar \
-	dist-tarZ dist-xz dist-zip distcheck distclean \
+	dist-tarZ dist-xz dist-zip dist-zstd distcheck distclean \
 	distclean-generic distclean-libtool distclean-local \
 	distclean-generic distclean-libtool distclean-local \
 	distclean-tags distcleancheck distdir distuninstallcheck dvi \
 	distclean-tags distcleancheck distdir distuninstallcheck dvi \
 	dvi-am html html-am info info-am install install-am \
 	dvi-am html html-am info info-am install install-am \

+ 92 - 112
aclocal.m4

@@ -1,6 +1,6 @@
-# generated automatically by aclocal 1.15 -*- Autoconf -*-
+# generated automatically by aclocal 1.16.3 -*- Autoconf -*-
 
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
 
 
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -20,7 +20,7 @@ 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.
 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-2014 Free Software Foundation, Inc.
+# Copyright (C) 2002-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -32,10 +32,10 @@ To do so, use the procedure documented by the package, typically 'autoreconf'.])
 # generated from the m4 files accompanying Automake X.Y.
 # generated from the m4 files accompanying Automake X.Y.
 # (This private macro should not be called outside this file.)
 # (This private macro should not be called outside this file.)
 AC_DEFUN([AM_AUTOMAKE_VERSION],
 AC_DEFUN([AM_AUTOMAKE_VERSION],
-[am__api_version='1.15'
+[am__api_version='1.16'
 dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
 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.
 dnl require some minimum version.  Point them to the right macro.
-m4_if([$1], [1.15], [],
+m4_if([$1], [1.16.3], [],
       [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
       [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
 ])
 ])
 
 
@@ -51,12 +51,12 @@ m4_define([_AM_AUTOCONF_VERSION], [])
 # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
 # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
 # This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
 # This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
 AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
 AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.15])dnl
+[AM_AUTOMAKE_VERSION([1.16.3])dnl
 m4_ifndef([AC_AUTOCONF_VERSION],
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
 _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
 _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
 
 
-# Copyright (C) 2011-2014 Free Software Foundation, Inc.
+# Copyright (C) 2011-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -118,7 +118,7 @@ AC_SUBST([AR])dnl
 
 
 # AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
 # AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
 
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -170,7 +170,7 @@ am_aux_dir=`cd "$ac_aux_dir" && pwd`
 
 
 # AM_CONDITIONAL                                            -*- Autoconf -*-
 # AM_CONDITIONAL                                            -*- Autoconf -*-
 
 
-# Copyright (C) 1997-2014 Free Software Foundation, Inc.
+# Copyright (C) 1997-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -201,7 +201,7 @@ AC_CONFIG_COMMANDS_PRE(
 Usually this means the macro was only invoked conditionally.]])
 Usually this means the macro was only invoked conditionally.]])
 fi])])
 fi])])
 
 
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -392,13 +392,12 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl
 
 
 # Generate code to set up dependency tracking.              -*- Autoconf -*-
 # Generate code to set up dependency tracking.              -*- Autoconf -*-
 
 
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 # with or without modifications, as long as this notice is preserved.
 
 
-
 # _AM_OUTPUT_DEPENDENCY_COMMANDS
 # _AM_OUTPUT_DEPENDENCY_COMMANDS
 # ------------------------------
 # ------------------------------
 AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
 AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
@@ -406,49 +405,43 @@ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
   # Older Autoconf quotes --file arguments for eval, but not when files
   # Older Autoconf quotes --file arguments for eval, but not when files
   # are listed without --file.  Let's play safe and only enable the eval
   # are listed without --file.  Let's play safe and only enable the eval
   # if we detect the quoting.
   # if we detect the quoting.
-  case $CONFIG_FILES in
-  *\'*) eval set x "$CONFIG_FILES" ;;
-  *)   set x $CONFIG_FILES ;;
-  esac
+  # TODO: see whether this extra hack can be removed once we start
+  # requiring Autoconf 2.70 or later.
+  AS_CASE([$CONFIG_FILES],
+          [*\'*], [eval set x "$CONFIG_FILES"],
+          [*], [set x $CONFIG_FILES])
   shift
   shift
-  for mf
+  # Used to flag and report bootstrapping failures.
+  am_rc=0
+  for am_mf
   do
   do
     # Strip MF so we end up with the name of the file.
     # 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
-    # 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.
-    # Grep'ing the whole file is not good either: AIX grep has a line
+    am_mf=`AS_ECHO(["$am_mf"]) | sed -e 's/:.*$//'`
+    # Check whether this is an Automake generated Makefile which includes
+    # dependency-tracking related rules and includes.
+    # Grep'ing the whole file directly is not great: AIX grep has a line
     # limit of 2048, but all sed's we know have understand at least 4000.
     # limit of 2048, but all sed's we know have understand at least 4000.
-    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
-      dirpart=`AS_DIRNAME("$mf")`
-    else
-      continue
-    fi
-    # Extract the definition of DEPDIR, am__include, and am__quote
-    # 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"`
-    # 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'`; do
-      # Make sure the directory exists.
-      test -f "$dirpart/$file" && continue
-      fdir=`AS_DIRNAME(["$file"])`
-      AS_MKDIR_P([$dirpart/$fdir])
-      # echo "creating $dirpart/$file"
-      echo '# dummy' > "$dirpart/$file"
-    done
+    sed -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \
+      || continue
+    am_dirpart=`AS_DIRNAME(["$am_mf"])`
+    am_filepart=`AS_BASENAME(["$am_mf"])`
+    AM_RUN_LOG([cd "$am_dirpart" \
+      && sed -e '/# am--include-marker/d' "$am_filepart" \
+        | $MAKE -f - am--depfiles]) || am_rc=$?
   done
   done
+  if test $am_rc -ne 0; then
+    AC_MSG_FAILURE([Something went wrong bootstrapping makefile fragments
+    for automatic dependency tracking.  If GNU make was not used, consider
+    re-running the configure script with MAKE="gmake" (or whatever is
+    necessary).  You can also try re-running configure with the
+    '--disable-dependency-tracking' option to at least be able to build
+    the package (albeit without support for automatic dependency tracking).])
+  fi
+  AS_UNSET([am_dirpart])
+  AS_UNSET([am_filepart])
+  AS_UNSET([am_mf])
+  AS_UNSET([am_rc])
+  rm -f conftest-deps.mk
 }
 }
 ])# _AM_OUTPUT_DEPENDENCY_COMMANDS
 ])# _AM_OUTPUT_DEPENDENCY_COMMANDS
 
 
@@ -457,17 +450,16 @@ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
 # -----------------------------
 # -----------------------------
 # This macro should only be invoked once -- use via AC_REQUIRE.
 # 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
-# need in order to bootstrap the dependency handling code.
+# This code is only required when automatic dependency tracking is enabled.
+# This creates each '.Po' and '.Plo' makefile fragment that we'll need in
+# order to bootstrap the dependency handling code.
 AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
 AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
 [AC_CONFIG_COMMANDS([depfiles],
 [AC_CONFIG_COMMANDS([depfiles],
      [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
      [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
-     [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
-])
+     [AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}"])])
 
 
 
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -491,7 +483,7 @@ fi], [AC_MSG_RESULT([no])])
 
 
 # Do all the work for Automake.                             -*- Autoconf -*-
 # Do all the work for Automake.                             -*- Autoconf -*-
 
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -578,8 +570,8 @@ AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
 AC_REQUIRE([AC_PROG_MKDIR_P])dnl
 AC_REQUIRE([AC_PROG_MKDIR_P])dnl
 # For better backward compatibility.  To be removed once Automake 1.9.x
 # For better backward compatibility.  To be removed once Automake 1.9.x
 # dies out for good.  For more background, see:
 # dies out for good.  For more background, see:
-# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
-# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
+# <https://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
+# <https://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
 AC_SUBST([mkdir_p], ['$(MKDIR_P)'])
 AC_SUBST([mkdir_p], ['$(MKDIR_P)'])
 # We need awk for the "check" target (and possibly the TAP driver).  The
 # We need awk for the "check" target (and possibly the TAP driver).  The
 # system "awk" is bad on some platforms.
 # system "awk" is bad on some platforms.
@@ -646,7 +638,7 @@ END
 Aborting the configuration process, to ensure you take notice of the issue.
 Aborting the configuration process, to ensure you take notice of the issue.
 
 
 You can download and install GNU coreutils to get an 'rm' implementation
 You can download and install GNU coreutils to get an 'rm' implementation
-that behaves properly: <http://www.gnu.org/software/coreutils/>.
+that behaves properly: <https://www.gnu.org/software/coreutils/>.
 
 
 If you want to complete the configuration process using your problematic
 If you want to complete the configuration process using your problematic
 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
@@ -688,7 +680,7 @@ for _am_header in $config_headers :; do
 done
 done
 echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
 echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
 
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -709,7 +701,7 @@ if test x"${install_sh+set}" != xset; then
 fi
 fi
 AC_SUBST([install_sh])])
 AC_SUBST([install_sh])])
 
 
-# Copyright (C) 2003-2014 Free Software Foundation, Inc.
+# Copyright (C) 2003-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -731,7 +723,7 @@ AC_SUBST([am__leading_dot])])
 # Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
 # Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
 # From Jim Meyering
 # From Jim Meyering
 
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -766,7 +758,7 @@ AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
 
 
 # Check to see how 'make' treats includes.	            -*- Autoconf -*-
 # Check to see how 'make' treats includes.	            -*- Autoconf -*-
 
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -774,49 +766,42 @@ AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
 
 
 # AM_MAKE_INCLUDE()
 # AM_MAKE_INCLUDE()
 # -----------------
 # -----------------
-# Check to see how make treats includes.
+# Check whether make has an 'include' directive that can support all
+# the idioms we need for our automatic dependency tracking code.
 AC_DEFUN([AM_MAKE_INCLUDE],
 AC_DEFUN([AM_MAKE_INCLUDE],
-[am_make=${MAKE-make}
-cat > confinc << 'END'
+[AC_MSG_CHECKING([whether ${MAKE-make} supports the include directive])
+cat > confinc.mk << 'END'
 am__doit:
 am__doit:
-	@echo this is the am__doit target
+	@echo this is the am__doit target >confinc.out
 .PHONY: am__doit
 .PHONY: am__doit
 END
 END
-# If we don't find an include directive, just comment out the code.
-AC_MSG_CHECKING([for style of include used by $am_make])
 am__include="#"
 am__include="#"
 am__quote=
 am__quote=
-_am_result=none
-# First try GNU make style include.
-echo "include confinc" > confmf
-# 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
-  am__quote=
-  _am_result=GNU
-  ;;
-esac
-# Now try BSD make style include.
-if test "$am__include" = "#"; then
-   echo '.include "confinc"' > confmf
-   case `$am_make -s -f confmf 2> /dev/null` in #(
-   *the\ am__doit\ target*)
-     am__include=.include
-     am__quote="\""
-     _am_result=BSD
-     ;;
-   esac
-fi
-AC_SUBST([am__include])
-AC_SUBST([am__quote])
-AC_MSG_RESULT([$_am_result])
-rm -f confinc confmf
-])
+# BSD make does it like this.
+echo '.include "confinc.mk" # ignored' > confmf.BSD
+# Other make implementations (GNU, Solaris 10, AIX) do it like this.
+echo 'include confinc.mk # ignored' > confmf.GNU
+_am_result=no
+for s in GNU BSD; do
+  AM_RUN_LOG([${MAKE-make} -f confmf.$s && cat confinc.out])
+  AS_CASE([$?:`cat confinc.out 2>/dev/null`],
+      ['0:this is the am__doit target'],
+      [AS_CASE([$s],
+          [BSD], [am__include='.include' am__quote='"'],
+          [am__include='include' am__quote=''])])
+  if test "$am__include" != "#"; then
+    _am_result="yes ($s style)"
+    break
+  fi
+done
+rm -f confinc.* confmf.*
+AC_MSG_RESULT([${_am_result}])
+AC_SUBST([am__include])])
+AC_SUBST([am__quote])])
 
 
 # Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
 # Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
 
 
-# Copyright (C) 1997-2014 Free Software Foundation, Inc.
+# Copyright (C) 1997-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -837,12 +822,7 @@ AC_DEFUN([AM_MISSING_HAS_RUN],
 [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
 [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
 AC_REQUIRE_AUX_FILE([missing])dnl
 AC_REQUIRE_AUX_FILE([missing])dnl
 if test x"${MISSING+set}" != xset; then
 if test x"${MISSING+set}" != xset; then
-  case $am_aux_dir in
-  *\ * | *\	*)
-    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
-  *)
-    MISSING="\${SHELL} $am_aux_dir/missing" ;;
-  esac
+  MISSING="\${SHELL} '$am_aux_dir/missing'"
 fi
 fi
 # Use eval to expand $SHELL
 # Use eval to expand $SHELL
 if eval "$MISSING --is-lightweight"; then
 if eval "$MISSING --is-lightweight"; then
@@ -855,7 +835,7 @@ fi
 
 
 # Helper functions for option handling.                     -*- Autoconf -*-
 # Helper functions for option handling.                     -*- Autoconf -*-
 
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -884,7 +864,7 @@ AC_DEFUN([_AM_SET_OPTIONS],
 AC_DEFUN([_AM_IF_OPTION],
 AC_DEFUN([_AM_IF_OPTION],
 [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
 [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
 
 
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -931,7 +911,7 @@ AC_LANG_POP([C])])
 # For backward compatibility.
 # For backward compatibility.
 AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
 AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
 
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -950,7 +930,7 @@ AC_DEFUN([AM_RUN_LOG],
 
 
 # Check to make sure that the build environment is sane.    -*- Autoconf -*-
 # Check to make sure that the build environment is sane.    -*- Autoconf -*-
 
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -1031,7 +1011,7 @@ AC_CONFIG_COMMANDS_PRE(
 rm -f conftest.file
 rm -f conftest.file
 ])
 ])
 
 
-# Copyright (C) 2009-2014 Free Software Foundation, Inc.
+# Copyright (C) 2009-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -1091,7 +1071,7 @@ AC_SUBST([AM_BACKSLASH])dnl
 _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
 _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
 ])
 ])
 
 
-# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -1119,7 +1099,7 @@ fi
 INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
 INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
 AC_SUBST([INSTALL_STRIP_PROGRAM])])
 AC_SUBST([INSTALL_STRIP_PROGRAM])])
 
 
-# Copyright (C) 2006-2014 Free Software Foundation, Inc.
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -1138,7 +1118,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
 
 
 # Check how to create a tarball.                            -*- Autoconf -*-
 # Check how to create a tarball.                            -*- Autoconf -*-
 
 
-# Copyright (C) 2004-2014 Free Software Foundation, Inc.
+# Copyright (C) 2004-2020 Free Software Foundation, Inc.
 #
 #
 # This file is free software; the Free Software Foundation
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,

+ 10 - 9
config/ar-lib

@@ -2,9 +2,9 @@
 # Wrapper for Microsoft lib.exe
 # Wrapper for Microsoft lib.exe
 
 
 me=ar-lib
 me=ar-lib
-scriptversion=2012-03-01.08; # UTC
+scriptversion=2019-07-04.01; # UTC
 
 
-# Copyright (C) 2010-2014 Free Software Foundation, Inc.
+# Copyright (C) 2010-2020 Free Software Foundation, Inc.
 # Written by Peter Rosin <peda@lysator.liu.se>.
 # Written by Peter Rosin <peda@lysator.liu.se>.
 #
 #
 # This program is free software; you can redistribute it and/or modify
 # This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,7 @@ scriptversion=2012-03-01.08; # UTC
 # GNU General Public License for more details.
 # GNU General Public License for more details.
 #
 #
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 
 # As a special exception to the GNU General Public License, if you
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # distribute this file as part of a program that contains a
@@ -53,7 +53,7 @@ func_file_conv ()
 	  MINGW*)
 	  MINGW*)
 	    file_conv=mingw
 	    file_conv=mingw
 	    ;;
 	    ;;
-	  CYGWIN*)
+	  CYGWIN* | MSYS*)
 	    file_conv=cygwin
 	    file_conv=cygwin
 	    ;;
 	    ;;
 	  *)
 	  *)
@@ -65,7 +65,7 @@ func_file_conv ()
 	mingw)
 	mingw)
 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
 	  ;;
 	  ;;
-	cygwin)
+	cygwin | msys)
 	  file=`cygpath -m "$file" || echo "$file"`
 	  file=`cygpath -m "$file" || echo "$file"`
 	  ;;
 	  ;;
 	wine)
 	wine)
@@ -224,10 +224,11 @@ elif test -n "$extract"; then
       esac
       esac
     done
     done
   else
   else
-    $AR -NOLOGO -LIST "$archive" | sed -e 's/\\/\\\\/g' | while read member
-    do
-      $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
-    done
+    $AR -NOLOGO -LIST "$archive" | tr -d '\r' | sed -e 's/\\/\\\\/g' \
+      | while read member
+        do
+          $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
+        done
   fi
   fi
 
 
 elif test -n "$quick$replace"; then
 elif test -n "$quick$replace"; then

+ 9 - 8
config/compile

@@ -1,9 +1,9 @@
 #! /bin/sh
 #! /bin/sh
 # Wrapper for compilers which do not understand '-c -o'.
 # Wrapper for compilers which do not understand '-c -o'.
 
 
-scriptversion=2012-10-14.11; # UTC
+scriptversion=2018-03-07.03; # UTC
 
 
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
 # Written by Tom Tromey <tromey@cygnus.com>.
 # Written by Tom Tromey <tromey@cygnus.com>.
 #
 #
 # This program is free software; you can redistribute it and/or modify
 # This program is free software; you can redistribute it and/or modify
@@ -17,7 +17,7 @@ scriptversion=2012-10-14.11; # UTC
 # GNU General Public License for more details.
 # GNU General Public License for more details.
 #
 #
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 
 # As a special exception to the GNU General Public License, if you
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # distribute this file as part of a program that contains a
@@ -53,7 +53,7 @@ func_file_conv ()
 	  MINGW*)
 	  MINGW*)
 	    file_conv=mingw
 	    file_conv=mingw
 	    ;;
 	    ;;
-	  CYGWIN*)
+	  CYGWIN* | MSYS*)
 	    file_conv=cygwin
 	    file_conv=cygwin
 	    ;;
 	    ;;
 	  *)
 	  *)
@@ -67,7 +67,7 @@ func_file_conv ()
 	mingw/*)
 	mingw/*)
 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
 	  ;;
 	  ;;
-	cygwin/*)
+	cygwin/* | msys/*)
 	  file=`cygpath -m "$file" || echo "$file"`
 	  file=`cygpath -m "$file" || echo "$file"`
 	  ;;
 	  ;;
 	wine/*)
 	wine/*)
@@ -255,7 +255,8 @@ EOF
     echo "compile $scriptversion"
     echo "compile $scriptversion"
     exit $?
     exit $?
     ;;
     ;;
-  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
+  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
+  icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
     func_cl_wrapper "$@"      # Doesn't return...
     func_cl_wrapper "$@"      # Doesn't return...
     ;;
     ;;
 esac
 esac
@@ -339,9 +340,9 @@ exit $ret
 # Local Variables:
 # Local Variables:
 # mode: shell-script
 # mode: shell-script
 # sh-indentation: 2
 # sh-indentation: 2
-# eval: (add-hook 'write-file-hooks 'time-stamp)
+# eval: (add-hook 'before-save-hook 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
+# time-stamp-time-zone: "UTC0"
 # time-stamp-end: "; # UTC"
 # time-stamp-end: "; # UTC"
 # End:
 # End:

File diff suppressed because it is too large
+ 371 - 312
config/config.guess


+ 148 - 154
config/config.sub

@@ -1,8 +1,8 @@
 #! /bin/sh
 #! /bin/sh
 # Configuration validation subroutine script.
 # Configuration validation subroutine script.
-#   Copyright 1992-2014 Free Software Foundation, Inc.
+#   Copyright 1992-2018 Free Software Foundation, Inc.
 
 
-timestamp='2014-12-03'
+timestamp='2018-02-22'
 
 
 # This file is free software; you can redistribute it and/or modify it
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
 # under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@ timestamp='2014-12-03'
 # General Public License for more details.
 # General Public License for more details.
 #
 #
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, see <http://www.gnu.org/licenses/>.
+# along with this program; if not, see <https://www.gnu.org/licenses/>.
 #
 #
 # As a special exception to the GNU General Public License, if you
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # distribute this file as part of a program that contains a
@@ -33,7 +33,7 @@ timestamp='2014-12-03'
 # Otherwise, we print the canonical config type on stdout and succeed.
 # Otherwise, we print the canonical config type on stdout and succeed.
 
 
 # You can get the latest version of this script from:
 # You can get the latest version of this script from:
-# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
 
 
 # This file is supposed to be the same for all GNU packages
 # This file is supposed to be the same for all GNU packages
 # and recognize all the CPU types, system types and aliases
 # and recognize all the CPU types, system types and aliases
@@ -53,12 +53,11 @@ timestamp='2014-12-03'
 me=`echo "$0" | sed -e 's,.*/,,'`
 me=`echo "$0" | sed -e 's,.*/,,'`
 
 
 usage="\
 usage="\
-Usage: $0 [OPTION] CPU-MFR-OPSYS
-       $0 [OPTION] ALIAS
+Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS
 
 
 Canonicalize a configuration name.
 Canonicalize a configuration name.
 
 
-Operation modes:
+Options:
   -h, --help         print this help, then exit
   -h, --help         print this help, then exit
   -t, --time-stamp   print date of last modification, then exit
   -t, --time-stamp   print date of last modification, then exit
   -v, --version      print version number, then exit
   -v, --version      print version number, then exit
@@ -68,7 +67,7 @@ Report bugs and patches to <config-patches@gnu.org>."
 version="\
 version="\
 GNU config.sub ($timestamp)
 GNU config.sub ($timestamp)
 
 
-Copyright 1992-2014 Free Software Foundation, Inc.
+Copyright 1992-2018 Free Software Foundation, Inc.
 
 
 This is free software; see the source for copying conditions.  There is NO
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -95,7 +94,7 @@ while test $# -gt 0 ; do
 
 
     *local*)
     *local*)
        # First pass through any local machine types.
        # First pass through any local machine types.
-       echo $1
+       echo "$1"
        exit ;;
        exit ;;
 
 
     * )
     * )
@@ -113,24 +112,24 @@ esac
 
 
 # Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
 # Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
 # Here we must recognize all the valid KERNEL-OS combinations.
 # Here we must recognize all the valid KERNEL-OS combinations.
-maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+maybe_os=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
 case $maybe_os in
 case $maybe_os in
   nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
   nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
   linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
   linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
-  knetbsd*-gnu* | netbsd*-gnu* | \
-  kopensolaris*-gnu* | \
+  knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \
+  kopensolaris*-gnu* | cloudabi*-eabi* | \
   storm-chaos* | os2-emx* | rtmk-nova*)
   storm-chaos* | os2-emx* | rtmk-nova*)
     os=-$maybe_os
     os=-$maybe_os
-    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+    basic_machine=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
     ;;
     ;;
   android-linux)
   android-linux)
     os=-linux-android
     os=-linux-android
-    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
+    basic_machine=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
     ;;
     ;;
   *)
   *)
-    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
-    if [ $basic_machine != $1 ]
-    then os=`echo $1 | sed 's/.*-/-/'`
+    basic_machine=`echo "$1" | sed 's/-[^-]*$//'`
+    if [ "$basic_machine" != "$1" ]
+    then os=`echo "$1" | sed 's/.*-/-/'`
     else os=; fi
     else os=; fi
     ;;
     ;;
 esac
 esac
@@ -179,44 +178,44 @@ case $os in
 		;;
 		;;
 	-sco6)
 	-sco6)
 		os=-sco5v6
 		os=-sco5v6
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
 		;;
 		;;
 	-sco5)
 	-sco5)
 		os=-sco3.2v5
 		os=-sco3.2v5
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
 		;;
 		;;
 	-sco4)
 	-sco4)
 		os=-sco3.2v4
 		os=-sco3.2v4
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
 		;;
 		;;
 	-sco3.2.[4-9]*)
 	-sco3.2.[4-9]*)
 		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
 		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
 		;;
 		;;
 	-sco3.2v[4-9]*)
 	-sco3.2v[4-9]*)
 		# Don't forget version if it is 3.2v4 or newer.
 		# Don't forget version if it is 3.2v4 or newer.
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
 		;;
 		;;
 	-sco5v6*)
 	-sco5v6*)
 		# Don't forget version if it is 3.2v4 or newer.
 		# Don't forget version if it is 3.2v4 or newer.
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
 		;;
 		;;
 	-sco*)
 	-sco*)
 		os=-sco3.2v2
 		os=-sco3.2v2
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
 		;;
 		;;
 	-udk*)
 	-udk*)
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
 		;;
 		;;
 	-isc)
 	-isc)
 		os=-isc2.2
 		os=-isc2.2
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
 		;;
 		;;
 	-clix*)
 	-clix*)
 		basic_machine=clipper-intergraph
 		basic_machine=clipper-intergraph
 		;;
 		;;
 	-isc*)
 	-isc*)
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
 		;;
 		;;
 	-lynx*178)
 	-lynx*178)
 		os=-lynxos178
 		os=-lynxos178
@@ -228,10 +227,7 @@ case $os in
 		os=-lynxos
 		os=-lynxos
 		;;
 		;;
 	-ptx*)
 	-ptx*)
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
-		;;
-	-windowsnt*)
-		os=`echo $os | sed -e 's/windowsnt/winnt/'`
+		basic_machine=`echo "$1" | sed -e 's/86-.*/86-sequent/'`
 		;;
 		;;
 	-psos*)
 	-psos*)
 		os=-psos
 		os=-psos
@@ -255,15 +251,16 @@ case $basic_machine in
 	| arc | arceb \
 	| arc | arceb \
 	| arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
 	| arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
 	| avr | avr32 \
 	| avr | avr32 \
+	| ba \
 	| be32 | be64 \
 	| be32 | be64 \
 	| bfin \
 	| bfin \
 	| c4x | c8051 | clipper \
 	| c4x | c8051 | clipper \
 	| d10v | d30v | dlx | dsp16xx \
 	| d10v | d30v | dlx | dsp16xx \
-	| epiphany \
-	| fido | fr30 | frv \
+	| e2k | epiphany \
+	| fido | fr30 | frv | ft32 \
 	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
 	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
 	| hexagon \
 	| hexagon \
-	| i370 | i860 | i960 | ia64 \
+	| i370 | i860 | i960 | ia16 | ia64 \
 	| ip2k | iq2000 \
 	| ip2k | iq2000 \
 	| k1om \
 	| k1om \
 	| le32 | le64 \
 	| le32 | le64 \
@@ -299,13 +296,14 @@ case $basic_machine in
 	| nios | nios2 | nios2eb | nios2el \
 	| nios | nios2 | nios2eb | nios2el \
 	| ns16k | ns32k \
 	| ns16k | ns32k \
 	| open8 | or1k | or1knd | or32 \
 	| open8 | or1k | or1knd | or32 \
-	| pdp10 | pdp11 | pj | pjl \
+	| pdp10 | pj | pjl \
 	| powerpc | powerpc64 | powerpc64le | powerpcle \
 	| powerpc | powerpc64 | powerpc64le | powerpcle \
+	| pru \
 	| pyramid \
 	| pyramid \
 	| riscv32 | riscv64 \
 	| riscv32 | riscv64 \
 	| rl78 | rx \
 	| rl78 | rx \
 	| score \
 	| score \
-	| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+	| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
 	| sh64 | sh64le \
 	| sh64 | sh64le \
 	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
 	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
 	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
 	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
@@ -314,7 +312,7 @@ case $basic_machine in
 	| ubicom32 \
 	| ubicom32 \
 	| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
 	| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
 	| visium \
 	| visium \
-	| we32k \
+	| wasm32 \
 	| x86 | xc16x | xstormy16 | xtensa \
 	| x86 | xc16x | xstormy16 | xtensa \
 	| z8k | z80)
 	| z8k | z80)
 		basic_machine=$basic_machine-unknown
 		basic_machine=$basic_machine-unknown
@@ -335,7 +333,7 @@ case $basic_machine in
 		basic_machine=$basic_machine-unknown
 		basic_machine=$basic_machine-unknown
 		os=-none
 		os=-none
 		;;
 		;;
-	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
+	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65)
 		;;
 		;;
 	ms1)
 	ms1)
 		basic_machine=mt-unknown
 		basic_machine=mt-unknown
@@ -364,7 +362,7 @@ case $basic_machine in
 	  ;;
 	  ;;
 	# Object if more than one company name word.
 	# Object if more than one company name word.
 	*-*-*)
 	*-*-*)
-		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		echo Invalid configuration \`"$1"\': machine \`"$basic_machine"\' not recognized 1>&2
 		exit 1
 		exit 1
 		;;
 		;;
 	# Recognize the basic CPU types with company name.
 	# Recognize the basic CPU types with company name.
@@ -376,17 +374,18 @@ case $basic_machine in
 	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
 	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
 	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
 	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
 	| avr-* | avr32-* \
 	| avr-* | avr32-* \
+	| ba-* \
 	| be32-* | be64-* \
 	| be32-* | be64-* \
 	| bfin-* | bs2000-* \
 	| bfin-* | bs2000-* \
 	| c[123]* | c30-* | [cjt]90-* | c4x-* \
 	| c[123]* | c30-* | [cjt]90-* | c4x-* \
 	| c8051-* | clipper-* | craynv-* | cydra-* \
 	| c8051-* | clipper-* | craynv-* | cydra-* \
 	| d10v-* | d30v-* | dlx-* \
 	| d10v-* | d30v-* | dlx-* \
-	| elxsi-* \
+	| e2k-* | elxsi-* \
 	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
 	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
 	| h8300-* | h8500-* \
 	| h8300-* | h8500-* \
 	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
 	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
 	| hexagon-* \
 	| hexagon-* \
-	| i*86-* | i860-* | i960-* | ia64-* \
+	| i*86-* | i860-* | i960-* | ia16-* | ia64-* \
 	| ip2k-* | iq2000-* \
 	| ip2k-* | iq2000-* \
 	| k1om-* \
 	| k1om-* \
 	| le32-* | le64-* \
 	| le32-* | le64-* \
@@ -427,13 +426,15 @@ case $basic_machine in
 	| orion-* \
 	| orion-* \
 	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
 	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
 	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
 	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
+	| pru-* \
 	| pyramid-* \
 	| pyramid-* \
+	| riscv32-* | riscv64-* \
 	| rl78-* | romp-* | rs6000-* | rx-* \
 	| rl78-* | romp-* | rs6000-* | rx-* \
 	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
 	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
 	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
 	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
 	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
 	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
 	| sparclite-* \
 	| sparclite-* \
-	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \
 	| tahoe-* \
 	| tahoe-* \
 	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
 	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
 	| tile*-* \
 	| tile*-* \
@@ -442,6 +443,7 @@ case $basic_machine in
 	| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
 	| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
 	| vax-* \
 	| vax-* \
 	| visium-* \
 	| visium-* \
+	| wasm32-* \
 	| we32k-* \
 	| we32k-* \
 	| x86-* | x86_64-* | xc16x-* | xps100-* \
 	| x86-* | x86_64-* | xc16x-* | xps100-* \
 	| xstormy16-* | xtensa*-* \
 	| xstormy16-* | xtensa*-* \
@@ -455,7 +457,7 @@ case $basic_machine in
 	# Recognize the various machine names and aliases which stand
 	# Recognize the various machine names and aliases which stand
 	# for a CPU type and a company and sometimes even an OS.
 	# for a CPU type and a company and sometimes even an OS.
 	386bsd)
 	386bsd)
-		basic_machine=i386-unknown
+		basic_machine=i386-pc
 		os=-bsd
 		os=-bsd
 		;;
 		;;
 	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
 	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
@@ -489,7 +491,7 @@ case $basic_machine in
 		basic_machine=x86_64-pc
 		basic_machine=x86_64-pc
 		;;
 		;;
 	amd64-*)
 	amd64-*)
-		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=x86_64-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	amdahl)
 	amdahl)
 		basic_machine=580-amdahl
 		basic_machine=580-amdahl
@@ -518,6 +520,9 @@ case $basic_machine in
 		basic_machine=i386-pc
 		basic_machine=i386-pc
 		os=-aros
 		os=-aros
 		;;
 		;;
+	asmjs)
+		basic_machine=asmjs-unknown
+		;;
 	aux)
 	aux)
 		basic_machine=m68k-apple
 		basic_machine=m68k-apple
 		os=-aux
 		os=-aux
@@ -531,7 +536,7 @@ case $basic_machine in
 		os=-linux
 		os=-linux
 		;;
 		;;
 	blackfin-*)
 	blackfin-*)
-		basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=bfin-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		os=-linux
 		os=-linux
 		;;
 		;;
 	bluegene*)
 	bluegene*)
@@ -539,13 +544,13 @@ case $basic_machine in
 		os=-cnk
 		os=-cnk
 		;;
 		;;
 	c54x-*)
 	c54x-*)
-		basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=tic54x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	c55x-*)
 	c55x-*)
-		basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=tic55x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	c6x-*)
 	c6x-*)
-		basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=tic6x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	c90)
 	c90)
 		basic_machine=c90-cray
 		basic_machine=c90-cray
@@ -634,10 +639,18 @@ case $basic_machine in
 		basic_machine=rs6000-bull
 		basic_machine=rs6000-bull
 		os=-bosx
 		os=-bosx
 		;;
 		;;
-	dpx2* | dpx2*-bull)
+	dpx2*)
 		basic_machine=m68k-bull
 		basic_machine=m68k-bull
 		os=-sysv3
 		os=-sysv3
 		;;
 		;;
+	e500v[12])
+		basic_machine=powerpc-unknown
+		os=$os"spe"
+		;;
+	e500v[12]-*)
+		basic_machine=powerpc-`echo "$basic_machine" | sed 's/^[^-]*-//'`
+		os=$os"spe"
+		;;
 	ebmon29k)
 	ebmon29k)
 		basic_machine=a29k-amd
 		basic_machine=a29k-amd
 		os=-ebmon
 		os=-ebmon
@@ -727,9 +740,6 @@ case $basic_machine in
 	hp9k8[0-9][0-9] | hp8[0-9][0-9])
 	hp9k8[0-9][0-9] | hp8[0-9][0-9])
 		basic_machine=hppa1.0-hp
 		basic_machine=hppa1.0-hp
 		;;
 		;;
-	hppa-next)
-		os=-nextstep3
-		;;
 	hppaosf)
 	hppaosf)
 		basic_machine=hppa1.1-hp
 		basic_machine=hppa1.1-hp
 		os=-osf
 		os=-osf
@@ -742,26 +752,26 @@ case $basic_machine in
 		basic_machine=i370-ibm
 		basic_machine=i370-ibm
 		;;
 		;;
 	i*86v32)
 	i*86v32)
-		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
 		os=-sysv32
 		os=-sysv32
 		;;
 		;;
 	i*86v4*)
 	i*86v4*)
-		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
 		os=-sysv4
 		os=-sysv4
 		;;
 		;;
 	i*86v)
 	i*86v)
-		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
 		os=-sysv
 		os=-sysv
 		;;
 		;;
 	i*86sol2)
 	i*86sol2)
-		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
 		os=-solaris2
 		os=-solaris2
 		;;
 		;;
 	i386mach)
 	i386mach)
 		basic_machine=i386-mach
 		basic_machine=i386-mach
 		os=-mach
 		os=-mach
 		;;
 		;;
-	i386-vsta | vsta)
+	vsta)
 		basic_machine=i386-unknown
 		basic_machine=i386-unknown
 		os=-vsta
 		os=-vsta
 		;;
 		;;
@@ -780,19 +790,16 @@ case $basic_machine in
 		os=-sysv
 		os=-sysv
 		;;
 		;;
 	leon-*|leon[3-9]-*)
 	leon-*|leon[3-9]-*)
-		basic_machine=sparc-`echo $basic_machine | sed 's/-.*//'`
+		basic_machine=sparc-`echo "$basic_machine" | sed 's/-.*//'`
 		;;
 		;;
 	m68knommu)
 	m68knommu)
 		basic_machine=m68k-unknown
 		basic_machine=m68k-unknown
 		os=-linux
 		os=-linux
 		;;
 		;;
 	m68knommu-*)
 	m68knommu-*)
-		basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=m68k-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		os=-linux
 		os=-linux
 		;;
 		;;
-	m88k-omron*)
-		basic_machine=m88k-omron
-		;;
 	magnum | m3230)
 	magnum | m3230)
 		basic_machine=mips-mips
 		basic_machine=mips-mips
 		os=-sysv
 		os=-sysv
@@ -824,10 +831,10 @@ case $basic_machine in
 		os=-mint
 		os=-mint
 		;;
 		;;
 	mips3*-*)
 	mips3*-*)
-		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+		basic_machine=`echo "$basic_machine" | sed -e 's/mips3/mips64/'`
 		;;
 		;;
 	mips3*)
 	mips3*)
-		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+		basic_machine=`echo "$basic_machine" | sed -e 's/mips3/mips64/'`-unknown
 		;;
 		;;
 	monitor)
 	monitor)
 		basic_machine=m68k-rom68k
 		basic_machine=m68k-rom68k
@@ -846,7 +853,7 @@ case $basic_machine in
 		os=-msdos
 		os=-msdos
 		;;
 		;;
 	ms1-*)
 	ms1-*)
-		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+		basic_machine=`echo "$basic_machine" | sed -e 's/ms1-/mt-/'`
 		;;
 		;;
 	msys)
 	msys)
 		basic_machine=i686-pc
 		basic_machine=i686-pc
@@ -888,7 +895,7 @@ case $basic_machine in
 		basic_machine=v70-nec
 		basic_machine=v70-nec
 		os=-sysv
 		os=-sysv
 		;;
 		;;
-	next | m*-next )
+	next | m*-next)
 		basic_machine=m68k-next
 		basic_machine=m68k-next
 		case $os in
 		case $os in
 		    -nextstep* )
 		    -nextstep* )
@@ -933,6 +940,12 @@ case $basic_machine in
 	nsr-tandem)
 	nsr-tandem)
 		basic_machine=nsr-tandem
 		basic_machine=nsr-tandem
 		;;
 		;;
+	nsv-tandem)
+		basic_machine=nsv-tandem
+		;;
+	nsx-tandem)
+		basic_machine=nsx-tandem
+		;;
 	op50n-* | op60c-*)
 	op50n-* | op60c-*)
 		basic_machine=hppa1.1-oki
 		basic_machine=hppa1.1-oki
 		os=-proelf
 		os=-proelf
@@ -965,7 +978,7 @@ case $basic_machine in
 		os=-linux
 		os=-linux
 		;;
 		;;
 	parisc-*)
 	parisc-*)
-		basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=hppa-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		os=-linux
 		os=-linux
 		;;
 		;;
 	pbd)
 	pbd)
@@ -981,7 +994,7 @@ case $basic_machine in
 		basic_machine=i386-pc
 		basic_machine=i386-pc
 		;;
 		;;
 	pc98-*)
 	pc98-*)
-		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=i386-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	pentium | p5 | k5 | k6 | nexgen | viac3)
 	pentium | p5 | k5 | k6 | nexgen | viac3)
 		basic_machine=i586-pc
 		basic_machine=i586-pc
@@ -996,16 +1009,16 @@ case $basic_machine in
 		basic_machine=i786-pc
 		basic_machine=i786-pc
 		;;
 		;;
 	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
 	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
-		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=i586-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	pentiumpro-* | p6-* | 6x86-* | athlon-*)
 	pentiumpro-* | p6-* | 6x86-* | athlon-*)
-		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=i686-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
 	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
-		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=i686-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	pentium4-*)
 	pentium4-*)
-		basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=i786-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	pn)
 	pn)
 		basic_machine=pn-gould
 		basic_machine=pn-gould
@@ -1015,23 +1028,23 @@ case $basic_machine in
 	ppc | ppcbe)	basic_machine=powerpc-unknown
 	ppc | ppcbe)	basic_machine=powerpc-unknown
 		;;
 		;;
 	ppc-* | ppcbe-*)
 	ppc-* | ppcbe-*)
-		basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=powerpc-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
-	ppcle | powerpclittle | ppc-le | powerpc-little)
+	ppcle | powerpclittle)
 		basic_machine=powerpcle-unknown
 		basic_machine=powerpcle-unknown
 		;;
 		;;
 	ppcle-* | powerpclittle-*)
 	ppcle-* | powerpclittle-*)
-		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=powerpcle-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	ppc64)	basic_machine=powerpc64-unknown
 	ppc64)	basic_machine=powerpc64-unknown
 		;;
 		;;
-	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
+	ppc64-*) basic_machine=powerpc64-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
-	ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+	ppc64le | powerpc64little)
 		basic_machine=powerpc64le-unknown
 		basic_machine=powerpc64le-unknown
 		;;
 		;;
 	ppc64le-* | powerpc64little-*)
 	ppc64le-* | powerpc64little-*)
-		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=powerpc64le-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	ps2)
 	ps2)
 		basic_machine=i386-ibm
 		basic_machine=i386-ibm
@@ -1085,17 +1098,10 @@ case $basic_machine in
 	sequent)
 	sequent)
 		basic_machine=i386-sequent
 		basic_machine=i386-sequent
 		;;
 		;;
-	sh)
-		basic_machine=sh-hitachi
-		os=-hms
-		;;
 	sh5el)
 	sh5el)
 		basic_machine=sh5le-unknown
 		basic_machine=sh5le-unknown
 		;;
 		;;
-	sh64)
-		basic_machine=sh64-unknown
-		;;
-	sparclite-wrs | simso-wrs)
+	simso-wrs)
 		basic_machine=sparclite-wrs
 		basic_machine=sparclite-wrs
 		os=-vxworks
 		os=-vxworks
 		;;
 		;;
@@ -1114,7 +1120,7 @@ case $basic_machine in
 		os=-sysv4
 		os=-sysv4
 		;;
 		;;
 	strongarm-* | thumb-*)
 	strongarm-* | thumb-*)
-		basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
+		basic_machine=arm-`echo "$basic_machine" | sed 's/^[^-]*-//'`
 		;;
 		;;
 	sun2)
 	sun2)
 		basic_machine=m68000-sun
 		basic_machine=m68000-sun
@@ -1236,6 +1242,9 @@ case $basic_machine in
 		basic_machine=hppa1.1-winbond
 		basic_machine=hppa1.1-winbond
 		os=-proelf
 		os=-proelf
 		;;
 		;;
+	x64)
+		basic_machine=x86_64-pc
+		;;
 	xbox)
 	xbox)
 		basic_machine=i686-pc
 		basic_machine=i686-pc
 		os=-mingw32
 		os=-mingw32
@@ -1244,20 +1253,12 @@ case $basic_machine in
 		basic_machine=xps100-honeywell
 		basic_machine=xps100-honeywell
 		;;
 		;;
 	xscale-* | xscalee[bl]-*)
 	xscale-* | xscalee[bl]-*)
-		basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
+		basic_machine=`echo "$basic_machine" | sed 's/^xscale/arm/'`
 		;;
 		;;
 	ymp)
 	ymp)
 		basic_machine=ymp-cray
 		basic_machine=ymp-cray
 		os=-unicos
 		os=-unicos
 		;;
 		;;
-	z8k-*-coff)
-		basic_machine=z8k-unknown
-		os=-sim
-		;;
-	z80-*-coff)
-		basic_machine=z80-unknown
-		os=-sim
-		;;
 	none)
 	none)
 		basic_machine=none-none
 		basic_machine=none-none
 		os=-none
 		os=-none
@@ -1286,10 +1287,6 @@ case $basic_machine in
 	vax)
 	vax)
 		basic_machine=vax-dec
 		basic_machine=vax-dec
 		;;
 		;;
-	pdp10)
-		# there are many clones, so DEC is not a safe bet
-		basic_machine=pdp10-unknown
-		;;
 	pdp11)
 	pdp11)
 		basic_machine=pdp11-dec
 		basic_machine=pdp11-dec
 		;;
 		;;
@@ -1299,9 +1296,6 @@ case $basic_machine in
 	sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
 	sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
 		basic_machine=sh-unknown
 		basic_machine=sh-unknown
 		;;
 		;;
-	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
-		basic_machine=sparc-sun
-		;;
 	cydra)
 	cydra)
 		basic_machine=cydra-cydrome
 		basic_machine=cydra-cydrome
 		;;
 		;;
@@ -1321,7 +1315,7 @@ case $basic_machine in
 		# Make sure to match an already-canonicalized machine name.
 		# Make sure to match an already-canonicalized machine name.
 		;;
 		;;
 	*)
 	*)
-		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		echo Invalid configuration \`"$1"\': machine \`"$basic_machine"\' not recognized 1>&2
 		exit 1
 		exit 1
 		;;
 		;;
 esac
 esac
@@ -1329,10 +1323,10 @@ esac
 # Here we canonicalize certain aliases for manufacturers.
 # Here we canonicalize certain aliases for manufacturers.
 case $basic_machine in
 case $basic_machine in
 	*-digital*)
 	*-digital*)
-		basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+		basic_machine=`echo "$basic_machine" | sed 's/digital.*/dec/'`
 		;;
 		;;
 	*-commodore*)
 	*-commodore*)
-		basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+		basic_machine=`echo "$basic_machine" | sed 's/commodore.*/cbm/'`
 		;;
 		;;
 	*)
 	*)
 		;;
 		;;
@@ -1343,8 +1337,8 @@ esac
 if [ x"$os" != x"" ]
 if [ x"$os" != x"" ]
 then
 then
 case $os in
 case $os in
-	# First match some system type aliases
-	# that might get confused with valid system types.
+	# First match some system type aliases that might get confused
+	# with valid system types.
 	# -solaris* is a basic system type, with this one exception.
 	# -solaris* is a basic system type, with this one exception.
 	-auroraux)
 	-auroraux)
 		os=-auroraux
 		os=-auroraux
@@ -1355,45 +1349,48 @@ case $os in
 	-solaris)
 	-solaris)
 		os=-solaris2
 		os=-solaris2
 		;;
 		;;
-	-svr4*)
-		os=-sysv4
-		;;
 	-unixware*)
 	-unixware*)
 		os=-sysv4.2uw
 		os=-sysv4.2uw
 		;;
 		;;
 	-gnu/linux*)
 	-gnu/linux*)
 		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
 		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
 		;;
 		;;
-	# First accept the basic system types.
+	# es1800 is here to avoid being matched by es* (a different OS)
+	-es1800*)
+		os=-ose
+		;;
+	# Now accept the basic system types.
 	# The portable systems comes first.
 	# The portable systems comes first.
-	# Each alternative MUST END IN A *, to match a version number.
+	# Each alternative MUST end in a * to match a version number.
 	# -sysv* is not here because it comes later, after sysvr4.
 	# -sysv* is not here because it comes later, after sysvr4.
 	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
 	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
 	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
 	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
 	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
 	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
 	      | -sym* | -kopensolaris* | -plan9* \
 	      | -sym* | -kopensolaris* | -plan9* \
 	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
 	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
-	      | -aos* | -aros* \
+	      | -aos* | -aros* | -cloudabi* | -sortix* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
-	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
-	      | -bitrig* | -openbsd* | -solidbsd* \
+	      | -hiux* | -knetbsd* | -mirbsd* | -netbsd* \
+	      | -bitrig* | -openbsd* | -solidbsd* | -libertybsd* \
 	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
 	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
 	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
 	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
 	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
 	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
-	      | -chorusos* | -chorusrdb* | -cegcc* \
+	      | -chorusos* | -chorusrdb* | -cegcc* | -glidix* \
 	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
 	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
-	      | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
+	      | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
 	      | -linux-newlib* | -linux-musl* | -linux-uclibc* \
 	      | -linux-newlib* | -linux-musl* | -linux-uclibc* \
 	      | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
 	      | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
-	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* \
 	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
 	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
 	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
 	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
 	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
 	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
-	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+	      | -morphos* | -superux* | -rtmk* | -windiss* \
 	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
 	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
-	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*)
+	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \
+	      | -onefs* | -tirtos* | -phoenix* | -fuchsia* | -redox* | -bme* \
+	      | -midnightbsd*)
 	# Remember, each alternative MUST END IN *, to match a version number.
 	# Remember, each alternative MUST END IN *, to match a version number.
 		;;
 		;;
 	-qnx*)
 	-qnx*)
@@ -1410,12 +1407,12 @@ case $os in
 	-nto*)
 	-nto*)
 		os=`echo $os | sed -e 's|nto|nto-qnx|'`
 		os=`echo $os | sed -e 's|nto|nto-qnx|'`
 		;;
 		;;
-	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
-	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
+	-sim | -xray | -os68k* | -v88r* \
+	      | -windows* | -osx | -abug | -netware* | -os9* \
 	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
 	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
 		;;
 		;;
 	-mac*)
 	-mac*)
-		os=`echo $os | sed -e 's|mac|macos|'`
+		os=`echo "$os" | sed -e 's|mac|macos|'`
 		;;
 		;;
 	-linux-dietlibc)
 	-linux-dietlibc)
 		os=-linux-dietlibc
 		os=-linux-dietlibc
@@ -1424,10 +1421,10 @@ case $os in
 		os=`echo $os | sed -e 's|linux|linux-gnu|'`
 		os=`echo $os | sed -e 's|linux|linux-gnu|'`
 		;;
 		;;
 	-sunos5*)
 	-sunos5*)
-		os=`echo $os | sed -e 's|sunos5|solaris2|'`
+		os=`echo "$os" | sed -e 's|sunos5|solaris2|'`
 		;;
 		;;
 	-sunos6*)
 	-sunos6*)
-		os=`echo $os | sed -e 's|sunos6|solaris3|'`
+		os=`echo "$os" | sed -e 's|sunos6|solaris3|'`
 		;;
 		;;
 	-opened*)
 	-opened*)
 		os=-openedition
 		os=-openedition
@@ -1438,12 +1435,6 @@ case $os in
 	-wince*)
 	-wince*)
 		os=-wince
 		os=-wince
 		;;
 		;;
-	-osfrose*)
-		os=-osfrose
-		;;
-	-osf*)
-		os=-osf
-		;;
 	-utek*)
 	-utek*)
 		os=-bsd
 		os=-bsd
 		;;
 		;;
@@ -1468,7 +1459,7 @@ case $os in
 	-nova*)
 	-nova*)
 		os=-rtmk-nova
 		os=-rtmk-nova
 		;;
 		;;
-	-ns2 )
+	-ns2)
 		os=-nextstep2
 		os=-nextstep2
 		;;
 		;;
 	-nsk*)
 	-nsk*)
@@ -1490,7 +1481,7 @@ case $os in
 	-oss*)
 	-oss*)
 		os=-sysv3
 		os=-sysv3
 		;;
 		;;
-	-svr4)
+	-svr4*)
 		os=-sysv4
 		os=-sysv4
 		;;
 		;;
 	-svr3)
 	-svr3)
@@ -1505,32 +1496,38 @@ case $os in
 	-ose*)
 	-ose*)
 		os=-ose
 		os=-ose
 		;;
 		;;
-	-es1800*)
-		os=-ose
-		;;
-	-xenix)
-		os=-xenix
-		;;
 	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
 	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
 		os=-mint
 		os=-mint
 		;;
 		;;
-	-aros*)
-		os=-aros
-		;;
 	-zvmoe)
 	-zvmoe)
 		os=-zvmoe
 		os=-zvmoe
 		;;
 		;;
 	-dicos*)
 	-dicos*)
 		os=-dicos
 		os=-dicos
 		;;
 		;;
+	-pikeos*)
+		# Until real need of OS specific support for
+		# particular features comes up, bare metal
+		# configurations are quite functional.
+		case $basic_machine in
+		    arm*)
+			os=-eabi
+			;;
+		    *)
+			os=-elf
+			;;
+		esac
+		;;
 	-nacl*)
 	-nacl*)
 		;;
 		;;
+	-ios)
+		;;
 	-none)
 	-none)
 		;;
 		;;
 	*)
 	*)
 		# Get rid of the `-' at the beginning of $os.
 		# Get rid of the `-' at the beginning of $os.
 		os=`echo $os | sed 's/[^-]*-//'`
 		os=`echo $os | sed 's/[^-]*-//'`
-		echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+		echo Invalid configuration \`"$1"\': system \`"$os"\' not recognized 1>&2
 		exit 1
 		exit 1
 		;;
 		;;
 esac
 esac
@@ -1620,12 +1617,12 @@ case $basic_machine in
 	sparc-* | *-sun)
 	sparc-* | *-sun)
 		os=-sunos4.1.1
 		os=-sunos4.1.1
 		;;
 		;;
+	pru-*)
+		os=-elf
+		;;
 	*-be)
 	*-be)
 		os=-beos
 		os=-beos
 		;;
 		;;
-	*-haiku)
-		os=-haiku
-		;;
 	*-ibm)
 	*-ibm)
 		os=-aix
 		os=-aix
 		;;
 		;;
@@ -1665,7 +1662,7 @@ case $basic_machine in
 	m88k-omron*)
 	m88k-omron*)
 		os=-luna
 		os=-luna
 		;;
 		;;
-	*-next )
+	*-next)
 		os=-nextstep
 		os=-nextstep
 		;;
 		;;
 	*-sequent)
 	*-sequent)
@@ -1680,9 +1677,6 @@ case $basic_machine in
 	i370-*)
 	i370-*)
 		os=-mvs
 		os=-mvs
 		;;
 		;;
-	*-next)
-		os=-nextstep3
-		;;
 	*-gould)
 	*-gould)
 		os=-sysv
 		os=-sysv
 		;;
 		;;
@@ -1792,15 +1786,15 @@ case $basic_machine in
 				vendor=stratus
 				vendor=stratus
 				;;
 				;;
 		esac
 		esac
-		basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+		basic_machine=`echo "$basic_machine" | sed "s/unknown/$vendor/"`
 		;;
 		;;
 esac
 esac
 
 
-echo $basic_machine$os
+echo "$basic_machine$os"
 exit
 exit
 
 
 # Local variables:
 # Local variables:
-# eval: (add-hook 'write-file-hooks 'time-stamp)
+# eval: (add-hook 'write-file-functions 'time-stamp)
 # time-stamp-start: "timestamp='"
 # time-stamp-start: "timestamp='"
 # time-stamp-format: "%:y-%02m-%02d"
 # time-stamp-format: "%:y-%02m-%02d"
 # time-stamp-end: "'"
 # time-stamp-end: "'"

+ 5 - 5
config/depcomp

@@ -1,9 +1,9 @@
 #! /bin/sh
 #! /bin/sh
 # depcomp - compile a program generating dependencies as side-effects
 # depcomp - compile a program generating dependencies as side-effects
 
 
-scriptversion=2013-05-30.07; # UTC
+scriptversion=2018-03-07.03; # UTC
 
 
-# Copyright (C) 1999-2014 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
 
 
 # This program is free software; you can redistribute it and/or modify
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@ scriptversion=2013-05-30.07; # UTC
 # GNU General Public License for more details.
 # GNU General Public License for more details.
 
 
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 
 # As a special exception to the GNU General Public License, if you
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # distribute this file as part of a program that contains a
@@ -783,9 +783,9 @@ exit 0
 # Local Variables:
 # Local Variables:
 # mode: shell-script
 # mode: shell-script
 # sh-indentation: 2
 # sh-indentation: 2
-# eval: (add-hook 'write-file-hooks 'time-stamp)
+# eval: (add-hook 'before-save-hook 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
+# time-stamp-time-zone: "UTC0"
 # time-stamp-end: "; # UTC"
 # time-stamp-end: "; # UTC"
 # End:
 # End:

+ 107 - 67
config/install-sh

@@ -1,7 +1,7 @@
 #!/bin/sh
 #!/bin/sh
 # install - install a program, script, or datafile
 # install - install a program, script, or datafile
 
 
-scriptversion=2013-12-25.23; # UTC
+scriptversion=2020-11-14.01; # UTC
 
 
 # This originates from X11R5 (mit/util/scripts/install.sh), which was
 # This originates from X11R5 (mit/util/scripts/install.sh), which was
 # later released in X11R6 (xc/config/util/install.sh) with the
 # later released in X11R6 (xc/config/util/install.sh) with the
@@ -69,6 +69,11 @@ posix_mkdir=
 # Desired mode of installed file.
 # Desired mode of installed file.
 mode=0755
 mode=0755
 
 
+# Create dirs (including intermediate dirs) using mode 755.
+# This is like GNU 'install' as of coreutils 8.32 (2020).
+mkdir_umask=22
+
+backupsuffix=
 chgrpcmd=
 chgrpcmd=
 chmodcmd=$chmodprog
 chmodcmd=$chmodprog
 chowncmd=
 chowncmd=
@@ -99,18 +104,28 @@ Options:
      --version  display version info and exit.
      --version  display version info and exit.
 
 
   -c            (ignored)
   -c            (ignored)
-  -C            install only if different (preserve the last data modification time)
+  -C            install only if different (preserve data modification time)
   -d            create directories instead of installing files.
   -d            create directories instead of installing files.
   -g GROUP      $chgrpprog installed files to GROUP.
   -g GROUP      $chgrpprog installed files to GROUP.
   -m MODE       $chmodprog installed files to MODE.
   -m MODE       $chmodprog installed files to MODE.
   -o USER       $chownprog installed files to USER.
   -o USER       $chownprog installed files to USER.
+  -p            pass -p to $cpprog.
   -s            $stripprog installed files.
   -s            $stripprog installed files.
+  -S SUFFIX     attempt to back up existing files, with suffix SUFFIX.
   -t DIRECTORY  install into DIRECTORY.
   -t DIRECTORY  install into DIRECTORY.
   -T            report an error if DSTFILE is a directory.
   -T            report an error if DSTFILE is a directory.
 
 
 Environment variables override the default commands:
 Environment variables override the default commands:
   CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
   CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
   RMPROG STRIPPROG
   RMPROG STRIPPROG
+
+By default, rm is invoked with -f; when overridden with RMPROG,
+it's up to you to specify -f if you want it.
+
+If -S is not specified, no backups are attempted.
+
+Email bug reports to bug-automake@gnu.org.
+Automake home page: https://www.gnu.org/software/automake/
 "
 "
 
 
 while test $# -ne 0; do
 while test $# -ne 0; do
@@ -137,8 +152,13 @@ while test $# -ne 0; do
     -o) chowncmd="$chownprog $2"
     -o) chowncmd="$chownprog $2"
         shift;;
         shift;;
 
 
+    -p) cpprog="$cpprog -p";;
+
     -s) stripcmd=$stripprog;;
     -s) stripcmd=$stripprog;;
 
 
+    -S) backupsuffix="$2"
+        shift;;
+
     -t)
     -t)
         is_target_a_directory=always
         is_target_a_directory=always
         dst_arg=$2
         dst_arg=$2
@@ -255,6 +275,10 @@ do
     dstdir=$dst
     dstdir=$dst
     test -d "$dstdir"
     test -d "$dstdir"
     dstdir_status=$?
     dstdir_status=$?
+    # Don't chown directories that already exist.
+    if test $dstdir_status = 0; then
+      chowncmd=""
+    fi
   else
   else
 
 
     # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
     # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
@@ -271,15 +295,18 @@ do
     fi
     fi
     dst=$dst_arg
     dst=$dst_arg
 
 
-    # If destination is a directory, append the input filename; won't work
-    # if double slashes aren't ignored.
+    # If destination is a directory, append the input filename.
     if test -d "$dst"; then
     if test -d "$dst"; then
       if test "$is_target_a_directory" = never; then
       if test "$is_target_a_directory" = never; then
         echo "$0: $dst_arg: Is a directory" >&2
         echo "$0: $dst_arg: Is a directory" >&2
         exit 1
         exit 1
       fi
       fi
       dstdir=$dst
       dstdir=$dst
-      dst=$dstdir/`basename "$src"`
+      dstbase=`basename "$src"`
+      case $dst in
+	*/) dst=$dst$dstbase;;
+	*)  dst=$dst/$dstbase;;
+      esac
       dstdir_status=0
       dstdir_status=0
     else
     else
       dstdir=`dirname "$dst"`
       dstdir=`dirname "$dst"`
@@ -288,27 +315,16 @@ do
     fi
     fi
   fi
   fi
 
 
+  case $dstdir in
+    */) dstdirslash=$dstdir;;
+    *)  dstdirslash=$dstdir/;;
+  esac
+
   obsolete_mkdir_used=false
   obsolete_mkdir_used=false
 
 
   if test $dstdir_status != 0; then
   if test $dstdir_status != 0; then
     case $posix_mkdir in
     case $posix_mkdir in
       '')
       '')
-        # Create intermediate dirs using mode 755 as modified by the umask.
-        # This is like FreeBSD 'install' as of 1997-10-28.
-        umask=`umask`
-        case $stripcmd.$umask in
-          # Optimize common cases.
-          *[2367][2367]) mkdir_umask=$umask;;
-          .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
-
-          *[0-7])
-            mkdir_umask=`expr $umask + 22 \
-              - $umask % 100 % 40 + $umask % 20 \
-              - $umask % 10 % 4 + $umask % 2
-            `;;
-          *) mkdir_umask=$umask,go-w;;
-        esac
-
         # With -d, create the new directory with the user-specified mode.
         # With -d, create the new directory with the user-specified mode.
         # Otherwise, rely on $mkdir_umask.
         # Otherwise, rely on $mkdir_umask.
         if test -n "$dir_arg"; then
         if test -n "$dir_arg"; then
@@ -318,43 +334,49 @@ do
         fi
         fi
 
 
         posix_mkdir=false
         posix_mkdir=false
-        case $umask in
-          *[123567][0-7][0-7])
-            # POSIX mkdir -p sets u+wx bits regardless of umask, which
-            # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
-            ;;
-          *)
-            tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
-            trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
-
-            if (umask $mkdir_umask &&
-                exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
-            then
-              if test -z "$dir_arg" || {
-                   # Check for POSIX incompatibilities with -m.
-                   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
-                   # other-writable bit of parent directory when it shouldn't.
-                   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
-                   ls_ld_tmpdir=`ls -ld "$tmpdir"`
-                   case $ls_ld_tmpdir in
-                     d????-?r-*) different_mode=700;;
-                     d????-?--*) different_mode=755;;
-                     *) false;;
-                   esac &&
-                   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
-                     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
-                     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
-                   }
-                 }
-              then posix_mkdir=:
-              fi
-              rmdir "$tmpdir/d" "$tmpdir"
-            else
-              # Remove any dirs left behind by ancient mkdir implementations.
-              rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
-            fi
-            trap '' 0;;
-        esac;;
+	# The $RANDOM variable is not portable (e.g., dash).  Use it
+	# here however when possible just to lower collision chance.
+	tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
+
+	trap '
+	  ret=$?
+	  rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null
+	  exit $ret
+	' 0
+
+	# Because "mkdir -p" follows existing symlinks and we likely work
+	# directly in world-writeable /tmp, make sure that the '$tmpdir'
+	# directory is successfully created first before we actually test
+	# 'mkdir -p'.
+	if (umask $mkdir_umask &&
+	    $mkdirprog $mkdir_mode "$tmpdir" &&
+	    exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
+	then
+	  if test -z "$dir_arg" || {
+	       # Check for POSIX incompatibilities with -m.
+	       # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
+	       # other-writable bit of parent directory when it shouldn't.
+	       # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
+	       test_tmpdir="$tmpdir/a"
+	       ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
+	       case $ls_ld_tmpdir in
+		 d????-?r-*) different_mode=700;;
+		 d????-?--*) different_mode=755;;
+		 *) false;;
+	       esac &&
+	       $mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
+		 ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
+		 test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
+	       }
+	     }
+	  then posix_mkdir=:
+	  fi
+	  rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
+	else
+	  # Remove any dirs left behind by ancient mkdir implementations.
+	  rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
+	fi
+	trap '' 0;;
     esac
     esac
 
 
     if
     if
@@ -365,7 +387,7 @@ do
     then :
     then :
     else
     else
 
 
-      # The umask is ridiculous, or mkdir does not conform to POSIX,
+      # mkdir does not conform to POSIX,
       # or it failed possibly due to a race condition.  Create the
       # or it failed possibly due to a race condition.  Create the
       # directory the slow way, step by step, checking for races as we go.
       # directory the slow way, step by step, checking for races as we go.
 
 
@@ -394,7 +416,7 @@ do
           prefixes=
           prefixes=
         else
         else
           if $posix_mkdir; then
           if $posix_mkdir; then
-            (umask=$mkdir_umask &&
+            (umask $mkdir_umask &&
              $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
              $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
             # Don't fail if two instances are running concurrently.
             # Don't fail if two instances are running concurrently.
             test -d "$prefix" || exit 1
             test -d "$prefix" || exit 1
@@ -427,14 +449,25 @@ do
   else
   else
 
 
     # Make a couple of temp file names in the proper directory.
     # Make a couple of temp file names in the proper directory.
-    dsttmp=$dstdir/_inst.$$_
-    rmtmp=$dstdir/_rm.$$_
+    dsttmp=${dstdirslash}_inst.$$_
+    rmtmp=${dstdirslash}_rm.$$_
 
 
     # Trap to clean up those temp files at exit.
     # Trap to clean up those temp files at exit.
     trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
     trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
 
 
     # Copy the file name to the temp name.
     # Copy the file name to the temp name.
-    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
+    (umask $cp_umask &&
+     { test -z "$stripcmd" || {
+	 # Create $dsttmp read-write so that cp doesn't create it read-only,
+	 # which would cause strip to fail.
+	 if test -z "$doit"; then
+	   : >"$dsttmp" # No need to fork-exec 'touch'.
+	 else
+	   $doit touch "$dsttmp"
+	 fi
+       }
+     } &&
+     $doit_exec $cpprog "$src" "$dsttmp") &&
 
 
     # and set any options; do chmod last to preserve setuid bits.
     # and set any options; do chmod last to preserve setuid bits.
     #
     #
@@ -460,6 +493,13 @@ do
     then
     then
       rm -f "$dsttmp"
       rm -f "$dsttmp"
     else
     else
+      # If $backupsuffix is set, and the file being installed
+      # already exists, attempt a backup.  Don't worry if it fails,
+      # e.g., if mv doesn't support -f.
+      if test -n "$backupsuffix" && test -f "$dst"; then
+        $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
+      fi
+
       # Rename the file to the real destination.
       # Rename the file to the real destination.
       $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
       $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
 
 
@@ -474,9 +514,9 @@ do
         # file should still install successfully.
         # file should still install successfully.
         {
         {
           test ! -f "$dst" ||
           test ! -f "$dst" ||
-          $doit $rmcmd -f "$dst" 2>/dev/null ||
+          $doit $rmcmd "$dst" 2>/dev/null ||
           { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
           { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
-            { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
+            { $doit $rmcmd "$rmtmp" 2>/dev/null; :; }
           } ||
           } ||
           { echo "$0: cannot unlink or rename $dst" >&2
           { echo "$0: cannot unlink or rename $dst" >&2
             (exit 1); exit 1
             (exit 1); exit 1
@@ -493,9 +533,9 @@ do
 done
 done
 
 
 # Local variables:
 # Local variables:
-# eval: (add-hook 'write-file-hooks 'time-stamp)
+# eval: (add-hook 'before-save-hook 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
+# time-stamp-time-zone: "UTC0"
 # time-stamp-end: "; # UTC"
 # time-stamp-end: "; # UTC"
 # End:
 # End:

+ 177 - 73
config/ltmain.sh

@@ -31,7 +31,7 @@
 
 
 PROGRAM=libtool
 PROGRAM=libtool
 PACKAGE=libtool
 PACKAGE=libtool
-VERSION=2.4.6
+VERSION="2.4.6 Debian-2.4.6-15"
 package_revision=2.4.6
 package_revision=2.4.6
 
 
 
 
@@ -387,7 +387,7 @@ EXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
 # putting '$debug_cmd' at the start of all your functions, you can get
 # putting '$debug_cmd' at the start of all your functions, you can get
 # bash to show function call trace with:
 # bash to show function call trace with:
 #
 #
-#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
+#    debug_cmd='echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
 debug_cmd=${debug_cmd-":"}
 debug_cmd=${debug_cmd-":"}
 exit_cmd=:
 exit_cmd=:
 
 
@@ -1370,7 +1370,7 @@ func_lt_ver ()
 #! /bin/sh
 #! /bin/sh
 
 
 # Set a version string for this script.
 # Set a version string for this script.
-scriptversion=2014-01-07.03; # UTC
+scriptversion=2015-10-07.11; # UTC
 
 
 # A portable, pluggable option parser for Bourne shell.
 # A portable, pluggable option parser for Bourne shell.
 # Written by Gary V. Vaughan, 2010
 # Written by Gary V. Vaughan, 2010
@@ -1530,6 +1530,8 @@ func_run_hooks ()
 {
 {
     $debug_cmd
     $debug_cmd
 
 
+    _G_rc_run_hooks=false
+
     case " $hookable_fns " in
     case " $hookable_fns " in
       *" $1 "*) ;;
       *" $1 "*) ;;
       *) func_fatal_error "'$1' does not support hook funcions.n" ;;
       *) func_fatal_error "'$1' does not support hook funcions.n" ;;
@@ -1538,16 +1540,16 @@ func_run_hooks ()
     eval _G_hook_fns=\$$1_hooks; shift
     eval _G_hook_fns=\$$1_hooks; shift
 
 
     for _G_hook in $_G_hook_fns; do
     for _G_hook in $_G_hook_fns; do
-      eval $_G_hook '"$@"'
-
-      # store returned options list back into positional
-      # parameters for next 'cmd' execution.
-      eval _G_hook_result=\$${_G_hook}_result
-      eval set dummy "$_G_hook_result"; shift
+      if eval $_G_hook '"$@"'; then
+        # store returned options list back into positional
+        # parameters for next 'cmd' execution.
+        eval _G_hook_result=\$${_G_hook}_result
+        eval set dummy "$_G_hook_result"; shift
+        _G_rc_run_hooks=:
+      fi
     done
     done
 
 
-    func_quote_for_eval ${1+"$@"}
-    func_run_hooks_result=$func_quote_for_eval_result
+    $_G_rc_run_hooks && func_run_hooks_result=$_G_hook_result
 }
 }
 
 
 
 
@@ -1557,10 +1559,16 @@ func_run_hooks ()
 ## --------------- ##
 ## --------------- ##
 
 
 # In order to add your own option parsing hooks, you must accept the
 # In order to add your own option parsing hooks, you must accept the
-# full positional parameter list in your hook function, remove any
-# options that you action, and then pass back the remaining unprocessed
+# full positional parameter list in your hook function, you may remove/edit
+# any options that you action, and then pass back the remaining unprocessed
 # options in '<hooked_function_name>_result', escaped suitably for
 # options in '<hooked_function_name>_result', escaped suitably for
-# 'eval'.  Like this:
+# 'eval'.  In this case you also must return $EXIT_SUCCESS to let the
+# hook's caller know that it should pay attention to
+# '<hooked_function_name>_result'.  Returning $EXIT_FAILURE signalizes that
+# arguments are left untouched by the hook and therefore caller will ignore the
+# result variable.
+#
+# Like this:
 #
 #
 #    my_options_prep ()
 #    my_options_prep ()
 #    {
 #    {
@@ -1570,9 +1578,11 @@ func_run_hooks ()
 #        usage_message=$usage_message'
 #        usage_message=$usage_message'
 #      -s, --silent       don'\''t print informational messages
 #      -s, --silent       don'\''t print informational messages
 #    '
 #    '
-#
-#        func_quote_for_eval ${1+"$@"}
-#        my_options_prep_result=$func_quote_for_eval_result
+#        # No change in '$@' (ignored completely by this hook).  There is
+#        # no need to do the equivalent (but slower) action:
+#        # func_quote_for_eval ${1+"$@"}
+#        # my_options_prep_result=$func_quote_for_eval_result
+#        false
 #    }
 #    }
 #    func_add_hook func_options_prep my_options_prep
 #    func_add_hook func_options_prep my_options_prep
 #
 #
@@ -1581,25 +1591,37 @@ func_run_hooks ()
 #    {
 #    {
 #        $debug_cmd
 #        $debug_cmd
 #
 #
+#        args_changed=false
+#
 #        # Note that for efficiency, we parse as many options as we can
 #        # Note that for efficiency, we parse as many options as we can
 #        # recognise in a loop before passing the remainder back to the
 #        # recognise in a loop before passing the remainder back to the
 #        # caller on the first unrecognised argument we encounter.
 #        # caller on the first unrecognised argument we encounter.
 #        while test $# -gt 0; do
 #        while test $# -gt 0; do
 #          opt=$1; shift
 #          opt=$1; shift
 #          case $opt in
 #          case $opt in
-#            --silent|-s) opt_silent=: ;;
+#            --silent|-s) opt_silent=:
+#                         args_changed=:
+#                         ;;
 #            # Separate non-argument short options:
 #            # Separate non-argument short options:
 #            -s*)         func_split_short_opt "$_G_opt"
 #            -s*)         func_split_short_opt "$_G_opt"
 #                         set dummy "$func_split_short_opt_name" \
 #                         set dummy "$func_split_short_opt_name" \
 #                             "-$func_split_short_opt_arg" ${1+"$@"}
 #                             "-$func_split_short_opt_arg" ${1+"$@"}
 #                         shift
 #                         shift
+#                         args_changed=:
 #                         ;;
 #                         ;;
-#            *)            set dummy "$_G_opt" "$*"; shift; break ;;
+#            *)           # Make sure the first unrecognised option "$_G_opt"
+#                         # is added back to "$@", we could need that later
+#                         # if $args_changed is true.
+#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
 #          esac
 #          esac
 #        done
 #        done
 #
 #
-#        func_quote_for_eval ${1+"$@"}
-#        my_silent_option_result=$func_quote_for_eval_result
+#        if $args_changed; then
+#          func_quote_for_eval ${1+"$@"}
+#          my_silent_option_result=$func_quote_for_eval_result
+#        fi
+#
+#        $args_changed
 #    }
 #    }
 #    func_add_hook func_parse_options my_silent_option
 #    func_add_hook func_parse_options my_silent_option
 #
 #
@@ -1611,16 +1633,32 @@ func_run_hooks ()
 #        $opt_silent && $opt_verbose && func_fatal_help "\
 #        $opt_silent && $opt_verbose && func_fatal_help "\
 #    '--silent' and '--verbose' options are mutually exclusive."
 #    '--silent' and '--verbose' options are mutually exclusive."
 #
 #
-#        func_quote_for_eval ${1+"$@"}
-#        my_option_validation_result=$func_quote_for_eval_result
+#        false
 #    }
 #    }
 #    func_add_hook func_validate_options my_option_validation
 #    func_add_hook func_validate_options my_option_validation
 #
 #
-# You'll alse need to manually amend $usage_message to reflect the extra
+# You'll also need to manually amend $usage_message to reflect the extra
 # options you parse.  It's preferable to append if you can, so that
 # options you parse.  It's preferable to append if you can, so that
 # multiple option parsing hooks can be added safely.
 # multiple option parsing hooks can be added safely.
 
 
 
 
+# func_options_finish [ARG]...
+# ----------------------------
+# Finishing the option parse loop (call 'func_options' hooks ATM).
+func_options_finish ()
+{
+    $debug_cmd
+
+    _G_func_options_finish_exit=false
+    if func_run_hooks func_options ${1+"$@"}; then
+      func_options_finish_result=$func_run_hooks_result
+      _G_func_options_finish_exit=:
+    fi
+
+    $_G_func_options_finish_exit
+}
+
+
 # func_options [ARG]...
 # func_options [ARG]...
 # ---------------------
 # ---------------------
 # All the functions called inside func_options are hookable. See the
 # All the functions called inside func_options are hookable. See the
@@ -1630,17 +1668,28 @@ func_options ()
 {
 {
     $debug_cmd
     $debug_cmd
 
 
-    func_options_prep ${1+"$@"}
-    eval func_parse_options \
-        ${func_options_prep_result+"$func_options_prep_result"}
-    eval func_validate_options \
-        ${func_parse_options_result+"$func_parse_options_result"}
+    _G_rc_options=false
+
+    for my_func in options_prep parse_options validate_options options_finish
+    do
+      if eval func_$my_func '${1+"$@"}'; then
+        eval _G_res_var='$'"func_${my_func}_result"
+        eval set dummy "$_G_res_var" ; shift
+        _G_rc_options=:
+      fi
+    done
 
 
-    eval func_run_hooks func_options \
-        ${func_validate_options_result+"$func_validate_options_result"}
+    # Save modified positional parameters for caller.  As a top-level
+    # options-parser function we always need to set the 'func_options_result'
+    # variable (regardless the $_G_rc_options value).
+    if $_G_rc_options; then
+      func_options_result=$_G_res_var
+    else
+      func_quote_for_eval ${1+"$@"}
+      func_options_result=$func_quote_for_eval_result
+    fi
 
 
-    # save modified positional parameters for caller
-    func_options_result=$func_run_hooks_result
+    $_G_rc_options
 }
 }
 
 
 
 
@@ -1649,9 +1698,9 @@ func_options ()
 # All initialisations required before starting the option parse loop.
 # All initialisations required before starting the option parse loop.
 # Note that when calling hook functions, we pass through the list of
 # Note that when calling hook functions, we pass through the list of
 # positional parameters.  If a hook function modifies that list, and
 # positional parameters.  If a hook function modifies that list, and
-# needs to propogate that back to rest of this script, then the complete
+# needs to propagate that back to rest of this script, then the complete
 # modified list must be put in 'func_run_hooks_result' before
 # modified list must be put in 'func_run_hooks_result' before
-# returning.
+# returning $EXIT_SUCCESS (otherwise $EXIT_FAILURE is returned).
 func_hookable func_options_prep
 func_hookable func_options_prep
 func_options_prep ()
 func_options_prep ()
 {
 {
@@ -1661,10 +1710,14 @@ func_options_prep ()
     opt_verbose=false
     opt_verbose=false
     opt_warning_types=
     opt_warning_types=
 
 
-    func_run_hooks func_options_prep ${1+"$@"}
+    _G_rc_options_prep=false
+    if func_run_hooks func_options_prep ${1+"$@"}; then
+      _G_rc_options_prep=:
+      # save modified positional parameters for caller
+      func_options_prep_result=$func_run_hooks_result
+    fi
 
 
-    # save modified positional parameters for caller
-    func_options_prep_result=$func_run_hooks_result
+    $_G_rc_options_prep
 }
 }
 
 
 
 
@@ -1678,18 +1731,20 @@ func_parse_options ()
 
 
     func_parse_options_result=
     func_parse_options_result=
 
 
+    _G_rc_parse_options=false
     # this just eases exit handling
     # this just eases exit handling
     while test $# -gt 0; do
     while test $# -gt 0; do
       # Defer to hook functions for initial option parsing, so they
       # Defer to hook functions for initial option parsing, so they
       # get priority in the event of reusing an option name.
       # get priority in the event of reusing an option name.
-      func_run_hooks func_parse_options ${1+"$@"}
-
-      # Adjust func_parse_options positional parameters to match
-      eval set dummy "$func_run_hooks_result"; shift
+      if func_run_hooks func_parse_options ${1+"$@"}; then
+        eval set dummy "$func_run_hooks_result"; shift
+        _G_rc_parse_options=:
+      fi
 
 
       # Break out of the loop if we already parsed every option.
       # Break out of the loop if we already parsed every option.
       test $# -gt 0 || break
       test $# -gt 0 || break
 
 
+      _G_match_parse_options=:
       _G_opt=$1
       _G_opt=$1
       shift
       shift
       case $_G_opt in
       case $_G_opt in
@@ -1704,7 +1759,10 @@ func_parse_options ()
 		      ;;
 		      ;;
 
 
         --warnings|--warning|-W)
         --warnings|--warning|-W)
-                      test $# = 0 && func_missing_arg $_G_opt && break
+                      if test $# = 0 && func_missing_arg $_G_opt; then
+                        _G_rc_parse_options=:
+                        break
+                      fi
                       case " $warning_categories $1" in
                       case " $warning_categories $1" in
                         *" $1 "*)
                         *" $1 "*)
                           # trailing space prevents matching last $1 above
                           # trailing space prevents matching last $1 above
@@ -1757,15 +1815,25 @@ func_parse_options ()
                       shift
                       shift
                       ;;
                       ;;
 
 
-        --)           break ;;
+        --)           _G_rc_parse_options=: ; break ;;
         -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
         -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
-        *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
+        *)            set dummy "$_G_opt" ${1+"$@"}; shift
+                      _G_match_parse_options=false
+                      break
+                      ;;
       esac
       esac
+
+      $_G_match_parse_options && _G_rc_parse_options=:
     done
     done
 
 
-    # save modified positional parameters for caller
-    func_quote_for_eval ${1+"$@"}
-    func_parse_options_result=$func_quote_for_eval_result
+
+    if $_G_rc_parse_options; then
+      # save modified positional parameters for caller
+      func_quote_for_eval ${1+"$@"}
+      func_parse_options_result=$func_quote_for_eval_result
+    fi
+
+    $_G_rc_parse_options
 }
 }
 
 
 
 
@@ -1778,16 +1846,21 @@ func_validate_options ()
 {
 {
     $debug_cmd
     $debug_cmd
 
 
+    _G_rc_validate_options=false
+
     # Display all warnings if -W was not given.
     # Display all warnings if -W was not given.
     test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
     test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
 
 
-    func_run_hooks func_validate_options ${1+"$@"}
+    if func_run_hooks func_validate_options ${1+"$@"}; then
+      # save modified positional parameters for caller
+      func_validate_options_result=$func_run_hooks_result
+      _G_rc_validate_options=:
+    fi
 
 
     # Bail if the options were screwed!
     # Bail if the options were screwed!
     $exit_cmd $EXIT_FAILURE
     $exit_cmd $EXIT_FAILURE
 
 
-    # save modified positional parameters for caller
-    func_validate_options_result=$func_run_hooks_result
+    $_G_rc_validate_options
 }
 }
 
 
 
 
@@ -2068,12 +2141,12 @@ include the following information:
        compiler:       $LTCC
        compiler:       $LTCC
        compiler flags: $LTCFLAGS
        compiler flags: $LTCFLAGS
        linker:         $LD (gnu? $with_gnu_ld)
        linker:         $LD (gnu? $with_gnu_ld)
-       version:        $progname (GNU libtool) 2.4.6
+       version:        $progname $scriptversion Debian-2.4.6-15
        automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
        automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
        autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
        autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
 
 
 Report bugs to <bug-libtool@gnu.org>.
 Report bugs to <bug-libtool@gnu.org>.
-GNU libtool home page: <http://www.gnu.org/software/libtool/>.
+GNU libtool home page: <http://www.gnu.org/s/libtool/>.
 General help using GNU software: <http://www.gnu.org/gethelp/>."
 General help using GNU software: <http://www.gnu.org/gethelp/>."
     exit 0
     exit 0
 }
 }
@@ -2270,6 +2343,8 @@ libtool_options_prep ()
     nonopt=
     nonopt=
     preserve_args=
     preserve_args=
 
 
+    _G_rc_lt_options_prep=:
+
     # Shorthand for --mode=foo, only valid as the first argument
     # Shorthand for --mode=foo, only valid as the first argument
     case $1 in
     case $1 in
     clean|clea|cle|cl)
     clean|clea|cle|cl)
@@ -2293,11 +2368,18 @@ libtool_options_prep ()
     uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
     uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
       shift; set dummy --mode uninstall ${1+"$@"}; shift
       shift; set dummy --mode uninstall ${1+"$@"}; shift
       ;;
       ;;
+    *)
+      _G_rc_lt_options_prep=false
+      ;;
     esac
     esac
 
 
-    # Pass back the list of options.
-    func_quote_for_eval ${1+"$@"}
-    libtool_options_prep_result=$func_quote_for_eval_result
+    if $_G_rc_lt_options_prep; then
+      # Pass back the list of options.
+      func_quote_for_eval ${1+"$@"}
+      libtool_options_prep_result=$func_quote_for_eval_result
+    fi
+
+    $_G_rc_lt_options_prep
 }
 }
 func_add_hook func_options_prep libtool_options_prep
 func_add_hook func_options_prep libtool_options_prep
 
 
@@ -2309,9 +2391,12 @@ libtool_parse_options ()
 {
 {
     $debug_cmd
     $debug_cmd
 
 
+    _G_rc_lt_parse_options=false
+
     # Perform our own loop to consume as many options as possible in
     # Perform our own loop to consume as many options as possible in
     # each iteration.
     # each iteration.
     while test $# -gt 0; do
     while test $# -gt 0; do
+      _G_match_lt_parse_options=:
       _G_opt=$1
       _G_opt=$1
       shift
       shift
       case $_G_opt in
       case $_G_opt in
@@ -2386,15 +2471,22 @@ libtool_parse_options ()
                         func_append preserve_args " $_G_opt"
                         func_append preserve_args " $_G_opt"
                         ;;
                         ;;
 
 
-	# An option not handled by this hook function:
-        *)		set dummy "$_G_opt" ${1+"$@"};	shift; break  ;;
+        # An option not handled by this hook function:
+        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
+                        _G_match_lt_parse_options=false
+                        break
+                        ;;
       esac
       esac
+      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
     done
     done
 
 
+    if $_G_rc_lt_parse_options; then
+      # save modified positional parameters for caller
+      func_quote_for_eval ${1+"$@"}
+      libtool_parse_options_result=$func_quote_for_eval_result
+    fi
 
 
-    # save modified positional parameters for caller
-    func_quote_for_eval ${1+"$@"}
-    libtool_parse_options_result=$func_quote_for_eval_result
+    $_G_rc_lt_parse_options
 }
 }
 func_add_hook func_parse_options libtool_parse_options
 func_add_hook func_parse_options libtool_parse_options
 
 
@@ -7272,10 +7364,16 @@ func_mode_link ()
       # -tp=*                Portland pgcc target processor selection
       # -tp=*                Portland pgcc target processor selection
       # --sysroot=*          for sysroot support
       # --sysroot=*          for sysroot support
       # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
       # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
+      # -specs=*             GCC specs files
       # -stdlib=*            select c++ std lib with clang
       # -stdlib=*            select c++ std lib with clang
+      # -fsanitize=*         Clang/GCC memory and address sanitizer
+      # -fuse-ld=*           Linker select flags for GCC
+      # -static-*            direct GCC to link specific libraries statically
+      # -fcilkplus           Cilk Plus language extension features for C/C++
       -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
       -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
       -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
       -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
-      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*)
+      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
+      -specs=*|-fsanitize=*|-fuse-ld=*|-static-*|-fcilkplus)
         func_quote_for_eval "$arg"
         func_quote_for_eval "$arg"
 	arg=$func_quote_for_eval_result
 	arg=$func_quote_for_eval_result
         func_append compile_command " $arg"
         func_append compile_command " $arg"
@@ -7568,7 +7666,10 @@ func_mode_link ()
 	case $pass in
 	case $pass in
 	dlopen) libs=$dlfiles ;;
 	dlopen) libs=$dlfiles ;;
 	dlpreopen) libs=$dlprefiles ;;
 	dlpreopen) libs=$dlprefiles ;;
-	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
+	link)
+	  libs="$deplibs %DEPLIBS%"
+	  test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
+	  ;;
 	esac
 	esac
       fi
       fi
       if test lib,dlpreopen = "$linkmode,$pass"; then
       if test lib,dlpreopen = "$linkmode,$pass"; then
@@ -7887,19 +7988,19 @@ func_mode_link ()
 	    # It is a libtool convenience library, so add in its objects.
 	    # It is a libtool convenience library, so add in its objects.
 	    func_append convenience " $ladir/$objdir/$old_library"
 	    func_append convenience " $ladir/$objdir/$old_library"
 	    func_append old_convenience " $ladir/$objdir/$old_library"
 	    func_append old_convenience " $ladir/$objdir/$old_library"
+	    tmp_libs=
+	    for deplib in $dependency_libs; do
+	      deplibs="$deplib $deplibs"
+	      if $opt_preserve_dup_deps; then
+		case "$tmp_libs " in
+		*" $deplib "*) func_append specialdeplibs " $deplib" ;;
+		esac
+	      fi
+	      func_append tmp_libs " $deplib"
+	    done
 	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
 	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
 	    func_fatal_error "'$lib' is not a convenience library"
 	    func_fatal_error "'$lib' is not a convenience library"
 	  fi
 	  fi
-	  tmp_libs=
-	  for deplib in $dependency_libs; do
-	    deplibs="$deplib $deplibs"
-	    if $opt_preserve_dup_deps; then
-	      case "$tmp_libs " in
-	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
-	      esac
-	    fi
-	    func_append tmp_libs " $deplib"
-	  done
 	  continue
 	  continue
 	fi # $pass = conv
 	fi # $pass = conv
 
 
@@ -8823,6 +8924,9 @@ func_mode_link ()
 	    revision=$number_minor
 	    revision=$number_minor
 	    lt_irix_increment=no
 	    lt_irix_increment=no
 	    ;;
 	    ;;
+	  *)
+	    func_fatal_configuration "$modename: unknown library version type '$version_type'"
+	    ;;
 	  esac
 	  esac
 	  ;;
 	  ;;
 	no)
 	no)

+ 8 - 8
config/missing

@@ -1,9 +1,9 @@
 #! /bin/sh
 #! /bin/sh
 # Common wrapper for a few potentially missing GNU programs.
 # Common wrapper for a few potentially missing GNU programs.
 
 
-scriptversion=2013-10-28.13; # UTC
+scriptversion=2018-03-07.03; # UTC
 
 
-# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
 # Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
 # Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
 
 
 # This program is free software; you can redistribute it and/or modify
 # This program is free software; you can redistribute it and/or modify
@@ -17,7 +17,7 @@ scriptversion=2013-10-28.13; # UTC
 # GNU General Public License for more details.
 # GNU General Public License for more details.
 
 
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 
 # As a special exception to the GNU General Public License, if you
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # distribute this file as part of a program that contains a
@@ -101,9 +101,9 @@ else
   exit $st
   exit $st
 fi
 fi
 
 
-perl_URL=http://www.perl.org/
-flex_URL=http://flex.sourceforge.net/
-gnu_software_URL=http://www.gnu.org/software
+perl_URL=https://www.perl.org/
+flex_URL=https://github.com/westes/flex
+gnu_software_URL=https://www.gnu.org/software
 
 
 program_details ()
 program_details ()
 {
 {
@@ -207,9 +207,9 @@ give_advice "$1" | sed -e '1s/^/WARNING: /' \
 exit $st
 exit $st
 
 
 # Local variables:
 # Local variables:
-# eval: (add-hook 'write-file-hooks 'time-stamp)
+# eval: (add-hook 'before-save-hook 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
+# time-stamp-time-zone: "UTC0"
 # time-stamp-end: "; # UTC"
 # time-stamp-end: "; # UTC"
 # End:
 # End:

+ 205 - 139
configure

@@ -1,6 +1,6 @@
 #! /bin/sh
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for tcpreplay 4.4.3.
+# Generated by GNU Autoconf 2.69 for tcpreplay 4.4.4.
 #
 #
 # Report bugs to <https://github.com/appneta/tcpreplay/issues>.
 # Report bugs to <https://github.com/appneta/tcpreplay/issues>.
 #
 #
@@ -590,8 +590,8 @@ MAKEFLAGS=
 # Identity of this package.
 # Identity of this package.
 PACKAGE_NAME='tcpreplay'
 PACKAGE_NAME='tcpreplay'
 PACKAGE_TARNAME='tcpreplay'
 PACKAGE_TARNAME='tcpreplay'
-PACKAGE_VERSION='4.4.3'
-PACKAGE_STRING='tcpreplay 4.4.3'
+PACKAGE_VERSION='4.4.4'
+PACKAGE_STRING='tcpreplay 4.4.4'
 PACKAGE_BUGREPORT='https://github.com/appneta/tcpreplay/issues'
 PACKAGE_BUGREPORT='https://github.com/appneta/tcpreplay/issues'
 PACKAGE_URL='http://tcpreplay.sourceforge.net/'
 PACKAGE_URL='http://tcpreplay.sourceforge.net/'
 
 
@@ -681,6 +681,7 @@ timestamp_trace_flag
 extra_debug_flag
 extra_debug_flag
 debug_run_time_flag
 debug_run_time_flag
 debug_flag
 debug_flag
+build_tsan
 build_asan
 build_asan
 WORDS_BIGENDIAN_FALSE
 WORDS_BIGENDIAN_FALSE
 WORDS_BIGENDIAN_TRUE
 WORDS_BIGENDIAN_TRUE
@@ -729,7 +730,6 @@ am__nodep
 AMDEPBACKSLASH
 AMDEPBACKSLASH
 AMDEP_FALSE
 AMDEP_FALSE
 AMDEP_TRUE
 AMDEP_TRUE
-am__quote
 am__include
 am__include
 DEPDIR
 DEPDIR
 OBJEXT
 OBJEXT
@@ -808,6 +808,7 @@ infodir
 docdir
 docdir
 oldincludedir
 oldincludedir
 includedir
 includedir
+runstatedir
 localstatedir
 localstatedir
 sharedstatedir
 sharedstatedir
 sysconfdir
 sysconfdir
@@ -826,7 +827,8 @@ PACKAGE_VERSION
 PACKAGE_TARNAME
 PACKAGE_TARNAME
 PACKAGE_NAME
 PACKAGE_NAME
 PATH_SEPARATOR
 PATH_SEPARATOR
-SHELL'
+SHELL
+am__quote'
 ac_subst_files=''
 ac_subst_files=''
 ac_user_opts='
 ac_user_opts='
 enable_option_checking
 enable_option_checking
@@ -846,6 +848,7 @@ with_sysroot
 enable_libtool_lock
 enable_libtool_lock
 enable_largefile
 enable_largefile
 enable_asan
 enable_asan
+enable_tsan
 enable_debug
 enable_debug
 enable_extra_debug
 enable_extra_debug
 enable_timestamp_trace
 enable_timestamp_trace
@@ -932,6 +935,7 @@ datadir='${datarootdir}'
 sysconfdir='${prefix}/etc'
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
 localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
 oldincludedir='/usr/include'
 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1184,6 +1188,15 @@ do
   | -silent | --silent | --silen | --sile | --sil)
   | -silent | --silent | --silen | --sile | --sil)
     silent=yes ;;
     silent=yes ;;
 
 
+  -runstatedir | --runstatedir | --runstatedi | --runstated \
+  | --runstate | --runstat | --runsta | --runst | --runs \
+  | --run | --ru | --r)
+    ac_prev=runstatedir ;;
+  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+  | --run=* | --ru=* | --r=*)
+    runstatedir=$ac_optarg ;;
+
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
     ac_prev=sbindir ;;
     ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1321,7 +1334,7 @@ fi
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-		libdir localedir mandir
+		libdir localedir mandir runstatedir
 do
 do
   eval ac_val=\$$ac_var
   eval ac_val=\$$ac_var
   # Remove trailing slashes.
   # Remove trailing slashes.
@@ -1434,7 +1447,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
   cat <<_ACEOF
-\`configure' configures tcpreplay 4.4.3 to adapt to many kinds of systems.
+\`configure' configures tcpreplay 4.4.4 to adapt to many kinds of systems.
 
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
 
@@ -1474,6 +1487,7 @@ Fine tuning of the installation directories:
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --includedir=DIR        C header files [PREFIX/include]
   --includedir=DIR        C header files [PREFIX/include]
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
@@ -1505,7 +1519,7 @@ fi
 
 
 if test -n "$ac_init_help"; then
 if test -n "$ac_init_help"; then
   case $ac_init_help in
   case $ac_init_help in
-     short | recursive ) echo "Configuration of tcpreplay 4.4.3:";;
+     short | recursive ) echo "Configuration of tcpreplay 4.4.4:";;
    esac
    esac
   cat <<\_ACEOF
   cat <<\_ACEOF
 
 
@@ -1529,6 +1543,7 @@ Optional Features:
   --disable-libtool-lock  avoid locking (might break parallel builds)
   --disable-libtool-lock  avoid locking (might break parallel builds)
   --disable-largefile     omit support for large files
   --disable-largefile     omit support for large files
   --enable-asan           Enable Address Sanitizer support
   --enable-asan           Enable Address Sanitizer support
+  --enable-tsan           Enable Thread Sanitizer support
   --enable-debug          Enable debugging code and support for the -d option
   --enable-debug          Enable debugging code and support for the -d option
   --enable-extra-debug    Enable additional debugging code (may affect
   --enable-extra-debug    Enable additional debugging code (may affect
                           performance)
                           performance)
@@ -1677,7 +1692,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
 if $ac_init_version; then
   cat <<\_ACEOF
   cat <<\_ACEOF
-tcpreplay configure 4.4.3
+tcpreplay configure 4.4.4
 generated by GNU Autoconf 2.69
 generated by GNU Autoconf 2.69
 
 
 Copyright (C) 2012 Free Software Foundation, Inc.
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2637,7 +2652,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 running configure, to aid debugging if configure makes a mistake.
 
 
-It was created by tcpreplay $as_me 4.4.3, which was
+It was created by tcpreplay $as_me 4.4.4, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
 
   $ $0 $@
   $ $0 $@
@@ -3318,7 +3333,7 @@ $as_echo "no" >&6; }
 fi
 fi
 
 
 
 
-am__api_version='1.15'
+am__api_version='1.16'
 
 
 # Find a good install program.  We prefer a C program (faster),
 # Find a good install program.  We prefer a C program (faster),
 # so one script is as good as another.  But avoid the broken or
 # so one script is as good as another.  But avoid the broken or
@@ -3494,12 +3509,7 @@ program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`
 am_aux_dir=`cd "$ac_aux_dir" && pwd`
 am_aux_dir=`cd "$ac_aux_dir" && pwd`
 
 
 if test x"${MISSING+set}" != xset; then
 if test x"${MISSING+set}" != xset; then
-  case $am_aux_dir in
-  *\ * | *\	*)
-    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
-  *)
-    MISSING="\${SHELL} $am_aux_dir/missing" ;;
-  esac
+  MISSING="\${SHELL} '$am_aux_dir/missing'"
 fi
 fi
 # Use eval to expand $SHELL
 # Use eval to expand $SHELL
 if eval "$MISSING --is-lightweight"; then
 if eval "$MISSING --is-lightweight"; then
@@ -3804,7 +3814,7 @@ fi
 
 
 # Define the identity of the package.
 # Define the identity of the package.
  PACKAGE='tcpreplay'
  PACKAGE='tcpreplay'
- VERSION='4.4.3'
+ VERSION='4.4.4'
 
 
 
 
 cat >>confdefs.h <<_ACEOF
 cat >>confdefs.h <<_ACEOF
@@ -3834,8 +3844,8 @@ MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
 
 
 # For better backward compatibility.  To be removed once Automake 1.9.x
 # For better backward compatibility.  To be removed once Automake 1.9.x
 # dies out for good.  For more background, see:
 # dies out for good.  For more background, see:
-# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
-# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
+# <https://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
+# <https://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
 mkdir_p='$(MKDIR_P)'
 mkdir_p='$(MKDIR_P)'
 
 
 # We need awk for the "check" target (and possibly the TAP driver).  The
 # We need awk for the "check" target (and possibly the TAP driver).  The
@@ -3886,7 +3896,7 @@ END
 Aborting the configuration process, to ensure you take notice of the issue.
 Aborting the configuration process, to ensure you take notice of the issue.
 
 
 You can download and install GNU coreutils to get an 'rm' implementation
 You can download and install GNU coreutils to get an 'rm' implementation
-that behaves properly: <http://www.gnu.org/software/coreutils/>.
+that behaves properly: <https://www.gnu.org/software/coreutils/>.
 
 
 If you want to complete the configuration process using your problematic
 If you want to complete the configuration process using your problematic
 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
@@ -3941,45 +3951,45 @@ DEPDIR="${am__leading_dot}deps"
 
 
 ac_config_commands="$ac_config_commands depfiles"
 ac_config_commands="$ac_config_commands depfiles"
 
 
-
-am_make=${MAKE-make}
-cat > confinc << 'END'
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} supports the include directive" >&5
+$as_echo_n "checking whether ${MAKE-make} supports the include directive... " >&6; }
+cat > confinc.mk << 'END'
 am__doit:
 am__doit:
-	@echo this is the am__doit target
+	@echo this is the am__doit target >confinc.out
 .PHONY: am__doit
 .PHONY: am__doit
 END
 END
-# If we don't find an include directive, just comment out the code.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5
-$as_echo_n "checking for style of include used by $am_make... " >&6; }
 am__include="#"
 am__include="#"
 am__quote=
 am__quote=
-_am_result=none
-# First try GNU make style include.
-echo "include confinc" > confmf
-# 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
-  am__quote=
-  _am_result=GNU
-  ;;
-esac
-# Now try BSD make style include.
-if test "$am__include" = "#"; then
-   echo '.include "confinc"' > confmf
-   case `$am_make -s -f confmf 2> /dev/null` in #(
-   *the\ am__doit\ target*)
-     am__include=.include
-     am__quote="\""
-     _am_result=BSD
+# BSD make does it like this.
+echo '.include "confinc.mk" # ignored' > confmf.BSD
+# Other make implementations (GNU, Solaris 10, AIX) do it like this.
+echo 'include confinc.mk # ignored' > confmf.GNU
+_am_result=no
+for s in GNU BSD; do
+  { echo "$as_me:$LINENO: ${MAKE-make} -f confmf.$s && cat confinc.out" >&5
+   (${MAKE-make} -f confmf.$s && cat confinc.out) >&5 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }
+  case $?:`cat confinc.out 2>/dev/null` in #(
+  '0:this is the am__doit target') :
+    case $s in #(
+  BSD) :
+    am__include='.include' am__quote='"' ;; #(
+  *) :
+    am__include='include' am__quote='' ;;
+esac ;; #(
+  *) :
      ;;
      ;;
-   esac
-fi
-
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5
-$as_echo "$_am_result" >&6; }
-rm -f confinc confmf
+esac
+  if test "$am__include" != "#"; then
+    _am_result="yes ($s style)"
+    break
+  fi
+done
+rm -f confinc.* confmf.*
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${_am_result}" >&5
+$as_echo "${_am_result}" >&6; }
 
 
 # Check whether --enable-dependency-tracking was given.
 # Check whether --enable-dependency-tracking was given.
 if test "${enable_dependency_tracking+set}" = set; then :
 if test "${enable_dependency_tracking+set}" = set; then :
@@ -6387,7 +6397,7 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
   lt_cv_deplibs_check_method=pass_all
   lt_cv_deplibs_check_method=pass_all
   ;;
   ;;
 
 
-netbsd*)
+netbsd* | netbsdelf*-gnu)
   if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
   if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
     lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
     lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
   else
   else
@@ -6749,7 +6759,7 @@ esac
 fi
 fi
 
 
 : ${AR=ar}
 : ${AR=ar}
-: ${AR_FLAGS=cru}
+: ${AR_FLAGS=cr}
 
 
 
 
 
 
@@ -7250,11 +7260,8 @@ _LT_EOF
   test $ac_status = 0; }; then
   test $ac_status = 0; }; then
     # Now try to grab the symbols.
     # Now try to grab the symbols.
     nlist=conftest.nm
     nlist=conftest.nm
-    if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5
-  (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } && test -s "$nlist"; then
+    $ECHO "$as_me:$LINENO: $NM conftest.$ac_objext | $lt_cv_sys_global_symbol_pipe > $nlist" >&5
+    if eval "$NM" conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist 2>&5 && test -s "$nlist"; then
       # Try sorting and uniquifying the output.
       # Try sorting and uniquifying the output.
       if sort "$nlist" | uniq > "$nlist"T; then
       if sort "$nlist" | uniq > "$nlist"T; then
 	mv -f "$nlist"T "$nlist"
 	mv -f "$nlist"T "$nlist"
@@ -8473,8 +8480,8 @@ int forced_loaded() { return 2;}
 _LT_EOF
 _LT_EOF
       echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5
       echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5
       $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5
       $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5
-      echo "$AR cru libconftest.a conftest.o" >&5
-      $AR cru libconftest.a conftest.o 2>&5
+      echo "$AR cr libconftest.a conftest.o" >&5
+      $AR cr libconftest.a conftest.o 2>&5
       echo "$RANLIB libconftest.a" >&5
       echo "$RANLIB libconftest.a" >&5
       $RANLIB libconftest.a 2>&5
       $RANLIB libconftest.a 2>&5
       cat > conftest.c << _LT_EOF
       cat > conftest.c << _LT_EOF
@@ -8506,11 +8513,11 @@ $as_echo "$lt_cv_ld_force_load" >&6; }
       # to the OS version, if on x86, and 10.4, the deployment
       # to the OS version, if on x86, and 10.4, the deployment
       # target defaults to 10.4. Don't you love it?
       # target defaults to 10.4. Don't you love it?
       case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
       case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
-	10.0,*86*-darwin8*|10.0,*-darwin[91]*)
+	10.0,*86*-darwin8*|10.0,*-darwin[912]*)
 	  _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
 	  _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
 	10.[012][,.]*)
 	10.[012][,.]*)
 	  _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;;
 	  _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;;
-	10.*)
+	10.*|11.*)
 	  _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
 	  _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
       esac
       esac
     ;;
     ;;
@@ -9603,6 +9610,12 @@ lt_prog_compiler_static=
 	lt_prog_compiler_pic='-KPIC'
 	lt_prog_compiler_pic='-KPIC'
 	lt_prog_compiler_static='-static'
 	lt_prog_compiler_static='-static'
         ;;
         ;;
+      # flang / f18. f95 an alias for gfortran or flang on Debian
+      flang* | f18* | f95*)
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='-fPIC'
+	lt_prog_compiler_static='-static'
+        ;;
       # icc used to be incompatible with GCC.
       # icc used to be incompatible with GCC.
       # ICC 10 doesn't accept -KPIC any more.
       # ICC 10 doesn't accept -KPIC any more.
       icc* | ifort*)
       icc* | ifort*)
@@ -10079,6 +10092,9 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
   openbsd* | bitrig*)
   openbsd* | bitrig*)
     with_gnu_ld=no
     with_gnu_ld=no
     ;;
     ;;
+  linux* | k*bsd*-gnu | gnu*)
+    link_all_deplibs=no
+    ;;
   esac
   esac
 
 
   ld_shlibs=yes
   ld_shlibs=yes
@@ -10333,7 +10349,7 @@ _LT_EOF
       fi
       fi
       ;;
       ;;
 
 
-    netbsd*)
+    netbsd* | netbsdelf*-gnu)
       if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
       if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
 	archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
 	archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
 	wlarc=
 	wlarc=
@@ -11003,6 +11019,7 @@ $as_echo "$lt_cv_irix_exported_symbol" >&6; }
 	if test yes = "$lt_cv_irix_exported_symbol"; then
 	if test yes = "$lt_cv_irix_exported_symbol"; then
           archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib'
           archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib'
 	fi
 	fi
+	link_all_deplibs=no
       else
       else
 	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib'
 	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib'
 	archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib'
 	archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib'
@@ -11024,7 +11041,7 @@ $as_echo "$lt_cv_irix_exported_symbol" >&6; }
       esac
       esac
       ;;
       ;;
 
 
-    netbsd*)
+    netbsd* | netbsdelf*-gnu)
       if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
       if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
 	archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
 	archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
       else
       else
@@ -12139,6 +12156,18 @@ fi
   dynamic_linker='GNU/Linux ld.so'
   dynamic_linker='GNU/Linux ld.so'
   ;;
   ;;
 
 
+netbsdelf*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='NetBSD ld.elf_so'
+  ;;
+
 netbsd*)
 netbsd*)
   version_type=sunos
   version_type=sunos
   need_lib_prefix=no
   need_lib_prefix=no
@@ -14672,7 +14701,7 @@ with_gnu_ld=$lt_cv_prog_gnu_ld
       # Commands to make compiler produce verbose output that lists
       # Commands to make compiler produce verbose output that lists
       # what "hidden" libraries, object files and flags are used when
       # what "hidden" libraries, object files and flags are used when
       # linking a shared library.
       # linking a shared library.
-      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"'
 
 
     else
     else
       GXX=no
       GXX=no
@@ -15164,7 +15193,7 @@ fi
             # explicitly linking system object files so we need to strip them
             # explicitly linking system object files so we need to strip them
             # from the output so that they don't get included in the library
             # from the output so that they don't get included in the library
             # dependencies.
             # dependencies.
-            output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+            output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
             ;;
             ;;
           *)
           *)
             if test yes = "$GXX"; then
             if test yes = "$GXX"; then
@@ -15229,7 +15258,7 @@ fi
 	    # explicitly linking system object files so we need to strip them
 	    # explicitly linking system object files so we need to strip them
 	    # from the output so that they don't get included in the library
 	    # from the output so that they don't get included in the library
 	    # dependencies.
 	    # dependencies.
-	    output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+	    output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
 	    ;;
 	    ;;
           *)
           *)
 	    if test yes = "$GXX"; then
 	    if test yes = "$GXX"; then
@@ -15568,7 +15597,7 @@ fi
 	      # Commands to make compiler produce verbose output that lists
 	      # Commands to make compiler produce verbose output that lists
 	      # what "hidden" libraries, object files and flags are used when
 	      # what "hidden" libraries, object files and flags are used when
 	      # linking a shared library.
 	      # linking a shared library.
-	      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+	      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"'
 
 
 	    else
 	    else
 	      # FIXME: insert proper C++ library support
 	      # FIXME: insert proper C++ library support
@@ -15652,7 +15681,7 @@ fi
 	        # Commands to make compiler produce verbose output that lists
 	        # Commands to make compiler produce verbose output that lists
 	        # what "hidden" libraries, object files and flags are used when
 	        # what "hidden" libraries, object files and flags are used when
 	        # linking a shared library.
 	        # linking a shared library.
-	        output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+	        output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"'
 	      else
 	      else
 	        # g++ 2.7 appears to require '-G' NOT '-shared' on this
 	        # g++ 2.7 appears to require '-G' NOT '-shared' on this
 	        # platform.
 	        # platform.
@@ -15663,7 +15692,7 @@ fi
 	        # Commands to make compiler produce verbose output that lists
 	        # Commands to make compiler produce verbose output that lists
 	        # what "hidden" libraries, object files and flags are used when
 	        # what "hidden" libraries, object files and flags are used when
 	        # linking a shared library.
 	        # linking a shared library.
-	        output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+	        output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"'
 	      fi
 	      fi
 
 
 	      hardcode_libdir_flag_spec_CXX='$wl-R $wl$libdir'
 	      hardcode_libdir_flag_spec_CXX='$wl-R $wl$libdir'
@@ -16176,7 +16205,7 @@ lt_prog_compiler_static_CXX=
 	    ;;
 	    ;;
 	esac
 	esac
 	;;
 	;;
-      netbsd*)
+      netbsd* | netbsdelf*-gnu)
 	;;
 	;;
       *qnx* | *nto*)
       *qnx* | *nto*)
         # QNX uses GNU C++, but need to define -shared option too, otherwise
         # QNX uses GNU C++, but need to define -shared option too, otherwise
@@ -16551,6 +16580,9 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie
       ;;
       ;;
     esac
     esac
     ;;
     ;;
+  linux* | k*bsd*-gnu | gnu*)
+    link_all_deplibs_CXX=no
+    ;;
   *)
   *)
     export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
     export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
     ;;
     ;;
@@ -17244,6 +17276,18 @@ fi
   dynamic_linker='GNU/Linux ld.so'
   dynamic_linker='GNU/Linux ld.so'
   ;;
   ;;
 
 
+netbsdelf*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='NetBSD ld.elf_so'
+  ;;
+
 netbsd*)
 netbsd*)
   version_type=sunos
   version_type=sunos
   need_lib_prefix=no
   need_lib_prefix=no
@@ -18806,7 +18850,7 @@ else
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 		       && LARGE_OFF_T % 2147483647 == 1)
 		       && LARGE_OFF_T % 2147483647 == 1)
 		      ? 1 : -1];
 		      ? 1 : -1];
@@ -18852,7 +18896,7 @@ else
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 		       && LARGE_OFF_T % 2147483647 == 1)
 		       && LARGE_OFF_T % 2147483647 == 1)
 		      ? 1 : -1];
 		      ? 1 : -1];
@@ -18876,7 +18920,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 		       && LARGE_OFF_T % 2147483647 == 1)
 		       && LARGE_OFF_T % 2147483647 == 1)
 		      ? 1 : -1];
 		      ? 1 : -1];
@@ -18921,7 +18965,7 @@ else
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 		       && LARGE_OFF_T % 2147483647 == 1)
 		       && LARGE_OFF_T % 2147483647 == 1)
 		      ? 1 : -1];
 		      ? 1 : -1];
@@ -18945,7 +18989,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 		       && LARGE_OFF_T % 2147483647 == 1)
 		       && LARGE_OFF_T % 2147483647 == 1)
 		      ? 1 : -1];
 		      ? 1 : -1];
@@ -20385,6 +20429,8 @@ main ()
     if (*(data + i) != *(data3 + i))
     if (*(data + i) != *(data3 + i))
       return 14;
       return 14;
   close (fd);
   close (fd);
+  free (data);
+  free (data3);
   return 0;
   return 0;
 }
 }
 _ACEOF
 _ACEOF
@@ -20799,12 +20845,30 @@ else
 fi
 fi
 
 
         CFLAGS="${CFLAGS} -O1 -g -fsanitize=address -fno-omit-frame-pointer"
         CFLAGS="${CFLAGS} -O1 -g -fsanitize=address -fno-omit-frame-pointer"
-                LDFLAGS="-lasan ${LDFLAGS}"
+                LDFLAGS="-fsanitize=address ${LDFLAGS}"
 else
 else
         build_asan=no
         build_asan=no
 fi
 fi
 
 
 
 
+# Check whether --enable-tsan was given.
+if test "${enable_tsan+set}" = set; then :
+  enableval=$enable_tsan;
+fi
+
+if test "x$enable_tsan" = "xyes"; then
+        build_tsan=yes
+        CFLAGS="${CFLAGS} -O1 -g -fsanitize=thread -fno-omit-frame-pointer"
+                LDFLAGS="-fsanitize=thread ${LDFLAGS}"
+else
+        build_tsan=no
+fi
+
+
+if test "$build_asan" = "yes" -a "$build_tsan" = "yes" ; then
+    as_fn_error $? "--enable-asan and --eanble-tsan are mutually exclusive" "$LINENO" 5
+fi
+
 debug=no
 debug=no
 debug_flag=NDEBUG
 debug_flag=NDEBUG
 debug_run_time_flag=
 debug_run_time_flag=
@@ -25717,7 +25781,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 # values after options handling.
 ac_log="
 ac_log="
-This file was extended by tcpreplay $as_me 4.4.3, which was
+This file was extended by tcpreplay $as_me 4.4.4, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_FILES    = $CONFIG_FILES
@@ -25784,7 +25848,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
 ac_cs_version="\\
-tcpreplay config.status 4.4.3
+tcpreplay config.status 4.4.4
 configured by $0, generated by GNU Autoconf 2.69,
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
   with options \\"\$ac_cs_config\\"
 
 
@@ -25903,7 +25967,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 #
 #
 # INIT-COMMANDS
 # INIT-COMMANDS
 #
 #
-AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"
+AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}"
 
 
 
 
 # The HP-UX ksh and POSIX shell print the target directory to stdout
 # The HP-UX ksh and POSIX shell print the target directory to stdout
@@ -26909,29 +26973,35 @@ $as_echo "$as_me: executing $ac_file commands" >&6;}
   # Older Autoconf quotes --file arguments for eval, but not when files
   # Older Autoconf quotes --file arguments for eval, but not when files
   # are listed without --file.  Let's play safe and only enable the eval
   # are listed without --file.  Let's play safe and only enable the eval
   # if we detect the quoting.
   # if we detect the quoting.
-  case $CONFIG_FILES in
-  *\'*) eval set x "$CONFIG_FILES" ;;
-  *)   set x $CONFIG_FILES ;;
-  esac
+  # TODO: see whether this extra hack can be removed once we start
+  # requiring Autoconf 2.70 or later.
+  case $CONFIG_FILES in #(
+  *\'*) :
+    eval set x "$CONFIG_FILES" ;; #(
+  *) :
+    set x $CONFIG_FILES ;; #(
+  *) :
+     ;;
+esac
   shift
   shift
-  for mf
+  # Used to flag and report bootstrapping failures.
+  am_rc=0
+  for am_mf
   do
   do
     # Strip MF so we end up with the name of the file.
     # 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
-    # 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.
-    # Grep'ing the whole file is not good either: AIX grep has a line
+    am_mf=`$as_echo "$am_mf" | sed -e 's/:.*$//'`
+    # Check whether this is an Automake generated Makefile which includes
+    # dependency-tracking related rules and includes.
+    # Grep'ing the whole file directly is not great: AIX grep has a line
     # limit of 2048, but all sed's we know have understand at least 4000.
     # limit of 2048, but all sed's we know have understand at least 4000.
-    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
-      dirpart=`$as_dirname -- "$mf" ||
-$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	 X"$mf" : 'X\(//\)[^/]' \| \
-	 X"$mf" : 'X\(//\)$' \| \
-	 X"$mf" : 'X\(/\)' \| . 2>/dev/null ||
-$as_echo X"$mf" |
+    sed -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \
+      || continue
+    am_dirpart=`$as_dirname -- "$am_mf" ||
+$as_expr X"$am_mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$am_mf" : 'X\(//\)[^/]' \| \
+	 X"$am_mf" : 'X\(//\)$' \| \
+	 X"$am_mf" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$am_mf" |
     sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
     sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
 	    s//\1/
 	    s//\1/
 	    q
 	    q
@@ -26949,53 +27019,50 @@ $as_echo X"$mf" |
 	    q
 	    q
 	  }
 	  }
 	  s/.*/./; q'`
 	  s/.*/./; q'`
-    else
-      continue
-    fi
-    # Extract the definition of DEPDIR, am__include, and am__quote
-    # 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"`
-    # 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'`; do
-      # Make sure the directory exists.
-      test -f "$dirpart/$file" && continue
-      fdir=`$as_dirname -- "$file" ||
-$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	 X"$file" : 'X\(//\)[^/]' \| \
-	 X"$file" : 'X\(//\)$' \| \
-	 X"$file" : 'X\(/\)' \| . 2>/dev/null ||
-$as_echo X"$file" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
-	    s//\1/
-	    q
-	  }
-	  /^X\(\/\/\)[^/].*/{
+    am_filepart=`$as_basename -- "$am_mf" ||
+$as_expr X/"$am_mf" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$am_mf" : 'X\(//\)$' \| \
+	 X"$am_mf" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$am_mf" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
 	    s//\1/
 	    s//\1/
 	    q
 	    q
 	  }
 	  }
-	  /^X\(\/\/\)$/{
+	  /^X\/\(\/\/\)$/{
 	    s//\1/
 	    s//\1/
 	    q
 	    q
 	  }
 	  }
-	  /^X\(\/\).*/{
+	  /^X\/\(\/\).*/{
 	    s//\1/
 	    s//\1/
 	    q
 	    q
 	  }
 	  }
 	  s/.*/./; q'`
 	  s/.*/./; q'`
-      as_dir=$dirpart/$fdir; as_fn_mkdir_p
-      # echo "creating $dirpart/$file"
-      echo '# dummy' > "$dirpart/$file"
-    done
+    { echo "$as_me:$LINENO: cd "$am_dirpart" \
+      && sed -e '/# am--include-marker/d' "$am_filepart" \
+        | $MAKE -f - am--depfiles" >&5
+   (cd "$am_dirpart" \
+      && sed -e '/# am--include-marker/d' "$am_filepart" \
+        | $MAKE -f - am--depfiles) >&5 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } || am_rc=$?
   done
   done
+  if test $am_rc -ne 0; 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 $? "Something went wrong bootstrapping makefile fragments
+    for automatic dependency tracking.  If GNU make was not used, consider
+    re-running the configure script with MAKE=\"gmake\" (or whatever is
+    necessary).  You can also try re-running configure with the
+    '--disable-dependency-tracking' option to at least be able to build
+    the package (albeit without support for automatic dependency tracking).
+See \`config.log' for more details" "$LINENO" 5; }
+  fi
+  { am_dirpart=; unset am_dirpart;}
+  { am_filepart=; unset am_filepart;}
+  { am_mf=; unset am_mf;}
+  { am_rc=; unset am_rc;}
+  rm -f conftest-deps.mk
 }
 }
  ;;
  ;;
     "libtool":C)
     "libtool":C)
@@ -27013,7 +27080,6 @@ $as_echo X"$file" |
     cat <<_LT_EOF >> "$cfgfile"
     cat <<_LT_EOF >> "$cfgfile"
 #! $SHELL
 #! $SHELL
 # Generated automatically by $as_me ($PACKAGE) $VERSION
 # Generated automatically by $as_me ($PACKAGE) $VERSION
-# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
 # NOTE: Changes made to this file will be lost: look at ltmain.sh.
 # NOTE: Changes made to this file will be lost: look at ltmain.sh.
 
 
 # Provide generalized library-building support services.
 # Provide generalized library-building support services.

+ 18 - 2
configure.ac

@@ -4,7 +4,7 @@ dnl $Id$
 AC_PREREQ([2.69])
 AC_PREREQ([2.69])
 
 
 dnl Set version info here!
 dnl Set version info here!
-AC_INIT([tcpreplay],[4.4.3],[https://github.com/appneta/tcpreplay/issues],[tcpreplay],[http://tcpreplay.sourceforge.net/])
+AC_INIT([tcpreplay],[4.4.4],[https://github.com/appneta/tcpreplay/issues],[tcpreplay],[http://tcpreplay.sourceforge.net/])
 AC_CONFIG_SRCDIR([src/tcpreplay.c])
 AC_CONFIG_SRCDIR([src/tcpreplay.c])
 AC_CONFIG_HEADERS([src/config.h])
 AC_CONFIG_HEADERS([src/config.h])
 AC_CONFIG_AUX_DIR(config)
 AC_CONFIG_AUX_DIR(config)
@@ -405,12 +405,28 @@ if test "x$enable_asan" = "xyes"; then
                 [AC_MSG_ERROR([libasan.so not found, this is required for --enable-asan])])
                 [AC_MSG_ERROR([libasan.so not found, this is required for --enable-asan])])
         CFLAGS="${CFLAGS} -O1 -g -fsanitize=address -fno-omit-frame-pointer"
         CFLAGS="${CFLAGS} -O1 -g -fsanitize=address -fno-omit-frame-pointer"
         dnl -lasan always need to be the first library
         dnl -lasan always need to be the first library
-        LDFLAGS="-lasan ${LDFLAGS}"
+        LDFLAGS="-fsanitize=address ${LDFLAGS}"
 else
 else
         build_asan=no
         build_asan=no
 fi
 fi
 AC_SUBST(build_asan)
 AC_SUBST(build_asan)
 
 
+AC_ARG_ENABLE([tsan],
+    AS_HELP_STRING([--enable-tsan],[Enable Thread Sanitizer support]))
+if test "x$enable_tsan" = "xyes"; then
+        build_tsan=yes
+        CFLAGS="${CFLAGS} -O1 -g -fsanitize=thread -fno-omit-frame-pointer"
+        dnl -ltsan always need to be the first library
+        LDFLAGS="-fsanitize=thread ${LDFLAGS}"
+else
+        build_tsan=no
+fi
+AC_SUBST(build_tsan)
+
+if test "$build_asan" = "yes" -a "$build_tsan" = "yes" ; then
+    AC_MSG_ERROR([--enable-asan and --eanble-tsan are mutually exclusive])
+fi
+
 dnl Enable debugging in code/compiler options
 dnl Enable debugging in code/compiler options
 debug=no
 debug=no
 debug_flag=NDEBUG
 debug_flag=NDEBUG

+ 8 - 0
docs/CHANGELOG

@@ -1,3 +1,11 @@
+06/04/2023 Version 4.4.4
+    - overflow check fix for parse_mpls (#795)
+    - tcpreplay-edit: prevent L2 flooding of ipv6 unicast packets (#793)
+    - CVE-2023-27786 bugs caused by strtok_r (#782 #784 #785 #786 #787 #788)
+    - CVE-2023-27783 reachable assert in tcpedit_dlt_cleanup (#780)
+    - add CI and C/C++ Linter and CodeQL (#773)
+    - reachable assert in fast_edit_packet (#772)
+
 01/01/2023 Version 4.4.3
 01/01/2023 Version 4.4.3
     - upgrade autogen/libopts to version 5.18.16 (#759)
     - upgrade autogen/libopts to version 5.18.16 (#759)
     - avoid implicit int in configure.ac (#757)
     - avoid implicit int in configure.ac (#757)

+ 4 - 1
docs/CREDIT

@@ -109,4 +109,7 @@ Halver <GitHub @Halver>
     - specify directories as files
     - specify directories as files
 
 
 Florian Weimer <GitHub @fweimer-rh>
 Florian Weimer <GitHub @fweimer-rh>
-    - Avoid implicit int in configure.ac
+    - Avoid implicit int in configure.ac
+
+David Guti <GitHub @david-guti>
+    - prevent L2 flooding of ipv6 unicast packets for tcpreplay-edit

+ 10 - 5
docs/Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.16.3 from Makefile.am.
 # @configure_input@
 # @configure_input@
 
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 
 # This Makefile.in is free software; the Free Software Foundation
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -240,6 +240,7 @@ build_alias = @build_alias@
 build_asan = @build_asan@
 build_asan = @build_asan@
 build_cpu = @build_cpu@
 build_cpu = @build_cpu@
 build_os = @build_os@
 build_os = @build_os@
+build_tsan = @build_tsan@
 build_vendor = @build_vendor@
 build_vendor = @build_vendor@
 builddir = @builddir@
 builddir = @builddir@
 datadir = @datadir@
 datadir = @datadir@
@@ -276,6 +277,7 @@ prefix = @prefix@
 program_transform_name = @program_transform_name@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
 psdir = @psdir@
 rmmod = @rmmod@
 rmmod = @rmmod@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
 srcdir = @srcdir@
@@ -313,8 +315,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	  *config.status*) \
 	  *config.status*) \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	  *) \
 	  *) \
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
 	esac;
 	esac;
 
 
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
@@ -338,7 +340,10 @@ ctags CTAGS:
 cscope cscopelist:
 cscope cscopelist:
 
 
 
 
-distdir: $(DISTFILES)
+distdir: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	list='$(DISTFILES)'; \
 	list='$(DISTFILES)'; \

+ 34 - 20
lib/Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.16.3 from Makefile.am.
 # @configure_input@
 # @configure_input@
 
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 
 # This Makefile.in is free software; the Free Software Foundation
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -132,7 +132,8 @@ am__v_at_0 = @
 am__v_at_1 = 
 am__v_at_1 = 
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
-am__depfiles_maybe = depfiles
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = ./$(DEPDIR)/strlcat.Po ./$(DEPDIR)/strlcpy.Po
 am__mv = mv -f
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -300,6 +301,7 @@ build_alias = @build_alias@
 build_asan = @build_asan@
 build_asan = @build_asan@
 build_cpu = @build_cpu@
 build_cpu = @build_cpu@
 build_os = @build_os@
 build_os = @build_os@
+build_tsan = @build_tsan@
 build_vendor = @build_vendor@
 build_vendor = @build_vendor@
 builddir = @builddir@
 builddir = @builddir@
 datadir = @datadir@
 datadir = @datadir@
@@ -336,6 +338,7 @@ prefix = @prefix@
 program_transform_name = @program_transform_name@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
 psdir = @psdir@
 rmmod = @rmmod@
 rmmod = @rmmod@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
 srcdir = @srcdir@
@@ -376,8 +379,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	  *config.status*) \
 	  *config.status*) \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	  *) \
 	  *) \
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
 	esac;
 	esac;
 
 
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
@@ -403,8 +406,14 @@ mostlyclean-compile:
 distclean-compile:
 distclean-compile:
 	-rm -f *.tab.c
 	-rm -f *.tab.c
 
 
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strlcat.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strlcpy.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strlcat.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strlcpy.Po@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+	@$(MKDIR_P) $(@D)
+	@echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
 
 
 .c.o:
 .c.o:
 @am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
 @am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@@ -488,7 +497,10 @@ cscopelist-am: $(am__tagged_files)
 distclean-tags:
 distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 
 
-distdir: $(DISTFILES)
+distdir: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	list='$(DISTFILES)'; \
 	list='$(DISTFILES)'; \
@@ -560,7 +572,8 @@ clean-am: clean-generic clean-libtool clean-noinstLIBRARIES \
 	mostlyclean-am
 	mostlyclean-am
 
 
 distclean: distclean-am
 distclean: distclean-am
-	-rm -rf ./$(DEPDIR)
+		-rm -f ./$(DEPDIR)/strlcat.Po
+	-rm -f ./$(DEPDIR)/strlcpy.Po
 	-rm -f Makefile
 	-rm -f Makefile
 distclean-am: clean-am distclean-compile distclean-generic \
 distclean-am: clean-am distclean-compile distclean-generic \
 	distclean-tags
 	distclean-tags
@@ -606,7 +619,8 @@ install-ps-am:
 installcheck-am:
 installcheck-am:
 
 
 maintainer-clean: maintainer-clean-am
 maintainer-clean: maintainer-clean-am
-	-rm -rf ./$(DEPDIR)
+		-rm -f ./$(DEPDIR)/strlcat.Po
+	-rm -f ./$(DEPDIR)/strlcpy.Po
 	-rm -f Makefile
 	-rm -f Makefile
 maintainer-clean-am: distclean-am maintainer-clean-generic
 maintainer-clean-am: distclean-am maintainer-clean-generic
 
 
@@ -627,16 +641,16 @@ uninstall-am:
 
 
 .MAKE: install-am install-strip
 .MAKE: install-am install-strip
 
 
-.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
-	clean-libtool clean-noinstLIBRARIES cscopelist-am ctags \
-	ctags-am distclean distclean-compile distclean-generic \
-	distclean-libtool distclean-tags distdir dvi dvi-am html \
-	html-am info info-am install install-am 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 \
+.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
+	clean-generic clean-libtool clean-noinstLIBRARIES \
+	cscopelist-am ctags ctags-am distclean distclean-compile \
+	distclean-generic distclean-libtool distclean-tags distdir dvi \
+	dvi-am html html-am info info-am install install-am \
+	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 \
 	maintainer-clean-generic mostlyclean mostlyclean-compile \
 	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
 	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
 	tags tags-am uninstall uninstall-am
 	tags tags-am uninstall uninstall-am

+ 20 - 21
lib/strlcat.c

@@ -16,7 +16,6 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
  */
 
 
-#include <sys/types.h>
 #include <string.h>
 #include <string.h>
 
 
 /*
 /*
@@ -29,27 +28,27 @@
 size_t
 size_t
 strlcat(char *dst, const char *src, size_t dsize)
 strlcat(char *dst, const char *src, size_t dsize)
 {
 {
-	const char *odst = dst;
-	const char *osrc = src;
-	size_t n = dsize;
-	size_t dlen;
+    const char *odst = dst;
+    const char *osrc = src;
+    size_t n = dsize;
+    size_t dlen;
 
 
-	/* Find the end of dst and adjust bytes left but don't go past end. */
-	while (n-- != 0 && *dst != '\0')
-		dst++;
-	dlen = dst - odst;
-	n = dsize - dlen;
+    /* Find the end of dst and adjust bytes left but don't go past end. */
+    while (n-- != 0 && *dst != '\0')
+        dst++;
+    dlen = dst - odst;
+    n = dsize - dlen;
 
 
-	if (n-- == 0)
-		return(dlen + strlen(src));
-	while (*src != '\0') {
-		if (n != 0) {
-			*dst++ = *src;
-			n--;
-		}
-		src++;
-	}
-	*dst = '\0';
+    if (n-- == 0)
+        return (dlen + strlen(src));
+    while (*src != '\0') {
+        if (n != 0) {
+            *dst++ = *src;
+            n--;
+        }
+        src++;
+    }
+    *dst = '\0';
 
 
-	return(dlen + (src - osrc));	/* count does not include NUL */
+    return (dlen + (src - osrc)); /* count does not include NUL */
 }
 }

+ 17 - 18
lib/strlcpy.c

@@ -16,7 +16,6 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
  */
 
 
-#include <sys/types.h>
 #include <string.h>
 #include <string.h>
 
 
 /*
 /*
@@ -27,24 +26,24 @@
 size_t
 size_t
 strlcpy(char *dst, const char *src, size_t dsize)
 strlcpy(char *dst, const char *src, size_t dsize)
 {
 {
-	const char *osrc = src;
-	size_t nleft = dsize;
+    const char *osrc = src;
+    size_t nleft = dsize;
 
 
-	/* Copy as many bytes as will fit. */
-	if (nleft != 0) {
-		while (--nleft != 0) {
-			if ((*dst++ = *src++) == '\0')
-				break;
-		}
-	}
+    /* Copy as many bytes as will fit. */
+    if (nleft != 0) {
+        while (--nleft != 0) {
+            if ((*dst++ = *src++) == '\0')
+                break;
+        }
+    }
 
 
-	/* Not enough room in dst, add NUL and traverse rest of src. */
-	if (nleft == 0) {
-		if (dsize != 0)
-			*dst = '\0';		/* NUL-terminate dst */
-		while (*src++)
-			;
-	}
+    /* Not enough room in dst, add NUL and traverse rest of src. */
+    if (nleft == 0) {
+        if (dsize != 0)
+            *dst = '\0'; /* NUL-terminate dst */
+        while (*src++)
+            ;
+    }
 
 
-	return(src - osrc - 1);	/* count does not include NUL */
+    return (src - osrc - 1); /* count does not include NUL */
 }
 }

+ 39 - 26
libopts/Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.16.3 from Makefile.am.
 # @configure_input@
 # @configure_input@
 
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 
 # This Makefile.in is free software; the Free Software Foundation
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -159,7 +159,8 @@ am__v_at_0 = @
 am__v_at_1 = 
 am__v_at_1 = 
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
-am__depfiles_maybe = depfiles
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = ./$(DEPDIR)/libopts_la-libopts.Plo
 am__mv = mv -f
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -323,6 +324,7 @@ build_alias = @build_alias@
 build_asan = @build_asan@
 build_asan = @build_asan@
 build_cpu = @build_cpu@
 build_cpu = @build_cpu@
 build_os = @build_os@
 build_os = @build_os@
+build_tsan = @build_tsan@
 build_vendor = @build_vendor@
 build_vendor = @build_vendor@
 builddir = @builddir@
 builddir = @builddir@
 datadir = @datadir@
 datadir = @datadir@
@@ -359,6 +361,7 @@ prefix = @prefix@
 program_transform_name = @program_transform_name@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
 psdir = @psdir@
 rmmod = @rmmod@
 rmmod = @rmmod@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
 srcdir = @srcdir@
@@ -422,8 +425,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	  *config.status*) \
 	  *config.status*) \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	  *) \
 	  *) \
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
 	esac;
 	esac;
 
 
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
@@ -490,7 +493,13 @@ mostlyclean-compile:
 distclean-compile:
 distclean-compile:
 	-rm -f *.tab.c
 	-rm -f *.tab.c
 
 
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libopts_la-libopts.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libopts_la-libopts.Plo@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+	@$(MKDIR_P) $(@D)
+	@echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
 
 
 .c.o:
 .c.o:
 @am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
 @am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@@ -581,7 +590,10 @@ cscopelist-am: $(am__tagged_files)
 distclean-tags:
 distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 
 
-distdir: $(DISTFILES)
+distdir: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	list='$(DISTFILES)'; \
 	list='$(DISTFILES)'; \
@@ -621,7 +633,8 @@ installdirs:
 	done
 	done
 install: $(BUILT_SOURCES)
 install: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) install-am
 	$(MAKE) $(AM_MAKEFLAGS) install-am
-install-exec: install-exec-am
+install-exec: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) install-exec-am
 install-data: install-data-am
 install-data: install-data-am
 uninstall: uninstall-am
 uninstall: uninstall-am
 
 
@@ -659,7 +672,7 @@ clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
 	clean-noinstLTLIBRARIES mostlyclean-am
 	clean-noinstLTLIBRARIES mostlyclean-am
 
 
 distclean: distclean-am
 distclean: distclean-am
-	-rm -rf ./$(DEPDIR)
+		-rm -f ./$(DEPDIR)/libopts_la-libopts.Plo
 	-rm -f Makefile
 	-rm -f Makefile
 distclean-am: clean-am distclean-compile distclean-generic \
 distclean-am: clean-am distclean-compile distclean-generic \
 	distclean-tags
 	distclean-tags
@@ -705,7 +718,7 @@ install-ps-am:
 installcheck-am:
 installcheck-am:
 
 
 maintainer-clean: maintainer-clean-am
 maintainer-clean: maintainer-clean-am
-	-rm -rf ./$(DEPDIR)
+		-rm -f ./$(DEPDIR)/libopts_la-libopts.Plo
 	-rm -f Makefile
 	-rm -f Makefile
 maintainer-clean-am: distclean-am maintainer-clean-generic
 maintainer-clean-am: distclean-am maintainer-clean-generic
 
 
@@ -724,22 +737,22 @@ ps-am:
 
 
 uninstall-am: uninstall-libLTLIBRARIES
 uninstall-am: uninstall-libLTLIBRARIES
 
 
-.MAKE: all check install install-am install-strip
-
-.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
-	clean-libLTLIBRARIES clean-libtool clean-noinstLTLIBRARIES \
-	cscopelist-am ctags ctags-am distclean distclean-compile \
-	distclean-generic distclean-libtool distclean-tags distdir dvi \
-	dvi-am html html-am info info-am install install-am \
-	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-libLTLIBRARIES \
-	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 \
-	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
-	uninstall-am uninstall-libLTLIBRARIES
+.MAKE: all check install install-am install-exec install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
+	clean-generic clean-libLTLIBRARIES clean-libtool \
+	clean-noinstLTLIBRARIES cscopelist-am ctags ctags-am distclean \
+	distclean-compile distclean-generic distclean-libtool \
+	distclean-tags distdir dvi dvi-am html html-am info info-am \
+	install install-am 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-libLTLIBRARIES 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 mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags tags-am uninstall uninstall-am uninstall-libLTLIBRARIES
 
 
 .PRECIOUS: Makefile
 .PRECIOUS: Makefile
 
 

+ 1 - 1
libopts/autoopts.h

@@ -455,7 +455,7 @@ typedef enum { AOFLAG_TABLE } ao_flags_t;
 #undef  _aof_
 #undef  _aof_
 
 
 static char const   zNil[] = "";
 static char const   zNil[] = "";
-static arg_types_t  argTypes             = { NULL };
+static arg_types_t  argTypes;
 static char         line_fmt_buf[32];
 static char         line_fmt_buf[32];
 static bool         displayEnum          = false;
 static bool         displayEnum          = false;
 static char const   pkgdatadir_default[] = PKGDATADIR;
 static char const   pkgdatadir_default[] = PKGDATADIR;

+ 2 - 1
libopts/enum.c

@@ -229,7 +229,8 @@ find_name(char const * name, tOptions * pOpts, tOptDesc * pOD,
 char const *
 char const *
 optionKeywordName(tOptDesc * pOD, unsigned int enum_val)
 optionKeywordName(tOptDesc * pOD, unsigned int enum_val)
 {
 {
-    tOptDesc od = { 0 };
+    tOptDesc od;
+    memset(&od, 0, sizeof(od));
     od.optArg.argEnum = enum_val;
     od.optArg.argEnum = enum_val;
 
 
     (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, &od );
     (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, &od );

+ 2 - 1
libopts/save.c

@@ -42,6 +42,7 @@ static char const *
 find_dir_name(tOptions * opts, int * p_free)
 find_dir_name(tOptions * opts, int * p_free)
 {
 {
     char const * dir;
     char const * dir;
+    int idx;
 
 
     if (  (opts->specOptIdx.save_opts == NO_EQUIVALENT)
     if (  (opts->specOptIdx.save_opts == NO_EQUIVALENT)
        || (opts->specOptIdx.save_opts == 0))
        || (opts->specOptIdx.save_opts == 0))
@@ -66,7 +67,7 @@ find_dir_name(tOptions * opts, int * p_free)
      *  This function only works if there is a directory where
      *  This function only works if there is a directory where
      *  we can stash the RC (INI) file.
      *  we can stash the RC (INI) file.
      */
      */
-    for (int idx = 0;; idx++) {
+    for (idx = 0;; idx++) {
         char f_name[ AG_PATH_MAX+1 ];
         char f_name[ AG_PATH_MAX+1 ];
 
 
         dir = opts->papzHomeList[idx];
         dir = opts->papzHomeList[idx];

+ 42 - 17
m4/libtool.m4

@@ -728,7 +728,6 @@ _LT_CONFIG_SAVE_COMMANDS([
     cat <<_LT_EOF >> "$cfgfile"
     cat <<_LT_EOF >> "$cfgfile"
 #! $SHELL
 #! $SHELL
 # Generated automatically by $as_me ($PACKAGE) $VERSION
 # Generated automatically by $as_me ($PACKAGE) $VERSION
-# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
 # NOTE: Changes made to this file will be lost: look at ltmain.sh.
 # NOTE: Changes made to this file will be lost: look at ltmain.sh.
 
 
 # Provide generalized library-building support services.
 # Provide generalized library-building support services.
@@ -1042,8 +1041,8 @@ int forced_loaded() { return 2;}
 _LT_EOF
 _LT_EOF
       echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD
       echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD
       $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD
       $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD
-      echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD
-      $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD
+      echo "$AR cr libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD
+      $AR cr libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD
       echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD
       echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD
       $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD
       $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD
       cat > conftest.c << _LT_EOF
       cat > conftest.c << _LT_EOF
@@ -1072,11 +1071,11 @@ _LT_EOF
       # to the OS version, if on x86, and 10.4, the deployment
       # to the OS version, if on x86, and 10.4, the deployment
       # target defaults to 10.4. Don't you love it?
       # target defaults to 10.4. Don't you love it?
       case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
       case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
-	10.0,*86*-darwin8*|10.0,*-darwin[[91]]*)
+	10.0,*86*-darwin8*|10.0,*-darwin[[912]]*)
 	  _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
 	  _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
 	10.[[012]][[,.]]*)
 	10.[[012]][[,.]]*)
 	  _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;;
 	  _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;;
-	10.*)
+	10.*|11.*)
 	  _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
 	  _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
       esac
       esac
     ;;
     ;;
@@ -1493,7 +1492,7 @@ need_locks=$enable_libtool_lock
 m4_defun([_LT_PROG_AR],
 m4_defun([_LT_PROG_AR],
 [AC_CHECK_TOOLS(AR, [ar], false)
 [AC_CHECK_TOOLS(AR, [ar], false)
 : ${AR=ar}
 : ${AR=ar}
-: ${AR_FLAGS=cru}
+: ${AR_FLAGS=cr}
 _LT_DECL([], [AR], [1], [The archiver])
 _LT_DECL([], [AR], [1], [The archiver])
 _LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive])
 _LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive])
 
 
@@ -2887,6 +2886,18 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
   dynamic_linker='GNU/Linux ld.so'
   dynamic_linker='GNU/Linux ld.so'
   ;;
   ;;
 
 
+netbsdelf*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='NetBSD ld.elf_so'
+  ;;
+
 netbsd*)
 netbsd*)
   version_type=sunos
   version_type=sunos
   need_lib_prefix=no
   need_lib_prefix=no
@@ -3546,7 +3557,7 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
   lt_cv_deplibs_check_method=pass_all
   lt_cv_deplibs_check_method=pass_all
   ;;
   ;;
 
 
-netbsd*)
+netbsd* | netbsdelf*-gnu)
   if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
   if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
     lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
     lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
   else
   else
@@ -4052,7 +4063,8 @@ _LT_EOF
   if AC_TRY_EVAL(ac_compile); then
   if AC_TRY_EVAL(ac_compile); then
     # Now try to grab the symbols.
     # Now try to grab the symbols.
     nlist=conftest.nm
     nlist=conftest.nm
-    if AC_TRY_EVAL(NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) && test -s "$nlist"; then
+    $ECHO "$as_me:$LINENO: $NM conftest.$ac_objext | $lt_cv_sys_global_symbol_pipe > $nlist" >&AS_MESSAGE_LOG_FD
+    if eval "$NM" conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist 2>&AS_MESSAGE_LOG_FD && test -s "$nlist"; then
       # Try sorting and uniquifying the output.
       # Try sorting and uniquifying the output.
       if sort "$nlist" | uniq > "$nlist"T; then
       if sort "$nlist" | uniq > "$nlist"T; then
 	mv -f "$nlist"T "$nlist"
 	mv -f "$nlist"T "$nlist"
@@ -4424,7 +4436,7 @@ m4_if([$1], [CXX], [
 	    ;;
 	    ;;
 	esac
 	esac
 	;;
 	;;
-      netbsd*)
+      netbsd* | netbsdelf*-gnu)
 	;;
 	;;
       *qnx* | *nto*)
       *qnx* | *nto*)
         # QNX uses GNU C++, but need to define -shared option too, otherwise
         # QNX uses GNU C++, but need to define -shared option too, otherwise
@@ -4692,6 +4704,12 @@ m4_if([$1], [CXX], [
 	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
 	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
 	_LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
 	_LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
         ;;
         ;;
+      # flang / f18. f95 an alias for gfortran or flang on Debian
+      flang* | f18* | f95*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
       # icc used to be incompatible with GCC.
       # icc used to be incompatible with GCC.
       # ICC 10 doesn't accept -KPIC any more.
       # ICC 10 doesn't accept -KPIC any more.
       icc* | ifort*)
       icc* | ifort*)
@@ -4936,6 +4954,9 @@ m4_if([$1], [CXX], [
       ;;
       ;;
     esac
     esac
     ;;
     ;;
+  linux* | k*bsd*-gnu | gnu*)
+    _LT_TAGVAR(link_all_deplibs, $1)=no
+    ;;
   *)
   *)
     _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
     _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
     ;;
     ;;
@@ -4998,6 +5019,9 @@ dnl Note also adjust exclude_expsyms for C++ above.
   openbsd* | bitrig*)
   openbsd* | bitrig*)
     with_gnu_ld=no
     with_gnu_ld=no
     ;;
     ;;
+  linux* | k*bsd*-gnu | gnu*)
+    _LT_TAGVAR(link_all_deplibs, $1)=no
+    ;;
   esac
   esac
 
 
   _LT_TAGVAR(ld_shlibs, $1)=yes
   _LT_TAGVAR(ld_shlibs, $1)=yes
@@ -5252,7 +5276,7 @@ _LT_EOF
       fi
       fi
       ;;
       ;;
 
 
-    netbsd*)
+    netbsd* | netbsdelf*-gnu)
       if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
       if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
 	_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
 	_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
 	wlarc=
 	wlarc=
@@ -5773,6 +5797,7 @@ _LT_EOF
 	if test yes = "$lt_cv_irix_exported_symbol"; then
 	if test yes = "$lt_cv_irix_exported_symbol"; then
           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib'
           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib'
 	fi
 	fi
+	_LT_TAGVAR(link_all_deplibs, $1)=no
       else
       else
 	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib'
 	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib'
 	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib'
 	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib'
@@ -5794,7 +5819,7 @@ _LT_EOF
       esac
       esac
       ;;
       ;;
 
 
-    netbsd*)
+    netbsd* | netbsdelf*-gnu)
       if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
       if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
 	_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
 	_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
       else
       else
@@ -6420,7 +6445,7 @@ if test yes != "$_lt_caught_CXX_error"; then
       # Commands to make compiler produce verbose output that lists
       # Commands to make compiler produce verbose output that lists
       # what "hidden" libraries, object files and flags are used when
       # what "hidden" libraries, object files and flags are used when
       # linking a shared library.
       # linking a shared library.
-      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"'
 
 
     else
     else
       GXX=no
       GXX=no
@@ -6795,7 +6820,7 @@ if test yes != "$_lt_caught_CXX_error"; then
             # explicitly linking system object files so we need to strip them
             # explicitly linking system object files so we need to strip them
             # from the output so that they don't get included in the library
             # from the output so that they don't get included in the library
             # dependencies.
             # dependencies.
-            output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+            output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
             ;;
             ;;
           *)
           *)
             if test yes = "$GXX"; then
             if test yes = "$GXX"; then
@@ -6860,7 +6885,7 @@ if test yes != "$_lt_caught_CXX_error"; then
 	    # explicitly linking system object files so we need to strip them
 	    # explicitly linking system object files so we need to strip them
 	    # from the output so that they don't get included in the library
 	    # from the output so that they don't get included in the library
 	    # dependencies.
 	    # dependencies.
-	    output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+	    output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
 	    ;;
 	    ;;
           *)
           *)
 	    if test yes = "$GXX"; then
 	    if test yes = "$GXX"; then
@@ -7199,7 +7224,7 @@ if test yes != "$_lt_caught_CXX_error"; then
 	      # Commands to make compiler produce verbose output that lists
 	      # Commands to make compiler produce verbose output that lists
 	      # what "hidden" libraries, object files and flags are used when
 	      # what "hidden" libraries, object files and flags are used when
 	      # linking a shared library.
 	      # linking a shared library.
-	      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+	      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"'
 
 
 	    else
 	    else
 	      # FIXME: insert proper C++ library support
 	      # FIXME: insert proper C++ library support
@@ -7283,7 +7308,7 @@ if test yes != "$_lt_caught_CXX_error"; then
 	        # Commands to make compiler produce verbose output that lists
 	        # Commands to make compiler produce verbose output that lists
 	        # what "hidden" libraries, object files and flags are used when
 	        # what "hidden" libraries, object files and flags are used when
 	        # linking a shared library.
 	        # linking a shared library.
-	        output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+	        output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"'
 	      else
 	      else
 	        # g++ 2.7 appears to require '-G' NOT '-shared' on this
 	        # g++ 2.7 appears to require '-G' NOT '-shared' on this
 	        # platform.
 	        # platform.
@@ -7294,7 +7319,7 @@ if test yes != "$_lt_caught_CXX_error"; then
 	        # Commands to make compiler produce verbose output that lists
 	        # Commands to make compiler produce verbose output that lists
 	        # what "hidden" libraries, object files and flags are used when
 	        # what "hidden" libraries, object files and flags are used when
 	        # linking a shared library.
 	        # linking a shared library.
-	        output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+	        output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"'
 	      fi
 	      fi
 
 
 	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $wl$libdir'
 	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $wl$libdir'

+ 10 - 5
scripts/Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.16.3 from Makefile.am.
 # @configure_input@
 # @configure_input@
 
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 
 # This Makefile.in is free software; the Free Software Foundation
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -240,6 +240,7 @@ build_alias = @build_alias@
 build_asan = @build_asan@
 build_asan = @build_asan@
 build_cpu = @build_cpu@
 build_cpu = @build_cpu@
 build_os = @build_os@
 build_os = @build_os@
+build_tsan = @build_tsan@
 build_vendor = @build_vendor@
 build_vendor = @build_vendor@
 builddir = @builddir@
 builddir = @builddir@
 datadir = @datadir@
 datadir = @datadir@
@@ -276,6 +277,7 @@ prefix = @prefix@
 program_transform_name = @program_transform_name@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
 psdir = @psdir@
 rmmod = @rmmod@
 rmmod = @rmmod@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
 srcdir = @srcdir@
@@ -312,8 +314,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	  *config.status*) \
 	  *config.status*) \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	  *) \
 	  *) \
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
 	esac;
 	esac;
 
 
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
@@ -337,7 +339,10 @@ ctags CTAGS:
 cscope cscopelist:
 cscope cscopelist:
 
 
 
 
-distdir: $(DISTFILES)
+distdir: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	list='$(DISTFILES)'; \
 	list='$(DISTFILES)'; \

+ 3 - 3
src/Makefile.am

@@ -41,10 +41,10 @@ tcpreplay.1: tcpreplay_opts.def
 tcpbridge.1: tcpbridge_opts.def
 tcpbridge.1: tcpbridge_opts.def
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 
 
-tcpliveplay.1: tcpliveplay_opts.def 
+tcpliveplay.1: tcpliveplay_opts.def
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 
 
-tcpcapinfo.1: tcpcapinfo_opts.def 
+tcpcapinfo.1: tcpcapinfo_opts.def
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 
 
 man_MANS = tcpreplay.1 tcpprep.1 tcprewrite.1 tcpreplay-edit.1 tcpcapinfo.1
 man_MANS = tcpreplay.1 tcpprep.1 tcprewrite.1 tcpreplay-edit.1 tcpcapinfo.1
@@ -58,7 +58,7 @@ man_MANS += tcpbridge.1
 endif
 endif
 
 
 if COMPILE_TCPLIVEPLAY
 if COMPILE_TCPLIVEPLAY
-bin_PROGRAMS += tcpliveplay 
+bin_PROGRAMS += tcpliveplay
 man_MANS += tcpliveplay.1
 man_MANS += tcpliveplay.1
 endif
 endif
 
 

+ 150 - 59
src/Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.16.3 from Makefile.am.
 # @configure_input@
 # @configure_input@
 
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 
 # This Makefile.in is free software; the Free Software Foundation
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -95,7 +95,7 @@ bin_PROGRAMS = tcpreplay$(EXEEXT) tcpprep$(EXEEXT) tcprewrite$(EXEEXT) \
 	$(am__EXEEXT_2)
 	$(am__EXEEXT_2)
 @COMPILE_TCPBRIDGE_TRUE@am__append_1 = tcpbridge 
 @COMPILE_TCPBRIDGE_TRUE@am__append_1 = tcpbridge 
 @COMPILE_TCPBRIDGE_TRUE@am__append_2 = tcpbridge.1
 @COMPILE_TCPBRIDGE_TRUE@am__append_2 = tcpbridge.1
-@COMPILE_TCPLIVEPLAY_TRUE@am__append_3 = tcpliveplay 
+@COMPILE_TCPLIVEPLAY_TRUE@am__append_3 = tcpliveplay
 @COMPILE_TCPLIVEPLAY_TRUE@am__append_4 = tcpliveplay.1
 @COMPILE_TCPLIVEPLAY_TRUE@am__append_4 = tcpliveplay.1
 subdir = src
 subdir = src
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -208,7 +208,33 @@ am__v_at_0 = @
 am__v_at_1 = 
 am__v_at_1 = 
 DEFAULT_INCLUDES = -I.@am__isrc@
 DEFAULT_INCLUDES = -I.@am__isrc@
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
-am__depfiles_maybe = depfiles
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = ./$(DEPDIR)/tcpbridge-bridge.Po \
+	./$(DEPDIR)/tcpbridge-tcpbridge.Po \
+	./$(DEPDIR)/tcpbridge-tcpbridge_opts.Po \
+	./$(DEPDIR)/tcpcapinfo-tcpcapinfo.Po \
+	./$(DEPDIR)/tcpcapinfo-tcpcapinfo_opts.Po \
+	./$(DEPDIR)/tcpliveplay-tcpliveplay.Po \
+	./$(DEPDIR)/tcpliveplay-tcpliveplay_opts.Po \
+	./$(DEPDIR)/tcpprep-tcpprep.Po \
+	./$(DEPDIR)/tcpprep-tcpprep_api.Po \
+	./$(DEPDIR)/tcpprep-tcpprep_opts.Po \
+	./$(DEPDIR)/tcpprep-tree.Po ./$(DEPDIR)/tcpreplay-replay.Po \
+	./$(DEPDIR)/tcpreplay-send_packets.Po \
+	./$(DEPDIR)/tcpreplay-signal_handler.Po \
+	./$(DEPDIR)/tcpreplay-sleep.Po \
+	./$(DEPDIR)/tcpreplay-tcpreplay.Po \
+	./$(DEPDIR)/tcpreplay-tcpreplay_api.Po \
+	./$(DEPDIR)/tcpreplay-tcpreplay_opts.Po \
+	./$(DEPDIR)/tcpreplay_edit-replay.Po \
+	./$(DEPDIR)/tcpreplay_edit-send_packets.Po \
+	./$(DEPDIR)/tcpreplay_edit-signal_handler.Po \
+	./$(DEPDIR)/tcpreplay_edit-sleep.Po \
+	./$(DEPDIR)/tcpreplay_edit-tcpreplay.Po \
+	./$(DEPDIR)/tcpreplay_edit-tcpreplay_api.Po \
+	./$(DEPDIR)/tcpreplay_edit-tcpreplay_edit_opts.Po \
+	./$(DEPDIR)/tcprewrite-tcprewrite.Po \
+	./$(DEPDIR)/tcprewrite-tcprewrite_opts.Po
 am__mv = mv -f
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -285,9 +311,9 @@ am__recursive_targets = \
   $(RECURSIVE_CLEAN_TARGETS) \
   $(RECURSIVE_CLEAN_TARGETS) \
   $(am__extra_recursive_targets)
   $(am__extra_recursive_targets)
 AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
 AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
-	distdir
-am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
-	$(LISP)config.h.in
+	distdir distdir-am
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
+	config.h.in
 # Read a list of newline-separated strings from the standard input,
 # Read a list of newline-separated strings from the standard input,
 # and print each of them once, without duplicates.  Input order is
 # and print each of them once, without duplicates.  Input order is
 # *not* preserved.
 # *not* preserved.
@@ -450,6 +476,7 @@ build_alias = @build_alias@
 build_asan = @build_asan@
 build_asan = @build_asan@
 build_cpu = @build_cpu@
 build_cpu = @build_cpu@
 build_os = @build_os@
 build_os = @build_os@
+build_tsan = @build_tsan@
 build_vendor = @build_vendor@
 build_vendor = @build_vendor@
 builddir = @builddir@
 builddir = @builddir@
 datadir = @datadir@
 datadir = @datadir@
@@ -486,6 +513,7 @@ prefix = @prefix@
 program_transform_name = @program_transform_name@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
 psdir = @psdir@
 rmmod = @rmmod@
 rmmod = @rmmod@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
 srcdir = @srcdir@
@@ -591,8 +619,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	  *config.status*) \
 	  *config.status*) \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	  *) \
 	  *) \
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
 	esac;
 	esac;
 
 
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
@@ -704,33 +732,39 @@ mostlyclean-compile:
 distclean-compile:
 distclean-compile:
 	-rm -f *.tab.c
 	-rm -f *.tab.c
 
 
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpbridge-bridge.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpbridge-tcpbridge.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpbridge-tcpbridge_opts.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpcapinfo-tcpcapinfo.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpcapinfo-tcpcapinfo_opts.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpliveplay-tcpliveplay.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpliveplay-tcpliveplay_opts.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpprep-tcpprep.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpprep-tcpprep_api.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpprep-tcpprep_opts.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpprep-tree.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-replay.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-send_packets.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-signal_handler.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-sleep.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-tcpreplay.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-tcpreplay_api.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-tcpreplay_opts.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-replay.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-send_packets.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-signal_handler.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-sleep.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-tcpreplay.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-tcpreplay_api.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-tcpreplay_edit_opts.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcprewrite-tcprewrite.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcprewrite-tcprewrite_opts.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpbridge-bridge.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpbridge-tcpbridge.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpbridge-tcpbridge_opts.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpcapinfo-tcpcapinfo.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpcapinfo-tcpcapinfo_opts.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpliveplay-tcpliveplay.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpliveplay-tcpliveplay_opts.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpprep-tcpprep.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpprep-tcpprep_api.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpprep-tcpprep_opts.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpprep-tree.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-replay.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-send_packets.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-signal_handler.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-sleep.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-tcpreplay.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-tcpreplay_api.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay-tcpreplay_opts.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-replay.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-send_packets.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-signal_handler.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-sleep.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-tcpreplay.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-tcpreplay_api.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreplay_edit-tcpreplay_edit_opts.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcprewrite-tcprewrite.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcprewrite-tcprewrite_opts.Po@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+	@$(MKDIR_P) $(@D)
+	@echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
 
 
 .c.o:
 .c.o:
 @am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
 @am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@@ -1282,7 +1316,10 @@ cscopelist-am: $(am__tagged_files)
 distclean-tags:
 distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 
 
-distdir: $(DISTFILES)
+distdir: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	list='$(DISTFILES)'; \
 	list='$(DISTFILES)'; \
@@ -1348,7 +1385,8 @@ installdirs-am:
 	done
 	done
 install: $(BUILT_SOURCES)
 install: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) install-recursive
 	$(MAKE) $(AM_MAKEFLAGS) install-recursive
-install-exec: install-exec-recursive
+install-exec: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) install-exec-recursive
 install-data: install-data-recursive
 install-data: install-data-recursive
 uninstall: uninstall-recursive
 uninstall: uninstall-recursive
 
 
@@ -1385,7 +1423,33 @@ clean: clean-recursive
 clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
 clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
 
 
 distclean: distclean-recursive
 distclean: distclean-recursive
-	-rm -rf ./$(DEPDIR)
+		-rm -f ./$(DEPDIR)/tcpbridge-bridge.Po
+	-rm -f ./$(DEPDIR)/tcpbridge-tcpbridge.Po
+	-rm -f ./$(DEPDIR)/tcpbridge-tcpbridge_opts.Po
+	-rm -f ./$(DEPDIR)/tcpcapinfo-tcpcapinfo.Po
+	-rm -f ./$(DEPDIR)/tcpcapinfo-tcpcapinfo_opts.Po
+	-rm -f ./$(DEPDIR)/tcpliveplay-tcpliveplay.Po
+	-rm -f ./$(DEPDIR)/tcpliveplay-tcpliveplay_opts.Po
+	-rm -f ./$(DEPDIR)/tcpprep-tcpprep.Po
+	-rm -f ./$(DEPDIR)/tcpprep-tcpprep_api.Po
+	-rm -f ./$(DEPDIR)/tcpprep-tcpprep_opts.Po
+	-rm -f ./$(DEPDIR)/tcpprep-tree.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-replay.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-send_packets.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-signal_handler.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-sleep.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-tcpreplay.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-tcpreplay_api.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-tcpreplay_opts.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-replay.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-send_packets.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-signal_handler.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-sleep.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-tcpreplay.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-tcpreplay_api.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-tcpreplay_edit_opts.Po
+	-rm -f ./$(DEPDIR)/tcprewrite-tcprewrite.Po
+	-rm -f ./$(DEPDIR)/tcprewrite-tcprewrite_opts.Po
 	-rm -f Makefile
 	-rm -f Makefile
 distclean-am: clean-am distclean-compile distclean-generic \
 distclean-am: clean-am distclean-compile distclean-generic \
 	distclean-hdr distclean-tags
 	distclean-hdr distclean-tags
@@ -1431,7 +1495,33 @@ install-ps-am:
 installcheck-am:
 installcheck-am:
 
 
 maintainer-clean: maintainer-clean-recursive
 maintainer-clean: maintainer-clean-recursive
-	-rm -rf ./$(DEPDIR)
+		-rm -f ./$(DEPDIR)/tcpbridge-bridge.Po
+	-rm -f ./$(DEPDIR)/tcpbridge-tcpbridge.Po
+	-rm -f ./$(DEPDIR)/tcpbridge-tcpbridge_opts.Po
+	-rm -f ./$(DEPDIR)/tcpcapinfo-tcpcapinfo.Po
+	-rm -f ./$(DEPDIR)/tcpcapinfo-tcpcapinfo_opts.Po
+	-rm -f ./$(DEPDIR)/tcpliveplay-tcpliveplay.Po
+	-rm -f ./$(DEPDIR)/tcpliveplay-tcpliveplay_opts.Po
+	-rm -f ./$(DEPDIR)/tcpprep-tcpprep.Po
+	-rm -f ./$(DEPDIR)/tcpprep-tcpprep_api.Po
+	-rm -f ./$(DEPDIR)/tcpprep-tcpprep_opts.Po
+	-rm -f ./$(DEPDIR)/tcpprep-tree.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-replay.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-send_packets.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-signal_handler.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-sleep.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-tcpreplay.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-tcpreplay_api.Po
+	-rm -f ./$(DEPDIR)/tcpreplay-tcpreplay_opts.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-replay.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-send_packets.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-signal_handler.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-sleep.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-tcpreplay.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-tcpreplay_api.Po
+	-rm -f ./$(DEPDIR)/tcpreplay_edit-tcpreplay_edit_opts.Po
+	-rm -f ./$(DEPDIR)/tcprewrite-tcprewrite.Po
+	-rm -f ./$(DEPDIR)/tcprewrite-tcprewrite_opts.Po
 	-rm -f Makefile
 	-rm -f Makefile
 maintainer-clean-am: distclean-am maintainer-clean-generic
 maintainer-clean-am: distclean-am maintainer-clean-generic
 
 
@@ -1453,23 +1543,24 @@ uninstall-am: uninstall-binPROGRAMS uninstall-man
 uninstall-man: uninstall-man1
 uninstall-man: uninstall-man1
 
 
 .MAKE: $(am__recursive_targets) all check install install-am \
 .MAKE: $(am__recursive_targets) all check install install-am \
-	install-strip
-
-.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \
-	check-am clean clean-binPROGRAMS clean-generic clean-libtool \
-	cscopelist-am ctags ctags-am distclean distclean-compile \
-	distclean-generic distclean-hdr distclean-libtool \
-	distclean-tags distdir 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-man1 install-pdf \
-	install-pdf-am install-ps install-ps-am install-strip \
-	installcheck installcheck-am installdirs installdirs-am \
-	maintainer-clean maintainer-clean-generic mostlyclean \
-	mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
-	pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \
-	uninstall-binPROGRAMS uninstall-man uninstall-man1
+	install-exec install-strip
+
+.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \
+	am--depfiles check check-am clean clean-binPROGRAMS \
+	clean-generic clean-libtool cscopelist-am ctags ctags-am \
+	distclean distclean-compile distclean-generic distclean-hdr \
+	distclean-libtool distclean-tags distdir 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-man1 \
+	install-pdf install-pdf-am install-ps install-ps-am \
+	install-strip installcheck installcheck-am installdirs \
+	installdirs-am maintainer-clean maintainer-clean-generic \
+	mostlyclean mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
+	uninstall-am uninstall-binPROGRAMS uninstall-man \
+	uninstall-man1
 
 
 .PRECIOUS: Makefile
 .PRECIOUS: Makefile
 
 
@@ -1494,10 +1585,10 @@ tcpreplay.1: tcpreplay_opts.def
 tcpbridge.1: tcpbridge_opts.def
 tcpbridge.1: tcpbridge_opts.def
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 
 
-tcpliveplay.1: tcpliveplay_opts.def 
+tcpliveplay.1: tcpliveplay_opts.def
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 
 
-tcpcapinfo.1: tcpcapinfo_opts.def 
+tcpcapinfo.1: tcpcapinfo_opts.def
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 	@AUTOGEN@ -T agman-cmd.tpl $(opts_list) $<
 tcpreplay_edit_OBJECTS: tcpreplay_opts.h
 tcpreplay_edit_OBJECTS: tcpreplay_opts.h
 tcpreplay_edit_opts.h: tcpreplay_edit_opts.c
 tcpreplay_edit_opts.h: tcpreplay_edit_opts.c

+ 54 - 93
src/bridge.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,27 +18,17 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include "bridge.h"
 #include "config.h"
 #include "config.h"
-#include "defines.h"
 #include "common.h"
 #include "common.h"
-
-#include <sys/time.h>
-#include <signal.h>
-#include <string.h>
-#include <netinet/in.h>
-#include <time.h>
+#include "tcpbridge.h"
 #include <errno.h>
 #include <errno.h>
+#include <signal.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
 
 
-#include "tcpbridge.h"
-#include "bridge.h"
-#include "tcpedit/tcpedit.h"
-
-extern tcpbridge_opt_t options;
 extern tcpreplay_stats_t stats;
 extern tcpreplay_stats_t stats;
-#ifdef DEBUG
-extern int debug;
-#endif
 volatile bool didsig;
 volatile bool didsig;
 
 
 static void live_callback(u_char *, const struct pcap_pkthdr *, const u_char *);
 static void live_callback(u_char *, const struct pcap_pkthdr *, const u_char *);
@@ -64,15 +54,6 @@ RB_PROTOTYPE(macsrc_tree, macsrc_t, node, rbmacsrc_comp)
 RB_GENERATE(macsrc_tree, macsrc_t, node, rbmacsrc_comp)
 RB_GENERATE(macsrc_tree, macsrc_t, node, rbmacsrc_comp)
 
 
 /**
 /**
- * redblack init
- */
-void
-rbinit(void)
-{
-    RB_INIT(&macsrc_root);
-}
-
-/**
  * create a new node... Malloc's memory
  * create a new node... Malloc's memory
  */
  */
 struct macsrc_t *
 struct macsrc_t *
@@ -86,7 +67,6 @@ new_node(void)
     return (node);
     return (node);
 }
 }
 
 
-
 /**
 /**
  * main loop for bridging in only one direction
  * main loop for bridging in only one direction
  * optimized to not use poll(), but rather libpcap's builtin pcap_loop()
  * optimized to not use poll(), but rather libpcap's builtin pcap_loop()
@@ -105,9 +85,8 @@ do_bridge_unidirectional(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
     livedata.pcap = options->pcap1;
     livedata.pcap = options->pcap1;
     livedata.options = options;
     livedata.options = options;
 
 
-    if ((retcode = pcap_loop(options->pcap1, options->limit_send,
-            live_callback, (u_char*)&livedata)) < 0) {
-        warnx("Error in pcap_loop(): %s", pcap_geterr(options->pcap1));
+    if ((retcode = pcap_loop(options->pcap1, (int)options->limit_send, live_callback, (u_char *)&livedata)) < 0) {
+        warnx("Error in %d pcap_loop(): %s", retcode, pcap_geterr(options->pcap1));
     }
     }
 }
 }
 
 
@@ -118,7 +97,7 @@ do_bridge_unidirectional(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
 static void
 static void
 do_bridge_bidirectional(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
 do_bridge_bidirectional(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
 {
 {
-    struct pollfd polls[2];     /* one for left & right pcap */
+    struct pollfd polls[2]; /* one for left & right pcap */
     int pollresult, pollcount, timeout;
     int pollresult, pollcount, timeout;
     struct live_data_t livedata;
     struct live_data_t livedata;
 
 
@@ -128,8 +107,7 @@ do_bridge_bidirectional(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
     livedata.tcpedit = tcpedit;
     livedata.tcpedit = tcpedit;
     livedata.options = options;
     livedata.options = options;
 
 
-
-    /* 
+    /*
      * loop until ctrl-C or we've sent enough packets
      * loop until ctrl-C or we've sent enough packets
      * note that if -L wasn't specified, limit_send is
      * note that if -L wasn't specified, limit_send is
      * set to 0 so this will loop infinately
      * set to 0 so this will loop infinately
@@ -138,8 +116,7 @@ do_bridge_bidirectional(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
         if (didsig)
         if (didsig)
             break;
             break;
 
 
-        dbgx(3, "limit_send: " COUNTER_SPEC " \t pkts_sent: " COUNTER_SPEC, 
-            options->limit_send, stats.pkts_sent);
+        dbgx(3, "limit_send: " COUNTER_SPEC " \t pkts_sent: " COUNTER_SPEC, options->limit_send, stats.pkts_sent);
 
 
         /* reset the result codes */
         /* reset the result codes */
         polls[PCAP_INT1].revents = 0;
         polls[PCAP_INT1].revents = 0;
@@ -165,8 +142,7 @@ do_bridge_bidirectional(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
                 dbg(5, "Processing first interface");
                 dbg(5, "Processing first interface");
                 livedata.source = PCAP_INT1;
                 livedata.source = PCAP_INT1;
                 livedata.pcap = options->pcap1;
                 livedata.pcap = options->pcap1;
-                pcap_dispatch(options->pcap1, -1, (pcap_handler) live_callback,
-                              (u_char *) &livedata);
+                pcap_dispatch(options->pcap1, -1, (pcap_handler)live_callback, (u_char *)&livedata);
             }
             }
 
 
             /* check the other interface?? */
             /* check the other interface?? */
@@ -174,16 +150,13 @@ do_bridge_bidirectional(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
                 dbg(5, "Processing second interface");
                 dbg(5, "Processing second interface");
                 livedata.source = PCAP_INT2;
                 livedata.source = PCAP_INT2;
                 livedata.pcap = options->pcap2;
                 livedata.pcap = options->pcap2;
-                pcap_dispatch(options->pcap2, -1, (pcap_handler) live_callback,
-                              (u_char *) &livedata);
+                pcap_dispatch(options->pcap2, -1, (pcap_handler)live_callback, (u_char *)&livedata);
             }
             }
 
 
-        }
-        else if (pollresult == 0) {
+        } else if (pollresult == 0) {
             dbg(3, "poll timeout exceeded...");
             dbg(3, "poll timeout exceeded...");
             /* do something here? */
             /* do something here? */
-        }
-        else {
+        } else {
             /* poll error, probably a Ctrl-C */
             /* poll error, probably a Ctrl-C */
             warnx("poll() error: %s", strerror(errno));
             warnx("poll() error: %s", strerror(errno));
         }
         }
@@ -193,9 +166,8 @@ do_bridge_bidirectional(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
 
 
 } /* do_bridge_bidirectional() */
 } /* do_bridge_bidirectional() */
 
 
-
 /**
 /**
- * Main entry point to bridging.  Does some initial setup and then calls the 
+ * Main entry point to bridging.  Does some initial setup and then calls the
  * correct loop (unidirectional or bidirectional)
  * correct loop (unidirectional or bidirectional)
  */
  */
 void
 void
@@ -217,7 +189,8 @@ do_bridge(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
         if (options->unidir == 0) {
         if (options->unidir == 0) {
             /* compile filter */
             /* compile filter */
             dbgx(2, "Try to compile pcap bpf filter: %s", options->bpf.filter);
             dbgx(2, "Try to compile pcap bpf filter: %s", options->bpf.filter);
-            if (pcap_compile(options->pcap2, &options->bpf.program, options->bpf.filter, options->bpf.optimize, 0) != 0) {
+            if (pcap_compile(options->pcap2, &options->bpf.program, options->bpf.filter, options->bpf.optimize, 0) !=
+                0) {
                 errx(-1, "Error compiling BPF filter: %s", pcap_geterr(options->pcap2));
                 errx(-1, "Error compiling BPF filter: %s", pcap_geterr(options->pcap2));
             }
             }
 
 
@@ -231,7 +204,6 @@ do_bridge(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
     didsig = 0;
     didsig = 0;
     (void)signal(SIGINT, signal_catcher);
     (void)signal(SIGINT, signal_catcher);
 
 
-
     if (options->unidir == 1) {
     if (options->unidir == 1) {
         do_bridge_unidirectional(options, tcpedit);
         do_bridge_unidirectional(options, tcpedit);
     } else {
     } else {
@@ -239,30 +211,28 @@ do_bridge(tcpbridge_opt_t *options, tcpedit_t *tcpedit)
     }
     }
 
 
     if (gettimeofday(&stats.end_time, NULL) < 0)
     if (gettimeofday(&stats.end_time, NULL) < 0)
-        errx(-1, "gettimeofday() failed: %s",  strerror(errno));
+        errx(-1, "gettimeofday() failed: %s", strerror(errno));
     packet_stats(&stats);
     packet_stats(&stats);
 }
 }
 
 
-
 /**
 /**
  * This is the callback we use with pcap_dispatch to process
  * This is the callback we use with pcap_dispatch to process
  * each packet received by libpcap on the two interfaces.
  * each packet received by libpcap on the two interfaces.
  * Need to return > 0 to denote success
  * Need to return > 0 to denote success
  */
  */
 static void
 static void
-live_callback(u_char *usr_data, const struct pcap_pkthdr *const_pkthdr,
-              const u_char * nextpkt)
+live_callback(u_char *usr_data, const struct pcap_pkthdr *const_pkthdr, const u_char *nextpkt)
 {
 {
-    struct live_data_t *livedata = (struct live_data_t*)usr_data;
+    struct live_data_t *livedata = (struct live_data_t *)usr_data;
     struct pcap_pkthdr pkthdr_buf = *const_pkthdr;
     struct pcap_pkthdr pkthdr_buf = *const_pkthdr;
     struct pcap_pkthdr *pkthdr = &pkthdr_buf;
     struct pcap_pkthdr *pkthdr = &pkthdr_buf;
     ipv4_hdr_t *ip_hdr = NULL;
     ipv4_hdr_t *ip_hdr = NULL;
     ipv6_hdr_t *ip6_hdr = NULL;
     ipv6_hdr_t *ip6_hdr = NULL;
     pcap_t *send = NULL;
     pcap_t *send = NULL;
-    static u_char *pktdata = NULL;     /* full packet buffer */
-    int cache_mode, retcode;
+    static u_char *pktdata = NULL; /* full packet buffer */
+    int cache_mode;
     static unsigned long packetnum = 0;
     static unsigned long packetnum = 0;
-    struct macsrc_t *node, finder;  /* rb tree nodes */
+    struct macsrc_t *node, finder; /* rb tree nodes */
 #ifdef DEBUG
 #ifdef DEBUG
     u_char dstmac[ETHER_ADDR_LEN];
     u_char dstmac[ETHER_ADDR_LEN];
 #endif
 #endif
@@ -283,28 +253,24 @@ live_callback(u_char *usr_data, const struct pcap_pkthdr *const_pkthdr,
     /* copy the packet to our buffer */
     /* copy the packet to our buffer */
     memcpy(pktdata, nextpkt, pkthdr->caplen);
     memcpy(pktdata, nextpkt, pkthdr->caplen);
 
 
-
 #ifdef ENABLE_VERBOSE
 #ifdef ENABLE_VERBOSE
     /* decode packet? */
     /* decode packet? */
     if (livedata->options->verbose)
     if (livedata->options->verbose)
         tcpdump_print(livedata->options->tcpdump, pkthdr, nextpkt);
         tcpdump_print(livedata->options->tcpdump, pkthdr, nextpkt);
 #endif
 #endif
 
 
-
     /* lookup our source MAC in the tree */
     /* lookup our source MAC in the tree */
     memcpy(&finder.key, &pktdata[ETHER_ADDR_LEN], ETHER_ADDR_LEN);
     memcpy(&finder.key, &pktdata[ETHER_ADDR_LEN], ETHER_ADDR_LEN);
 #ifdef DEBUG
 #ifdef DEBUG
     memcpy(&dstmac, pktdata, ETHER_ADDR_LEN);
     memcpy(&dstmac, pktdata, ETHER_ADDR_LEN);
-    dbgx(1, "SRC MAC: " MAC_FORMAT "\tDST MAC: " MAC_FORMAT,
-        MAC_STR(finder.key), MAC_STR(dstmac));
+    dbgx(1, "SRC MAC: " MAC_FORMAT "\tDST MAC: " MAC_FORMAT, MAC_STR(finder.key), MAC_STR(dstmac));
 #endif
 #endif
 
 
     /* first, is this a packet sent locally?  If so, ignore it */
     /* first, is this a packet sent locally?  If so, ignore it */
     if ((memcmp(livedata->options->intf1_mac, &finder.key, ETHER_ADDR_LEN)) == 0) {
     if ((memcmp(livedata->options->intf1_mac, &finder.key, ETHER_ADDR_LEN)) == 0) {
         dbgx(1, "Packet matches the MAC of %s, skipping.", livedata->options->intf1);
         dbgx(1, "Packet matches the MAC of %s, skipping.", livedata->options->intf1);
         return;
         return;
-    }
-    else if ((memcmp(livedata->options->intf2_mac, &finder.key, ETHER_ADDR_LEN)) == 0) {
+    } else if ((memcmp(livedata->options->intf2_mac, &finder.key, ETHER_ADDR_LEN)) == 0) {
         dbgx(1, "Packet matches the MAC of %s, skipping.", livedata->options->intf2);
         dbgx(1, "Packet matches the MAC of %s, skipping.", livedata->options->intf2);
         return;
         return;
     }
     }
@@ -333,27 +299,25 @@ live_callback(u_char *usr_data, const struct pcap_pkthdr *const_pkthdr,
     /* what is our cache mode? */
     /* what is our cache mode? */
     cache_mode = livedata->source == PCAP_INT1 ? TCPR_DIR_C2S : TCPR_DIR_S2C;
     cache_mode = livedata->source == PCAP_INT1 ? TCPR_DIR_C2S : TCPR_DIR_S2C;
 
 
-    l2proto = tcpedit_l3proto(livedata->tcpedit, BEFORE_PROCESS, pktdata, pkthdr->len);
+    l2proto = tcpedit_l3proto(livedata->tcpedit, BEFORE_PROCESS, pktdata, (int)pkthdr->len);
     dbgx(2, "Packet protocol: %04hx", l2proto);
     dbgx(2, "Packet protocol: %04hx", l2proto);
 
 
     /* should we skip this packet based on CIDR match? */
     /* should we skip this packet based on CIDR match? */
     if (l2proto == ETHERTYPE_IP) {
     if (l2proto == ETHERTYPE_IP) {
         dbg(3, "Packet is IPv4");
         dbg(3, "Packet is IPv4");
-        ip_hdr = (ipv4_hdr_t *)tcpedit_l3data(livedata->tcpedit, BEFORE_PROCESS, pktdata, pkthdr->len);
+        ip_hdr = (ipv4_hdr_t *)tcpedit_l3data(livedata->tcpedit, BEFORE_PROCESS, pktdata, (int)pkthdr->len);
 
 
         /* look for include or exclude CIDR match */
         /* look for include or exclude CIDR match */
         if (livedata->options->xX.cidr != NULL) {
         if (livedata->options->xX.cidr != NULL) {
-            if (!ip_hdr ||
-                    !process_xX_by_cidr_ipv4(livedata->options->xX.mode, livedata->options->xX.cidr, ip_hdr)) {
+            if (!ip_hdr || !process_xX_by_cidr_ipv4(livedata->options->xX.mode, livedata->options->xX.cidr, ip_hdr)) {
                 dbg(2, "Skipping IPv4 packet due to CIDR match");
                 dbg(2, "Skipping IPv4 packet due to CIDR match");
                 return;
                 return;
             }
             }
         }
         }
 
 
-    }
-    else if (l2proto == ETHERTYPE_IP6) {
+    } else if (l2proto == ETHERTYPE_IP6) {
         dbg(3, "Packet is IPv6");
         dbg(3, "Packet is IPv6");
-        ip6_hdr = (ipv6_hdr_t *)tcpedit_l3data(livedata->tcpedit, BEFORE_PROCESS, pktdata, pkthdr->len);
+        ip6_hdr = (ipv6_hdr_t *)tcpedit_l3data(livedata->tcpedit, BEFORE_PROCESS, pktdata, (int)pkthdr->len);
 
 
         /* look for include or exclude CIDR match */
         /* look for include or exclude CIDR match */
         if (livedata->options->xX.cidr != NULL) {
         if (livedata->options->xX.cidr != NULL) {
@@ -362,40 +326,38 @@ live_callback(u_char *usr_data, const struct pcap_pkthdr *const_pkthdr,
                 return;
                 return;
             }
             }
         }
         }
-
     }
     }
 
 
-    if ((retcode = tcpedit_packet(livedata->tcpedit, &pkthdr, &pktdata, cache_mode)) < 0)
+    if (tcpedit_packet(livedata->tcpedit, &pkthdr, &pktdata, cache_mode) < 0)
         return;
         return;
 
 
-    /* 
+    /*
      * send packets out the OTHER interface
      * send packets out the OTHER interface
      * and update the dst mac if necessary
      * and update the dst mac if necessary
      */
      */
-    switch(node->source) {
-        case PCAP_INT1:
-            dbgx(2, "Packet source was %s... sending out on %s", livedata->options->intf1, 
-                livedata->options->intf2);
-            send = livedata->options->pcap2;
-            break;
-
-        case PCAP_INT2:
-            dbgx(2, "Packet source was %s... sending out on %s", livedata->options->intf2, 
-                livedata->options->intf1);
-            send = livedata->options->pcap1;
-            break;
-
-        default:
-            errx(-1, "wtf?  our node->source != PCAP_INT1 and != PCAP_INT2: %c", 
-                 node->source);
+    switch (node->source) {
+    case PCAP_INT1:
+        dbgx(2, "Packet source was %s... sending out on %s", livedata->options->intf1, livedata->options->intf2);
+        send = livedata->options->pcap2;
+        break;
+
+    case PCAP_INT2:
+        dbgx(2, "Packet source was %s... sending out on %s", livedata->options->intf2, livedata->options->intf1);
+        send = livedata->options->pcap1;
+        break;
+
+    default:
+        errx(-1, "wtf?  our node->source != PCAP_INT1 and != PCAP_INT2: %c", node->source);
     }
     }
 
 
     /*
     /*
-     * write packet out on the network 
+     * write packet out on the network
      */
      */
-     if (pcap_sendpacket(send, pktdata, pkthdr->caplen) < 0)
-         errx(-1, "Unable to send packet out %s: %s", 
-            send == livedata->options->pcap1 ? livedata->options->intf1 : livedata->options->intf2, pcap_geterr(send));
+    if (pcap_sendpacket(send, pktdata, (int)pkthdr->caplen) < 0)
+        errx(-1,
+             "Unable to send packet out %s: %s",
+             send == livedata->options->pcap1 ? livedata->options->intf1 : livedata->options->intf2,
+             pcap_geterr(send));
 
 
     stats.bytes_sent += pkthdr->caplen;
     stats.bytes_sent += pkthdr->caplen;
     stats.pkts_sent++;
     stats.pkts_sent++;
@@ -409,5 +371,4 @@ signal_catcher(int signo)
     /* stdio in signal handlers causes a race condition, instead set a flag */
     /* stdio in signal handlers causes a race condition, instead set a flag */
     if (signo == SIGINT)
     if (signo == SIGINT)
         didsig = true;
         didsig = true;
-
 }
 }

+ 10 - 14
src/bridge.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,23 +18,22 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-
-#ifndef __BRIDGE_H__
-#define __BRIDGE_H__
+#pragma once
 
 
 #include "config.h"
 #include "config.h"
-#include "lib/tree.h"
-#include "tcpedit/tcpedit.h"
+#include "tcpbridge.h"
+#include <lib/tree.h>
+#include <tcpedit/tcpedit.h>
 
 
 /*
 /*
- * RBTree node object for tracking which side of tcpreplay where 
+ * RBTree node object for tracking which side of tcpreplay where
  * each source MAC address lives
  * each source MAC address lives
  */
  */
 struct macsrc_t {
 struct macsrc_t {
     RB_ENTRY(macsrc_t) node;
     RB_ENTRY(macsrc_t) node;
     u_char key[ETHER_ADDR_LEN];
     u_char key[ETHER_ADDR_LEN];
-    u_char source;              /* interface device name we first saw the source MAC */
-    sendpacket_t *sp;           /* sendpacket handle to send packets out */
+    u_char source;    /* interface device name we first saw the source MAC */
+    sendpacket_t *sp; /* sendpacket handle to send packets out */
 };
 };
 
 
 /* pri and secondary pcap interfaces */
 /* pri and secondary pcap interfaces */
@@ -55,6 +54,3 @@ struct live_data_t {
 
 
 void rbinit(void);
 void rbinit(void);
 void do_bridge(tcpbridge_opt_t *, tcpedit_t *);
 void do_bridge(tcpbridge_opt_t *, tcpedit_t *);
-
-
-#endif

+ 23 - 27
src/common.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,40 +18,36 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#pragma once
 
 
-#ifndef __COMMON_H__
-#define __COMMON_H__
-#include <assert.h>
 #include "config.h"
 #include "config.h"
+#include <assert.h>
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
 #endif
 #endif
 
 
-#include "common/pcap_dlt.h"
-#include "common/cache.h"
-#include "common/cidr.h"
-#include "common/err.h"
-#include "common/get.h"
-#include "common/fakepcap.h"
-#include "common/fakepcapnav.h"
-#include "common/fakepoll.h"
-#include "common/list.h"
-#include "common/mac.h"
-#include "common/services.h"
-#include "common/utils.h"
-#include "common/xX.h"
-#include "common/tcpdump.h"
-#include "common/timer.h"
-#include "common/sendpacket.h"
-#include "common/interface.h"
-#include "common/flows.h"
+#include <common/cache.h>
+#include <common/cidr.h>
+#include <common/err.h>
+#include <common/fakepcap.h>
+#include <common/fakepcapnav.h>
+#include <common/fakepoll.h>
+#include <common/flows.h>
+#include <common/get.h>
+#include <common/interface.h>
+#include <common/list.h>
+#include <common/mac.h>
+#include <common/pcap_dlt.h>
+#include <common/sendpacket.h>
+#include <common/services.h>
+#include <common/tcpdump.h>
+#include <common/timer.h>
+#include <common/utils.h>
+#include <common/xX.h>
 
 
 const char *git_version(void); /* git_version.c */
 const char *git_version(void); /* git_version.c */
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif
-
-#endif
-

+ 104 - 42
src/common/Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.16.3 from Makefile.am.
 # @configure_input@
 # @configure_input@
 
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 
 # This Makefile.in is free software; the Free Software Foundation
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -144,7 +144,17 @@ am__v_at_0 = @
 am__v_at_1 = 
 am__v_at_1 = 
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
-am__depfiles_maybe = depfiles
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = ./$(DEPDIR)/cache.Po ./$(DEPDIR)/cidr.Po \
+	./$(DEPDIR)/dlt_names.Po ./$(DEPDIR)/err.Po \
+	./$(DEPDIR)/fakepcap.Po ./$(DEPDIR)/fakepcapnav.Po \
+	./$(DEPDIR)/fakepoll.Po ./$(DEPDIR)/flows.Po \
+	./$(DEPDIR)/get.Po ./$(DEPDIR)/git_version.Po \
+	./$(DEPDIR)/interface.Po ./$(DEPDIR)/list.Po \
+	./$(DEPDIR)/mac.Po ./$(DEPDIR)/netmap.Po \
+	./$(DEPDIR)/sendpacket.Po ./$(DEPDIR)/services.Po \
+	./$(DEPDIR)/tcpdump.Po ./$(DEPDIR)/timer.Po \
+	./$(DEPDIR)/txring.Po ./$(DEPDIR)/utils.Po ./$(DEPDIR)/xX.Po
 am__mv = mv -f
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -312,6 +322,7 @@ build_alias = @build_alias@
 build_asan = @build_asan@
 build_asan = @build_asan@
 build_cpu = @build_cpu@
 build_cpu = @build_cpu@
 build_os = @build_os@
 build_os = @build_os@
+build_tsan = @build_tsan@
 build_vendor = @build_vendor@
 build_vendor = @build_vendor@
 builddir = @builddir@
 builddir = @builddir@
 datadir = @datadir@
 datadir = @datadir@
@@ -348,6 +359,7 @@ prefix = @prefix@
 program_transform_name = @program_transform_name@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
 psdir = @psdir@
 rmmod = @rmmod@
 rmmod = @rmmod@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
 srcdir = @srcdir@
@@ -402,8 +414,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	  *config.status*) \
 	  *config.status*) \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	  *) \
 	  *) \
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
 	esac;
 	esac;
 
 
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
@@ -429,27 +441,33 @@ mostlyclean-compile:
 distclean-compile:
 distclean-compile:
 	-rm -f *.tab.c
 	-rm -f *.tab.c
 
 
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cache.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cidr.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dlt_names.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/err.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fakepcap.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fakepcapnav.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fakepoll.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flows.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/git_version.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interface.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mac.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netmap.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sendpacket.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/services.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpdump.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/txring.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xX.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cache.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cidr.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dlt_names.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/err.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fakepcap.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fakepcapnav.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fakepoll.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flows.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/git_version.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interface.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mac.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netmap.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sendpacket.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/services.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpdump.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/txring.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xX.Po@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+	@$(MKDIR_P) $(@D)
+	@echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
 
 
 .c.o:
 .c.o:
 @am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
 @am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@@ -533,7 +551,10 @@ cscopelist-am: $(am__tagged_files)
 distclean-tags:
 distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 
 
-distdir: $(DISTFILES)
+distdir: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	list='$(DISTFILES)'; \
 	list='$(DISTFILES)'; \
@@ -570,7 +591,8 @@ all-am: Makefile $(LIBRARIES) $(HEADERS)
 installdirs:
 installdirs:
 install: $(BUILT_SOURCES)
 install: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) install-am
 	$(MAKE) $(AM_MAKEFLAGS) install-am
-install-exec: install-exec-am
+install-exec: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) install-exec-am
 install-data: install-data-am
 install-data: install-data-am
 uninstall: uninstall-am
 uninstall: uninstall-am
 
 
@@ -608,7 +630,27 @@ clean-am: clean-generic clean-libtool clean-noinstLIBRARIES \
 	mostlyclean-am
 	mostlyclean-am
 
 
 distclean: distclean-am
 distclean: distclean-am
-	-rm -rf ./$(DEPDIR)
+		-rm -f ./$(DEPDIR)/cache.Po
+	-rm -f ./$(DEPDIR)/cidr.Po
+	-rm -f ./$(DEPDIR)/dlt_names.Po
+	-rm -f ./$(DEPDIR)/err.Po
+	-rm -f ./$(DEPDIR)/fakepcap.Po
+	-rm -f ./$(DEPDIR)/fakepcapnav.Po
+	-rm -f ./$(DEPDIR)/fakepoll.Po
+	-rm -f ./$(DEPDIR)/flows.Po
+	-rm -f ./$(DEPDIR)/get.Po
+	-rm -f ./$(DEPDIR)/git_version.Po
+	-rm -f ./$(DEPDIR)/interface.Po
+	-rm -f ./$(DEPDIR)/list.Po
+	-rm -f ./$(DEPDIR)/mac.Po
+	-rm -f ./$(DEPDIR)/netmap.Po
+	-rm -f ./$(DEPDIR)/sendpacket.Po
+	-rm -f ./$(DEPDIR)/services.Po
+	-rm -f ./$(DEPDIR)/tcpdump.Po
+	-rm -f ./$(DEPDIR)/timer.Po
+	-rm -f ./$(DEPDIR)/txring.Po
+	-rm -f ./$(DEPDIR)/utils.Po
+	-rm -f ./$(DEPDIR)/xX.Po
 	-rm -f Makefile
 	-rm -f Makefile
 distclean-am: clean-am distclean-compile distclean-generic \
 distclean-am: clean-am distclean-compile distclean-generic \
 	distclean-tags
 	distclean-tags
@@ -654,7 +696,27 @@ install-ps-am:
 installcheck-am:
 installcheck-am:
 
 
 maintainer-clean: maintainer-clean-am
 maintainer-clean: maintainer-clean-am
-	-rm -rf ./$(DEPDIR)
+		-rm -f ./$(DEPDIR)/cache.Po
+	-rm -f ./$(DEPDIR)/cidr.Po
+	-rm -f ./$(DEPDIR)/dlt_names.Po
+	-rm -f ./$(DEPDIR)/err.Po
+	-rm -f ./$(DEPDIR)/fakepcap.Po
+	-rm -f ./$(DEPDIR)/fakepcapnav.Po
+	-rm -f ./$(DEPDIR)/fakepoll.Po
+	-rm -f ./$(DEPDIR)/flows.Po
+	-rm -f ./$(DEPDIR)/get.Po
+	-rm -f ./$(DEPDIR)/git_version.Po
+	-rm -f ./$(DEPDIR)/interface.Po
+	-rm -f ./$(DEPDIR)/list.Po
+	-rm -f ./$(DEPDIR)/mac.Po
+	-rm -f ./$(DEPDIR)/netmap.Po
+	-rm -f ./$(DEPDIR)/sendpacket.Po
+	-rm -f ./$(DEPDIR)/services.Po
+	-rm -f ./$(DEPDIR)/tcpdump.Po
+	-rm -f ./$(DEPDIR)/timer.Po
+	-rm -f ./$(DEPDIR)/txring.Po
+	-rm -f ./$(DEPDIR)/utils.Po
+	-rm -f ./$(DEPDIR)/xX.Po
 	-rm -f Makefile
 	-rm -f Makefile
 maintainer-clean-am: distclean-am maintainer-clean-generic
 maintainer-clean-am: distclean-am maintainer-clean-generic
 
 
@@ -673,18 +735,18 @@ ps-am:
 
 
 uninstall-am:
 uninstall-am:
 
 
-.MAKE: all check install install-am install-strip
-
-.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
-	clean-libtool clean-noinstLIBRARIES cscopelist-am ctags \
-	ctags-am distclean distclean-compile distclean-generic \
-	distclean-libtool distclean-tags distdir dvi dvi-am html \
-	html-am info info-am install install-am 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 \
+.MAKE: all check install install-am install-exec install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
+	clean-generic clean-libtool clean-noinstLIBRARIES \
+	cscopelist-am ctags ctags-am distclean distclean-compile \
+	distclean-generic distclean-libtool distclean-tags distdir dvi \
+	dvi-am html html-am info info-am install install-am \
+	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 \
 	maintainer-clean-generic mostlyclean mostlyclean-compile \
 	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
 	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
 	tags tags-am uninstall uninstall-am
 	tags tags-am uninstall uninstall-am

+ 62 - 76
src/common/cache.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,23 +18,16 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
-
+#include <errno.h>
 #include <fcntl.h>
 #include <fcntl.h>
-#include <stdlib.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <string.h>
 #include <sys/types.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <unistd.h>
-#include <errno.h>
-
-#ifdef DEBUG
-extern int debug;
-#endif
 
 
 static tcpr_cache_t *new_cache(void);
 static tcpr_cache_t *new_cache(void);
 
 
@@ -44,8 +37,9 @@ static tcpr_cache_t *new_cache(void);
  */
  */
 #ifdef DEBUG
 #ifdef DEBUG
 static char *
 static char *
-byte2bits(char byte, char *bitstring) {
-    int i = 1, j = 7;
+byte2bits(char byte, char *bitstring)
+{
+    int i, j = 7;
 
 
     for (i = 1; i <= 255; i = i << 1) {
     for (i = 1; i <= 255; i = i << 1) {
         if (byte & i)
         if (byte & i)
@@ -61,7 +55,7 @@ byte2bits(char byte, char *bitstring) {
  * simple function to read in a cache file created with tcpprep this let's us
  * simple function to read in a cache file created with tcpprep this let's us
  * be really damn fast in picking an interface to send the packet out returns
  * be really damn fast in picking an interface to send the packet out returns
  * number of cache entries read
  * number of cache entries read
- * 
+ *
  * now also checks for the cache magic and version
  * now also checks for the cache magic and version
  */
  */
 
 
@@ -70,8 +64,8 @@ read_cache(char **cachedata, const char *cachefile, char **comment)
 {
 {
     int cachefd;
     int cachefd;
     tcpr_cache_file_hdr_t header;
     tcpr_cache_file_hdr_t header;
-    ssize_t read_size = 0;
-    COUNTER cache_size = 0;
+    ssize_t read_size;
+    COUNTER cache_size;
 
 
     assert(cachedata);
     assert(cachedata);
     assert(comment);
     assert(comment);
@@ -92,50 +86,48 @@ read_cache(char **cachedata, const char *cachefile, char **comment)
         errx(-1, "Unable to process %s: not a tcpprep cache file", cachefile);
         errx(-1, "Unable to process %s: not a tcpprep cache file", cachefile);
 
 
     /* verify version */
     /* verify version */
-    if (atoi(header.version) != atoi(CACHEVERSION))
-        errx(-1, "Unable to process %s: cache file version mismatch",
-             cachefile);
+    if (strtol(header.version, NULL, 10) != strtol(CACHEVERSION, NULL, 10))
+        errx(-1, "Unable to process %s: cache file version mismatch", cachefile);
 
 
     /* read the comment */
     /* read the comment */
     header.comment_len = ntohs(header.comment_len);
     header.comment_len = ntohs(header.comment_len);
     if (header.comment_len > 65534)
     if (header.comment_len > 65534)
-        errx(-1, "Unable to process %s: invalid comment length %u",
-                cachefile, header.comment_len);
+        errx(-1, "Unable to process %s: invalid comment length %u", cachefile, header.comment_len);
 
 
     *comment = (char *)safe_malloc(header.comment_len + 1);
     *comment = (char *)safe_malloc(header.comment_len + 1);
 
 
     dbgx(1, "Comment length: %d", header.comment_len);
     dbgx(1, "Comment length: %d", header.comment_len);
-    
+
     if ((read_size = read(cachefd, *comment, header.comment_len)) < 0)
     if ((read_size = read(cachefd, *comment, header.comment_len)) < 0)
         errx(-1, "Error reading comment: %s", strerror(errno));
         errx(-1, "Error reading comment: %s", strerror(errno));
 
 
     if (read_size != (ssize_t)header.comment_len)
     if (read_size != (ssize_t)header.comment_len)
-        errx(-1, "Invalid comment read: expected=%u actual=%zd bytes",
-            header.comment_len, read_size);
+        errx(-1, "Invalid comment read: expected=%u actual=%zd bytes", header.comment_len, read_size);
 
 
     dbgx(1, "Cache file comment: %s", *comment);
     dbgx(1, "Cache file comment: %s", *comment);
 
 
     /* malloc our cache block */
     /* malloc our cache block */
     header.num_packets = ntohll(header.num_packets);
     header.num_packets = ntohll(header.num_packets);
-    header.packets_per_byte = ntohs(header.packets_per_byte);    
+    header.packets_per_byte = ntohs(header.packets_per_byte);
     cache_size = header.num_packets / header.packets_per_byte;
     cache_size = header.num_packets / header.packets_per_byte;
-        
+
     /* deal with any remainder, because above division is integer */
     /* deal with any remainder, because above division is integer */
     if (header.num_packets % header.packets_per_byte)
     if (header.num_packets % header.packets_per_byte)
-      cache_size ++;
+        cache_size++;
 
 
-    dbgx(1, "Cache file contains %" PRIu64 " packets in " COUNTER_SPEC " bytes",
-        header.num_packets, cache_size);
+    dbgx(1, "Cache file contains %" PRIu64 " packets in " COUNTER_SPEC " bytes", header.num_packets, cache_size);
 
 
     dbgx(1, "Cache uses %d packets per byte", header.packets_per_byte);
     dbgx(1, "Cache uses %d packets per byte", header.packets_per_byte);
 
 
     *cachedata = (char *)safe_malloc(cache_size);
     *cachedata = (char *)safe_malloc(cache_size);
 
 
     /* read in the cache */
     /* read in the cache */
-    if ((COUNTER)(read_size = read(cachefd, *cachedata, cache_size)) 
-            != cache_size)
-        errx(-1, "Cache data length (%zu bytes) doesn't match "
-            "cache header (" COUNTER_SPEC " bytes)", read_size, cache_size);
+    if ((COUNTER)(read_size = read(cachefd, *cachedata, cache_size)) != cache_size)
+        errx(-1,
+             "Cache data length (%zu bytes) doesn't match "
+             "cache header (" COUNTER_SPEC " bytes)",
+             read_size,
+             cache_size);
 
 
     dbgx(1, "Loaded in %" PRIu64 " packets from cache.", header.num_packets);
     dbgx(1, "Loaded in %" PRIu64 " packets from cache.", header.num_packets);
 
 
@@ -143,29 +135,26 @@ read_cache(char **cachedata, const char *cachefile, char **comment)
     return (header.num_packets);
     return (header.num_packets);
 }
 }
 
 
-
 /**
 /**
  * writes out the cache file header, comment and then the
  * writes out the cache file header, comment and then the
- * contents of *cachedata to out_file and then returns the number 
+ * contents of *cachedata to out_file and then returns the number
  * of cache entries written
  * of cache entries written
  */
  */
 COUNTER
 COUNTER
-write_cache(tcpr_cache_t * cachedata, const int out_file, COUNTER numpackets, 
-    char *comment)
+write_cache(tcpr_cache_t *cachedata, const int out_file, COUNTER numpackets, char *comment)
 {
 {
     tcpr_cache_t *mycache = NULL;
     tcpr_cache_t *mycache = NULL;
     tcpr_cache_file_hdr_t *cache_header = NULL;
     tcpr_cache_file_hdr_t *cache_header = NULL;
     uint32_t chars, last = 0;
     uint32_t chars, last = 0;
     COUNTER packets = 0;
     COUNTER packets = 0;
-    ssize_t written = 0;
+    ssize_t written;
 
 
     assert(out_file);
     assert(out_file);
 
 
     /* write a header to our file */
     /* write a header to our file */
-    cache_header = (tcpr_cache_file_hdr_t *)
-        safe_malloc(sizeof(tcpr_cache_file_hdr_t));
-    strncpy(cache_header->magic, CACHEMAGIC, strlen(CACHEMAGIC)+1);
-    strncpy(cache_header->version, CACHEVERSION, strlen(CACHEVERSION)+1);
+    cache_header = (tcpr_cache_file_hdr_t *)safe_malloc(sizeof(tcpr_cache_file_hdr_t));
+    strncpy(cache_header->magic, CACHEMAGIC, strlen(CACHEMAGIC) + 1);
+    strncpy(cache_header->version, CACHEVERSION, strlen(CACHEVERSION) + 1);
     cache_header->packets_per_byte = htons(CACHE_PACKETS_PER_BYTE);
     cache_header->packets_per_byte = htons(CACHE_PACKETS_PER_BYTE);
     cache_header->num_packets = htonll((u_int64_t)numpackets);
     cache_header->num_packets = htonll((u_int64_t)numpackets);
 
 
@@ -180,18 +169,22 @@ write_cache(tcpr_cache_t * cachedata, const int out_file, COUNTER numpackets,
     dbgx(1, "Wrote %zu bytes of cache file header", written);
     dbgx(1, "Wrote %zu bytes of cache file header", written);
 
 
     if (written != sizeof(tcpr_cache_file_hdr_t))
     if (written != sizeof(tcpr_cache_file_hdr_t))
-        errx(-1, "Only wrote %zu of %zu bytes of the cache file header!\n%s",
-             written, sizeof(tcpr_cache_file_hdr_t),
+        errx(-1,
+             "Only wrote %zu of %zu bytes of the cache file header!\n%s",
+             written,
+             sizeof(tcpr_cache_file_hdr_t),
              written == -1 ? strerror(errno) : "");
              written == -1 ? strerror(errno) : "");
 
 
     /* don't write comment if there is none */
     /* don't write comment if there is none */
     if (comment != NULL) {
     if (comment != NULL) {
         written = write(out_file, comment, strlen(comment));
         written = write(out_file, comment, strlen(comment));
         dbgx(1, "Wrote %zu bytes of comment", written);
         dbgx(1, "Wrote %zu bytes of comment", written);
-        
+
         if (written != (ssize_t)strlen(comment))
         if (written != (ssize_t)strlen(comment))
-            errx(-1, "Only wrote %zu of %zu bytes of the comment!\n%s",
-                 written, strlen(comment), 
+            errx(-1,
+                 "Only wrote %zu of %zu bytes of the comment!\n%s",
+                 written,
+                 strlen(comment),
                  written == -1 ? strerror(errno) : "");
                  written == -1 ? strerror(errno) : "");
     }
     }
 
 
@@ -206,8 +199,7 @@ write_cache(tcpr_cache_t * cachedata, const int out_file, COUNTER numpackets,
             chars = mycache->packets / CACHE_PACKETS_PER_BYTE;
             chars = mycache->packets / CACHE_PACKETS_PER_BYTE;
             if (mycache->packets % CACHE_PACKETS_PER_BYTE) {
             if (mycache->packets % CACHE_PACKETS_PER_BYTE) {
                 chars++;
                 chars++;
-                dbgx(1, "Bumping up to the next byte: %d %% %d", mycache->packets,
-                        CACHE_PACKETS_PER_BYTE);
+                dbgx(1, "Bumping up to the next byte: %d %% %d", mycache->packets, CACHE_PACKETS_PER_BYTE);
             }
             }
 
 
             /* write to file, and verify it wrote properly */
             /* write to file, and verify it wrote properly */
@@ -222,8 +214,7 @@ write_cache(tcpr_cache_t * cachedata, const int out_file, COUNTER numpackets,
              */
              */
             if (mycache->next != NULL) {
             if (mycache->next != NULL) {
                 mycache = mycache->next;
                 mycache = mycache->next;
-            }
-            else {
+            } else {
                 last = 1;
                 last = 1;
             }
             }
         }
         }
@@ -252,10 +243,10 @@ new_cache(void)
  */
  */
 
 
 tcpr_dir_t
 tcpr_dir_t
-add_cache(tcpr_cache_t ** cachedata, const int send, const tcpr_dir_t interface)
+add_cache(tcpr_cache_t **cachedata, const int send, const tcpr_dir_t interface)
 {
 {
     static tcpr_cache_t *lastcache = NULL;
     static tcpr_cache_t *lastcache = NULL;
-    tcpr_dir_t result = TCPR_DIR_ERROR;
+    tcpr_dir_t result;
 #ifdef DEBUG
 #ifdef DEBUG
     char bitstring[9] = EIGHT_ZEROS;
     char bitstring[9] = EIGHT_ZEROS;
 #endif
 #endif
@@ -266,8 +257,7 @@ add_cache(tcpr_cache_t ** cachedata, const int send, const tcpr_dir_t interface)
     if (*cachedata == NULL || lastcache == NULL) {
     if (*cachedata == NULL || lastcache == NULL) {
         *cachedata = new_cache();
         *cachedata = new_cache();
         lastcache = *cachedata;
         lastcache = *cachedata;
-    }
-    else {
+    } else {
         /* check to see if this is the last bit in this struct */
         /* check to see if this is the last bit in this struct */
         if ((lastcache->packets + 1) > (CACHEDATASIZE * CACHE_PACKETS_PER_BYTE)) {
         if ((lastcache->packets + 1) > (CACHEDATASIZE * CACHE_PACKETS_PER_BYTE)) {
             /*
             /*
@@ -290,12 +280,11 @@ add_cache(tcpr_cache_t ** cachedata, const int send, const tcpr_dir_t interface)
         u_char *byte;
         u_char *byte;
 
 
         index = (lastcache->packets - 1) / (COUNTER)CACHE_PACKETS_PER_BYTE;
         index = (lastcache->packets - 1) / (COUNTER)CACHE_PACKETS_PER_BYTE;
-        bit = (((lastcache->packets - 1) % (COUNTER)CACHE_PACKETS_PER_BYTE) * 
-               (COUNTER)CACHE_BITS_PER_PACKET) + 1;
+        bit = (((lastcache->packets - 1) % (COUNTER)CACHE_PACKETS_PER_BYTE) * (COUNTER)CACHE_BITS_PER_PACKET) + 1;
         dbgx(3, "Bit: %d", bit);
         dbgx(3, "Bit: %d", bit);
 
 
-        byte = (u_char *) & lastcache->data[index];
-        *byte += (u_char) (1 << bit);
+        byte = (u_char *)&lastcache->data[index];
+        *byte += (u_char)(1 << bit);
 
 
         dbgx(2, "set send bit: byte " COUNTER_SPEC " = 0x%x", index, *byte);
         dbgx(2, "set send bit: byte " COUNTER_SPEC " = 0x%x", index, *byte);
 
 
@@ -305,19 +294,17 @@ add_cache(tcpr_cache_t ** cachedata, const int send, const tcpr_dir_t interface)
 
 
             dbgx(2, "set interface bit: byte " COUNTER_SPEC " = 0x%x", index, *byte);
             dbgx(2, "set interface bit: byte " COUNTER_SPEC " = 0x%x", index, *byte);
             result = TCPR_DIR_C2S;
             result = TCPR_DIR_C2S;
-        }
-        else {
+        } else {
             dbgx(2, "don't set interface bit: byte " COUNTER_SPEC " = 0x%x", index, *byte);
             dbgx(2, "don't set interface bit: byte " COUNTER_SPEC " = 0x%x", index, *byte);
             result = TCPR_DIR_S2C;
             result = TCPR_DIR_S2C;
         }
         }
 
 
 #ifdef DEBUG
 #ifdef DEBUG
-        /* 
+        /*
          * only build the byte string when not in debug mode since
          * only build the byte string when not in debug mode since
          * the calculation is a bit expensive
          * the calculation is a bit expensive
          */
          */
-        dbgx(3, "Current cache byte: %c%c%c%c%c%c%c%c",
-            BIT_STR(byte2bits(*byte, bitstring)));
+        dbgx(3, "Current cache byte: %c%c%c%c%c%c%c%c", BIT_STR(byte2bits(*byte, bitstring)));
 #endif
 #endif
     } else {
     } else {
         dbg(1, "not setting send bit");
         dbg(1, "not setting send bit");
@@ -327,14 +314,13 @@ add_cache(tcpr_cache_t ** cachedata, const int send, const tcpr_dir_t interface)
     return result;
     return result;
 }
 }
 
 
-
 /**
 /**
  * returns the action for a given packet based on the CACHE
  * returns the action for a given packet based on the CACHE
  */
  */
 tcpr_dir_t
 tcpr_dir_t
 check_cache(char *cachedata, COUNTER packetid)
 check_cache(char *cachedata, COUNTER packetid)
 {
 {
-    COUNTER index = 0;
+    COUNTER index;
     uint32_t bit;
     uint32_t bit;
 
 
     assert(cachedata);
     assert(cachedata);
@@ -343,12 +329,15 @@ check_cache(char *cachedata, COUNTER packetid)
         err(-1, "packetid must be > 0");
         err(-1, "packetid must be > 0");
 
 
     index = (packetid - 1) / (COUNTER)CACHE_PACKETS_PER_BYTE;
     index = (packetid - 1) / (COUNTER)CACHE_PACKETS_PER_BYTE;
-    bit = (uint32_t)(((packetid - 1) % (COUNTER)CACHE_PACKETS_PER_BYTE) * 
-        (COUNTER)CACHE_BITS_PER_PACKET) + 1;
+    bit = (uint32_t)(((packetid - 1) % (COUNTER)CACHE_PACKETS_PER_BYTE) * (COUNTER)CACHE_BITS_PER_PACKET) + 1;
 
 
 #ifdef DEBUG
 #ifdef DEBUG
-    dbgx(3, "Index: " COUNTER_SPEC "\tBit: %d\tByte: %hhu\tMask: %hhu", index, bit,
-        cachedata[index], (uint8_t)(cachedata[index] & (char)(1 << bit)));
+    dbgx(3,
+         "Index: " COUNTER_SPEC "\tBit: %d\tByte: %hhu\tMask: %hhu",
+         index,
+         bit,
+         cachedata[index],
+         (uint8_t)(cachedata[index] & (char)(1 << bit)));
 #endif
 #endif
 
 
     if (!(cachedata[index] & (char)(1 << bit))) {
     if (!(cachedata[index] & (char)(1 << bit))) {
@@ -359,10 +348,7 @@ check_cache(char *cachedata, COUNTER packetid)
     bit--;
     bit--;
     if (cachedata[index] & (char)(1 << bit)) {
     if (cachedata[index] & (char)(1 << bit)) {
         return TCPR_DIR_C2S;
         return TCPR_DIR_C2S;
-    }
-    else {
+    } else {
         return TCPR_DIR_S2C;
         return TCPR_DIR_S2C;
     }
     }
-
-    return TCPR_DIR_ERROR;
 }
 }

+ 3 - 4
src/common/cache.h

@@ -18,8 +18,9 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef __CACHE_H__
-#define __CACHE_H__
+#pragma once
+
+#include "defines.h"
 
 
 #define CACHEMAGIC "tcpprep"
 #define CACHEMAGIC "tcpprep"
 #define CACHEVERSION "04"
 #define CACHEVERSION "04"
@@ -99,5 +100,3 @@ tcpr_dir_t check_cache(char *, COUNTER);
 
 
 /* string of 8 zeros */
 /* string of 8 zeros */
 #define EIGHT_ZEROS "\060\060\060\060\060\060\060\060"
 #define EIGHT_ZEROS "\060\060\060\060\060\060\060\060"
-
-#endif

+ 63 - 164
src/common/cidr.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,22 +18,15 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
+#include <arpa/inet.h>
+#include <netinet/in.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
-/* required for inet_aton() */
 #include <sys/socket.h>
 #include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-
-#ifdef DEBUG
-extern int debug;
-#endif
 
 
 static tcpr_cidr_t *cidr2cidr(char *);
 static tcpr_cidr_t *cidr2cidr(char *);
 
 
@@ -41,7 +34,7 @@ static tcpr_cidr_t *cidr2cidr(char *);
  * prints to the given fd all the entries in mycidr
  * prints to the given fd all the entries in mycidr
  */
  */
 void
 void
-print_cidr(tcpr_cidr_t * mycidr)
+print_cidr(tcpr_cidr_t *mycidr)
 {
 {
     tcpr_cidr_t *cidr_ptr;
     tcpr_cidr_t *cidr_ptr;
 
 
@@ -50,14 +43,12 @@ print_cidr(tcpr_cidr_t * mycidr)
     cidr_ptr = mycidr;
     cidr_ptr = mycidr;
     while (cidr_ptr != NULL) {
     while (cidr_ptr != NULL) {
         /* print it */
         /* print it */
-        fprintf(stderr, "%s/%d, ", get_cidr2name(cidr_ptr, RESOLVE),
-                cidr_ptr->masklen);
+        fprintf(stderr, "%s/%d, ", get_cidr2name(cidr_ptr, RESOLVE), cidr_ptr->masklen);
 
 
         /* go to the next */
         /* go to the next */
         if (cidr_ptr->next != NULL) {
         if (cidr_ptr->next != NULL) {
             cidr_ptr = cidr_ptr->next;
             cidr_ptr = cidr_ptr->next;
-        }
-        else {
+        } else {
             break;
             break;
         }
         }
     }
     }
@@ -68,24 +59,21 @@ print_cidr(tcpr_cidr_t * mycidr)
  * deletes all entries in a cidr and destroys the datastructure
  * deletes all entries in a cidr and destroys the datastructure
  */
  */
 void
 void
-destroy_cidr(tcpr_cidr_t * cidr)
+destroy_cidr(tcpr_cidr_t *cidr)
 {
 {
-
     if (cidr != NULL) {
     if (cidr != NULL) {
         if (cidr->next != NULL)
         if (cidr->next != NULL)
             destroy_cidr(cidr->next);
             destroy_cidr(cidr->next);
 
 
         safe_free(cidr);
         safe_free(cidr);
     }
     }
-    return;
-
 }
 }
 
 
 /**
 /**
  * adds a new tcpr_cidr_t entry to cidrdata
  * adds a new tcpr_cidr_t entry to cidrdata
  */
  */
 void
 void
-add_cidr(tcpr_cidr_t ** cidrdata, tcpr_cidr_t ** newcidr)
+add_cidr(tcpr_cidr_t **cidrdata, tcpr_cidr_t **newcidr)
 {
 {
     tcpr_cidr_t *cidr_ptr;
     tcpr_cidr_t *cidr_ptr;
     dbg(1, "Running new_cidr()");
     dbg(1, "Running new_cidr()");
@@ -103,30 +91,6 @@ add_cidr(tcpr_cidr_t ** cidrdata, tcpr_cidr_t ** newcidr)
 }
 }
 
 
 /**
 /**
- * takes in an IP and masklen, and returns a string in
- * cidr format: x.x.x.x/y.  This malloc's memory.
- */
-u_char *
-ip2cidr(const unsigned long ip, const int masklen)
-{
-    u_char *network;
-    char mask[32];
-
-    network = (u_char *)safe_malloc(20);
-
-    strlcpy((char *)network, (char *)get_addr2name4(ip, RESOLVE), 20);
-
-    strcat((char *)network, "/");
-    snprintf(mask, sizeof(mask), "%d", masklen);
-    if (masklen < 10)
-        strncat((char *)network, mask, 1);
-    else
-        strncat((char *)network, mask, 2);
-
-    return (network);
-}
-
-/**
  * Mallocs and sets to sane defaults a tcpr_cidr_t structure
  * Mallocs and sets to sane defaults a tcpr_cidr_t structure
  */
  */
 
 
@@ -136,7 +100,7 @@ new_cidr(void)
     tcpr_cidr_t *newcidr;
     tcpr_cidr_t *newcidr;
 
 
     newcidr = (tcpr_cidr_t *)safe_malloc(sizeof(tcpr_cidr_t));
     newcidr = (tcpr_cidr_t *)safe_malloc(sizeof(tcpr_cidr_t));
-    
+
     memset(newcidr, '\0', sizeof(tcpr_cidr_t));
     memset(newcidr, '\0', sizeof(tcpr_cidr_t));
     newcidr->masklen = 99;
     newcidr->masklen = 99;
     newcidr->next = NULL;
     newcidr->next = NULL;
@@ -153,14 +117,13 @@ new_cidr_map(void)
     tcpr_cidrmap_t *new;
     tcpr_cidrmap_t *new;
 
 
     new = (tcpr_cidrmap_t *)safe_malloc(sizeof(tcpr_cidrmap_t));
     new = (tcpr_cidrmap_t *)safe_malloc(sizeof(tcpr_cidrmap_t));
-    
+
     memset(new, '\0', sizeof(tcpr_cidrmap_t));
     memset(new, '\0', sizeof(tcpr_cidrmap_t));
     new->next = NULL;
     new->next = NULL;
 
 
     return (new);
     return (new);
 }
 }
 
 
-
 /**
 /**
  * Converts a single cidr (string) in the form of x.x.x.x/y into a
  * Converts a single cidr (string) in the form of x.x.x.x/y into a
  * tcpr_cidr_t structure.  Will malloc the tcpr_cidr_t structure.
  * tcpr_cidr_t structure.  Will malloc the tcpr_cidr_t structure.
@@ -168,12 +131,12 @@ new_cidr_map(void)
 static tcpr_cidr_t *
 static tcpr_cidr_t *
 cidr2cidr(char *cidr)
 cidr2cidr(char *cidr)
 {
 {
-    int count = 0;
-    unsigned int octets[4];     /* used in sscanf */
+    int count;
+    unsigned int octets[4]; /* used in sscanf */
     tcpr_cidr_t *newcidr;
     tcpr_cidr_t *newcidr;
     char networkip[16], tempoctet[4];
     char networkip[16], tempoctet[4];
     int family;
     int family;
-    char* p;
+    char *p;
 
 
     assert(cidr);
     assert(cidr);
 
 
@@ -192,8 +155,7 @@ cidr2cidr(char *cidr)
      * scan it, and make sure it scanned correctly, also copy over the
      * scan it, and make sure it scanned correctly, also copy over the
      * masklen
      * masklen
      */
      */
-    count = sscanf(cidr, "%u.%u.%u.%u/%d", &octets[0], &octets[1],
-        &octets[2], &octets[3], &newcidr->masklen);
+    count = sscanf(cidr, "%u.%u.%u.%u/%d", &octets[0], &octets[1], &octets[2], &octets[3], &newcidr->masklen);
 
 
     if (count == 4) {
     if (count == 4) {
         newcidr->masklen = 32;
         newcidr->masklen = 32;
@@ -215,7 +177,7 @@ cidr2cidr(char *cidr)
 
 
         /* skip past the opening [ */
         /* skip past the opening [ */
         if (*cidr == '[')
         if (*cidr == '[')
-            cidr ++;
+            cidr++;
 
 
         if (get_name2addr6(cidr, RESOLVE, &newcidr->u.network6) > 0) {
         if (get_name2addr6(cidr, RESOLVE, &newcidr->u.network6) > 0) {
             family = AF_INET6;
             family = AF_INET6;
@@ -248,10 +210,8 @@ cidr2cidr(char *cidr)
 #elif HAVE_INET_ADDR
 #elif HAVE_INET_ADDR
         newcidr->network = inet_addr(networkip);
         newcidr->network = inet_addr(networkip);
 #endif
 #endif
-    } else if (family == AF_INET6) {
-        /* Everything's done */
     } else {
     } else {
-        goto error;
+        /* Everything's done */
     }
     }
 
 
     newcidr->family = family;
     newcidr->family = family;
@@ -260,20 +220,18 @@ cidr2cidr(char *cidr)
     /* we only get here on error parsing input */
     /* we only get here on error parsing input */
 error:
 error:
     errx(-1, "%s: %s", "Unable to parse as a valid CIDR", cidr);
     errx(-1, "%s: %s", "Unable to parse as a valid CIDR", cidr);
-    return NULL;
 }
 }
 
 
-static void 
-mask_cidr6(char **cidrin, char* delim)
+static void
+mask_cidr6(char **cidrin, const char *delim)
 {
 {
     if (**cidrin == '[' && *delim == ':') {
     if (**cidrin == '[' && *delim == ':') {
         char *p;
         char *p;
         ++*cidrin;
         ++*cidrin;
         /* make strtok happy */
         /* make strtok happy */
         for (p = *cidrin; *p && *p != ']'; ++p) {
         for (p = *cidrin; *p && *p != ']'; ++p) {
-            if (*p == ':') {
+            if (*p == ':')
                 *p = '#';
                 *p = '#';
-            }
         }
         }
     }
     }
 }
 }
@@ -285,9 +243,9 @@ mask_cidr6(char **cidrin, char* delim)
  * since we use strtok to process cidr, it gets zeroed out.
  * since we use strtok to process cidr, it gets zeroed out.
  */
  */
 int
 int
-parse_cidr(tcpr_cidr_t ** cidrdata, char *cidrin, char *delim)
+parse_cidr(tcpr_cidr_t **cidrdata, char *cidrin, char *delim)
 {
 {
-    tcpr_cidr_t *cidr_ptr;             /* ptr to current cidr record */
+    tcpr_cidr_t *cidr_ptr; /* ptr to current cidr record */
     char *network;
     char *network;
     char *token = NULL;
     char *token = NULL;
 
 
@@ -295,6 +253,8 @@ parse_cidr(tcpr_cidr_t ** cidrdata, char *cidrin, char *delim)
 
 
     /* first iteration of input using strtok */
     /* first iteration of input using strtok */
     network = strtok_r(cidrin, delim, &token);
     network = strtok_r(cidrin, delim, &token);
+    if (network == NULL)
+        return 0;
 
 
     *cidrdata = cidr2cidr(network);
     *cidrdata = cidr2cidr(network);
     cidr_ptr = *cidrdata;
     cidr_ptr = *cidrdata;
@@ -313,8 +273,8 @@ parse_cidr(tcpr_cidr_t ** cidrdata, char *cidrin, char *delim)
         cidr_ptr->next = cidr2cidr(network);
         cidr_ptr->next = cidr2cidr(network);
         cidr_ptr = cidr_ptr->next;
         cidr_ptr = cidr_ptr->next;
     }
     }
-    return 1;
 
 
+    return 1;
 }
 }
 
 
 /**
 /**
@@ -324,7 +284,7 @@ parse_cidr(tcpr_cidr_t ** cidrdata, char *cidrin, char *delim)
  * since we use strtok to process optarg, it gets zeroed out
  * since we use strtok to process optarg, it gets zeroed out
  */
  */
 int
 int
-parse_endpoints(tcpr_cidrmap_t ** cidrmap1, tcpr_cidrmap_t ** cidrmap2, const char *optarg)
+parse_endpoints(tcpr_cidrmap_t **cidrmap1, tcpr_cidrmap_t **cidrmap2, const char *optarg)
 {
 {
 #define NEWMAP_LEN (INET6_ADDRSTRLEN * 2)
 #define NEWMAP_LEN (INET6_ADDRSTRLEN * 2)
     char *map = NULL, newmap[NEWMAP_LEN];
     char *map = NULL, newmap[NEWMAP_LEN];
@@ -341,13 +301,13 @@ parse_endpoints(tcpr_cidrmap_t ** cidrmap1, tcpr_cidrmap_t ** cidrmap2, const ch
         p = strstr(string, "]:[");
         p = strstr(string, "]:[");
         if (!p)
         if (!p)
             goto done;
             goto done;
-            
+
         *p = 0;
         *p = 0;
         strlcpy(newmap, "[::/0]:", NEWMAP_LEN);
         strlcpy(newmap, "[::/0]:", NEWMAP_LEN);
         strlcat(newmap, string, NEWMAP_LEN);
         strlcat(newmap, string, NEWMAP_LEN);
         strlcat(newmap, "]", NEWMAP_LEN);
         strlcat(newmap, "]", NEWMAP_LEN);
-        
-        if (! parse_cidr_map(cidrmap1, newmap))
+
+        if (!parse_cidr_map(cidrmap1, newmap))
             goto done;
             goto done;
 
 
         /* do again with the second IP */
         /* do again with the second IP */
@@ -355,29 +315,31 @@ parse_endpoints(tcpr_cidrmap_t ** cidrmap1, tcpr_cidrmap_t ** cidrmap2, const ch
         strlcpy(newmap, "[::/0]:", NEWMAP_LEN);
         strlcpy(newmap, "[::/0]:", NEWMAP_LEN);
         strlcat(newmap, p + 2, NEWMAP_LEN);
         strlcat(newmap, p + 2, NEWMAP_LEN);
 
 
-        if (! parse_cidr_map(cidrmap2, newmap))
+        if (!parse_cidr_map(cidrmap2, newmap))
             goto done;
             goto done;
 
 
     } else {
     } else {
         /* ipv4 mode */
         /* ipv4 mode */
         memset(newmap, '\0', NEWMAP_LEN);
         memset(newmap, '\0', NEWMAP_LEN);
         map = strtok_r(string, ":", &token);
         map = strtok_r(string, ":", &token);
+        if (map == NULL)
+            goto done;
 
 
         strlcpy(newmap, "0.0.0.0/0:", NEWMAP_LEN);
         strlcpy(newmap, "0.0.0.0/0:", NEWMAP_LEN);
         strlcat(newmap, map, NEWMAP_LEN);
         strlcat(newmap, map, NEWMAP_LEN);
-        if (! parse_cidr_map(cidrmap1, newmap))
+        if (!parse_cidr_map(cidrmap1, newmap))
             goto done;
             goto done;
-    
+
         /* do again with the second IP */
         /* do again with the second IP */
         memset(newmap, '\0', NEWMAP_LEN);
         memset(newmap, '\0', NEWMAP_LEN);
         map = strtok_r(NULL, ":", &token);
         map = strtok_r(NULL, ":", &token);
-    
+
         strlcpy(newmap, "0.0.0.0/0:", NEWMAP_LEN);
         strlcpy(newmap, "0.0.0.0/0:", NEWMAP_LEN);
         strlcat(newmap, map, NEWMAP_LEN);
         strlcat(newmap, map, NEWMAP_LEN);
-        if (! parse_cidr_map(cidrmap2, newmap))
+        if (!parse_cidr_map(cidrmap2, newmap))
             goto done;
             goto done;
     }
     }
-    
+
     /* success */
     /* success */
     res = 1;
     res = 1;
 
 
@@ -386,7 +348,6 @@ done:
     return res;
     return res;
 }
 }
 
 
-
 /**
 /**
  * parses a list of tcpr_cidrmap_t's input from the user which should be in the form
  * parses a list of tcpr_cidrmap_t's input from the user which should be in the form
  * of x.x.x.x/y:x.x.x.x/y,...
  * of x.x.x.x/y:x.x.x.x/y,...
@@ -402,12 +363,12 @@ parse_cidr_map(tcpr_cidrmap_t **cidrmap, const char *optarg)
     char *token = NULL, *string;
     char *token = NULL, *string;
     tcpr_cidrmap_t *ptr;
     tcpr_cidrmap_t *ptr;
     int res = 0;
     int res = 0;
-    
+
     string = safe_strdup(optarg);
     string = safe_strdup(optarg);
 
 
     /* first iteration */
     /* first iteration */
     map = strtok_r(string, ",", &token);
     map = strtok_r(string, ",", &token);
-    if (! parse_cidr(&cidr, map, ":"))
+    if (!parse_cidr(&cidr, map, ":"))
         goto done;
         goto done;
 
 
     /* must return a linked list of two */
     /* must return a linked list of two */
@@ -423,12 +384,12 @@ parse_cidr_map(tcpr_cidrmap_t **cidrmap, const char *optarg)
     ptr->from->next = NULL;
     ptr->from->next = NULL;
 
 
     /* do the same with the reset of the input */
     /* do the same with the reset of the input */
-    while(1) {
+    while (1) {
         map = strtok_r(NULL, ",", &token);
         map = strtok_r(NULL, ",", &token);
         if (map == NULL)
         if (map == NULL)
             break;
             break;
 
 
-        if (! parse_cidr(&cidr, map, ":"))
+        if (!parse_cidr(&cidr, map, ":"))
             goto done;
             goto done;
 
 
         /* must return a linked list of two */
         /* must return a linked list of two */
@@ -456,14 +417,14 @@ done:
  * returns 1 for true, 0 for false
  * returns 1 for true, 0 for false
  */
  */
 int
 int
-ip_in_cidr(const tcpr_cidr_t * mycidr, const unsigned long ip)
+ip_in_cidr(const tcpr_cidr_t *mycidr, const unsigned long ip)
 {
 {
-    unsigned long ipaddr = 0, network = 0, mask = 0;
-    int ret = 0;
+    unsigned long ipaddr, network, mask;
+    int ret;
 #ifdef DEBUG
 #ifdef DEBUG
     char netstr[20];
     char netstr[20];
 #endif
 #endif
-    
+
     if (mycidr->family != AF_INET)
     if (mycidr->family != AF_INET)
         return 0;
         return 0;
 
 
@@ -471,7 +432,7 @@ ip_in_cidr(const tcpr_cidr_t * mycidr, const unsigned long ip)
     if (mycidr->masklen == 0 && mycidr->u.network == 0)
     if (mycidr->masklen == 0 && mycidr->u.network == 0)
         return 1;
         return 1;
 
 
-    mask = ~0;                  /* turn on all the bits */
+    mask = ~0; /* turn on all the bits */
 
 
     /* shift over by the correct number of bits */
     /* shift over by the correct number of bits */
     mask = mask << (32 - mycidr->masklen);
     mask = mask << (32 - mycidr->masklen);
@@ -481,7 +442,6 @@ ip_in_cidr(const tcpr_cidr_t * mycidr, const unsigned long ip)
 
 
     network = htonl(mycidr->u.network) & mask;
     network = htonl(mycidr->u.network) & mask;
 
 
-
 #ifdef DEBUG
 #ifdef DEBUG
     /* copy this for debug purposes, since it's not re-entrant */
     /* copy this for debug purposes, since it's not re-entrant */
     strlcpy(netstr, get_addr2name4(mycidr->u.network, RESOLVE), 20);
     strlcpy(netstr, get_addr2name4(mycidr->u.network, RESOLVE), 20);
@@ -490,32 +450,29 @@ ip_in_cidr(const tcpr_cidr_t * mycidr, const unsigned long ip)
     /* if they're the same, then ip is in network */
     /* if they're the same, then ip is in network */
     if (network == ipaddr) {
     if (network == ipaddr) {
 #ifdef DEBUG
 #ifdef DEBUG
-        dbgx(1, "The ip %s is inside of %s/%d",
-            get_addr2name4(ip, RESOLVE), netstr, mycidr->masklen);
+        dbgx(1, "The ip %s is inside of %s/%d", get_addr2name4(ip, RESOLVE), netstr, mycidr->masklen);
 #endif
 #endif
         ret = 1;
         ret = 1;
     } else {
     } else {
 #ifdef DEBUG
 #ifdef DEBUG
-        dbgx(1, "The ip %s is not inside of %s/%d",
-            get_addr2name4(ip, RESOLVE), netstr, mycidr->masklen);
+        dbgx(1, "The ip %s is not inside of %s/%d", get_addr2name4(ip, RESOLVE), netstr, mycidr->masklen);
 #endif
 #endif
         ret = 0;
         ret = 0;
     }
     }
     return ret;
     return ret;
-
 }
 }
 
 
 static int
 static int
 ip6_addr_is_unspec(const struct tcpr_in6_addr *addr)
 ip6_addr_is_unspec(const struct tcpr_in6_addr *addr)
 {
 {
-    return addr->tcpr_s6_addr32[0] == 0 && addr->tcpr_s6_addr32[1] == 0 &&
-      addr->tcpr_s6_addr32[2] == 0 && addr->tcpr_s6_addr32[3] == 0;
+    return addr->tcpr_s6_addr32[0] == 0 && addr->tcpr_s6_addr32[1] == 0 && addr->tcpr_s6_addr32[2] == 0 &&
+           addr->tcpr_s6_addr32[3] == 0;
 }
 }
 
 
 int
 int
-ip6_in_cidr(const tcpr_cidr_t * mycidr, const struct tcpr_in6_addr *addr)
+ip6_in_cidr(const tcpr_cidr_t *mycidr, const struct tcpr_in6_addr *addr)
 {
 {
-    int ret = 0;
+    int ret;
 #ifdef DEBUG
 #ifdef DEBUG
     char netstr[INET6_ADDRSTRLEN];
     char netstr[INET6_ADDRSTRLEN];
 #endif
 #endif
@@ -536,7 +493,7 @@ ip6_in_cidr(const tcpr_cidr_t * mycidr, const struct tcpr_in6_addr *addr)
             goto out;
             goto out;
         }
         }
     }
     }
-    
+
     if ((k = mycidr->masklen % 8) == 0) {
     if ((k = mycidr->masklen % 8) == 0) {
         ret = 1;
         ret = 1;
         goto out;
         goto out;
@@ -556,47 +513,42 @@ out:
     /* if they're the same, then ip is in network */
     /* if they're the same, then ip is in network */
     if (ret) {
     if (ret) {
 #ifdef DEBUG
 #ifdef DEBUG
-        dbgx(1, "The ip %s is inside of %s/%d",
-            get_addr2name6(addr, RESOLVE), netstr, mycidr->masklen);
+        dbgx(1, "The ip %s is inside of %s/%d", get_addr2name6(addr, RESOLVE), netstr, mycidr->masklen);
 #endif
 #endif
     } else {
     } else {
 #ifdef DEBUG
 #ifdef DEBUG
-        dbgx(1, "The ip %s is not inside of %s/%d",
-            get_addr2name6(addr, RESOLVE), netstr, mycidr->masklen);
+        dbgx(1, "The ip %s is not inside of %s/%d", get_addr2name6(addr, RESOLVE), netstr, mycidr->masklen);
 #endif
 #endif
     }
     }
     return ret;
     return ret;
-
 }
 }
 
 
-
 /**
 /**
  * iterates over cidrdata to find if a given ip matches
  * iterates over cidrdata to find if a given ip matches
  * returns 1 for true, 0 for false
  * returns 1 for true, 0 for false
  */
  */
 
 
 int
 int
-check_ip_cidr(tcpr_cidr_t * cidrdata, const unsigned long ip)
+check_ip_cidr(tcpr_cidr_t *cidrdata, const unsigned long ip)
 {
 {
     tcpr_cidr_t *mycidr;
     tcpr_cidr_t *mycidr;
 
 
-    /* if we have no cidrdata, of course it isn't in there 
+    /* if we have no cidrdata, of course it isn't in there
      * this actually should happen occasionally, so don't put an assert here
      * this actually should happen occasionally, so don't put an assert here
      */
      */
     if (cidrdata == NULL)
     if (cidrdata == NULL)
         return 1;
         return 1;
-        
+
     mycidr = cidrdata;
     mycidr = cidrdata;
 
 
     /* loop through cidr */
     /* loop through cidr */
     while (1) {
     while (1) {
-
         /* if match, return 1 */
         /* if match, return 1 */
         if (ip_in_cidr(mycidr, ip)) {
         if (ip_in_cidr(mycidr, ip)) {
             dbgx(3, "Found %s in cidr", get_addr2name4(ip, RESOLVE));
             dbgx(3, "Found %s in cidr", get_addr2name4(ip, RESOLVE));
             return 1;
             return 1;
         }
         }
-        
+
         /* check for next record */
         /* check for next record */
         if (mycidr->next != NULL) {
         if (mycidr->next != NULL) {
             mycidr = mycidr->next;
             mycidr = mycidr->next;
@@ -611,7 +563,7 @@ check_ip_cidr(tcpr_cidr_t * cidrdata, const unsigned long ip)
 }
 }
 
 
 int
 int
-check_ip6_cidr(tcpr_cidr_t * cidrdata, const struct tcpr_in6_addr *addr)
+check_ip6_cidr(tcpr_cidr_t *cidrdata, const struct tcpr_in6_addr *addr)
 {
 {
     tcpr_cidr_t *mycidr;
     tcpr_cidr_t *mycidr;
 
 
@@ -626,13 +578,12 @@ check_ip6_cidr(tcpr_cidr_t * cidrdata, const struct tcpr_in6_addr *addr)
 
 
     /* loop through cidr */
     /* loop through cidr */
     while (1) {
     while (1) {
-
         /* if match, return 1 */
         /* if match, return 1 */
         if (ip6_in_cidr(mycidr, addr)) {
         if (ip6_in_cidr(mycidr, addr)) {
             dbgx(3, "Found %s in cidr", get_addr2name6(addr, RESOLVE));
             dbgx(3, "Found %s in cidr", get_addr2name6(addr, RESOLVE));
             return 1;
             return 1;
         }
         }
-        
+
         /* check for next record */
         /* check for next record */
         if (mycidr->next != NULL) {
         if (mycidr->next != NULL) {
             mycidr = mycidr->next;
             mycidr = mycidr->next;
@@ -645,55 +596,3 @@ check_ip6_cidr(tcpr_cidr_t * cidrdata, const struct tcpr_in6_addr *addr)
     dbgx(3, "Didn't find %s in cidr", get_addr2name6(addr, RESOLVE));
     dbgx(3, "Didn't find %s in cidr", get_addr2name6(addr, RESOLVE));
     return 0;
     return 0;
 }
 }
-
-
-/**
- * cidr2ip takes a tcpr_cidr_t and a delimiter
- * and returns a string which lists all the IP addresses in the cidr
- * deliminated by the given char
- */
-char *
-cidr2iplist(tcpr_cidr_t * cidr, char delim)
-{
-    char *list = NULL;
-    char ipaddr[18], tempbuff[20];
-    u_int32_t size, addr, first, last, numips;
-    struct in_addr in;
-    int i;
-
-    /* 
-     * 16 bytes per IP + delim
-     * # of IP's = 2^(32-masklen)
-     */
-    numips = 2;
-    for (i = 2; i <= (32 - cidr->masklen); i++)
-        numips *= 2;
-
-    size = 17 * numips - 1;
-
-    list = (char *)safe_malloc(size);
-
-    memset(list, 0, size);
-
-    /* first and last should not include network or broadcast */
-    first = ntohl(cidr->u.network) + 1;
-    last = first + numips - 3;
-
-    dbgx(1, "First: %u\t\tLast: %u", first, last);
-
-    /* loop through all but the last one */
-    for (addr = first; addr < last; addr++) {
-        in.s_addr = htonl(addr);
-        snprintf(tempbuff, 17, "%s%c", inet_ntoa(in), delim);
-        memcpy(ipaddr, tempbuff, 16);
-        dbgx(2, "%s", ipaddr);
-        strlcat(list, ipaddr, size);
-    }
-
-    /* last is a special case, end in \0 */
-    in.s_addr = htonl(addr);
-    snprintf(ipaddr, 17, "%s", inet_ntoa(in));
-    strlcat(list, ipaddr, size);
-
-    return list;
-}

+ 7 - 12
src/common/cidr.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,13 +18,12 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#include "cache.h"
+#pragma once
 
 
-#ifndef __CIDR_H__
-#define __CIDR_H__
+#include "cache.h"
 
 
 struct tcpr_cidr_s {
 struct tcpr_cidr_s {
-    int family;                 /* AF_INET or AF_INET6 */
+    int family; /* AF_INET or AF_INET6 */
     union {
     union {
         u_int32_t network;
         u_int32_t network;
         struct tcpr_in6_addr network6;
         struct tcpr_in6_addr network6;
@@ -48,15 +47,11 @@ int check_ip6_cidr(tcpr_cidr_t *, const struct tcpr_in6_addr *addr);
 int parse_cidr(tcpr_cidr_t **, char *, char *delim);
 int parse_cidr(tcpr_cidr_t **, char *, char *delim);
 int parse_cidr_map(tcpr_cidrmap_t **, const char *);
 int parse_cidr_map(tcpr_cidrmap_t **, const char *);
 int parse_endpoints(tcpr_cidrmap_t **, tcpr_cidrmap_t **, const char *);
 int parse_endpoints(tcpr_cidrmap_t **, tcpr_cidrmap_t **, const char *);
-u_char *ip2cidr(const unsigned long, const int);
 void add_cidr(tcpr_cidr_t **, tcpr_cidr_t **);
 void add_cidr(tcpr_cidr_t **, tcpr_cidr_t **);
 tcpr_cidr_t *new_cidr(void);
 tcpr_cidr_t *new_cidr(void);
 tcpr_cidrmap_t *new_cidr_map(void);
 tcpr_cidrmap_t *new_cidr_map(void);
 void destroy_cidr(tcpr_cidr_t *);
 void destroy_cidr(tcpr_cidr_t *);
 void print_cidr(tcpr_cidr_t *);
 void print_cidr(tcpr_cidr_t *);
-char *cidr2iplist(tcpr_cidr_t *, char);
 
 
-int ip6_in_cidr(const tcpr_cidr_t * mycidr, const struct tcpr_in6_addr *addr);
+int ip6_in_cidr(const tcpr_cidr_t *mycidr, const struct tcpr_in6_addr *addr);
 int check_ip6_cidr(tcpr_cidr_t *, const struct tcpr_in6_addr *addr);
 int check_ip6_cidr(tcpr_cidr_t *, const struct tcpr_in6_addr *addr);
-
-#endif

+ 14 - 19
src/common/err.c

@@ -44,18 +44,11 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-#include "defines.h"
 #include "common.h"
 #include "common.h"
-
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
-#include <stdarg.h>
 #include <string.h>
 #include <string.h>
-#include <errno.h>
-
-#ifdef DEBUG
-extern int debug;
-#endif
 
 
 /**
 /**
  * writes a notice message to stderr.  Always forces a newline
  * writes a notice message to stderr.  Always forces a newline
@@ -76,21 +69,19 @@ notice(const char *fmt, ...)
 /**
 /**
  * Inner call to dbgx() which prints the function, line & function along
  * Inner call to dbgx() which prints the function, line & function along
  * with the message to stderr.  Always forces a newline.
  * with the message to stderr.  Always forces a newline.
- * 
+ *
  * You don't actually want to call this!  use dbgx() instead!
  * You don't actually want to call this!  use dbgx() instead!
  */
  */
 #ifdef DEBUG
 #ifdef DEBUG
 void
 void
-_our_verbose_dbgx(int dbg_level, const char *fmt, const char *function, 
-        const int line, const char *file, ...)
+our_verbose_dbgx(int dbg_level, const char *fmt, const char *function, const int line, const char *file, ...)
 {
 {
     va_list ap;
     va_list ap;
 
 
     if (debug < dbg_level)
     if (debug < dbg_level)
         return;
         return;
 
 
-    fprintf(stderr, "DEBUG%d in %s:%s() line %d: ", dbg_level, file, 
-            function, line);
+    fprintf(stderr, "DEBUG%d in %s:%s() line %d: ", dbg_level, file, function, line);
 
 
     va_start(ap, file);
     va_start(ap, file);
 
 
@@ -108,10 +99,12 @@ _our_verbose_dbgx(int dbg_level, const char *fmt, const char *function,
  */
  */
 #ifdef DEBUG
 #ifdef DEBUG
 void
 void
-_our_verbose_errx(int eval, const char *fmt, const char *function, const int line, const char *file, ...) {
+our_verbose_errx(int eval, const char *fmt, const char *function, const int line, const char *file, ...)
+{
 #else
 #else
 void
 void
-_our_verbose_errx(int eval, const char *fmt, ...) {
+our_verbose_errx(int eval, const char *fmt, ...)
+{
 #endif
 #endif
 
 
     va_list ap;
     va_list ap;
@@ -125,7 +118,7 @@ _our_verbose_errx(int eval, const char *fmt, ...) {
 #endif
 #endif
 
 
     if (fmt != NULL)
     if (fmt != NULL)
-        (void)vfprintf(stderr,  fmt, ap);
+        (void)vfprintf(stderr, fmt, ap);
     (void)fprintf(stderr, "\n");
     (void)fprintf(stderr, "\n");
     va_end(ap);
     va_end(ap);
     exit(eval);
     exit(eval);
@@ -137,10 +130,12 @@ _our_verbose_errx(int eval, const char *fmt, ...) {
  */
  */
 #ifdef DEBUG
 #ifdef DEBUG
 void
 void
-_our_verbose_warnx(const char *fmt, const char *function, const int line, const char *file, ...) {
+our_verbose_warnx(const char *fmt, const char *function, const int line, const char *file, ...)
+{
 #else
 #else
-void 
-_our_verbose_warnx(const char *fmt, ...) {
+void
+our_verbose_warnx(const char *fmt, ...)
+{
 #endif
 #endif
 
 
     va_list ap;
     va_list ap;

+ 2 - 5
src/common/err.h

@@ -45,9 +45,9 @@
  *    @(#)err.h    8.1 (Berkeley) 6/2/93
  *    @(#)err.h    8.1 (Berkeley) 6/2/93
  */
  */
 
 
-#ifndef _ERR_H_
-#define _ERR_H_
+#pragma once
 
 
+#include "defines.h"
 #include <stdlib.h>
 #include <stdlib.h>
 
 
 #ifdef DEBUG
 #ifdef DEBUG
@@ -145,6 +145,3 @@ void notice(const char *fmt, ...);
         fflush(NULL); \
         fflush(NULL); \
     } while (0)
     } while (0)
 #endif /* DEBUG */
 #endif /* DEBUG */
-
-
-#endif /* !_ERR_H_ */

+ 6 - 9
src/common/fakepcap.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -21,14 +21,13 @@
 /*
 /*
  * This file implements missing libpcap functions which only exist in really
  * This file implements missing libpcap functions which only exist in really
  * recent versions of libpcap.  We assume the user has at least 0.6, so anything
  * recent versions of libpcap.  We assume the user has at least 0.6, so anything
- * after that needs to be re-implimented here unless we want to start 
+ * after that needs to be re-implimented here unless we want to start
  * requiring a newer version
  * requiring a newer version
  */
  */
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
 #include <stdlib.h>
 #include <stdlib.h>
 
 
 #ifndef HAVE_DLT_VAL_TO_DESC
 #ifndef HAVE_DLT_VAL_TO_DESC
@@ -44,7 +43,6 @@ pcap_datalink_val_to_description(int dlt)
         return "Unknown";
         return "Unknown";
 
 
     return dlt2desc[dlt];
     return dlt2desc[dlt];
-
 }
 }
 
 
 /**
 /**
@@ -56,9 +54,8 @@ pcap_datalink_val_to_name(int dlt)
 {
 {
     if (dlt > DLT2NAME_LEN)
     if (dlt > DLT2NAME_LEN)
         return "Unknown";
         return "Unknown";
-        
+
     return dlt2name[dlt];
     return dlt2name[dlt];
-    
 }
 }
 
 
 #endif
 #endif

+ 1 - 4
src/common/fakepcap.h

@@ -18,8 +18,7 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef _FAKEPCAP_H_
-#define _FAKEPCAP_H_
+#pragma once
 
 
 #include "config.h"
 #include "config.h"
 
 
@@ -44,5 +43,3 @@ const char *pcap_datalink_val_to_description(int dlt);
 const char *pcap_datalink_val_to_name(int dlt);
 const char *pcap_datalink_val_to_name(int dlt);
 
 
 #endif
 #endif
-
-#endif /* end of _FAKEPCAP_H_ */

+ 14 - 18
src/common/fakepcapnav.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -19,30 +19,27 @@
  */
  */
 
 
 /*  This file implements a fake, non-functioning version of the libpcapnav
 /*  This file implements a fake, non-functioning version of the libpcapnav
- *  API based on libpcap.  It's solely here for people who don't have 
+ *  API based on libpcap.  It's solely here for people who don't have
  *  libpcapnav installed on their system, and to keep the code maintainable.
  *  libpcapnav installed on their system, and to keep the code maintainable.
  */
  */
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
 #include <stdlib.h>
 #include <stdlib.h>
 
 
 #ifndef HAVE_PCAPNAV
 #ifndef HAVE_PCAPNAV
 
 
 /**
 /**
- * pcapnav_init does nothing!  
+ * pcapnav_init does nothing!
  */
  */
 void
 void
 pcapnav_init(void)
 pcapnav_init(void)
-{
-    return;
-}
+{}
 
 
 /**
 /**
- * pcapnav_open_offline opens a pcap file, 
- * and creates the struct for our use  
+ * pcapnav_open_offline opens a pcap file,
+ * and creates the struct for our use
  */
  */
 pcapnav_t *
 pcapnav_t *
 pcapnav_open_offline(const char *filename)
 pcapnav_open_offline(const char *filename)
@@ -50,7 +47,7 @@ pcapnav_open_offline(const char *filename)
     pcapnav_t *pcapnav;
     pcapnav_t *pcapnav;
     char errbuf[PCAP_ERRBUF_SIZE];
     char errbuf[PCAP_ERRBUF_SIZE];
 
 
-    pcapnav = (pcapnav_t *) malloc(sizeof(pcapnav_t));
+    pcapnav = (pcapnav_t *)malloc(sizeof(pcapnav_t));
     if (pcapnav == NULL) {
     if (pcapnav == NULL) {
         err(-1, "malloc() error: unable to malloc pcapnav_t");
         err(-1, "malloc() error: unable to malloc pcapnav_t");
     }
     }
@@ -64,23 +61,22 @@ pcapnav_open_offline(const char *filename)
 }
 }
 
 
 /**
 /**
- * closes our pcap file and free's the pcapnav 
+ * closes our pcap file and free's the pcapnav
  */
  */
 void
 void
-pcapnav_close(pcapnav_t * pcapnav)
+pcapnav_close(pcapnav_t *pcapnav)
 {
 {
     pcap_close(pcapnav->pcap);
     pcap_close(pcapnav->pcap);
     safe_free(pcapnav);
     safe_free(pcapnav);
 }
 }
 
 
 /**
 /**
- * returns the pcap_t data struct 
+ * returns the pcap_t data struct
  */
  */
 pcap_t *
 pcap_t *
-pcapnav_pcap(pcapnav_t * pcapnav)
+pcapnav_pcap(pcapnav_t *pcapnav)
 {
 {
     return (pcapnav->pcap);
     return (pcapnav->pcap);
 }
 }
 
 
-
 #endif
 #endif

+ 6 - 9
src/common/fakepcapnav.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,16 +18,15 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#pragma once
+
 #ifdef HAVE_PCAPNAV
 #ifdef HAVE_PCAPNAV
 #include <pcapnav.h>
 #include <pcapnav.h>
 #define _FAKEPCAPNAV_H_
 #define _FAKEPCAPNAV_H_
 #endif
 #endif
 
 
-#ifndef _FAKEPCAPNAV_H_
-#define _FAKEPCAPNAV_H_
-
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 
 
 #ifndef HAVE_PCAPNAV
 #ifndef HAVE_PCAPNAV
 
 
@@ -43,5 +42,3 @@ void pcapnav_close(pcapnav_t *);
 pcap_t *pcapnav_pcap(pcapnav_t *);
 pcap_t *pcapnav_pcap(pcapnav_t *);
 
 
 #endif
 #endif
-
-#endif

+ 10 - 11
src/common/fakepoll.c

@@ -6,7 +6,7 @@
  * On systems where 'poll' doesn't exist, fake it with 'select'.
  * On systems where 'poll' doesn't exist, fake it with 'select'.
  *
  *
  * Copyright (c) 2001-2003, Nick Mathewson <nickm@freehaven.net>
  * Copyright (c) 2001-2003, Nick Mathewson <nickm@freehaven.net>
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
  * modification, are permitted provided that the following conditions are
  * met:
  * met:
@@ -22,7 +22,7 @@
  *   * Neither the names of the copyright owners nor the names of its
  *   * Neither the names of the copyright owners nor the names of its
  *   contributors may be used to endorse or promote products derived from
  *   contributors may be used to endorse or promote products derived from
  *   this software without specific prior written permission.
  *   this software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -36,19 +36,19 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  */
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
 
 
 /* prevents ISO C error */
 /* prevents ISO C error */
 #ifdef USE_FAKE_POLL
 #ifdef USE_FAKE_POLL
-static void FAKEPOLL(int stop)
-{ 
-    if (! stop)
-        FAKEPOLL(1); 
+static void
+FAKEPOLL(int stop)
+{
+    if (!stop)
+        FAKEPOLL(1);
     return;
     return;
-
-} 
+}
 
 
 #include <sys/types.h>
 #include <sys/types.h>
 #ifdef HAVE_UNISTD_H
 #ifdef HAVE_UNISTD_H
@@ -118,8 +118,7 @@ poll(struct pollfd *ufds, unsigned int nfds, int timeout)
         return 0;
         return 0;
     }
     }
 #endif
 #endif
-    r = select(maxfd + 1, &readfds, &writefds, &exceptfds,
-               timeout == -1 ? NULL : &_timeout);
+    r = select(maxfd + 1, &readfds, &writefds, &exceptfds, timeout == -1 ? NULL : &_timeout);
     if (r <= 0)
     if (r <= 0)
         return r;
         return r;
     r = 0;
     r = 0;

+ 11 - 9
src/common/fakepoll.h

@@ -6,7 +6,7 @@
  * On systems where 'poll' doesn't exist, fake it with 'select'.
  * On systems where 'poll' doesn't exist, fake it with 'select'.
  *
  *
  * Copyright (c) 2001-2003, Nick Mathewson <nickm@freehaven.net>
  * Copyright (c) 2001-2003, Nick Mathewson <nickm@freehaven.net>
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
  * modification, are permitted provided that the following conditions are
  * met:
  * met:
@@ -22,7 +22,7 @@
  *   * Neither the names of the copyright owners nor the names of its
  *   * Neither the names of the copyright owners nor the names of its
  *   contributors may be used to endorse or promote products derived from
  *   contributors may be used to endorse or promote products derived from
  *   this software without specific prior written permission.
  *   this software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -36,13 +36,15 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  */
 
 
+#pragma once
+
 /* don't warn on OS X that poll is emulated */
 /* don't warn on OS X that poll is emulated */
-#define POLL_NO_WARN 
+#define POLL_NO_WARN
 #define SYS_POLL_NO_WARN
 #define SYS_POLL_NO_WARN
 
 
 #ifdef HAVE_POLL_H
 #ifdef HAVE_POLL_H
 #include <poll.h>
 #include <poll.h>
-#define  __FAKEPOLL_H
+#define __FAKEPOLL_H
 #elif HAVE_SYS_POLL_H
 #elif HAVE_SYS_POLL_H
 #include <sys/poll.h>
 #include <sys/poll.h>
 #define __FAKEPOLL_H
 #define __FAKEPOLL_H
@@ -63,11 +65,11 @@ struct pollfd {
     short revents;
     short revents;
 };
 };
 
 
-#define POLLIN   0x0001
-#define POLLPRI  0x0002
-#define POLLOUT  0x0004
-#define POLLERR  0x0008
-#define POLLHUP  0x0010
+#define POLLIN 0x0001
+#define POLLPRI 0x0002
+#define POLLOUT 0x0004
+#define POLLERR 0x0008
+#define POLLHUP 0x0010
 #define POLLNVAL 0x0020
 #define POLLNVAL 0x0020
 
 
 int poll(struct pollfd *ufds, unsigned int nfds, int timeout);
 int poll(struct pollfd *ufds, unsigned int nfds, int timeout);

+ 4 - 2
src/common/flows.c

@@ -21,7 +21,6 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
-#include "../../lib/sll.h"
 
 
 #define JUNIPER_FLAG_NO_L2          0x02     /* L2 header */
 #define JUNIPER_FLAG_NO_L2          0x02     /* L2 header */
 #define JUNIPER_FLAG_EXT            0x80     /* Juniper extensions present */
 #define JUNIPER_FLAG_EXT            0x80     /* Juniper extensions present */
@@ -120,7 +119,7 @@ static inline flow_entry_type_t hash_put_data(flow_hash_table_t *fht, const uint
 {
 {
     uint32_t hash_value = key & (fht->num_buckets - 1);
     uint32_t hash_value = key & (fht->num_buckets - 1);
     flow_hash_entry_t *he;
     flow_hash_entry_t *he;
-    flow_entry_type_t res = FLOW_ENTRY_INVALID;
+    flow_entry_type_t res;
 
 
     for (he = fht->buckets[hash_value]; he; he = he->next) {
     for (he = fht->buckets[hash_value]; he; he = he->next) {
         /*
         /*
@@ -263,6 +262,9 @@ flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr *
         entry.src_port = icmp_hdr->icmp_type;
         entry.src_port = icmp_hdr->icmp_type;
         entry.dst_port = icmp_hdr->icmp_code;
         entry.dst_port = icmp_hdr->icmp_code;
         break;
         break;
+    default:
+        entry.src_port = 0;
+        entry.dst_port = 0;
     }
     }
 
 
     /* hash the 5-tuple */
     /* hash the 5-tuple */

+ 16 - 16
src/common/flows.h

@@ -2,9 +2,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -15,27 +15,27 @@
  *   You should have received a copy of the GNU General Public License
  *   You should have received a copy of the GNU General Public License
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
-#ifndef FLOWS_H_
-#define FLOWS_H_
+#pragma once
 
 
 #include "defines.h"
 #include "defines.h"
 #include "common.h"
 #include "common.h"
 
 
-#define DEFAULT_FLOW_HASH_BUCKET_SIZE (1 << 16)       /* 64K - must be a power of two */
+#define DEFAULT_FLOW_HASH_BUCKET_SIZE (1 << 16) /* 64K - must be a power of two */
 
 
 typedef enum flow_entry_type_e {
 typedef enum flow_entry_type_e {
-    FLOW_ENTRY_INVALID,     /* unknown packet type */
-    FLOW_ENTRY_NON_IP,      /* is a flow, but non-IP */
-    FLOW_ENTRY_NEW,         /* flow never seen before */
-    FLOW_ENTRY_EXISTING,    /* flow already seen */
-    FLOW_ENTRY_EXPIRED,     /* flow existed but was expired */
+    FLOW_ENTRY_INVALID,  /* unknown packet type */
+    FLOW_ENTRY_NON_IP,   /* is a flow, but non-IP */
+    FLOW_ENTRY_NEW,      /* flow never seen before */
+    FLOW_ENTRY_EXISTING, /* flow already seen */
+    FLOW_ENTRY_EXPIRED,  /* flow existed but was expired */
 } flow_entry_type_t;
 } flow_entry_type_t;
 
 
 typedef struct flow_hash_table flow_hash_table_t;
 typedef struct flow_hash_table flow_hash_table_t;
 
 
 flow_hash_table_t *flow_hash_table_init(size_t n);
 flow_hash_table_t *flow_hash_table_init(size_t n);
-void flow_hash_table_release(flow_hash_table_t * table);
-flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr *pkthdr,
-        const u_char *pktdata, const int datalink, const int expiry);
-
-#endif /* FLOWS_H_ */
+void flow_hash_table_release(flow_hash_table_t *table);
+flow_entry_type_t flow_decode(flow_hash_table_t *fht,
+                              const struct pcap_pkthdr *pkthdr,
+                              const u_char *pktdata,
+                              const int datalink,
+                              const int expiry);

+ 111 - 164
src/common/get.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,43 +18,36 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-#include "../../lib/sll.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
+#include <lib/sll.h>
 #include <arpa/inet.h>
 #include <arpa/inet.h>
 #include <ctype.h>
 #include <ctype.h>
-#include <string.h>
+#include <netinet/in.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/types.h>
 
 
-#ifdef DEBUG
-extern int debug;
-#endif
-
-#if defined HAVE_PCAP_VERSION && ! defined HAVE_WIN32
+#if defined HAVE_PCAP_VERSION && !defined HAVE_WIN32
 extern const char pcap_version[];
 extern const char pcap_version[];
 #endif
 #endif
 
 
-#define JUNIPER_FLAG_NO_L2          0x02     /* L2 header */
-#define JUNIPER_FLAG_EXT            0x80     /* Juniper extensions present */
-#define JUNIPER_PCAP_MAGIC          "MGC"
+#define JUNIPER_FLAG_NO_L2 0x02 /* L2 header */
+#define JUNIPER_FLAG_EXT 0x80   /* Juniper extensions present */
+#define JUNIPER_PCAP_MAGIC "MGC"
 
 
-static void *
-get_ipv6_next(struct tcpr_ipv6_ext_hdr_base *exthdr, const u_char *end_ptr);
+static void *get_ipv6_next(struct tcpr_ipv6_ext_hdr_base *exthdr, const u_char *end_ptr);
 
 
 /**
 /**
- * Depending on what version of libpcap/WinPcap there are different ways to get 
- * the version of the libpcap/WinPcap library.  This presents a unified way to 
+ * Depending on what version of libpcap/WinPcap there are different ways to get
+ * the version of the libpcap/WinPcap library.  This presents a unified way to
  * get that information.
  * get that information.
  */
  */
 const char *
 const char *
 get_pcap_version(void)
 get_pcap_version(void)
 {
 {
-
 #if defined HAVE_WINPCAP
 #if defined HAVE_WINPCAP
     static char ourver[255];
     static char ourver[255];
     char *last, *version;
     char *last, *version;
@@ -91,11 +84,8 @@ get_pcap_version(void)
  *
  *
  * return 0 on success, -1 on failure
  * return 0 on success, -1 on failure
  */
  */
-int parse_mpls(const u_char *pktdata,
-               const uint32_t datalen,
-               uint16_t *next_protocol,
-               uint32_t *l2len,
-               uint32_t *l2offset)
+int
+parse_mpls(const u_char *pktdata, uint32_t datalen, uint16_t *next_protocol, uint32_t *l2len, uint32_t *l2offset)
 {
 {
     struct tcpr_mpls_label *mpls_label;
     struct tcpr_mpls_label *mpls_label;
     const u_char *end_ptr = pktdata + datalen;
     const u_char *end_ptr = pktdata + datalen;
@@ -116,7 +106,7 @@ int parse_mpls(const u_char *pktdata,
         if (pktdata + len + sizeof(*mpls_label) > end_ptr)
         if (pktdata + len + sizeof(*mpls_label) > end_ptr)
             return -1;
             return -1;
 
 
-        mpls_label = (struct tcpr_mpls_label*)(pktdata + len);
+        mpls_label = (struct tcpr_mpls_label *)(pktdata + len);
         len += sizeof(*mpls_label);
         len += sizeof(*mpls_label);
         bos = (ntohl(mpls_label->entry) & MPLS_LS_S_MASK) != 0;
         bos = (ntohl(mpls_label->entry) & MPLS_LS_S_MASK) != 0;
         label = ntohl(mpls_label->entry) >> MPLS_LS_LABEL_SHIFT;
         label = ntohl(mpls_label->entry) >> MPLS_LS_LABEL_SHIFT;
@@ -127,11 +117,11 @@ int parse_mpls(const u_char *pktdata,
         }
         }
     }
     }
 
 
-    if ((u_char*)mpls_label + 1 > end_ptr)
+    if ((u_char *)(mpls_label + 1) + 1 > end_ptr)
         return -1;
         return -1;
 
 
     first_nibble = *((u_char *)(mpls_label + 1)) >> 4;
     first_nibble = *((u_char *)(mpls_label + 1)) >> 4;
-    switch(first_nibble) {
+    switch (first_nibble) {
     case 4:
     case 4:
         *next_protocol = ETHERTYPE_IP;
         *next_protocol = ETHERTYPE_IP;
         break;
         break;
@@ -147,7 +137,7 @@ int parse_mpls(const u_char *pktdata,
 
 
         len += 4;
         len += 4;
         *l2offset = len;
         *l2offset = len;
-        eth_hdr = (eth_hdr_t*)(pktdata + len);
+        eth_hdr = (eth_hdr_t *)(pktdata + len);
         len += sizeof(*eth_hdr);
         len += sizeof(*eth_hdr);
         *next_protocol = ntohs(eth_hdr->ether_type);
         *next_protocol = ntohs(eth_hdr->ether_type);
         break;
         break;
@@ -171,16 +161,14 @@ int parse_mpls(const u_char *pktdata,
  *
  *
  * return 0 on success, -1 on failure
  * return 0 on success, -1 on failure
  */
  */
-int parse_vlan(const u_char *pktdata,
-               const uint32_t datalen,
-               uint16_t *next_protocol,
-               uint32_t *l2len)
+int
+parse_vlan(const u_char *pktdata, uint32_t datalen, uint16_t *next_protocol, uint32_t *l2len)
 {
 {
     vlan_hdr_t *vlan_hdr;
     vlan_hdr_t *vlan_hdr;
     if ((size_t)datalen < *l2len + sizeof(*vlan_hdr))
     if ((size_t)datalen < *l2len + sizeof(*vlan_hdr))
         return -1;
         return -1;
 
 
-    vlan_hdr = (vlan_hdr_t*)(pktdata + *l2len);
+    vlan_hdr = (vlan_hdr_t *)(pktdata + *l2len);
     *next_protocol = ntohs(vlan_hdr->vlan_tpid);
     *next_protocol = ntohs(vlan_hdr->vlan_tpid);
     *l2len += sizeof(vlan_hdr_t);
     *l2len += sizeof(vlan_hdr_t);
 
 
@@ -199,12 +187,13 @@ int parse_vlan(const u_char *pktdata,
  *
  *
  * return 0 on success, -1 on failure
  * return 0 on success, -1 on failure
  */
  */
-static int parse_metadata(const u_char *pktdata,
-                          const uint32_t datalen,
-                          uint16_t *next_protocol,
-                          uint32_t *l2len,
-                          uint32_t *l2offset,
-                          uint32_t *vlan_offset)
+static int
+parse_metadata(const u_char *pktdata,
+               uint32_t datalen,
+               uint16_t *next_protocol,
+               uint32_t *l2len,
+               uint32_t *l2offset,
+               uint32_t *vlan_offset)
 {
 {
     bool done = false;
     bool done = false;
     int res = 0;
     int res = 0;
@@ -246,25 +235,22 @@ static int parse_metadata(const u_char *pktdata,
  *
  *
  * return 0 on success, -1 on failure
  * return 0 on success, -1 on failure
  */
  */
-int get_l2len_protocol(const u_char *pktdata,
-                       const uint32_t datalen,
-                       const int datalink,
-                       uint16_t *protocol,
-                       uint32_t *l2len,
-                       uint32_t *l2offset,
-                       uint32_t *vlan_offset)
+int
+get_l2len_protocol(const u_char *pktdata,
+                   uint32_t datalen,
+                   int datalink,
+                   uint16_t *protocol,
+                   uint32_t *l2len,
+                   uint32_t *l2offset,
+                   uint32_t *vlan_offset)
 {
 {
     assert(protocol);
     assert(protocol);
     assert(l2len);
     assert(l2len);
     assert(l2offset);
     assert(l2offset);
     assert(vlan_offset);
     assert(vlan_offset);
 
 
-    if (!pktdata || !datalen) {
-        errx(-1, "get_l2len_protocol: invalid L2 parameters: pktdata=0x%p len=%d",
-             pktdata,
-             datalen);
-        return -1;
-    }
+    if (!pktdata || !datalen)
+        errx(-1, "get_l2len_protocol: invalid L2 parameters: pktdata=0x%p len=%d", pktdata, datalen);
 
 
     *protocol = 0;
     *protocol = 0;
     *l2len = 0;
     *l2len = 0;
@@ -274,9 +260,6 @@ int get_l2len_protocol(const u_char *pktdata,
     switch (datalink) {
     switch (datalink) {
     case DLT_NULL:
     case DLT_NULL:
     case DLT_RAW:
     case DLT_RAW:
-        if (datalen == 0)
-            return -1;
-
         if ((pktdata[0] >> 4) == 4)
         if ((pktdata[0] >> 4) == 4)
             *protocol = ETHERTYPE_IP;
             *protocol = ETHERTYPE_IP;
         else if ((pktdata[0] >> 4) == 6)
         else if ((pktdata[0] >> 4) == 6)
@@ -286,7 +269,7 @@ int get_l2len_protocol(const u_char *pktdata,
         if (datalen < 4)
         if (datalen < 4)
             return -1;
             return -1;
 
 
-        if (memcmp(pktdata, JUNIPER_PCAP_MAGIC, 3)) {
+        if (memcmp(pktdata, JUNIPER_PCAP_MAGIC, 3) != 0) {
             warnx("No Magic Number found during protocol lookup: %s (0x%x)",
             warnx("No Magic Number found during protocol lookup: %s (0x%x)",
                   pcap_datalink_val_to_description(datalink),
                   pcap_datalink_val_to_description(datalink),
                   datalink);
                   datalink);
@@ -297,7 +280,7 @@ int get_l2len_protocol(const u_char *pktdata,
             if (datalen < 6)
             if (datalen < 6)
                 return -1;
                 return -1;
 
 
-            *l2offset = ntohs(*((uint16_t*)&pktdata[4]));
+            *l2offset = ntohs(*((uint16_t *)&pktdata[4]));
             *l2offset += 6; /* MGC + flags + ext_total_len */
             *l2offset += 6; /* MGC + flags + ext_total_len */
         } else {
         } else {
             *l2offset = 4; /* MGC + flags (no header extensions) */
             *l2offset = 4; /* MGC + flags (no header extensions) */
@@ -318,8 +301,7 @@ int get_l2len_protocol(const u_char *pktdata,
         }
         }
 
 
         /* fall through */
         /* fall through */
-    case DLT_EN10MB:
-    {
+    case DLT_EN10MB: {
         eth_hdr_t *eth_hdr;
         eth_hdr_t *eth_hdr;
         uint16_t ether_type;
         uint16_t ether_type;
         uint32_t l2_net_off = sizeof(*eth_hdr) + *l2offset;
         uint32_t l2_net_off = sizeof(*eth_hdr) + *l2offset;
@@ -327,14 +309,9 @@ int get_l2len_protocol(const u_char *pktdata,
         if (datalen <= l2_net_off)
         if (datalen <= l2_net_off)
             return -1;
             return -1;
 
 
-        eth_hdr = (eth_hdr_t*)(pktdata + *l2offset);
+        eth_hdr = (eth_hdr_t *)(pktdata + *l2offset);
         ether_type = ntohs(eth_hdr->ether_type);
         ether_type = ntohs(eth_hdr->ether_type);
-        if (parse_metadata(pktdata,
-                           datalen,
-                           &ether_type,
-                           &l2_net_off,
-                           l2offset,
-                           vlan_offset))
+        if (parse_metadata(pktdata, datalen, &ether_type, &l2_net_off, l2offset, vlan_offset))
             return -1;
             return -1;
 
 
         if (datalen <= l2_net_off)
         if (datalen <= l2_net_off)
@@ -360,7 +337,7 @@ int get_l2len_protocol(const u_char *pktdata,
         if ((size_t)datalen < sizeof(struct tcpr_pppserial_hdr))
         if ((size_t)datalen < sizeof(struct tcpr_pppserial_hdr))
             return -1;
             return -1;
 
 
-        struct tcpr_pppserial_hdr *ppp = (struct tcpr_pppserial_hdr*)pktdata;
+        struct tcpr_pppserial_hdr *ppp = (struct tcpr_pppserial_hdr *)pktdata;
         *l2len = sizeof(*ppp);
         *l2len = sizeof(*ppp);
         if (ntohs(ppp->protocol) == 0x0021)
         if (ntohs(ppp->protocol) == 0x0021)
             *protocol = ETHERTYPE_IP;
             *protocol = ETHERTYPE_IP;
@@ -372,7 +349,7 @@ int get_l2len_protocol(const u_char *pktdata,
         if (datalen < CISCO_HDLC_LEN)
         if (datalen < CISCO_HDLC_LEN)
             return -1;
             return -1;
 
 
-        hdlc_hdr_t *hdlc_hdr = (hdlc_hdr_t*)pktdata;
+        hdlc_hdr_t *hdlc_hdr = (hdlc_hdr_t *)pktdata;
         *l2len = sizeof(*hdlc_hdr);
         *l2len = sizeof(*hdlc_hdr);
         *protocol = ntohs(hdlc_hdr->protocol);
         *protocol = ntohs(hdlc_hdr->protocol);
         break;
         break;
@@ -380,12 +357,13 @@ int get_l2len_protocol(const u_char *pktdata,
         if (datalen < SLL_HDR_LEN)
         if (datalen < SLL_HDR_LEN)
             return -1;
             return -1;
 
 
-        sll_hdr_t *sll_hdr = (sll_hdr_t*)pktdata;
+        sll_hdr_t *sll_hdr = (sll_hdr_t *)pktdata;
         *l2len = sizeof(*sll_hdr);
         *l2len = sizeof(*sll_hdr);
         *protocol = ntohs(sll_hdr->sll_protocol);
         *protocol = ntohs(sll_hdr->sll_protocol);
         break;
         break;
     default:
     default:
-        errx(-1, "Unable to process unsupported DLT type: %s (0x%x)",
+        errx(-1,
+             "Unable to process unsupported DLT type: %s (0x%x)",
              pcap_datalink_val_to_description(datalink),
              pcap_datalink_val_to_description(datalink),
              datalink);
              datalink);
     }
     }
@@ -397,25 +375,19 @@ int get_l2len_protocol(const u_char *pktdata,
  * returns the length in number of bytes of the L2 header, or -1 on error
  * returns the length in number of bytes of the L2 header, or -1 on error
  */
  */
 int
 int
-get_l2len(const u_char *pktdata, const int datalen, const int datalink)
+get_l2len(const u_char *pktdata, int datalen, int datalink)
 {
 {
     uint16_t _U_ protocol;
     uint16_t _U_ protocol;
     uint32_t _U_ l2offset;
     uint32_t _U_ l2offset;
     uint32_t _U_ vlan_offset;
     uint32_t _U_ vlan_offset;
     uint32_t l2len = 0;
     uint32_t l2len = 0;
 
 
-    int res = get_l2len_protocol(pktdata,
-                                 datalen,
-                                 datalink,
-                                 &protocol,
-                                 &l2len,
-                                 &l2offset,
-                                 &vlan_offset);
+    int res = get_l2len_protocol(pktdata, datalen, datalink, &protocol, &l2len, &l2offset, &vlan_offset);
 
 
     if (res == -1)
     if (res == -1)
         return 0;
         return 0;
 
 
-    return l2len;
+    return (int)l2len;
 }
 }
 
 
 /**
 /**
@@ -425,7 +397,7 @@ get_l2len(const u_char *pktdata, const int datalen, const int datalink)
  * on strictly aligned systems where the layer 2 header doesn't
  * on strictly aligned systems where the layer 2 header doesn't
  * fall on a 4 byte boundary (like a standard Ethernet header)
  * fall on a 4 byte boundary (like a standard Ethernet header)
  *
  *
- * Note: you can cast the result as an ip_hdr_t, but you'll be able 
+ * Note: you can cast the result as an ip_hdr_t, but you'll be able
  * to access data above the header minus any stripped L2 data
  * to access data above the header minus any stripped L2 data
  */
  */
 const u_char *
 const u_char *
@@ -444,13 +416,7 @@ get_ipv4(const u_char *pktdata, int datalen, int datalink, u_char **newbuff)
     assert(pkt_len);
     assert(pkt_len);
     assert(*newbuff);
     assert(*newbuff);
 
 
-    res = get_l2len_protocol(packet,
-                             pkt_len,
-                             datalink,
-                             &proto,
-                             &l2len,
-                             &l2offset,
-                             &vlan_offset);
+    res = get_l2len_protocol(packet, pkt_len, datalink, &proto, &l2len, &l2offset, &vlan_offset);
 
 
     /* sanity... pkt_len must be > l2len + IP header len*/
     /* sanity... pkt_len must be > l2len + IP header len*/
     if (res == -1 || l2len + TCPR_IPV4_H > pkt_len) {
     if (res == -1 || l2len + TCPR_IPV4_H > pkt_len) {
@@ -463,13 +429,13 @@ get_ipv4(const u_char *pktdata, int datalen, int datalink, u_char **newbuff)
 
 
     packet += l2offset;
     packet += l2offset;
     l2len -= l2offset;
     l2len -= l2offset;
+#ifdef FORCE_ALIGN
     pkt_len -= l2offset;
     pkt_len -= l2offset;
 
 
-#ifdef FORCE_ALIGN
     /*
     /*
      * copy layer 3 and up to our temp packet buffer
      * copy layer 3 and up to our temp packet buffer
      * for now on, we have to edit the packetbuff because
      * for now on, we have to edit the packetbuff because
-     * just before we send the packet, we copy the packetbuff 
+     * just before we send the packet, we copy the packetbuff
      * back onto the pkt.data + l2len buffer
      * back onto the pkt.data + l2len buffer
      * we do all this work to prevent byte alignment issues
      * we do all this work to prevent byte alignment issues
      */
      */
@@ -477,13 +443,12 @@ get_ipv4(const u_char *pktdata, int datalen, int datalink, u_char **newbuff)
         memcpy(*newbuff, (packet + l2len), (pkt_len - l2len));
         memcpy(*newbuff, (packet + l2len), (pkt_len - l2len));
         ip_hdr = *newbuff;
         ip_hdr = *newbuff;
     } else {
     } else {
-
         /* we don't have to do a memcpy if l2len lands on a boundary */
         /* we don't have to do a memcpy if l2len lands on a boundary */
         ip_hdr = (packet + l2len);
         ip_hdr = (packet + l2len);
     }
     }
 #else
 #else
     /*
     /*
-     * on non-strict byte align systems, don't need to memcpy(), 
+     * on non-strict byte align systems, don't need to memcpy(),
      * just point to l2len bytes into the existing buffer
      * just point to l2len bytes into the existing buffer
      */
      */
     ip_hdr = (packet + l2len);
     ip_hdr = (packet + l2len);
@@ -492,7 +457,6 @@ get_ipv4(const u_char *pktdata, int datalen, int datalink, u_char **newbuff)
     return ip_hdr;
     return ip_hdr;
 }
 }
 
 
-
 /**
 /**
  * \brief returns a ptr to the ipv6 header + data or NULL if it's not IP
  * \brief returns a ptr to the ipv6 header + data or NULL if it's not IP
  *
  *
@@ -500,7 +464,7 @@ get_ipv4(const u_char *pktdata, int datalen, int datalink, u_char **newbuff)
  * on strictly aligned systems where the layer 2 header doesn't
  * on strictly aligned systems where the layer 2 header doesn't
  * fall on a 4 byte boundary (like a standard Ethernet header)
  * fall on a 4 byte boundary (like a standard Ethernet header)
  *
  *
- * Note: you can cast the result as an ip_hdr_t, but you'll be able 
+ * Note: you can cast the result as an ip_hdr_t, but you'll be able
  * to access data above the header minus any stripped L2 data
  * to access data above the header minus any stripped L2 data
  */
  */
 const u_char *
 const u_char *
@@ -519,13 +483,7 @@ get_ipv6(const u_char *pktdata, int datalen, int datalink, u_char **newbuff)
     assert(pkt_len);
     assert(pkt_len);
     assert(*newbuff);
     assert(*newbuff);
 
 
-    res = get_l2len_protocol(packet,
-                             pkt_len,
-                             datalink,
-                             &proto,
-                             &l2len,
-                             &l2offset,
-                             &vlan_offset);
+    res = get_l2len_protocol(packet, pkt_len, datalink, &proto, &l2len, &l2offset, &vlan_offset);
 
 
     /* sanity... pkt_len must be > l2len + IP header len*/
     /* sanity... pkt_len must be > l2len + IP header len*/
     if (res == -1 || l2len + TCPR_IPV6_H > pkt_len) {
     if (res == -1 || l2len + TCPR_IPV6_H > pkt_len) {
@@ -538,9 +496,9 @@ get_ipv6(const u_char *pktdata, int datalen, int datalink, u_char **newbuff)
 
 
     packet += l2offset;
     packet += l2offset;
     l2len -= l2offset;
     l2len -= l2offset;
+#ifdef FORCE_ALIGN
     pkt_len -= l2offset;
     pkt_len -= l2offset;
 
 
-#ifdef FORCE_ALIGN
     /*
     /*
      * copy layer 3 and up to our temp packet buffer
      * copy layer 3 and up to our temp packet buffer
      * for now on, we have to edit the packetbuff because
      * for now on, we have to edit the packetbuff because
@@ -552,7 +510,6 @@ get_ipv6(const u_char *pktdata, int datalen, int datalink, u_char **newbuff)
         memcpy(*newbuff, (packet + l2len), (pkt_len - l2len));
         memcpy(*newbuff, (packet + l2len), (pkt_len - l2len));
         ip6_hdr = *newbuff;
         ip6_hdr = *newbuff;
     } else {
     } else {
-
         /* we don't have to do a memcpy if l2len lands on a boundary */
         /* we don't have to do a memcpy if l2len lands on a boundary */
         ip6_hdr = (packet + l2len);
         ip6_hdr = (packet + l2len);
     }
     }
@@ -605,7 +562,7 @@ get_layer4_v6(const ipv6_hdr_t *ip6_hdr, const u_char *end_ptr)
 
 
     /* jump to the end of the IPv6 header */
     /* jump to the end of the IPv6 header */
     next = (struct tcpr_ipv6_ext_hdr_base *)((u_char *)ip6_hdr + TCPR_IPV6_H);
     next = (struct tcpr_ipv6_ext_hdr_base *)((u_char *)ip6_hdr + TCPR_IPV6_H);
-    if ((u_char*)next > end_ptr)
+    if ((u_char *)next > end_ptr)
         return NULL;
         return NULL;
 
 
     proto = ip6_hdr->ip_nh;
     proto = ip6_hdr->ip_nh;
@@ -649,9 +606,8 @@ get_layer4_v6(const ipv6_hdr_t *ip6_hdr, const u_char *end_ptr)
          */
          */
         default:
         default:
             if (proto != ip6_hdr->ip_nh) {
             if (proto != ip6_hdr->ip_nh) {
-                dbgx(3, "Returning byte offset of this ext header: %u", 
-                        IPV6_EXTLEN_TO_BYTES(next->ip_len));
-                next =  (void *)((u_char *)next + IPV6_EXTLEN_TO_BYTES(next->ip_len));
+                dbgx(3, "Returning byte offset of this ext header: %u", IPV6_EXTLEN_TO_BYTES(next->ip_len));
+                next = (void *)((u_char *)next + IPV6_EXTLEN_TO_BYTES(next->ip_len));
             } else {
             } else {
                 dbgx(3, "%s", "Returning end of IPv6 Header");
                 dbgx(3, "%s", "Returning end of IPv6 Header");
             }
             }
@@ -666,7 +622,6 @@ get_layer4_v6(const ipv6_hdr_t *ip6_hdr, const u_char *end_ptr)
     return next;
     return next;
 }
 }
 
 
-
 /**
 /**
  * returns the next payload or header of the current extension header
  * returns the next payload or header of the current extension header
  * returns NULL for none/ESP.
  * returns NULL for none/ESP.
@@ -674,11 +629,11 @@ get_layer4_v6(const ipv6_hdr_t *ip6_hdr, const u_char *end_ptr)
 static void *
 static void *
 get_ipv6_next(struct tcpr_ipv6_ext_hdr_base *exthdr, const u_char *end_ptr)
 get_ipv6_next(struct tcpr_ipv6_ext_hdr_base *exthdr, const u_char *end_ptr)
 {
 {
-    uint8_t extlen = 0;
+    uint8_t extlen;
     u_char *ptr;
     u_char *ptr;
     assert(exthdr);
     assert(exthdr);
 
 
-    if ((u_char*)exthdr + sizeof(*exthdr) > end_ptr)
+    if ((u_char *)exthdr + sizeof(*exthdr) > end_ptr)
         return NULL;
         return NULL;
 
 
     dbgx(3, "Jumping to next IPv6 header.  Processing 0x%02x", exthdr->ip_nh);
     dbgx(3, "Jumping to next IPv6 header.  Processing 0x%02x", exthdr->ip_nh);
@@ -688,10 +643,9 @@ get_ipv6_next(struct tcpr_ipv6_ext_hdr_base *exthdr, const u_char *end_ptr)
     case TCPR_IPV6_NH_ESP:
     case TCPR_IPV6_NH_ESP:
         dbg(3, "No-Next or ESP... can't go any further...");
         dbg(3, "No-Next or ESP... can't go any further...");
         return NULL;
         return NULL;
-        break;
 
 
     /*
     /*
-     * fragment header is fixed size 
+     * fragment header is fixed size
      * FIXME: Frag header has further ext headers (has a ip_nh field)
      * FIXME: Frag header has further ext headers (has a ip_nh field)
      * but I don't support it because there's never a full L4 + payload beyond.
      * but I don't support it because there's never a full L4 + payload beyond.
      */
      */
@@ -701,7 +655,6 @@ get_ipv6_next(struct tcpr_ipv6_ext_hdr_base *exthdr, const u_char *end_ptr)
         if (ptr > end_ptr)
         if (ptr > end_ptr)
             return NULL;
             return NULL;
         return (void *)ptr;
         return (void *)ptr;
-        break;
 
 
     /* all the rest require us to go deeper using the ip_len field */
     /* all the rest require us to go deeper using the ip_len field */
     case TCPR_IPV6_NH_IPV6:
     case TCPR_IPV6_NH_IPV6:
@@ -710,18 +663,19 @@ get_ipv6_next(struct tcpr_ipv6_ext_hdr_base *exthdr, const u_char *end_ptr)
     case TCPR_IPV6_NH_HBH:
     case TCPR_IPV6_NH_HBH:
     case TCPR_IPV6_NH_AH:
     case TCPR_IPV6_NH_AH:
         extlen = IPV6_EXTLEN_TO_BYTES(exthdr->ip_len);
         extlen = IPV6_EXTLEN_TO_BYTES(exthdr->ip_len);
-        dbgx(3, "Looks like we're an ext header (0x%hhx).  Jumping %u bytes"
-                " to the next", exthdr->ip_nh, extlen);
+        dbgx(3,
+             "Looks like we're an ext header (0x%hhx).  Jumping %u bytes"
+             " to the next",
+             exthdr->ip_nh,
+             extlen);
         ptr = (u_char *)exthdr + extlen;
         ptr = (u_char *)exthdr + extlen;
         if (ptr > end_ptr)
         if (ptr > end_ptr)
             return NULL;
             return NULL;
         return (void *)ptr;
         return (void *)ptr;
-        break;
 
 
     default:
     default:
         dbg(3, "Must not be a v6 extension header... returning self");
         dbg(3, "Must not be a v6 extension header... returning self");
         return (void *)exthdr;
         return (void *)exthdr;
-        break;
     }
     }
 }
 }
 
 
@@ -729,7 +683,7 @@ get_ipv6_next(struct tcpr_ipv6_ext_hdr_base *exthdr, const u_char *end_ptr)
  * returns the protocol of the actual layer4 header by processing through
  * returns the protocol of the actual layer4 header by processing through
  * the extension headers
  * the extension headers
  */
  */
-uint8_t 
+uint8_t
 get_ipv6_l4proto(const ipv6_hdr_t *ip6_hdr, const u_char *end_ptr)
 get_ipv6_l4proto(const ipv6_hdr_t *ip6_hdr, const u_char *end_ptr)
 {
 {
     u_char *ptr = (u_char *)ip6_hdr + TCPR_IPV6_H; /* jump to the end of the IPv6 header */
     u_char *ptr = (u_char *)ip6_hdr + TCPR_IPV6_H; /* jump to the end of the IPv6 header */
@@ -745,46 +699,43 @@ get_ipv6_l4proto(const ipv6_hdr_t *ip6_hdr, const u_char *end_ptr)
     while (TRUE) {
     while (TRUE) {
         dbgx(3, "Processing next proto 0x%02X", proto);
         dbgx(3, "Processing next proto 0x%02X", proto);
         switch (proto) {
         switch (proto) {
-            /* no further processing for IPV6 types with nothing beyond them */
-            case TCPR_IPV6_NH_NO_NEXT:
-            case TCPR_IPV6_NH_FRAGMENT:
-            case TCPR_IPV6_NH_ESP:
-                dbg(3, "No-Next or ESP... can't go any further...");
-                return proto;
-                break;
+        /* no further processing for IPV6 types with nothing beyond them */
+        case TCPR_IPV6_NH_NO_NEXT:
+        case TCPR_IPV6_NH_FRAGMENT:
+        case TCPR_IPV6_NH_ESP:
+            dbg(3, "No-Next or ESP... can't go any further...");
+            return proto;
 
 
-            /* recurse */
-            case TCPR_IPV6_NH_IPV6:
-                dbg(3, "Recursing due to v6 in v6");
-                return get_ipv6_l4proto((ipv6_hdr_t *)ptr, end_ptr);
-                break;
+        /* recurse */
+        case TCPR_IPV6_NH_IPV6:
+            dbg(3, "Recursing due to v6 in v6");
+            return get_ipv6_l4proto((ipv6_hdr_t *)ptr, end_ptr);
 
 
-            /* loop again */
-            case TCPR_IPV6_NH_AH:
-            case TCPR_IPV6_NH_ROUTING:
-            case TCPR_IPV6_NH_DESTOPTS:
-            case TCPR_IPV6_NH_HBH:
-                dbgx(3, "Jumping to next extension header (0x%hhx)", proto);
-                exthdr = get_ipv6_next((struct tcpr_ipv6_ext_hdr_base *)ptr,
-                        end_ptr);
-                if (exthdr == NULL || (u_char*)exthdr + sizeof(*exthdr) > end_ptr)
-                    return TCPR_IPV6_NH_NO_NEXT;
-                proto = exthdr->ip_nh;
-                ptr = (u_char *)exthdr;
-                break;
+        /* loop again */
+        case TCPR_IPV6_NH_AH:
+        case TCPR_IPV6_NH_ROUTING:
+        case TCPR_IPV6_NH_DESTOPTS:
+        case TCPR_IPV6_NH_HBH:
+            dbgx(3, "Jumping to next extension header (0x%hhx)", proto);
+            exthdr = get_ipv6_next((struct tcpr_ipv6_ext_hdr_base *)ptr, end_ptr);
+            if (exthdr == NULL || (u_char *)exthdr + sizeof(*exthdr) > end_ptr)
+                return TCPR_IPV6_NH_NO_NEXT;
+            proto = exthdr->ip_nh;
+            ptr = (u_char *)exthdr;
+            break;
 
 
-            /* should be TCP, UDP or the like */
-            default:
-                dbgx(3, "Selecting next L4 Proto as: 0x%02x", proto);
-                return proto;
+        /* should be TCP, UDP or the like */
+        default:
+            dbgx(3, "Selecting next L4 Proto as: 0x%02x", proto);
+            return proto;
         } /* switch */
         } /* switch */
-    } /* while */
+    }     /* while */
 }
 }
 
 
 /**
 /**
  * \brief Converts a human readable IPv4 address to a binary one
  * \brief Converts a human readable IPv4 address to a binary one
  *
  *
- * stolen from LIBNET since I didn't want to have to deal with 
+ * stolen from LIBNET since I didn't want to have to deal with
  * passing a libnet_t around.  Returns 0xFFFFFFFF (255.255.255.255)
  * passing a libnet_t around.  Returns 0xFFFFFFFF (255.255.255.255)
  * on error
  * on error
  */
  */
@@ -792,14 +743,14 @@ uint32_t
 get_name2addr4(const char *hostname, bool dnslookup)
 get_name2addr4(const char *hostname, bool dnslookup)
 {
 {
     struct in_addr addr;
     struct in_addr addr;
-#if ! defined HAVE_INET_ATON && defined HAVE_INET_ADDR
-    struct hostent *host_ent; 
+#if !defined HAVE_INET_ATON && defined HAVE_INET_ADDR
+    struct hostent *host_ent;
 #endif
 #endif
 
 
     if (dnslookup) {
     if (dnslookup) {
 #ifdef HAVE_INET_ATON
 #ifdef HAVE_INET_ATON
         if (inet_aton(hostname, &addr) != 1) {
         if (inet_aton(hostname, &addr) != 1) {
-            return(0xffffffff);
+            return (0xffffffff);
         }
         }
 #elif defined HAVE_INET_ADDR
 #elif defined HAVE_INET_ADDR
 
 
@@ -811,12 +762,12 @@ get_name2addr4(const char *hostname, bool dnslookup)
             }
             }
 
 
             /* was: host_ent->h_length); */
             /* was: host_ent->h_length); */
-            memcpy(&addr.s_addr, host_ent->h_addr, sizeof(addr.s_addr)); 
+            memcpy(&addr.s_addr, host_ent->h_addr, sizeof(addr.s_addr));
         }
         }
 #else
 #else
         warn("Unable to support get_name2addr4 w/ resolve");
         warn("Unable to support get_name2addr4 w/ resolve");
         /* call ourselves recursively once w/o resolving the hostname */
         /* call ourselves recursively once w/o resolving the hostname */
-        return get_name2addr4(hostname, DNS_DONT_RESOLVE); 
+        return get_name2addr4(hostname, DNS_DONT_RESOLVE);
 #endif
 #endif
         /* return in network byte order */
         /* return in network byte order */
         return (addr.s_addr);
         return (addr.s_addr);
@@ -828,13 +779,11 @@ get_name2addr4(const char *hostname, bool dnslookup)
         uint32_t m;
         uint32_t m;
 
 
         if (!isdigit(hostname[0])) {
         if (!isdigit(hostname[0])) {
-            warnx("Expected dotted-quad notation (%s) when DNS lookups are disabled", 
-                    hostname);
+            warnx("Expected dotted-quad notation (%s) when DNS lookups are disabled", hostname);
             /* XXX - this is actually 255.255.255.255 */
             /* XXX - this is actually 255.255.255.255 */
             return (-1);
             return (-1);
         }
         }
 
 
-
         m = 0;
         m = 0;
         for (i = 0; i < 4; i++) {
         for (i = 0; i < 4; i++) {
             u_int val;
             u_int val;
@@ -859,7 +808,7 @@ get_name2addr4(const char *hostname, bool dnslookup)
             }
             }
         }
         }
         /* host byte order */
         /* host byte order */
-       return (ntohl(m));
+        return (ntohl(m));
     }
     }
 }
 }
 
 
@@ -880,7 +829,6 @@ get_name2addr6(const char *hostname, bool dnslookup, struct tcpr_in6_addr *addr)
 #else
 #else
 #error "Unable to support get_name2addr6: Missing inet_pton() support."
 #error "Unable to support get_name2addr6: Missing inet_pton() support."
 #endif
 #endif
-    return -1;
 }
 }
 
 
 /**
 /**
@@ -890,7 +838,7 @@ get_name2addr6(const char *hostname, bool dnslookup, struct tcpr_in6_addr *addr)
  * is available on your system. Does not support DNS.
  * is available on your system. Does not support DNS.
  */
  */
 const char *
 const char *
-get_addr2name4(const uint32_t ip, bool _U_ dnslookup)
+get_addr2name4(uint32_t ip, bool _U_ dnslookup)
 {
 {
     struct in_addr addr;
     struct in_addr addr;
     static char *new_string = NULL;
     static char *new_string = NULL;
@@ -954,4 +902,3 @@ get_cidr2name(const tcpr_cidr_t *cidr_ptr, bool dnslookup)
         return NULL;
         return NULL;
     }
     }
 }
 }
-

+ 7 - 11
src/common/get.h

@@ -18,8 +18,7 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef __GET_H__
-#define __GET_H__
+#pragma once
 
 
 #include "config.h"
 #include "config.h"
 #include "defines.h"
 #include "defines.h"
@@ -27,21 +26,21 @@
 
 
 
 
 int parse_mpls(const u_char *pktdata,
 int parse_mpls(const u_char *pktdata,
-               const uint32_t datalen,
+               uint32_t datalen,
                uint16_t *protocol,
                uint16_t *protocol,
                uint32_t *l2len,
                uint32_t *l2len,
                uint32_t *l2offset);
                uint32_t *l2offset);
 
 
 int parse_vlan(const u_char *pktdata,
 int parse_vlan(const u_char *pktdata,
-               const uint32_t datalen,
+               uint32_t datalen,
                uint16_t *next_protocol,
                uint16_t *next_protocol,
                uint32_t *l2len);
                uint32_t *l2len);
 
 
-int get_l2len(const u_char *pktdata, const int datalen, const int datalink);
+int get_l2len(const u_char *pktdata, int datalen, int datalink);
 
 
 int get_l2len_protocol(const u_char *pktdata,
 int get_l2len_protocol(const u_char *pktdata,
-                       const uint32_t datalen,
-                       const int datalink,
+                       uint32_t datalen,
+                       int datalink,
                        uint16_t *protocol,
                        uint16_t *protocol,
                        uint32_t *l2len,
                        uint32_t *l2len,
                        uint32_t *l2offset,
                        uint32_t *l2offset,
@@ -56,7 +55,7 @@ const u_char *get_ipv4(const u_char *pktdata, int datalen, int datalink, u_char
 const u_char *get_ipv6(const u_char *pktdata, int datalen, int datalink, u_char **newbuff);
 const u_char *get_ipv6(const u_char *pktdata, int datalen, int datalink, u_char **newbuff);
 
 
 u_int32_t get_name2addr4(const char *hostname, bool dnslookup);
 u_int32_t get_name2addr4(const char *hostname, bool dnslookup);
-const char *get_addr2name4(const u_int32_t ip, bool dnslookup);
+const char *get_addr2name4(u_int32_t ip, bool dnslookup);
 const char *get_addr2name6(const struct tcpr_in6_addr *addr, bool dnslookup);
 const char *get_addr2name6(const struct tcpr_in6_addr *addr, bool dnslookup);
 const char *get_pcap_version(void);
 const char *get_pcap_version(void);
 
 
@@ -64,6 +63,3 @@ int get_name2addr6(const char *hostname, bool dnslookup, struct tcpr_in6_addr *a
 
 
 
 
 const char *get_cidr2name(const tcpr_cidr_t *cidr_ptr, bool dnslookup);
 const char *get_cidr2name(const tcpr_cidr_t *cidr_ptr, bool dnslookup);
-
-
-#endif

+ 1 - 1
src/common/git_version.c

@@ -1,4 +1,4 @@
-const char GIT_Version[] = "git:v4.4.3";
+const char GIT_Version[] = "git:v4.4.4";
 const char *git_version(void) {
 const char *git_version(void) {
     return GIT_Version;
     return GIT_Version;
 }
 }

+ 21 - 36
src/common/interface.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,33 +18,21 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <sys/ioctl.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-
+#include "interface.h"
 #include "config.h"
 #include "config.h"
-#include "defines.h"
 #include "common.h"
 #include "common.h"
-#include "interface.h"
-#ifdef HAVE_NETMAP
-#include "common/netmap.h"
-#endif
-
-#ifdef DEBUG
-extern int debug;
-#endif
+#include <dirent.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
 
 
 /**
 /**
  * Method takes a user specified device name and returns
  * Method takes a user specified device name and returns
- * the canonical name for that device.  This allows me to 
+ * the canonical name for that device.  This allows me to
  * create named interface aliases on platforms like Windows
  * create named interface aliases on platforms like Windows
  * which use horrifically long interface names
  * which use horrifically long interface names
- * 
+ *
  * Returns NULL on error
  * Returns NULL on error
  */
  */
 char *
 char *
@@ -58,17 +46,16 @@ get_interface(interface_list_t *list, const char *alias)
 
 
     while (ptr) {
     while (ptr) {
         /* check both the alias & name fields */
         /* check both the alias & name fields */
-        if (strcmp(alias, ptr->alias) == 0 ||
-                strcmp(alias, ptr->name) == 0)
-            return(ptr->name);
+        if (strcmp(alias, ptr->alias) == 0 || strcmp(alias, ptr->name) == 0)
+            return (ptr->name);
 
 
         ptr = ptr->next;
         ptr = ptr->next;
     }
     }
 
 
-    return(NULL);
+    return (NULL);
 }
 }
 
 
-/** 
+/**
  * Get all available interfaces as an interface_list *
  * Get all available interfaces as an interface_list *
  */
  */
 interface_list_t *
 interface_list_t *
@@ -124,13 +111,12 @@ get_interface_list(void)
          *
          *
          * available at http://code.google.com/p/netmap-libpcap/
          * available at http://code.google.com/p/netmap-libpcap/
          */
          */
-        if (!(pcap_if_ptr->flags & PCAP_IF_LOOPBACK)
-                && strcmp("any", pcap_if_ptr->name)) {
+        if (!(pcap_if_ptr->flags & PCAP_IF_LOOPBACK) && strcmp("any", pcap_if_ptr->name)) {
 #endif
 #endif
 #ifdef HAVE_NETMAP
 #ifdef HAVE_NETMAP
             int fd = -1;
             int fd = -1;
 
 
-            if (netmap_version != -1 && (fd = open ("/dev/netmap", O_RDWR)) < 0)
+            if (netmap_version != -1 && (fd = open("/dev/netmap", O_RDWR)) < 0)
                 continue;
                 continue;
 
 
             bzero(&nmr, sizeof(nmr));
             bzero(&nmr, sizeof(nmr));
@@ -218,7 +204,7 @@ get_interface_list(void)
     }
     }
 
 
     dbg(1, "xxx get_interface_list end");
     dbg(1, "xxx get_interface_list end");
-    return(list_head);
+    return (list_head);
 }
 }
 
 
 /**
 /**
@@ -235,12 +221,11 @@ list_interfaces(interface_list_t *list)
     }
     }
 
 
     printf("Available network interfaces:\n");
     printf("Available network interfaces:\n");
-        
-#ifdef HAVE_WIN32  /* Win32 has alias/name/description */
+
+#ifdef HAVE_WIN32 /* Win32 has alias/name/description */
     printf("Alias\tName\tDescription\n");
     printf("Alias\tName\tDescription\n");
 #endif
 #endif
-    
-    
+
     ptr = list;
     ptr = list;
 
 
     do {
     do {

+ 6 - 7
src/common/interface.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,8 +18,9 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef _INTERFACE_H_
-#define _INTERFACE_H_
+#pragma once
+
+#include "defines.h"
 
 
 typedef struct interface_list_s {
 typedef struct interface_list_s {
     char name[255];
     char name[255];
@@ -34,5 +35,3 @@ typedef struct interface_list_s {
 char *get_interface(interface_list_t *, const char *);
 char *get_interface(interface_list_t *, const char *);
 interface_list_t *get_interface_list(void);
 interface_list_t *get_interface_list(void);
 void list_interfaces(interface_list_t *);
 void list_interfaces(interface_list_t *);
-
-#endif

+ 12 - 24
src/common/list.c

@@ -2,9 +2,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -24,16 +24,13 @@
  * if an integer exists in the list.
  * if an integer exists in the list.
  */
  */
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
+#include <regex.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 #include <sys/types.h>
 #include <sys/types.h>
-#include <regex.h>
-#include <errno.h>
-
 
 
 /**
 /**
  * Creates a new tcpr_list entry.  Malloc's memory.
  * Creates a new tcpr_list entry.  Malloc's memory.
@@ -49,11 +46,11 @@ new_list()
 
 
 /**
 /**
  * Processes a string (ourstr) containing the list in human readable
  * Processes a string (ourstr) containing the list in human readable
- * format and places the data in **list and finally returns 1 for 
+ * format and places the data in **list and finally returns 1 for
  * success, 0 for fail.
  * success, 0 for fail.
  */
  */
 int
 int
-parse_list(tcpr_list_t ** listdata, char *ourstr)
+parse_list(tcpr_list_t **listdata, char *ourstr)
 {
 {
     tcpr_list_t *listcur, *list_ptr;
     tcpr_list_t *listcur, *list_ptr;
     char *this = NULL;
     char *this = NULL;
@@ -64,7 +61,6 @@ parse_list(tcpr_list_t ** listdata, char *ourstr)
     char *token = NULL;
     char *token = NULL;
     u_int i;
     u_int i;
 
 
-
     /* compile the regex first */
     /* compile the regex first */
     if ((rcode = regcomp(&preg, regex, REG_EXTENDED | REG_NOSUB)) != 0) {
     if ((rcode = regcomp(&preg, regex, REG_EXTENDED | REG_NOSUB)) != 0) {
         char ebuf[EBUF_SIZE];
         char ebuf[EBUF_SIZE];
@@ -78,7 +74,7 @@ parse_list(tcpr_list_t ** listdata, char *ourstr)
     second = NULL;
     second = NULL;
 
 
     /* regex test */
     /* regex test */
-    if (regexec(&preg, this, 0, NULL, 0) != 0) {
+    if (this == NULL || regexec(&preg, this, 0, NULL, 0) != 0) {
         warnx("Unable to parse: %s", this);
         warnx("Unable to parse: %s", this);
         regfree(&preg);
         regfree(&preg);
         return 0;
         return 0;
@@ -98,8 +94,7 @@ parse_list(tcpr_list_t ** listdata, char *ourstr)
     list_ptr->min = strtoull(first, NULL, 0);
     list_ptr->min = strtoull(first, NULL, 0);
     if (second != NULL) {
     if (second != NULL) {
         list_ptr->max = strtoull(second, NULL, 0);
         list_ptr->max = strtoull(second, NULL, 0);
-    }
-    else {
+    } else {
         list_ptr->max = list_ptr->min;
         list_ptr->max = list_ptr->min;
     }
     }
 
 
@@ -111,7 +106,6 @@ parse_list(tcpr_list_t ** listdata, char *ourstr)
         first = this;
         first = this;
         second = NULL;
         second = NULL;
 
 
-
         /* regex test */
         /* regex test */
         if (regexec(&preg, this, 0, NULL, 0) != 0) {
         if (regexec(&preg, this, 0, NULL, 0) != 0) {
             warnx("Unable to parse: %s", this);
             warnx("Unable to parse: %s", this);
@@ -132,11 +126,9 @@ parse_list(tcpr_list_t ** listdata, char *ourstr)
         listcur->min = strtoull(first, NULL, 0);
         listcur->min = strtoull(first, NULL, 0);
         if (second != NULL) {
         if (second != NULL) {
             listcur->max = strtoull(second, NULL, 0);
             listcur->max = strtoull(second, NULL, 0);
-        }
-        else {
+        } else {
             listcur->max = listcur->min;
             listcur->max = listcur->min;
         }
         }
-
     }
     }
 
 
     regfree(&preg);
     regfree(&preg);
@@ -144,14 +136,12 @@ parse_list(tcpr_list_t ** listdata, char *ourstr)
     return 1;
     return 1;
 }
 }
 
 
-
-
 /**
 /**
  * Checks to see if the given integer exists in the LIST.
  * Checks to see if the given integer exists in the LIST.
  * Return 1 if in the list, otherwise 0
  * Return 1 if in the list, otherwise 0
  */
  */
 tcpr_dir_t
 tcpr_dir_t
-check_list(tcpr_list_t * list, COUNTER value)
+check_list(tcpr_list_t *list, COUNTER value)
 {
 {
     tcpr_list_t *current;
     tcpr_list_t *current;
     current = list;
     current = list;
@@ -177,14 +167,12 @@ check_list(tcpr_list_t * list, COUNTER value)
     return 0;
     return 0;
 }
 }
 
 
-
 /**
 /**
  * Free's all the memory associated with the given LIST
  * Free's all the memory associated with the given LIST
  */
  */
 void
 void
-free_list(tcpr_list_t * list)
+free_list(tcpr_list_t *list)
 {
 {
-
     /* recursively go down the list */
     /* recursively go down the list */
     if (list->next != NULL)
     if (list->next != NULL)
         free_list(list->next);
         free_list(list->next);

+ 4 - 7
src/common/list.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,8 +18,7 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef __LIST_H__
-#define __LIST_H__
+#pragma once
 
 
 struct list_s {
 struct list_s {
     COUNTER max;
     COUNTER max;
@@ -32,5 +31,3 @@ typedef struct list_s tcpr_list_t;
 int parse_list(tcpr_list_t **, char *);
 int parse_list(tcpr_list_t **, char *);
 int check_list(tcpr_list_t *, COUNTER);
 int check_list(tcpr_list_t *, COUNTER);
 void free_list(tcpr_list_t *);
 void free_list(tcpr_list_t *);
-
-#endif

+ 29 - 34
src/common/mac.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,19 +18,16 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include "mac.h"
 #include "config.h"
 #include "config.h"
-#include "defines.h"
 #include "common.h"
 #include "common.h"
-#include <string.h>
-#include <stdlib.h>
-#include <limits.h>
 #include <ctype.h>
 #include <ctype.h>
-
-#include "mac.h"
+#include <stdlib.h>
+#include <string.h>
 
 
 /**
 /**
- * converts a string representation of a MAC address, based on 
- * non-portable ether_aton() 
+ * converts a string representation of a MAC address, based on
+ * non-portable ether_aton()
  */
  */
 void
 void
 mac2hex(const char *mac, u_char *dst, int len)
 mac2hex(const char *mac, u_char *dst, int len)
@@ -51,14 +48,14 @@ mac2hex(const char *mac, u_char *dst, int len)
             return;
             return;
         if (!(*pp == ':' || (i == 5 && (isspace(*pp) || *pp == '\0'))))
         if (!(*pp == ':' || (i == 5 && (isspace(*pp) || *pp == '\0'))))
             return;
             return;
-        dst[i] = (u_char) l;
+        dst[i] = (u_char)l;
         mac = pp + 1;
         mac = pp + 1;
     }
     }
 }
 }
 
 
 /**
 /**
  * converts a string representation of TWO MAC addresses, which
  * converts a string representation of TWO MAC addresses, which
- * are comma deliminated into two hex values.  Either *first or *second 
+ * are comma deliminated into two hex values.  Either *first or *second
  * can be NULL if there is nothing before or after the comma.
  * can be NULL if there is nothing before or after the comma.
  * returns:
  * returns:
  * 1 = first mac
  * 1 = first mac
@@ -75,10 +72,8 @@ dualmac2hex(const char *dualmac, u_char *first, u_char *second, int len)
     string = safe_strdup(dualmac);
     string = safe_strdup(dualmac);
 
 
     /* if we've only got a comma, then return NULL's */
     /* if we've only got a comma, then return NULL's */
-    if (len <= 1) {
-        second = first = NULL;
+    if (len <= 1)
         goto done;
         goto done;
-    }
 
 
     temp = strtok_r(string, ",", &tok);
     temp = strtok_r(string, ",", &tok);
     if (strlen(temp)) {
     if (strlen(temp)) {
@@ -88,12 +83,12 @@ dualmac2hex(const char *dualmac, u_char *first, u_char *second, int len)
 
 
     temp = strtok_r(NULL, ",", &tok);
     temp = strtok_r(NULL, ",", &tok);
     /* temp is null if no comma */
     /* temp is null if no comma */
-    if (temp != NULL) { 
+    if (temp != NULL) {
         if (strlen(temp)) {
         if (strlen(temp)) {
             mac2hex(temp, second, len);
             mac2hex(temp, second, len);
             ret += 2;
             ret += 2;
         }
         }
-    } 
+    }
 
 
 done:
 done:
     safe_free(string);
     safe_free(string);
@@ -112,36 +107,36 @@ macinstring(const char *macstring, const u_char *mac)
     char *tok = NULL, *tempstr, *ourstring;
     char *tok = NULL, *tempstr, *ourstring;
     u_char tempmac[6];
     u_char tempmac[6];
     int len = 6, ret = TCPR_DIR_S2C;
     int len = 6, ret = TCPR_DIR_S2C;
-    
+
     ourstring = safe_strdup(macstring);
     ourstring = safe_strdup(macstring);
     memset(&tempmac[0], 0, sizeof(tempmac));
     memset(&tempmac[0], 0, sizeof(tempmac));
-    
+
     tempstr = strtok_r(ourstring, ",", &tok);
     tempstr = strtok_r(ourstring, ",", &tok);
-    if (strlen(tempstr)) {
-       mac2hex(tempstr, tempmac, len);
-       if (memcmp(mac, tempmac, len) == 0) {
-           dbgx(3, "Packet matches: " MAC_FORMAT " sending out primary.\n", MAC_STR(tempmac));
-           ret = TCPR_DIR_C2S;
-           goto EXIT_MACINSTRING;
-       }
+    if (tempstr != NULL && strlen(tempstr)) {
+        mac2hex(tempstr, tempmac, len);
+        if (memcmp(mac, tempmac, len) == 0) {
+            dbgx(3, "Packet matches: " MAC_FORMAT " sending out primary.\n", MAC_STR(tempmac));
+            ret = TCPR_DIR_C2S;
+            goto EXIT_MACINSTRING;
+        }
     } else {
     } else {
         goto EXIT_MACINSTRING;
         goto EXIT_MACINSTRING;
     }
     }
 
 
     while ((tempstr = strtok_r(NULL, ",", &tok)) != NULL) {
     while ((tempstr = strtok_r(NULL, ",", &tok)) != NULL) {
-       mac2hex(tempstr, tempmac, len);
-       if (memcmp(mac, tempmac, len) == 0) {
-           ret = TCPR_DIR_C2S;
-           dbgx(3, "Packet matches: " MAC_FORMAT " sending out primary.\n", MAC_STR(tempmac));
-           goto EXIT_MACINSTRING;
-       }
+        mac2hex(tempstr, tempmac, len);
+        if (memcmp(mac, tempmac, len) == 0) {
+            ret = TCPR_DIR_C2S;
+            dbgx(3, "Packet matches: " MAC_FORMAT " sending out primary.\n", MAC_STR(tempmac));
+            goto EXIT_MACINSTRING;
+        }
     }
     }
 
 
 EXIT_MACINSTRING:
 EXIT_MACINSTRING:
     safe_free(ourstring);
     safe_free(ourstring);
 #ifdef DEBUG
 #ifdef DEBUG
     if (ret == TCPR_DIR_S2C)
     if (ret == TCPR_DIR_S2C)
-       dbg(3, "Packet doesn't match any MAC addresses sending out secondary.\n");
+        dbg(3, "Packet doesn't match any MAC addresses sending out secondary.\n");
 #endif
 #endif
     return ret;
     return ret;
 }
 }

+ 4 - 4
src/common/mac.h

@@ -18,11 +18,11 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef __MAC_H__
-#define __MAC_H__
+#pragma once
+
+#include "cache.h"
+#include "defines.h"
 
 
 void mac2hex(const char *mac, u_char *dst, int len);
 void mac2hex(const char *mac, u_char *dst, int len);
 int dualmac2hex(const char *dualmac, u_char *first, u_char *second, int len);
 int dualmac2hex(const char *dualmac, u_char *first, u_char *second, int len);
 tcpr_dir_t macinstring(const char *macstring, const u_char *mac);
 tcpr_dir_t macinstring(const char *macstring, const u_char *mac);
-
-#endif /* __MAC_H__ */

+ 107 - 96
src/common/netmap.c

@@ -1,9 +1,9 @@
 /*
 /*
  *   Copyright (c) 2013 Fred Klassen <fklassen at appneta dot com> - AppNeta
  *   Copyright (c) 2013 Fred Klassen <fklassen at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -15,28 +15,20 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <sys/ioctl.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-#include <errno.h>
-
+#include "netmap.h"
 #include "config.h"
 #include "config.h"
-#include "defines.h"
 #include "common.h"
 #include "common.h"
 #include "tcpreplay_api.h"
 #include "tcpreplay_api.h"
-#include "netmap.h"
-
-#ifdef DEBUG
-extern int debug;
-#endif
-
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/mman.h>
-static int nm_do_ioctl (sendpacket_t *sp, u_long what, int subcmd);
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+static int nm_do_ioctl(sendpacket_t *sp, u_long what, int subcmd);
 
 
 /**
 /**
  * Method takes an open "/dev/netmap" file descriptor and returns
  * Method takes an open "/dev/netmap" file descriptor and returns
@@ -51,18 +43,17 @@ get_netmap_version()
     nmreq_t nmr;
     nmreq_t nmr;
     int fd;
     int fd;
 
 
-    if ((fd = open ("/dev/netmap", O_RDWR)) < 0)
+    if ((fd = open("/dev/netmap", O_RDWR)) < 0)
         return -1;
         return -1;
 
 
     /* netmap version discovery */
     /* netmap version discovery */
-    bzero (&nmr, sizeof(nmr));
+    bzero(&nmr, sizeof(nmr));
     nmr.nr_version = NETMAP_API;
     nmr.nr_version = NETMAP_API;
 
 
     /* attempt using the netmap API version that this was compiled under */
     /* attempt using the netmap API version that this was compiled under */
-    if(ioctl(fd, NIOCGINFO, &nmr) == 0) {
+    if (ioctl(fd, NIOCGINFO, &nmr) == 0) {
         netmap_version = nmr.nr_version;
         netmap_version = nmr.nr_version;
-        dbgx(1, "netmap detected API version %d which matches compiled version\n",
-                netmap_version);
+        dbgx(1, "netmap detected API version %d which matches compiled version\n", netmap_version);
     } else {
     } else {
         /* failed.
         /* failed.
          *
          *
@@ -71,12 +62,14 @@ get_netmap_version()
          */
          */
         int x;
         int x;
         for (x = 0; x < 50; ++x) {
         for (x = 0; x < 50; ++x) {
-            bzero (&nmr, sizeof(nmr));
+            bzero(&nmr, sizeof(nmr));
             nmr.nr_version = x;
             nmr.nr_version = x;
-            if(ioctl(fd, NIOCGINFO, &nmr) == 0) {
+            if (ioctl(fd, NIOCGINFO, &nmr) == 0) {
                 netmap_version = nmr.nr_version;
                 netmap_version = nmr.nr_version;
-                dbgx(1, "netmap detected API version %d which doesn't match compiled version %d\n",
-                        netmap_version, NETMAP_API);
+                dbgx(1,
+                     "netmap detected API version %d which doesn't match compiled version %d\n",
+                     netmap_version,
+                     NETMAP_API);
                 break;
                 break;
             }
             }
         }
         }
@@ -84,13 +77,15 @@ get_netmap_version()
 
 
     close(fd);
     close(fd);
 
 
-    return netmap_version;
+    return (int)netmap_version;
 }
 }
 
 
 /**
 /**
  * ioctl support for netmap
  * ioctl support for netmap
  */
  */
-static int nm_do_ioctl (sendpacket_t *sp, u_long what, int subcmd) {
+static int
+nm_do_ioctl(sendpacket_t *sp, u_long what, int subcmd)
+{
     struct ifreq ifr;
     struct ifreq ifr;
     int error;
     int error;
     int fd;
     int fd;
@@ -100,14 +95,14 @@ static int nm_do_ioctl (sendpacket_t *sp, u_long what, int subcmd) {
 
 
     assert(sp);
     assert(sp);
 
 
-    fd = socket (AF_INET, SOCK_DGRAM, 0);
+    fd = socket(AF_INET, SOCK_DGRAM, 0);
     if (fd < 0) {
     if (fd < 0) {
         dbg(1, "ioctl error: cannot get device control socket.\n");
         dbg(1, "ioctl error: cannot get device control socket.\n");
         return -1;
         return -1;
     }
     }
 
 
-    bzero (&ifr, sizeof(ifr));
-    strncpy (ifr.ifr_name, sp->device, sizeof(ifr.ifr_name));
+    bzero(&ifr, sizeof(ifr));
+    strncpy(ifr.ifr_name, sp->device, sizeof(ifr.ifr_name));
 
 
     switch (what) {
     switch (what) {
     case SIOCSIFFLAGS:
     case SIOCSIFFLAGS:
@@ -125,7 +120,7 @@ static int nm_do_ioctl (sendpacket_t *sp, u_long what, int subcmd) {
 #endif
 #endif
     }
     }
 
 
-    error = ioctl (fd, what, &ifr);
+    error = ioctl(fd, what, &ifr);
     if (error)
     if (error)
         goto done;
         goto done;
 
 
@@ -157,14 +152,17 @@ static int nm_do_ioctl (sendpacket_t *sp, u_long what, int subcmd) {
             sp->txcsum = eval.data;
             sp->txcsum = eval.data;
             dbgx(1, "ioctl SIOCETHTOOL ETHTOOL_GTXCSUM=%u", eval.data);
             dbgx(1, "ioctl SIOCETHTOOL ETHTOOL_GTXCSUM=%u", eval.data);
             break;
             break;
+        default:
+            return -1;
         }
         }
         break;
         break;
 #endif
 #endif
-
+    default:
+        return -1;
     }
     }
 
 
 done:
 done:
-    close (fd);
+    close(fd);
 
 
     if (error)
     if (error)
         warnx("ioctl error %d %lu:%d", error, what, subcmd);
         warnx("ioctl error %d %lu:%d", error, what, subcmd);
@@ -175,8 +173,9 @@ done:
  * Inner sendpacket_open() method for using netmap
  * Inner sendpacket_open() method for using netmap
  */
  */
 void *
 void *
-sendpacket_open_netmap(const char *device, char *errbuf, void *arg) {
-    tcpreplay_t *ctx = (tcpreplay_t*)arg;
+sendpacket_open_netmap(const char *device, char *errbuf, void *arg)
+{
+    tcpreplay_t *ctx = (tcpreplay_t *)arg;
     sendpacket_t *sp = NULL;
     sendpacket_t *sp = NULL;
     nmreq_t nmr;
     nmreq_t nmr;
     char ifname_buf[MAX_IFNAMELEN];
     char ifname_buf[MAX_IFNAMELEN];
@@ -205,8 +204,10 @@ sendpacket_open_netmap(const char *device, char *errbuf, void *arg) {
     /* get the version of the netmap driver. If < 0, driver is not installed */
     /* get the version of the netmap driver. If < 0, driver is not installed */
     sp->netmap_version = get_netmap_version();
     sp->netmap_version = get_netmap_version();
     if (sp->netmap_version < 0) {
     if (sp->netmap_version < 0) {
-        snprintf(errbuf, SENDPACKET_ERRBUF_SIZE, "Unable to determine the running netmap version.\n"
-                "See INSTALL document for details on installing or upgrading netmap.");
+        snprintf(errbuf,
+                 SENDPACKET_ERRBUF_SIZE,
+                 "Unable to determine the running netmap version.\n"
+                 "See INSTALL document for details on installing or upgrading netmap.");
         goto NETMAP_NOT_INSTALLED;
         goto NETMAP_NOT_INSTALLED;
     }
     }
 
 
@@ -259,9 +260,11 @@ sendpacket_open_netmap(const char *device, char *errbuf, void *arg) {
      */
      */
     if ((sp->handle.fd = open("/dev/netmap", O_RDWR)) < 0) {
     if ((sp->handle.fd = open("/dev/netmap", O_RDWR)) < 0) {
         dbg(1, "sendpacket_open_netmap: Unable to access netmap");
         dbg(1, "sendpacket_open_netmap: Unable to access netmap");
-        snprintf(errbuf, SENDPACKET_ERRBUF_SIZE, "Unable to access netmap.\n"
-                "See INSTALL to learn which NICs are supported and\n"
-                "how to set up netmap-capable network drivers.");
+        snprintf(errbuf,
+                 SENDPACKET_ERRBUF_SIZE,
+                 "Unable to access netmap.\n"
+                 "See INSTALL to learn which NICs are supported and\n"
+                 "how to set up netmap-capable network drivers.");
         goto OPEN_FAILED;
         goto OPEN_FAILED;
     }
     }
 
 
@@ -275,7 +278,7 @@ sendpacket_open_netmap(const char *device, char *errbuf, void *arg) {
         switch (*port) {
         switch (*port) {
         case '-': /* one NIC */
         case '-': /* one NIC */
             nr_flags = NR_REG_ONE_NIC;
             nr_flags = NR_REG_ONE_NIC;
-            nr_ringid = atoi(port + 1);
+            nr_ringid = strtol(port + 1, NULL, 10);
             break;
             break;
 
 
         case '*': /* NIC and SW, ignore port */
         case '*': /* NIC and SW, ignore port */
@@ -296,19 +299,19 @@ sendpacket_open_netmap(const char *device, char *errbuf, void *arg) {
 
 
         case '{':
         case '{':
             nr_flags = NR_REG_PIPE_MASTER;
             nr_flags = NR_REG_PIPE_MASTER;
-            nr_ringid = atoi(port + 1);
+            nr_ringid = strtol(port + 1, NULL, 10);
             break;
             break;
 
 
         case '}':
         case '}':
             nr_flags = NR_REG_PIPE_SLAVE;
             nr_flags = NR_REG_PIPE_SLAVE;
-            nr_ringid = atoi(port + 1);
+            nr_ringid = strtol(port + 1, NULL, 10);
             break;
             break;
 
 
         case '!':
         case '!':
             nr_flags = NR_REG_ALL_NIC;
             nr_flags = NR_REG_ALL_NIC;
             break;
             break;
 
 
-        default:  /* '\0', no suffix */
+        default: /* '\0', no suffix */
             nr_flags = NR_REG_ALL_NIC;
             nr_flags = NR_REG_ALL_NIC;
             is_default = 1;
             is_default = 1;
             break;
             break;
@@ -335,35 +338,35 @@ sendpacket_open_netmap(const char *device, char *errbuf, void *arg) {
      *
      *
      * Cards take a long time to reset the PHY.
      * Cards take a long time to reset the PHY.
      */
      */
-    fprintf(stderr, "Switching network driver for %s to netmap bypass mode... ",
-            sp->device);
+    fprintf(stderr, "Switching network driver for %s to netmap bypass mode... ", sp->device);
     fflush(NULL);
     fflush(NULL);
-    sleep(1);   /* ensure message prints when user is connected via ssh */
-
-    if (ioctl (sp->handle.fd, NIOCREGIF, &nmr)) {
-        snprintf(errbuf, SENDPACKET_ERRBUF_SIZE, "Failure accessing netmap.\n"
-                "\tRequest for netmap version %d failed.\n\tCompiled netmap driver is version %d.\n\tError=%s\n",
-                sp->netmap_version, NETMAP_API, strerror(errno));
+    sleep(1); /* ensure message prints when user is connected via ssh */
+
+    if (ioctl(sp->handle.fd, NIOCREGIF, &nmr)) {
+        snprintf(errbuf,
+                 SENDPACKET_ERRBUF_SIZE,
+                 "Failure accessing netmap.\n"
+                 "\tRequest for netmap version %d failed.\n\tCompiled netmap driver is version %d.\n\tError=%s\n",
+                 sp->netmap_version,
+                 NETMAP_API,
+                 strerror(errno));
         goto NETMAP_IF_FAILED;
         goto NETMAP_IF_FAILED;
     }
     }
 
 
     if (!nmr.nr_memsize) {
     if (!nmr.nr_memsize) {
-        snprintf(errbuf, SENDPACKET_ERRBUF_SIZE, "Netmap interface '%s' not configured.\n",
-                device);
+        snprintf(errbuf, SENDPACKET_ERRBUF_SIZE, "Netmap interface '%s' not configured.\n", device);
         goto NETMAP_IF_FAILED;
         goto NETMAP_IF_FAILED;
     }
     }
 
 
     sp->mmap_size = nmr.nr_memsize;
     sp->mmap_size = nmr.nr_memsize;
-    sp->mmap_addr = (struct netmap_d *)mmap (0, sp->mmap_size,
-            PROT_WRITE | PROT_READ, MAP_SHARED, sp->handle.fd, 0);
+    sp->mmap_addr = (struct netmap_d *)mmap(0, sp->mmap_size, PROT_WRITE | PROT_READ, MAP_SHARED, sp->handle.fd, 0);
 
 
     if (!sp->mmap_addr || sp->mmap_addr == MAP_FAILED) {
     if (!sp->mmap_addr || sp->mmap_addr == MAP_FAILED) {
-        snprintf (errbuf, SENDPACKET_ERRBUF_SIZE, "mmap: %s", strerror (errno));
+        snprintf(errbuf, SENDPACKET_ERRBUF_SIZE, "mmap: %s", strerror(errno));
         goto MMAP_FAILED;
         goto MMAP_FAILED;
     }
     }
 
 
-    dbgx(1, "sendpacket_open_netmap: mapping %d Kbytes queues=%d",
-            sp->mmap_size >> 10, nmr.nr_tx_rings);
+    dbgx(1, "sendpacket_open_netmap: mapping %d Kbytes queues=%d", sp->mmap_size >> 10, nmr.nr_tx_rings);
 
 
     sp->nm_if = NETMAP_IF(sp->mmap_addr, nmr.nr_offset);
     sp->nm_if = NETMAP_IF(sp->mmap_addr, nmr.nr_offset);
     sp->nmr = nmr;
     sp->nmr = nmr;
@@ -371,8 +374,8 @@ sendpacket_open_netmap(const char *device, char *errbuf, void *arg) {
 
 
     /* set up ring IDs */
     /* set up ring IDs */
     sp->cur_tx_ring = 0;
     sp->cur_tx_ring = 0;
-    switch(nr_flags) {
-    case NR_REG_DEFAULT:    /* only use one queue to prevent TX reordering */
+    switch (nr_flags) {
+    case NR_REG_DEFAULT: /* only use one queue to prevent TX reordering */
         sp->first_tx_ring = sp->last_tx_ring = sp->cur_tx_ring = 0;
         sp->first_tx_ring = sp->last_tx_ring = sp->cur_tx_ring = 0;
         break;
         break;
 
 
@@ -405,16 +408,23 @@ sendpacket_open_netmap(const char *device, char *errbuf, void *arg) {
         /* debugging code */
         /* debugging code */
         int i;
         int i;
 
 
-        dbgx(1, "%s tx first=%d last=%d  num=%d", ifname,
-                sp->first_tx_ring, sp->last_tx_ring, sp->nmr.nr_tx_rings);
+        dbgx(1, "%s tx first=%d last=%d  num=%d", ifname, sp->first_tx_ring, sp->last_tx_ring, sp->nmr.nr_tx_rings);
         for (i = 0; i <= sp->nmr.nr_tx_rings; i++) {
         for (i = 0; i <= sp->nmr.nr_tx_rings; i++) {
 #ifdef HAVE_NETMAP_RING_HEAD_TAIL
 #ifdef HAVE_NETMAP_RING_HEAD_TAIL
-            dbgx(1, "TX%d 0x%p head=%d cur=%d tail=%d", i, NETMAP_TXRING(sp->nm_if, i),
-                    (NETMAP_TXRING(sp->nm_if, i))->head,
-                    (NETMAP_TXRING(sp->nm_if, i))->cur, (NETMAP_TXRING(sp->nm_if, i))->tail);
+            dbgx(1,
+                 "TX%d 0x%p head=%d cur=%d tail=%d",
+                 i,
+                 NETMAP_TXRING(sp->nm_if, i),
+                 (NETMAP_TXRING(sp->nm_if, i))->head,
+                 (NETMAP_TXRING(sp->nm_if, i))->cur,
+                 (NETMAP_TXRING(sp->nm_if, i))->tail);
 #else
 #else
-            dbgx(1, "TX%d 0x%p cur=%d avail=%d", i, NETMAP_TXRING(sp->nm_if, i),
-                    (NETMAP_TXRING(sp->nm_if, i))->cur, (NETMAP_TXRING(sp->nm_if, i))->avail);
+            dbgx(1,
+                 "TX%d 0x%p cur=%d avail=%d",
+                 i,
+                 NETMAP_TXRING(sp->nm_if, i),
+                 (NETMAP_TXRING(sp->nm_if, i))->cur,
+                 (NETMAP_TXRING(sp->nm_if, i))->avail);
 #endif
 #endif
         }
         }
     }
     }
@@ -429,7 +439,7 @@ sendpacket_open_netmap(const char *device, char *errbuf, void *arg) {
 
 
         if ((sp->if_flags & IFF_RUNNING) == 0) {
         if ((sp->if_flags & IFF_RUNNING) == 0) {
             dbgx(1, "sendpacket_open_netmap: %s is not running", sp->device);
             dbgx(1, "sendpacket_open_netmap: %s is not running", sp->device);
-            snprintf (errbuf, SENDPACKET_ERRBUF_SIZE, "interface %s is not running - check cables\n", sp->device);
+            snprintf(errbuf, SENDPACKET_ERRBUF_SIZE, "interface %s is not running - check cables\n", sp->device);
             goto NETMAP_IF_NOT_RUNNING;
             goto NETMAP_IF_NOT_RUNNING;
         }
         }
 
 
@@ -450,22 +460,18 @@ sendpacket_open_netmap(const char *device, char *errbuf, void *arg) {
          * - rx-checksumming
          * - rx-checksumming
          * - tx-checksumming
          * - tx-checksumming
          */
          */
-        if (nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_GGSO) < 0 ||
-                nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_GTSO) < 0 ||
-                nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_GRXCSUM) < 0 ||
-                nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_GTXCSUM) < 0)
+        if (nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_GGSO) < 0 || nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_GTSO) < 0 ||
+            nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_GRXCSUM) < 0 || nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_GTXCSUM) < 0)
             goto NM_DO_IOCTL_FAILED;
             goto NM_DO_IOCTL_FAILED;
 
 
         sp->data = 0;
         sp->data = 0;
-        if (nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_SGSO) < 0 ||
-                nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_STSO) < 0 ||
-                nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_SRXCSUM) < 0 ||
-                nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_STXCSUM))
+        if (nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_SGSO) < 0 || nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_STSO) < 0 ||
+            nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_SRXCSUM) < 0 || nm_do_ioctl(sp, SIOCETHTOOL, ETHTOOL_STXCSUM))
             goto NM_DO_IOCTL_FAILED;
             goto NM_DO_IOCTL_FAILED;
 #endif
 #endif
     }
     }
 
 
-    if(sp->abort)
+    if (sp->abort)
         goto NETMAP_ABORT;
         goto NETMAP_ABORT;
 
 
     notice("done!");
     notice("done!");
@@ -473,12 +479,11 @@ sendpacket_open_netmap(const char *device, char *errbuf, void *arg) {
     return sp;
     return sp;
 
 
 NM_DO_IOCTL_FAILED:
 NM_DO_IOCTL_FAILED:
-    snprintf (errbuf, SENDPACKET_ERRBUF_SIZE, "nm_do_ioctl: %s", strerror (errno));
+    snprintf(errbuf, SENDPACKET_ERRBUF_SIZE, "nm_do_ioctl: %s", strerror(errno));
 NETMAP_IF_NOT_RUNNING:
 NETMAP_IF_NOT_RUNNING:
     notice("failed!");
     notice("failed!");
 NETMAP_ABORT:
 NETMAP_ABORT:
-    fprintf(stderr, " Switching network driver for %s to normal mode... ",
-            sp->device);
+    fprintf(stderr, " Switching network driver for %s to normal mode... ", sp->device);
     fflush(NULL);
     fflush(NULL);
     munmap(sp->mmap_addr, sp->mmap_size);
     munmap(sp->mmap_addr, sp->mmap_size);
 MMAP_FAILED:
 MMAP_FAILED:
@@ -487,7 +492,7 @@ MMAP_FAILED:
 #endif
 #endif
 NETMAP_IF_FAILED:
 NETMAP_IF_FAILED:
 NETMAP_IF_PARSE_FAIL:
 NETMAP_IF_PARSE_FAIL:
-    close (sp->handle.fd);
+    close(sp->handle.fd);
 OPEN_FAILED:
 OPEN_FAILED:
     safe_free(sp);
     safe_free(sp);
 IFACENAME_INVALID:
 IFACENAME_INVALID:
@@ -496,11 +501,11 @@ NETMAP_NOT_INSTALLED:
     return NULL;
     return NULL;
 }
 }
 
 
-void sendpacket_close_netmap(void *p)
+void
+sendpacket_close_netmap(void *p)
 {
 {
     sendpacket_t *sp = p;
     sendpacket_t *sp = p;
-    fprintf(stderr, "Switching network driver for %s to normal mode... ",
-            sp->device);
+    fprintf(stderr, "Switching network driver for %s to normal mode... ", sp->device);
     fflush(NULL);
     fflush(NULL);
 
 
     /* flush any remaining packets */
     /* flush any remaining packets */
@@ -511,7 +516,6 @@ void sendpacket_close_netmap(void *p)
     sleep(sp->netmap_delay);
     sleep(sp->netmap_delay);
     dbg(2, "Ready!");
     dbg(2, "Ready!");
 
 
-
 #ifdef linux
 #ifdef linux
     if (!sp->is_vale) {
     if (!sp->is_vale) {
         /* restore original settings:
         /* restore original settings:
@@ -541,7 +545,8 @@ void sendpacket_close_netmap(void *p)
     notice("done!");
     notice("done!");
 }
 }
 
 
-bool netmap_tx_queues_empty(void *p)
+bool
+netmap_tx_queues_empty(void *p)
 {
 {
     sendpacket_t *sp = p;
     sendpacket_t *sp = p;
     struct netmap_ring *txring;
     struct netmap_ring *txring;
@@ -570,7 +575,8 @@ bool netmap_tx_queues_empty(void *p)
     return false;
     return false;
 }
 }
 
 
-int sendpacket_send_netmap(void *p, const u_char *data, size_t len)
+int
+sendpacket_send_netmap(void *p, const u_char *data, size_t len)
 {
 {
     sendpacket_t *sp = p;
     sendpacket_t *sp = p;
     struct netmap_ring *txring;
     struct netmap_ring *txring;
@@ -625,9 +631,14 @@ int sendpacket_send_netmap(void *p, const u_char *data, size_t len)
     if (avail <= 1)
     if (avail <= 1)
         slot->flags = NS_REPORT;
         slot->flags = NS_REPORT;
 
 
-    dbgx(3, "netmap cur=%d slot index=%d flags=0x%x empty=%d avail=%u bufsize=%d\n",
-            cur, slot->buf_idx, slot->flags, NETMAP_TX_RING_EMPTY(txring),
-            nm_ring_space(txring), txring->nr_buf_size);
+    dbgx(3,
+         "netmap cur=%d slot index=%d flags=0x%x empty=%d avail=%u bufsize=%d\n",
+         cur,
+         slot->buf_idx,
+         slot->flags,
+         NETMAP_TX_RING_EMPTY(txring),
+         nm_ring_space(txring),
+         txring->nr_buf_size);
 
 
     /* let kernel know that packet is available */
     /* let kernel know that packet is available */
     cur = NETMAP_RING_NEXT(txring, cur);
     cur = NETMAP_RING_NEXT(txring, cur);

+ 37 - 40
src/common/netmap.h

@@ -1,9 +1,9 @@
 /*
 /*
  *   Copyright (c) 2013 Fred Klassen <fklassen at appneta dot com> - AppNeta
  *   Copyright (c) 2013 Fred Klassen <fklassen at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -14,11 +14,10 @@
  *   You should have received a copy of the GNU General Public License
  *   You should have received a copy of the GNU General Public License
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
-#ifndef NETMAP_H_
-#define NETMAP_H_
+#pragma once
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include <sys/socket.h>
 #include <sys/socket.h>
 #ifdef __NetBSD__
 #ifdef __NetBSD__
 #include <net/if_ether.h>
 #include <net/if_ether.h>
@@ -31,8 +30,8 @@
 #include <net/netmap_user.h>
 #include <net/netmap_user.h>
 
 
 #ifdef linux
 #ifdef linux
-#   include <linux/ethtool.h>
-#   include <linux/sockios.h>
+#include <linux/ethtool.h>
+#include <linux/sockios.h>
 #endif /* linux */
 #endif /* linux */
 
 
 #ifndef NETMAP_API
 #ifndef NETMAP_API
@@ -50,9 +49,10 @@
 #endif
 #endif
 
 
 #ifndef HAVE_NETMAP_NR_REG
 #ifndef HAVE_NETMAP_NR_REG
-#define NR_REG_MASK     0xf     /* values for nr_flags */
+#define NR_REG_MASK 0xf /* values for nr_flags */
 #if NETMAP_API < 11
 #if NETMAP_API < 11
-enum {  NR_REG_DEFAULT  = 0,    /* backward compat, used in older versions. */
+enum {
+    NR_REG_DEFAULT = 0, /* backward compat, used in older versions. */
     NR_REG_ALL_NIC,
     NR_REG_ALL_NIC,
     NR_REG_SW,
     NR_REG_SW,
     NR_REG_NIC_SW,
     NR_REG_NIC_SW,
@@ -64,72 +64,69 @@ enum {  NR_REG_DEFAULT  = 0,    /* backward compat, used in older versions. */
 #endif
 #endif
 
 
 #ifndef NETMAP_HW_RING
 #ifndef NETMAP_HW_RING
-#define NETMAP_HW_RING      0x4000  /* single NIC ring pair */
+#define NETMAP_HW_RING 0x4000 /* single NIC ring pair */
 #endif
 #endif
 #ifndef NETMAP_SW_RING
 #ifndef NETMAP_SW_RING
-#define NETMAP_SW_RING      0x2000  /* only host ring pair */
+#define NETMAP_SW_RING 0x2000 /* only host ring pair */
 #endif
 #endif
 #ifndef NETMAP_RING_MASK
 #ifndef NETMAP_RING_MASK
-#define NETMAP_RING_MASK    0x0fff  /* the ring number */
+#define NETMAP_RING_MASK 0x0fff /* the ring number */
 #endif
 #endif
 #ifndef NETMAP_NO_TX_POLL
 #ifndef NETMAP_NO_TX_POLL
-#define NETMAP_NO_TX_POLL   0x1000  /* no automatic txsync on poll */
+#define NETMAP_NO_TX_POLL 0x1000 /* no automatic txsync on poll */
 #endif
 #endif
 #ifndef NETMAP_DO_RX_POLL
 #ifndef NETMAP_DO_RX_POLL
-#define NETMAP_DO_RX_POLL   0x8000  /* DO automatic rxsync on poll */
+#define NETMAP_DO_RX_POLL 0x8000 /* DO automatic rxsync on poll */
 #endif
 #endif
 #ifndef NETMAP_BDG_ATTACH
 #ifndef NETMAP_BDG_ATTACH
-#define NETMAP_BDG_ATTACH   1   /* attach the NIC */
+#define NETMAP_BDG_ATTACH 1 /* attach the NIC */
 #endif
 #endif
 #ifndef NETMAP_BDG_DETACH
 #ifndef NETMAP_BDG_DETACH
-#define NETMAP_BDG_DETACH   2   /* detach the NIC */
+#define NETMAP_BDG_DETACH 2 /* detach the NIC */
 #endif
 #endif
 #ifndef NETMAP_BDG_LOOKUP_REG
 #ifndef NETMAP_BDG_LOOKUP_REG
-#define NETMAP_BDG_LOOKUP_REG   3   /* register lookup function */
+#define NETMAP_BDG_LOOKUP_REG 3 /* register lookup function */
 #endif
 #endif
 #ifndef NETMAP_BDG_LIST
 #ifndef NETMAP_BDG_LIST
-#define NETMAP_BDG_LIST     4   /* get bridge's info */
+#define NETMAP_BDG_LIST 4 /* get bridge's info */
 #endif
 #endif
 #ifndef NETMAP_BDG_VNET_HDR
 #ifndef NETMAP_BDG_VNET_HDR
-#define NETMAP_BDG_VNET_HDR     5       /* set the port virtio-net-hdr length */
+#define NETMAP_BDG_VNET_HDR 5 /* set the port virtio-net-hdr length */
 #endif
 #endif
 #ifndef NETMAP_BDG_OFFSET
 #ifndef NETMAP_BDG_OFFSET
-#define NETMAP_BDG_OFFSET   NETMAP_BDG_VNET_HDR /* deprecated alias */
+#define NETMAP_BDG_OFFSET NETMAP_BDG_VNET_HDR /* deprecated alias */
 #endif
 #endif
 #ifndef NETMAP_BDG_HOST
 #ifndef NETMAP_BDG_HOST
-#define NETMAP_BDG_HOST     1   /* attach the host stack on ATTACH */
+#define NETMAP_BDG_HOST 1 /* attach the host stack on ATTACH */
 #endif
 #endif
 
 
 #ifdef HAVE_NETMAP_NR_FLAGS
 #ifdef HAVE_NETMAP_NR_FLAGS
 typedef struct nmreq nmreq_t;
 typedef struct nmreq nmreq_t;
 #else
 #else
 struct tcpr_nmreq {
 struct tcpr_nmreq {
-    char        nr_name[IFNAMSIZ];
-    uint32_t    nr_version; /* API version */
-    uint32_t    nr_offset;  /* nifp offset in the shared region */
-    uint32_t    nr_memsize; /* size of the shared region */
-    uint32_t    nr_tx_slots;    /* slots in tx rings */
-    uint32_t    nr_rx_slots;    /* slots in rx rings */
-    uint16_t    nr_tx_rings;    /* number of tx rings */
-    uint16_t    nr_rx_rings;    /* number of rx rings */
-    uint16_t    nr_ringid;  /* ring(s) we care about */
-    uint16_t    nr_cmd;
-    uint16_t    nr_arg1;    /* reserve extra rings in NIOCREGIF */
-    uint16_t    nr_arg2;
-    uint32_t    nr_arg3;    /* req. extra buffers in NIOCREGIF */
-    uint32_t    nr_flags;
+    char nr_name[IFNAMSIZ];
+    uint32_t nr_version;  /* API version */
+    uint32_t nr_offset;   /* nifp offset in the shared region */
+    uint32_t nr_memsize;  /* size of the shared region */
+    uint32_t nr_tx_slots; /* slots in tx rings */
+    uint32_t nr_rx_slots; /* slots in rx rings */
+    uint16_t nr_tx_rings; /* number of tx rings */
+    uint16_t nr_rx_rings; /* number of rx rings */
+    uint16_t nr_ringid;   /* ring(s) we care about */
+    uint16_t nr_cmd;
+    uint16_t nr_arg1; /* reserve extra rings in NIOCREGIF */
+    uint16_t nr_arg2;
+    uint32_t nr_arg3; /* req. extra buffers in NIOCREGIF */
+    uint32_t nr_flags;
     /* various modes, extends nr_ringid */
     /* various modes, extends nr_ringid */
-    uint32_t    spare2[1];
+    uint32_t spare2[1];
 };
 };
 typedef struct tcpr_nmreq nmreq_t;
 typedef struct tcpr_nmreq nmreq_t;
 
 
 #endif /* HAVE_NETMAP_NR_FLAGS */
 #endif /* HAVE_NETMAP_NR_FLAGS */
 
 
-#define NETMAP_TX_TIMEOUT_SEC 10
 int get_netmap_version(void);
 int get_netmap_version(void);
 void *sendpacket_open_netmap(const char *device, char *errbuf, void *arg);
 void *sendpacket_open_netmap(const char *device, char *errbuf, void *arg);
 void sendpacket_close_netmap(void *p);
 void sendpacket_close_netmap(void *p);
 bool netmap_tx_queues_empty(void *p);
 bool netmap_tx_queues_empty(void *p);
 int sendpacket_send_netmap(void *p, const u_char *data, size_t len);
 int sendpacket_send_netmap(void *p, const u_char *data, size_t len);
-
-#endif /* NETMAP_H_ */

+ 5 - 11
src/common/pcap_dlt.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,11 +18,10 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef _PCAP_DLT_H_
-#define _PCAP_DLT_H_
+#pragma once
 
 
 /*
 /*
- * Cisco HDLC.  Used by Dag interfaces for SONET 
+ * Cisco HDLC.  Used by Dag interfaces for SONET
  * and possibly others
  * and possibly others
  */
  */
 
 
@@ -33,8 +32,3 @@ struct hdlc_hdr_s {
     u_int16_t protocol;
     u_int16_t protocol;
 };
 };
 typedef struct hdlc_hdr_s hdlc_hdr_t;
 typedef struct hdlc_hdr_s hdlc_hdr_t;
-
-
-#endif /* _PCAP_DLT_H_ */
-
-

File diff suppressed because it is too large
+ 354 - 360
src/common/sendpacket.c


+ 10 - 18
src/common/sendpacket.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,9 +18,10 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#include "config.h"
-#include "defines.h"
+#pragma once
 
 
+#include "defines.h"
+#include "config.h"
 #include <sys/socket.h>
 #include <sys/socket.h>
 
 
 #ifdef __NetBSD__
 #ifdef __NetBSD__
@@ -56,9 +57,6 @@
 #endif
 #endif
 #endif
 #endif
 
 
-#ifndef _SENDPACKET_H_
-#define _SENDPACKET_H_
-
 typedef enum sendpacket_type_e {
 typedef enum sendpacket_type_e {
     SP_TYPE_NONE,
     SP_TYPE_NONE,
     SP_TYPE_LIBNET,
     SP_TYPE_LIBNET,
@@ -73,8 +71,8 @@ typedef enum sendpacket_type_e {
 } sendpacket_type_t;
 } sendpacket_type_t;
 
 
 /* these are the file_operations ioctls */
 /* these are the file_operations ioctls */
-#define KHIAL_SET_DIRECTION  (0x1)
-#define KHIAL_GET_DIRECTION  (0x2)
+#define KHIAL_SET_DIRECTION (0x1)
+#define KHIAL_GET_DIRECTION (0x2)
 
 
 /* these are the directions */
 /* these are the directions */
 typedef enum khial_direction_e {
 typedef enum khial_direction_e {
@@ -82,7 +80,6 @@ typedef enum khial_direction_e {
     KHIAL_DIRECTION_TX,
     KHIAL_DIRECTION_TX,
 } khial_direction_t;
 } khial_direction_t;
 
 
-
 union sendpacket_handle {
 union sendpacket_handle {
     pcap_t *pcap;
     pcap_t *pcap;
     int fd;
     int fd;
@@ -92,7 +89,7 @@ union sendpacket_handle {
 };
 };
 
 
 #define SENDPACKET_ERRBUF_SIZE 1024
 #define SENDPACKET_ERRBUF_SIZE 1024
-#define MAX_IFNAMELEN   64
+#define MAX_IFNAMELEN 64
 
 
 struct sendpacket_s {
 struct sendpacket_s {
     tcpr_dir_t cache_dir;
     tcpr_dir_t cache_dir;
@@ -128,7 +125,6 @@ struct sendpacket_s {
     uint32_t if_flags;
     uint32_t if_flags;
     uint32_t is_vale;
     uint32_t is_vale;
     int netmap_version;
     int netmap_version;
-    int tx_timeouts;
     uint16_t first_tx_ring, last_tx_ring, cur_tx_ring;
     uint16_t first_tx_ring, last_tx_ring, cur_tx_ring;
 #ifdef linux
 #ifdef linux
     uint32_t data;
     uint32_t data;
@@ -142,7 +138,7 @@ struct sendpacket_s {
 #ifdef HAVE_PF_PACKET
 #ifdef HAVE_PF_PACKET
     struct sockaddr_ll sa;
     struct sockaddr_ll sa;
 #ifdef HAVE_TX_RING
 #ifdef HAVE_TX_RING
-    txring_t * tx_ring;
+    txring_t *tx_ring;
 #endif
 #endif
 #endif
 #endif
     bool abort;
     bool abort;
@@ -159,7 +155,3 @@ struct tcpr_ether_addr *sendpacket_get_hwaddr(sendpacket_t *);
 int sendpacket_get_dlt(sendpacket_t *);
 int sendpacket_get_dlt(sendpacket_t *);
 const char *sendpacket_get_method(sendpacket_t *);
 const char *sendpacket_get_method(sendpacket_t *);
 void sendpacket_abort(sendpacket_t *);
 void sendpacket_abort(sendpacket_t *);
-
-#endif /* _SENDPACKET_H_ */
-
-

+ 1 - 2
src/common/services.c

@@ -22,7 +22,6 @@
 #include "defines.h"
 #include "defines.h"
 #include "common.h"
 #include "common.h"
 
 
-#include <sys/types.h>
 #include <regex.h>
 #include <regex.h>
 #include <errno.h>
 #include <errno.h>
 #include <string.h>
 #include <string.h>
@@ -76,7 +75,7 @@ parse_services(const char *file, tcpr_services_t *services)
             strncpy(proto, &service_line[pmatch[2].rm_so], (pmatch[2].rm_eo - pmatch[2].rm_so));
             strncpy(proto, &service_line[pmatch[2].rm_so], (pmatch[2].rm_eo - pmatch[2].rm_so));
 
 
             /* convert port[] into an integer */
             /* convert port[] into an integer */
-            portc = (uint16_t)atoi(port);
+            portc = (uint16_t)strtol(port, NULL, 10);
 
 
             /* update appropriate service array with the server port */
             /* update appropriate service array with the server port */
             if (strcmp(proto, "tcp") == 0) {
             if (strcmp(proto, "tcp") == 0) {

+ 4 - 7
src/common/services.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,12 +18,9 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef __SERVICES_H__
-#define __SERVICES_H__
+#pragma once
 
 
 void parse_services(const char *file, tcpr_services_t *services);
 void parse_services(const char *file, tcpr_services_t *services);
 
 
 /* max width of a line in /etc/services */
 /* max width of a line in /etc/services */
 #define MAXLINE 1024
 #define MAXLINE 1024
-
-#endif

+ 55 - 86
src/common/tcpdump.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -32,27 +32,21 @@
  * Lawrence Berkeley Laboratory and its contributors
  * Lawrence Berkeley Laboratory and its contributors
  */
  */
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
+#include <errno.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/types.h>
-#include <unistd.h>
-#include <sys/socket.h>
 #include <sys/wait.h>
 #include <sys/wait.h>
-#include <errno.h>
-#include <string.h>
+#include <unistd.h>
 #ifdef HAVE_SIGNAL_H
 #ifdef HAVE_SIGNAL_H
 #include <signal.h>
 #include <signal.h>
 #endif
 #endif
 
 
 #include "tcpdump.h"
 #include "tcpdump.h"
 
 
-#ifdef DEBUG
-extern int debug;
-#endif
-
 char *options_vec[OPTIONS_VEC_SIZE];
 char *options_vec[OPTIONS_VEC_SIZE];
 static int tcpdump_fill_in_options(char *opt);
 static int tcpdump_fill_in_options(char *opt);
 static int can_exec(const char *filename);
 static int can_exec(const char *filename);
@@ -71,8 +65,8 @@ tcpdump_print(tcpdump_t *tcpdump, struct pcap_pkthdr *pkthdr, const u_char *data
             uint32_t ts_sec;
             uint32_t ts_sec;
             uint32_t ts_usec;
             uint32_t ts_usec;
         } ts;
         } ts;
-        uint32_t caplen;              /* length of portion present */
-        uint32_t len;                 /* length this packet (off wire) */
+        uint32_t caplen; /* length of portion present */
+        uint32_t len;    /* length this packet (off wire) */
     } actual_pkthdr;
     } actual_pkthdr;
 
 
     assert(tcpdump);
     assert(tcpdump);
@@ -94,30 +88,30 @@ header_again:
     /* wait until we can write the header to the tcpdump pipe */
     /* wait until we can write the header to the tcpdump pipe */
     res = poll(&poller, 1, TCPDUMP_POLL_TIMEOUT);
     res = poll(&poller, 1, TCPDUMP_POLL_TIMEOUT);
     if (res < 0)
     if (res < 0)
-        errx(-1, "Error writing header to fd %d during poll() to write to tcpdump\n%s",
-                PARENT_WRITE_FD, strerror(errno));
+        errx(-1,
+             "Error writing header to fd %d during poll() to write to tcpdump\n%s",
+             PARENT_WRITE_FD,
+             strerror(errno));
 
 
     if (res == 0)
     if (res == 0)
-        err(-1, "poll() timeout... tcpdump seems to be having a problem keeping up\n"
+        err(-1,
+            "poll() timeout... tcpdump seems to be having a problem keeping up\n"
             "Try increasing TCPDUMP_POLL_TIMEOUT");
             "Try increasing TCPDUMP_POLL_TIMEOUT");
 
 
 #ifdef DEBUG
 #ifdef DEBUG
     if (debug >= 5) {
     if (debug >= 5) {
-        if (write(tcpdump->debugfd, (char *)&actual_pkthdr, sizeof(actual_pkthdr))
-            != sizeof(actual_pkthdr))
+        if (write(tcpdump->debugfd, (char *)&actual_pkthdr, sizeof(actual_pkthdr)) != sizeof(actual_pkthdr))
             errx(-1, "Error writing pcap file header to tcpdump debug\n%s", strerror(errno));
             errx(-1, "Error writing pcap file header to tcpdump debug\n%s", strerror(errno));
     }
     }
 #endif
 #endif
     /* res > 0 if we get here */
     /* res > 0 if we get here */
     while (total != sizeof(actual_pkthdr) &&
     while (total != sizeof(actual_pkthdr) &&
-            (res = write(PARENT_WRITE_FD, &actual_pkthdr + total,
-                    sizeof(actual_pkthdr) - total))) {
+           (res = (int)write(PARENT_WRITE_FD, &actual_pkthdr + total, sizeof(actual_pkthdr) - total))) {
         if (res < 0) {
         if (res < 0) {
             if (errno == EAGAIN)
             if (errno == EAGAIN)
                 goto header_again;
                 goto header_again;
 
 
-            errx(-1, "Error writing pcap file header to tcpdump\n%s",
-                    strerror(errno));
+            errx(-1, "Error writing pcap file header to tcpdump\n%s", strerror(errno));
         }
         }
 
 
         total += res;
         total += res;
@@ -132,11 +126,11 @@ data_again:
 
 
     res = poll(&poller, 1, TCPDUMP_POLL_TIMEOUT);
     res = poll(&poller, 1, TCPDUMP_POLL_TIMEOUT);
     if (res < 0)
     if (res < 0)
-        errx(-1, "Error writing to fd %d during poll() to write to tcpdump\n%s",
-                PARENT_WRITE_FD, strerror(errno));
+        errx(-1, "Error writing to fd %d during poll() to write to tcpdump\n%s", PARENT_WRITE_FD, strerror(errno));
 
 
     if (res == 0)
     if (res == 0)
-        err(-1, "poll() timeout... tcpdump seems to be having a problem keeping up\n"
+        err(-1,
+            "poll() timeout... tcpdump seems to be having a problem keeping up\n"
             "Try increasing TCPDUMP_POLL_TIMEOUT");
             "Try increasing TCPDUMP_POLL_TIMEOUT");
 
 
 #ifdef DEBUG
 #ifdef DEBUG
@@ -147,7 +141,7 @@ data_again:
 #endif
 #endif
 
 
     while (total != (ssize_t)pkthdr->caplen &&
     while (total != (ssize_t)pkthdr->caplen &&
-            (res = write(PARENT_WRITE_FD, data + total, pkthdr->caplen - total))) {
+           (res = (int)write(PARENT_WRITE_FD, data + total, pkthdr->caplen - total))) {
         if (res < 0) {
         if (res < 0) {
             if (errno == EAGAIN)
             if (errno == EAGAIN)
                 goto data_again;
                 goto data_again;
@@ -165,14 +159,14 @@ data_again:
 
 
     res = poll(&poller, 1, TCPDUMP_POLL_TIMEOUT);
     res = poll(&poller, 1, TCPDUMP_POLL_TIMEOUT);
     if (res < 0)
     if (res < 0)
-        errx(-1, "Error out to fd %d during poll() to read from tcpdump\n%s",
-                PARENT_READ_FD, strerror(errno));
+        errx(-1, "Error out to fd %d during poll() to read from tcpdump\n%s", PARENT_READ_FD, strerror(errno));
 
 
     if (res == 0)
     if (res == 0)
-        err(-1, "poll() timeout... tcpdump seems to be having a problem keeping up\n"
+        err(-1,
+            "poll() timeout... tcpdump seems to be having a problem keeping up\n"
             "Try increasing TCPDUMP_POLL_TIMEOUT");
             "Try increasing TCPDUMP_POLL_TIMEOUT");
 
 
-    while ((res = read(PARENT_READ_FD, decode, TCPDUMP_DECODE_LEN))) {
+    while ((res = (int)read(PARENT_READ_FD, decode, TCPDUMP_DECODE_LEN))) {
         if (res < 0) {
         if (res < 0) {
             if (errno == EAGAIN)
             if (errno == EAGAIN)
                 break;
                 break;
@@ -180,7 +174,7 @@ data_again:
             errx(-1, "Error reading tcpdump decode: %s", strerror(errno));
             errx(-1, "Error reading tcpdump decode: %s", strerror(errno));
         }
         }
 
 
-        decode[min(res, TCPDUMP_DECODE_LEN-1)] = 0;
+        decode[min(res, TCPDUMP_DECODE_LEN - 1)] = 0;
         dbgx(4, "read %d byte from tcpdump", res);
         dbgx(4, "read %d byte from tcpdump", res);
         printf("%s", decode);
         printf("%s", decode);
     }
     }
@@ -205,17 +199,18 @@ tcpdump_open(tcpdump_t *tcpdump, pcap_t *pcap)
     }
     }
 
 
     /* is tcpdump executable? */
     /* is tcpdump executable? */
-    if (! can_exec(TCPDUMP_BINARY)) {
+    if (!can_exec(TCPDUMP_BINARY)) {
         errx(-1, "Unable to execute tcpdump binary: %s", TCPDUMP_BINARY);
         errx(-1, "Unable to execute tcpdump binary: %s", TCPDUMP_BINARY);
     }
     }
 
 
 #ifdef DEBUG
 #ifdef DEBUG
-     strlcpy(tcpdump->debugfile, TCPDUMP_DEBUG, sizeof(tcpdump->debugfile));
-     if (debug >= 5) {
-         dbgx(5, "Opening tcpdump debug file: %s", tcpdump->debugfile);
+    strlcpy(tcpdump->debugfile, TCPDUMP_DEBUG, sizeof(tcpdump->debugfile));
+    if (debug >= 5) {
+        dbgx(5, "Opening tcpdump debug file: %s", tcpdump->debugfile);
 
 
-         if ((tcpdump->debugfd = open(tcpdump->debugfile, O_WRONLY|O_CREAT|O_TRUNC, 
-                S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) == -1) {
+        if ((tcpdump->debugfd =
+                     open(tcpdump->debugfile, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE | S_IRGRP | S_IROTH)) ==
+            -1) {
             errx(-1, "Error opening tcpdump debug file: %s\n%s", tcpdump->debugfile, strerror(errno));
             errx(-1, "Error opening tcpdump debug file: %s\n%s", tcpdump->debugfile, strerror(errno));
         }
         }
     }
     }
@@ -228,11 +223,10 @@ tcpdump_open(tcpdump_t *tcpdump, pcap_t *pcap)
     dbg(2, "Starting tcpdump...");
     dbg(2, "Starting tcpdump...");
 
 
     /* create our pipe to send packet data to tcpdump via */
     /* create our pipe to send packet data to tcpdump via */
-    if (pipe(tcpdump->pipes[PARENT_READ_PIPE]) < 0 ||
-            pipe(tcpdump->pipes[PARENT_WRITE_PIPE]) < 0)
+    if (pipe(tcpdump->pipes[PARENT_READ_PIPE]) < 0 || pipe(tcpdump->pipes[PARENT_WRITE_PIPE]) < 0)
         errx(-1, "Unable to create pipe: %s", strerror(errno));
         errx(-1, "Unable to create pipe: %s", strerror(errno));
 
 
-    if ((tcpdump->pid = fork() ) < 0)
+    if ((tcpdump->pid = fork()) < 0)
         errx(-1, "Fork failed: %s", strerror(errno));
         errx(-1, "Fork failed: %s", strerror(errno));
 
 
     dbgx(2, "tcpdump pid: %d", tcpdump->pid);
     dbgx(2, "tcpdump pid: %d", tcpdump->pid);
@@ -241,8 +235,7 @@ tcpdump_open(tcpdump_t *tcpdump, pcap_t *pcap)
         /* parent - we're still in tcpreplay */
         /* parent - we're still in tcpreplay */
 
 
         /* close fds not required by parent */
         /* close fds not required by parent */
-        dbgx(2, "[parent] closing child read/write fd %d/%d", CHILD_READ_FD,
-                CHILD_WRITE_FD);
+        dbgx(2, "[parent] closing child read/write fd %d/%d", CHILD_READ_FD, CHILD_WRITE_FD);
         close(CHILD_READ_FD);
         close(CHILD_READ_FD);
         close(CHILD_WRITE_FD);
         close(CHILD_WRITE_FD);
         CHILD_READ_FD = 0;
         CHILD_READ_FD = 0;
@@ -255,7 +248,7 @@ tcpdump_open(tcpdump_t *tcpdump, pcap_t *pcap)
             return FALSE;
             return FALSE;
         }
         }
 
 
-        pcap_dump_flush((pcap_dumper_t*)writer);
+        pcap_dump_flush((pcap_dumper_t *)writer);
 
 
         if (fcntl(PARENT_WRITE_FD, F_SETFL, O_NONBLOCK) < 0)
         if (fcntl(PARENT_WRITE_FD, F_SETFL, O_NONBLOCK) < 0)
             warnx("[parent] Unable to fcntl write pipe:\n%s", strerror(errno));
             warnx("[parent] Unable to fcntl write pipe:\n%s", strerror(errno));
@@ -267,21 +260,18 @@ tcpdump_open(tcpdump_t *tcpdump, pcap_t *pcap)
 
 
         /* we're in the child process - run "tcpdump  <options> -r -" */
         /* we're in the child process - run "tcpdump  <options> -r -" */
         if (dup2(CHILD_READ_FD, STDIN_FILENO) != STDIN_FILENO) {
         if (dup2(CHILD_READ_FD, STDIN_FILENO) != STDIN_FILENO) {
-            errx(-1, "[child] Unable to duplicate socket to stdin: %s",
-                                strerror(errno));
+            errx(-1, "[child] Unable to duplicate socket to stdin: %s", strerror(errno));
         }
         }
 
 
         if (dup2(CHILD_WRITE_FD, STDOUT_FILENO) != STDOUT_FILENO) {
         if (dup2(CHILD_WRITE_FD, STDOUT_FILENO) != STDOUT_FILENO) {
-            errx(-1, "[child] Unable to duplicate socket to stdout: %s",
-                                strerror(errno));
+            errx(-1, "[child] Unable to duplicate socket to stdout: %s", strerror(errno));
         }
         }
 
 
         /*
         /*
          * Close sockets not required by child. The exec'ed program must
          * Close sockets not required by child. The exec'ed program must
          * not know that they ever existed.
          * not know that they ever existed.
          */
          */
-        dbgx(2, "[child] closing in fds %d/%d/%d/%d", CHILD_READ_FD,
-                CHILD_WRITE_FD, PARENT_READ_FD, PARENT_WRITE_FD);
+        dbgx(2, "[child] closing in fds %d/%d/%d/%d", CHILD_READ_FD, CHILD_WRITE_FD, PARENT_READ_FD, PARENT_WRITE_FD);
         close(CHILD_READ_FD);
         close(CHILD_READ_FD);
         close(CHILD_WRITE_FD);
         close(CHILD_WRITE_FD);
         close(PARENT_READ_FD);
         close(PARENT_READ_FD);
@@ -299,12 +289,12 @@ tcpdump_open(tcpdump_t *tcpdump, pcap_t *pcap)
 }
 }
 
 
 /**
 /**
- * shutdown tcpdump 
+ * shutdown tcpdump
  */
  */
 void
 void
 tcpdump_close(tcpdump_t *tcpdump)
 tcpdump_close(tcpdump_t *tcpdump)
 {
 {
-    if (! tcpdump)
+    if (!tcpdump)
         return;
         return;
 
 
     if (tcpdump->pid <= 0)
     if (tcpdump->pid <= 0)
@@ -324,21 +314,6 @@ tcpdump_close(tcpdump_t *tcpdump)
     PARENT_WRITE_FD = 0;
     PARENT_WRITE_FD = 0;
 }
 }
 
 
-/** 
- * forcefully kill tcpdump 
- */
-void
-tcpdump_kill(tcpdump_t *tcpdump)
-{
-    if (tcpdump->pid) {
-        if (kill(tcpdump->pid, SIGTERM) != 0)
-            kill(tcpdump->pid, SIGKILL);
-    }
-
-    tcpdump->pid = 0;
-}
-
-
 /**
 /**
  * copy the string of args (*opt) to the vector (**opt_vec)
  * copy the string of args (*opt) to the vector (**opt_vec)
  * for a max of opt_len.  Returns the number of options
  * for a max of opt_len.  Returns the number of options
@@ -354,10 +329,9 @@ tcpdump_fill_in_options(char *opt)
 
 
     /* zero out our options_vec for execv() */
     /* zero out our options_vec for execv() */
     memset(options_vec, '\0', sizeof(options_vec));
     memset(options_vec, '\0', sizeof(options_vec));
-    
+
     /* first arg should be the binary (by convention) */
     /* first arg should be the binary (by convention) */
     options_vec[0] = TCPDUMP_BINARY;
     options_vec[0] = TCPDUMP_BINARY;
-       
 
 
     /* prep args */
     /* prep args */
     memset(options, '\0', 256);
     memset(options, '\0', 256);
@@ -367,31 +341,27 @@ tcpdump_fill_in_options(char *opt)
     strlcat(options, TCPDUMP_ARGS, sizeof(options));
     strlcat(options, TCPDUMP_ARGS, sizeof(options));
     dbgx(2, "[child] Will execute: tcpdump %s", options);
     dbgx(2, "[child] Will execute: tcpdump %s", options);
 
 
-
     /* process args */
     /* process args */
-    
+
     /* process the first argument */
     /* process the first argument */
     arg = strtok_r(options, OPT_DELIM, &token);
     arg = strtok_r(options, OPT_DELIM, &token);
-    arglen = strlen(arg) + 2; /* -{arg}\0 */
+    arglen = (int)strlen(arg) + 2; /* -{arg}\0 */
     newarg = (char *)safe_malloc(arglen);
     newarg = (char *)safe_malloc(arglen);
-    strlcat(newarg, "-", arglen); 
+    strlcat(newarg, "-", arglen);
     strlcat(newarg, arg, arglen);
     strlcat(newarg, arg, arglen);
     options_vec[i++] = newarg;
     options_vec[i++] = newarg;
 
 
-    /* process the remaining args 
+    /* process the remaining args
      * note that i < OPTIONS_VEC_SIZE - 1
      * note that i < OPTIONS_VEC_SIZE - 1
      * because: a) we need to add '-' as an option to the end
      * because: a) we need to add '-' as an option to the end
      * b) because the array has to be null terminated
      * b) because the array has to be null terminated
      */
      */
-    while (((arg = strtok_r(NULL, OPT_DELIM, &token)) != NULL) &&
-           (i < OPTIONS_VEC_SIZE - 1)) {
-
-        arglen = strlen(arg) + 2;
+    while (((arg = strtok_r(NULL, OPT_DELIM, &token)) != NULL) && (i < OPTIONS_VEC_SIZE - 1)) {
+        arglen = (int)strlen(arg) + 2;
         newarg = (char *)safe_malloc(arglen);
         newarg = (char *)safe_malloc(arglen);
         strlcat(newarg, "-", arglen);
         strlcat(newarg, "-", arglen);
         strlcat(newarg, arg, arglen);
         strlcat(newarg, arg, arglen);
         options_vec[i++] = newarg;
         options_vec[i++] = newarg;
-
     }
     }
 
 
     /* tell -r to read from stdin */
     /* tell -r to read from stdin */
@@ -400,16 +370,17 @@ tcpdump_fill_in_options(char *opt)
     return i;
     return i;
 }
 }
 
 
-
 /**
 /**
- * can we exec the given file? 
+ * can we exec the given file?
  */
  */
 static int
 static int
 can_exec(const char *filename)
 can_exec(const char *filename)
 {
 {
     struct stat st;
     struct stat st;
 
 
-    if (!filename || filename[0] == '\0')
+    assert (filename);
+
+    if (filename[0] == '\0')
         return FALSE;
         return FALSE;
 
 
     /* Stat the file to see if it's executable and
     /* Stat the file to see if it's executable and
@@ -418,9 +389,7 @@ can_exec(const char *filename)
     if (lstat(filename, &st) < 0)
     if (lstat(filename, &st) < 0)
         return FALSE;
         return FALSE;
 
 
-    if ((st.st_mode & S_IXUSR) ||
-        (st.st_mode & S_IXGRP) ||
-        (st.st_mode & S_IXOTH))
+    if ((st.st_mode & S_IXUSR) || (st.st_mode & S_IXGRP) || (st.st_mode & S_IXOTH))
         return TRUE;
         return TRUE;
 
 
     return FALSE;
     return FALSE;

+ 11 - 15
src/common/tcpdump.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,8 +18,7 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef __TCPDUMP_H__
-#define __TCPDUMP_H__
+#pragma once
 
 
 /* line buffer stdout, read from stdin */
 /* line buffer stdout, read from stdin */
 #define TCPDUMP_ARGS " -n -l -r -"
 #define TCPDUMP_ARGS " -n -l -r -"
@@ -56,7 +55,7 @@
  * 1. data from parent to child's STDIN
  * 1. data from parent to child's STDIN
  * 2. child's STDOUT to this program
  * 2. child's STDOUT to this program
  */
  */
-#define NUM_PIPES   2
+#define NUM_PIPES 2
 
 
 /* unidirectional rule for pipes: pipe[0] for read, pipe[1] for writes  */
 /* unidirectional rule for pipes: pipe[0] for read, pipe[1] for writes  */
 enum {
 enum {
@@ -69,11 +68,11 @@ enum {
     PARENT_WRITE_PIPE,
     PARENT_WRITE_PIPE,
 };
 };
 
 
-#define PARENT_READ_FD  (tcpdump->pipes[PARENT_READ_PIPE][READ_FD])
+#define PARENT_READ_FD (tcpdump->pipes[PARENT_READ_PIPE][READ_FD])
 #define PARENT_WRITE_FD (tcpdump->pipes[PARENT_WRITE_PIPE][WRITE_FD])
 #define PARENT_WRITE_FD (tcpdump->pipes[PARENT_WRITE_PIPE][WRITE_FD])
 
 
-#define CHILD_READ_FD   (tcpdump->pipes[PARENT_WRITE_PIPE][READ_FD])
-#define CHILD_WRITE_FD  (tcpdump->pipes[PARENT_READ_PIPE][WRITE_FD])
+#define CHILD_READ_FD (tcpdump->pipes[PARENT_WRITE_PIPE][READ_FD])
+#define CHILD_WRITE_FD (tcpdump->pipes[PARENT_READ_PIPE][WRITE_FD])
 
 
 typedef struct tcpdump_s {
 typedef struct tcpdump_s {
     char *filename;
     char *filename;
@@ -83,7 +82,7 @@ typedef struct tcpdump_s {
     int pipes[NUM_PIPES][2];
     int pipes[NUM_PIPES][2];
 
 
     /* following vars are for figuring out exactly what we send to
     /* following vars are for figuring out exactly what we send to
-     * tcpdump.  See TCPDUMP_DEBUG 
+     * tcpdump.  See TCPDUMP_DEBUG
      */
      */
 #ifdef DEBUG
 #ifdef DEBUG
     int debugfd;
     int debugfd;
@@ -91,11 +90,8 @@ typedef struct tcpdump_s {
 #endif
 #endif
 } tcpdump_t;
 } tcpdump_t;
 
 
-//int tcpdump_init(tcpdump_t *tcpdump);
+// int tcpdump_init(tcpdump_t *tcpdump);
 int tcpdump_open(tcpdump_t *tcpdump, pcap_t *pcap);
 int tcpdump_open(tcpdump_t *tcpdump, pcap_t *pcap);
-//int tcpdump_open_live(tcpdump_t *tcpdump, pcap_t *pcap);
+// int tcpdump_open_live(tcpdump_t *tcpdump, pcap_t *pcap);
 int tcpdump_print(tcpdump_t *tcpdump, struct pcap_pkthdr *pkthdr, const u_char *data);
 int tcpdump_print(tcpdump_t *tcpdump, struct pcap_pkthdr *pkthdr, const u_char *data);
 void tcpdump_close(tcpdump_t *tcpdump);
 void tcpdump_close(tcpdump_t *tcpdump);
-void tcpdump_kill(tcpdump_t *tcpdump);
-
-#endif

+ 10 - 58
src/common/timer.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,71 +18,24 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#include "config.h"
-#include "defines.h"
-#include "common.h"
-
 #include "timer.h"
 #include "timer.h"
-
+#include "config.h"
 #include <stdlib.h>
 #include <stdlib.h>
 
 
 /* Miscellaneous timeval routines */
 /* Miscellaneous timeval routines */
 
 
-/**
- * Divide tvp by div, storing the result in tvp 
- */
-void
-timerdiv_float(struct timeval *tvp, float div)
-{
-    double interval;
-
-    if (div == 0 || div == 1)
-        return;
-
-    interval = ((double)tvp->tv_sec * 1000000 + tvp->tv_usec) / (double)div;
-    tvp->tv_sec = interval / (int)1000000;
-    tvp->tv_usec = interval - (tvp->tv_sec * 1000000);
-}
-
 /* Divide tvs by div, storing the result in tvs */
 /* Divide tvs by div, storing the result in tvs */
-void timesdiv_float(struct timespec *tvs, float div)
-{
-    double interval;
-
-    if (div == 0 || div == 1)
-        return;
-
-    interval = ((double)tvs->tv_sec * 1000000000 + tvs->tv_nsec) / (double)div;
-    tvs->tv_sec = interval / (int)1000000000;
-    tvs->tv_nsec = interval - (tvs->tv_sec * 1000000000);
-}
-
 void
 void
-timerdiv(struct timeval *tvp, COUNTER div)
+timesdiv_float(struct timespec *tvs, float div)
 {
 {
-  uint64_t interval;
+    double interval;
 
 
-    if (div == 0 || div == 1)
+    if (div == 0.0 || div == 1.0)
         return;
         return;
 
 
-    interval = (uint64_t)tvp->tv_sec * 1000000 + tvp->tv_usec;
-    do_div(interval, div);
-    tvp->tv_sec = interval / 1000000;
-    tvp->tv_usec = interval - (tvp->tv_sec * 1000000);
-}
-
-/* Divide tvs by div, storing the result in tvs */
-void timesdiv(struct timespec *tvs, COUNTER div)
-{
-    uint64_t interval;
-    
-    if (div == 0 || div == 1)
-        return;
-        
-    interval = (uint64_t)tvs->tv_sec * 1000000000 + tvs->tv_nsec;
-    do_div(interval, div);
-    tvs->tv_sec = interval / 1000000000;
-    tvs->tv_nsec = interval - (tvs->tv_sec * 1000000000);
+    interval = ((double)tvs->tv_sec * 1000000000.0 + (double)tvs->tv_nsec) / (double)div;
+    tvs->tv_sec = (time_t)interval / (time_t)1000000000;
+    tvs->tv_nsec = (time_t)interval - (tvs->tv_sec * 1000000000);
 }
 }
 
 
 void
 void
@@ -90,4 +43,3 @@ init_timestamp(timestamp_t *ctx)
 {
 {
     timerclear(ctx);
     timerclear(ctx);
 }
 }
-

+ 62 - 85
src/common/timer.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,18 +18,15 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef _TIMER_H_
-#define _TIMER_H_
+#pragma once
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
-#include "tcpreplay.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
-#include <time.h>
-#include <sys/time.h>
+#include "tcpreplay.h"
 #include <math.h>
 #include <math.h>
-
+#include <sys/time.h>
+#include <time.h>
 
 
 /*
 /*
  * 1 sec = 1,0000 millisec (ms)
  * 1 sec = 1,0000 millisec (ms)
@@ -39,138 +36,118 @@
  * 1 microsec = 1,000 nanosec
  * 1 microsec = 1,000 nanosec
  */
  */
 
 
-void timerdiv_float(struct timeval *tvp, float div);
 void timesdiv_float(struct timespec *tvs, float div);
 void timesdiv_float(struct timespec *tvs, float div);
-void timerdiv(struct timeval *tvp, COUNTER div);
-void timesdiv(struct timespec *tvs, COUNTER div);
 
 
 /* convert float time to struct timeval *tvp */
 /* convert float time to struct timeval *tvp */
 #ifndef float2timer
 #ifndef float2timer
-#define float2timer(time, tvp)                            \
-    do {                                                  \
-        (tvp)->tv_sec = time;                             \
-        (tvp)->tv_usec = (time - (tvp)->tv_sec) * 100000; \
+#define float2timer(time, tvp)                                                                                         \
+    do {                                                                                                               \
+        (tvp)->tv_sec = time;                                                                                          \
+        (tvp)->tv_usec = (time - (tvp)->tv_sec) * 100000;                                                              \
     } while (0)
     } while (0)
 #endif
 #endif
 
 
 /* timesec to float */
 /* timesec to float */
 #ifndef timer2float
 #ifndef timer2float
-#define timer2float(tvp, time)                           \
-    do {                                                 \
-        time = (tvp)->tv_sec;                            \
-        time += (float)((tvp)->tv_usec / 10000) * 0.01;  \
+#define timer2float(tvp, time)                                                                                         \
+    do {                                                                                                               \
+        time = (tvp)->tv_sec;                                                                                          \
+        time += (float)((tvp)->tv_usec / 10000) * 0.01;                                                                \
     } while (0)
     } while (0)
 #endif
 #endif
 
 
 #ifndef TIMEVAL_TO_TIMESPEC
 #ifndef TIMEVAL_TO_TIMESPEC
-#define TIMEVAL_TO_TIMESPEC(tv, ts) {                 \
-            (ts)->tv_sec = (tv)->tv_sec;              \
-            (ts)->tv_nsec = (tv)->tv_usec * 1000; }
+#define TIMEVAL_TO_TIMESPEC(tv, ts)                                                                                    \
+    {                                                                                                                  \
+        (ts)->tv_sec = (tv)->tv_sec;                                                                                   \
+        (ts)->tv_nsec = (tv)->tv_usec * 1000;                                                                          \
+    }
 #endif
 #endif
 
 
 #ifndef TIMESPEC_TO_TIMEVAL
 #ifndef TIMESPEC_TO_TIMEVAL
-#define TIMESPEC_TO_TIMEVAL(tv, ts) {           \
-    (tv)->tv_sec = (ts)->tv_sec;                \
-    (tv)->tv_usec = (ts)->tv_nsec / 1000; }
+#define TIMESPEC_TO_TIMEVAL(tv, ts)                                                                                    \
+    {                                                                                                                  \
+        (tv)->tv_sec = (ts)->tv_sec;                                                                                   \
+        (tv)->tv_usec = (ts)->tv_nsec / 1000;                                                                          \
+    }
 #endif
 #endif
 
 
 #ifndef ROUND_TIMESPEC_TO_MICROSEC
 #ifndef ROUND_TIMESPEC_TO_MICROSEC
-#define ROUND_TIMESPEC_TO_MICROSEC(ts)      \
-    do {                                    \
-        (ts)->tv_nsec = ((((ts)->tv_nsec / 1000) + ((ts)->tv_nsec % 1000 >= 500 ? 1 : 0)) * 1000);   \
+#define ROUND_TIMESPEC_TO_MICROSEC(ts)                                                                                 \
+    do {                                                                                                               \
+        (ts)->tv_nsec = ((((ts)->tv_nsec / 1000) + ((ts)->tv_nsec % 1000 >= 500 ? 1 : 0)) * 1000);                     \
     } while (0)
     } while (0)
 #endif
 #endif
 
 
-
-
 /* zero out a timer */
 /* zero out a timer */
 #ifndef timerclear
 #ifndef timerclear
-#define timerclear(tvp)     (tvp)->tv_sec = (tvp)->tv_usec = 0
+#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
 #endif
 #endif
 
 
 /* zero out a timespec */
 /* zero out a timespec */
 #ifndef timesclear
 #ifndef timesclear
-#define timesclear(tvs)     (tvs)->tv_sec = (tvs)->tv_nsec = 0
+#define timesclear(tvs) (tvs)->tv_sec = (tvs)->tv_nsec = 0
 #endif
 #endif
 
 
 /* is timer non-zero? */
 /* is timer non-zero? */
 #ifndef timerisset
 #ifndef timerisset
-#define timerisset(tvp)     ((tvp)->tv_sec || (tvp)->tv_usec)
+#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
 #endif
 #endif
 
 
 /* is timespec non-zero? */
 /* is timespec non-zero? */
 #ifndef timesisset
 #ifndef timesisset
-#define timesisset(tvs)     ((tvs)->tv_sec || (tvs)->tv_nsec)
+#define timesisset(tvs) ((tvs)->tv_sec || (tvs)->tv_nsec)
 #endif
 #endif
 
 
-
 /* add tvp and uvp and store in vvp */
 /* add tvp and uvp and store in vvp */
 #ifndef timeradd
 #ifndef timeradd
-#define timeradd(tvp, uvp, vvp)                             \
-    do {                                                    \
-        (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;      \
-        (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;   \
-        if ((vvp)->tv_usec >= 1000000) {                    \
-            (vvp)->tv_sec++;                                \
-            (vvp)->tv_usec -= 1000000;                      \
-        }                                                   \
+#define timeradd(tvp, uvp, vvp)                                                                                        \
+    do {                                                                                                               \
+        (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;                                                                 \
+        (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;                                                              \
+        if ((vvp)->tv_usec >= 1000000) {                                                                               \
+            (vvp)->tv_sec++;                                                                                           \
+            (vvp)->tv_usec -= 1000000;                                                                                 \
+        }                                                                                                              \
     } while (0)
     } while (0)
 #endif
 #endif
 
 
 /* subtract uvp from tvp and store in vvp */
 /* subtract uvp from tvp and store in vvp */
 #ifndef timersub
 #ifndef timersub
-#define  timersub(tvp, uvp, vvp)                             \
-    do {                                                    \
-        (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;      \
-        (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;   \
-        if ((vvp)->tv_usec < 0) {                           \
-            (vvp)->tv_sec--;                                \
-            (vvp)->tv_usec += 1000000;                      \
-        }                                                   \
+#define timersub(tvp, uvp, vvp)                                                                                        \
+    do {                                                                                                               \
+        (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;                                                                 \
+        (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;                                                              \
+        if ((vvp)->tv_usec < 0) {                                                                                      \
+            (vvp)->tv_sec--;                                                                                           \
+            (vvp)->tv_usec += 1000000;                                                                                 \
+        }                                                                                                              \
     } while (0)
     } while (0)
 #endif
 #endif
 
 
 #ifndef timessub
 #ifndef timessub
-#define  timessub(tsp, usp, vsp)                            \
-    do {                                                   \
-        (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;     \
-        (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;  \
-        if ((vsp)->tv_nsec < 0) {                          \
-            (vsp)->tv_sec--;                               \
-            (vsp)->tv_nsec += 1000000000;                  \
-        }                                                  \
+#define timessub(tsp, usp, vsp)                                                                                        \
+    do {                                                                                                               \
+        (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;                                                                 \
+        (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;                                                              \
+        if ((vsp)->tv_nsec < 0) {                                                                                      \
+            (vsp)->tv_sec--;                                                                                           \
+            (vsp)->tv_nsec += 1000000000;                                                                              \
+        }                                                                                                              \
     } while (0)
     } while (0)
 #endif
 #endif
 
 
 /* compare tvp and uvp using cmp */
 /* compare tvp and uvp using cmp */
 #ifndef timercmp
 #ifndef timercmp
-#define timercmp(tvp, uvp, cmp)            \
-    (((tvp)->tv_sec == (uvp)->tv_sec) ?    \
-     ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
-     ((tvp)->tv_sec cmp (uvp)->tv_sec))
+#define timercmp(tvp, uvp, cmp)                                                                                        \
+    (((tvp)->tv_sec == (uvp)->tv_sec) ? ((tvp)->tv_usec cmp(uvp)->tv_usec) : ((tvp)->tv_sec cmp(uvp)->tv_sec))
 #endif
 #endif
 
 
 #ifndef timescmp
 #ifndef timescmp
-#define timescmp(tsp, usp, cmp)              \
-    (((tsp)->tv_sec == (usp)->tv_sec) ?      \
-     ((tsp)->tv_nsec cmp (usp)->tv_nsec) :   \
-     ((tsp)->tv_sec cmp (usp)->tv_sec))
+#define timescmp(tsp, usp, cmp)                                                                                        \
+    (((tsp)->tv_sec == (usp)->tv_sec) ? ((tsp)->tv_nsec cmp(usp)->tv_nsec) : ((tsp)->tv_sec cmp(usp)->tv_sec))
 #endif
 #endif
 
 
-/* multiply tvp by x and store in uvp */
-#define timermul(tvp, uvp, x)                   \
-    do {                                        \
-        (uvp)->tv_sec = (tvp)->tv_sec * x;      \
-        (uvp)->tv_usec = (tvp)->tv_usec * x;    \
-        while((uvp)->tv_usec > 1000000) {       \
-            (uvp)->tv_sec++;                    \
-            (uvp)->tv_usec -= 1000000;          \
-        }                                       \
-    } while(0)
-
-    typedef struct timeval timestamp_t;
+typedef struct timeval timestamp_t;
 
 
 void init_timestamp(timestamp_t *ctx);
 void init_timestamp(timestamp_t *ctx);
-
-
-#endif /* _TIMER_H_ */

+ 55 - 59
src/common/txring.c

@@ -33,18 +33,17 @@
 
 
 #ifdef HAVE_TX_RING
 #ifdef HAVE_TX_RING
 
 
+#include "txring.h"
 #include "err.h"
 #include "err.h"
 #include "utils.h"
 #include "utils.h"
-#include "txring.h"
-#include <unistd.h>
+#include <errno.h>
 #include <string.h>
 #include <string.h>
 #include <sys/mman.h>
 #include <sys/mman.h>
-#include <errno.h>
+#include <unistd.h>
 
 
 volatile int shutdown_flag = 0;
 volatile int shutdown_flag = 0;
 int tdata_offset = TPACKET_HDRLEN - sizeof(struct sockaddr_ll);
 int tdata_offset = TPACKET_HDRLEN - sizeof(struct sockaddr_ll);
 
 
-
 /**
 /**
  * This task will call send() procedure
  * This task will call send() procedure
  */
  */
@@ -57,67 +56,65 @@ txring_send(void *arg)
 
 
     do {
     do {
         /* send all buffers with TP_STATUS_SEND_REQUEST */
         /* send all buffers with TP_STATUS_SEND_REQUEST */
-        ec_send=sendto(fd_socket, NULL, 0, MSG_DONTWAIT,
-                (struct sockaddr *)NULL, sizeof(struct sockaddr_ll));
+        ec_send = sendto(fd_socket, NULL, 0, MSG_DONTWAIT, (struct sockaddr *)NULL, sizeof(struct sockaddr_ll));
 
 
         if (ec_send > 0) {
         if (ec_send > 0) {
             total += ec_send;
             total += ec_send;
             dbgx(2, "Sent %d bytes (+%d bytes)", total, ec_send);
             dbgx(2, "Sent %d bytes (+%d bytes)", total, ec_send);
-        } else  {
+        } else {
             /* nothing to do => schedule : useful if no SMP */
             /* nothing to do => schedule : useful if no SMP */
             usleep(100);
             usleep(100);
         }
         }
 
 
-
     } while (!shutdown_flag);
     } while (!shutdown_flag);
 
 
-    //if(blocking) printf("end of task send()\n");
-    //printf("end of task send(ec=%x)\n", ec_send);
+    // if(blocking) printf("end of task send()\n");
+    // printf("end of task send(ec=%x)\n", ec_send);
 
 
-    return (void*) ec_send;
+    return (void *)ec_send;
 }
 }
 
 
 /**
 /**
  * Put data in TX ring buffer and rotate it if necessary
  * Put data in TX ring buffer and rotate it if necessary
  */
  */
 int
 int
-txring_put(txring_t *txp, const void * data, size_t length)
+txring_put(txring_t *txp, const void *data, size_t length)
 {
 {
     struct tpacket_hdr *ps_header;
     struct tpacket_hdr *ps_header;
-    char * to_data;
+    char *to_data;
     int loop = 1;
     int loop = 1;
     int first_loop = 1;
     int first_loop = 1;
     unsigned int start_index = txp->tx_index;
     unsigned int start_index = txp->tx_index;
 
 
     do {
     do {
-        ps_header = ((struct tpacket_hdr *)((void *)txp->tx_head + 
-                    (txp->treq->tp_frame_size * txp->tx_index)));
-        to_data = ((void*) ps_header) + tdata_offset;
+        ps_header = ((struct tpacket_hdr *)((void *)txp->tx_head + (txp->treq->tp_frame_size * txp->tx_index)));
+        to_data = ((void *)ps_header) + tdata_offset;
 
 
         switch ((volatile uint32_t)ps_header->tp_status) {
         switch ((volatile uint32_t)ps_header->tp_status) {
-            case TP_STATUS_WRONG_FORMAT:
-                warnx("TP_STATUS_WRONG_FORMAT occuries O_o. Frame %d, pkt len %d\n", 
-                        txp->tx_index, length);
-                break;
-
-            case TP_STATUS_AVAILABLE:
-                if (length > txp->treq->tp_frame_size) {
-                    //TODO Fragment packet
-                    warnx("[!] %d bytes from %d packet truncated\n",
-                            length-txp->treq->tp_frame_size, length);
-                    length = txp->treq->tp_frame_size;
-                }
-                memcpy(to_data, data, length);
-                ps_header->tp_len = length;
-                ps_header->tp_status = TP_STATUS_SEND_REQUEST;
-                loop = 0;
-                break;
-
-            default:
-                dbgx(2,"TPACKET status %u at frame %d with length %d\n",
-                        ps_header->tp_status, txp->tx_index, ps_header->tp_len);
-                usleep(0);
-                break;
+        case TP_STATUS_WRONG_FORMAT:
+            warnx("TP_STATUS_WRONG_FORMAT occuries O_o. Frame %d, pkt len %d\n", txp->tx_index, length);
+            break;
+
+        case TP_STATUS_AVAILABLE:
+            if (length > txp->treq->tp_frame_size) {
+                // TODO Fragment packet
+                warnx("[!] %d bytes from %d packet truncated\n", length - txp->treq->tp_frame_size, length);
+                length = txp->treq->tp_frame_size;
+            }
+            memcpy(to_data, data, length);
+            ps_header->tp_len = length;
+            ps_header->tp_status = TP_STATUS_SEND_REQUEST;
+            loop = 0;
+            break;
+
+        default:
+            dbgx(2,
+                 "TPACKET status %u at frame %d with length %d\n",
+                 ps_header->tp_status,
+                 txp->tx_index,
+                 ps_header->tp_len);
+            usleep(0);
+            break;
         }
         }
         txp->tx_index++;
         txp->tx_index++;
 
 
@@ -131,24 +128,23 @@ txring_put(txring_t *txp, const void * data, size_t length)
             errno = ENOBUFS;
             errno = ENOBUFS;
             return -1;
             return -1;
         }
         }
-    } while(loop == 1);
+    } while (loop == 1);
 
 
     return ps_header->tp_len;
     return ps_header->tp_len;
 }
 }
 
 
-
 /**
 /**
  * \brief Build TX ring buffer request structure
  * \brief Build TX ring buffer request structure
  *
  *
  * This builds a ring buffer request structure making sure
  * This builds a ring buffer request structure making sure
  * that we have buffers big enough so that a frame which
  * that we have buffers big enough so that a frame which
  * is the size of the MTU doesn't get truncated. We also
  * is the size of the MTU doesn't get truncated. We also
- * need to structure things with minimum memory wastage 
+ * need to structure things with minimum memory wastage
  */
  */
 void
 void
-txring_mkreq(struct tpacket_req* treq, unsigned int mtu)
+txring_mkreq(struct tpacket_req *treq, unsigned int mtu)
 {
 {
-    unsigned int pg,bs;
+    unsigned int pg, bs;
     unsigned int s;
     unsigned int s;
     unsigned int mult = 1;
     unsigned int mult = 1;
     unsigned nr_blocks = 1000;
     unsigned nr_blocks = 1000;
@@ -158,27 +154,30 @@ txring_mkreq(struct tpacket_req* treq, unsigned int mtu)
 
 
     memset(treq, 0, sizeof(struct tpacket_req));
     memset(treq, 0, sizeof(struct tpacket_req));
     if (bs <= s) {
     if (bs <= s) {
-        while(bs < s) {
+        while (bs < s) {
             bs += pg;
             bs += pg;
             mult++;
             mult++;
         }
         }
 
 
         treq->tp_block_size = bs;
         treq->tp_block_size = bs;
         treq->tp_frame_size = bs / mult;
         treq->tp_frame_size = bs / mult;
-        treq->tp_block_nr   = nr_blocks;
-        treq->tp_frame_nr   = mult * nr_blocks;
+        treq->tp_block_nr = nr_blocks;
+        treq->tp_frame_nr = mult * nr_blocks;
     } else {
     } else {
-        while ((s * (mult + 1)) <=pg) {
+        while ((s * (mult + 1)) <= pg) {
             mult++;
             mult++;
         }
         }
         treq->tp_block_size = pg;
         treq->tp_block_size = pg;
         treq->tp_frame_size = pg / mult;
         treq->tp_frame_size = pg / mult;
-        treq->tp_block_nr   = nr_blocks;
-        treq->tp_frame_nr   = mult * nr_blocks;
+        treq->tp_block_nr = nr_blocks;
+        treq->tp_frame_nr = mult * nr_blocks;
     }
     }
-    dbgx(1, "txring: block_size=%d block_nr=%d frame_size=%d frame_nr=%d", 
-            treq->tp_block_size, treq->tp_block_nr, treq->tp_frame_size, 
-            treq->tp_frame_nr);
+    dbgx(1,
+         "txring: block_size=%d block_nr=%d frame_size=%d frame_nr=%d",
+         treq->tp_block_size,
+         treq->tp_block_nr,
+         treq->tp_frame_size,
+         treq->tp_frame_nr);
 }
 }
 
 
 /**
 /**
@@ -203,22 +202,19 @@ txring_init(int fd, unsigned int mtu)
     txp->tx_index = 0; /* Set index on start*/
     txp->tx_index = 0; /* Set index on start*/
 
 
     /* Set PACKET_LOSS sockoption */
     /* Set PACKET_LOSS sockoption */
-    if (setsockopt(fd, SOL_PACKET, PACKET_LOSS, (char *)&mode_loss,
-                sizeof(mode_loss)) < 0) {
+    if (setsockopt(fd, SOL_PACKET, PACKET_LOSS, (char *)&mode_loss, sizeof(mode_loss)) < 0) {
         perror("setsockopt: PACKET_LOSS");
         perror("setsockopt: PACKET_LOSS");
         return NULL;
         return NULL;
     }
     }
 
 
     /* Enable TX Ring */
     /* Enable TX Ring */
-    if (setsockopt(fd, SOL_PACKET, PACKET_TX_RING, (char *)txp->treq,
-                sizeof(struct tpacket_req)) < 0) {
+    if (setsockopt(fd, SOL_PACKET, PACKET_TX_RING, (char *)txp->treq, sizeof(struct tpacket_req)) < 0) {
         perror("Can't setsockopt PACKET_TX_RING");
         perror("Can't setsockopt PACKET_TX_RING");
         return NULL;
         return NULL;
     }
     }
 
 
-
     /* mmap unswapped memory with TX ring buffer*/
     /* mmap unswapped memory with TX ring buffer*/
-    txp->tx_head = mmap(0, txp->tx_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+    txp->tx_head = mmap(0, txp->tx_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
     if (txp->tx_head == MAP_FAILED) {
     if (txp->tx_head == MAP_FAILED) {
         perror("mmap() failed ");
         perror("mmap() failed ");
         return NULL;
         return NULL;

+ 13 - 17
src/common/txring.h

@@ -31,37 +31,33 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  */
 
 
-
-#ifndef COMMON_TXRING_H
-#define COMMON_TXRING_H
-#include "config.h"
-#include "defines.h"
+#pragma once
 
 
 #ifdef HAVE_TX_RING
 #ifdef HAVE_TX_RING
 
 
+#include "defines.h"
+#include "config.h"
+
 #if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
 #if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
+#include <net/ethernet.h> /* the L2 protocols */
 #include <netpacket/packet.h>
 #include <netpacket/packet.h>
-#include <net/ethernet.h>       /* the L2 protocols */
 #else
 #else
 #include <asm/types.h>
 #include <asm/types.h>
+#include <linux/if_ether.h> /* The L2 protocols */
 #include <linux/if_packet.h>
 #include <linux/if_packet.h>
-#include <linux/if_ether.h>     /* The L2 protocols */
 #endif
 #endif
 #include <pthread.h>
 #include <pthread.h>
 
 
-struct txring_s
-{
+struct txring_s {
     pthread_t tx_send; /*Poll TX thread*/
     pthread_t tx_send; /*Poll TX thread*/
 
 
-    volatile struct tpacket_hdr * tx_head; /* Pointer to mmaped memory with TX ring */
-    struct tpacket_req* treq; /* TX ring parametrs */
-    volatile unsigned int tx_index; /* TX index */
-    int tx_size; /* Size of mmaped TX ring */
+    volatile struct tpacket_hdr *tx_head; /* Pointer to mmaped memory with TX ring */
+    struct tpacket_req *treq;             /* TX ring parametrs */
+    volatile unsigned int tx_index;       /* TX index */
+    int tx_size;                          /* Size of mmaped TX ring */
 };
 };
 typedef struct txring_s txring_t;
 typedef struct txring_s txring_t;
 
 
-int txring_put(txring_t *txp, const void * data, size_t length);
-txring_t* txring_init(int fd, unsigned int mtu);
+int txring_put(txring_t *txp, const void *data, size_t length);
+txring_t *txring_init(int fd, unsigned int mtu);
 #endif /* HAVE_TX_RING */
 #endif /* HAVE_TX_RING */
-
-#endif /*COMMON_TXRING_H */

+ 115 - 80
src/common/utils.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,24 +18,16 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
-#include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
-#include <errno.h>
-#include <ctype.h>
-#include <unistd.h>
+#include <string.h>
 
 
 #ifdef HAVE_SYS_IOCTL_H
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #include <sys/ioctl.h>
 #endif
 #endif
 
 
-#ifdef DEBUG
-extern int debug;
-#endif
-
 /**
 /**
  * this is wrapped up in a #define safe_malloc
  * this is wrapped up in a #define safe_malloc
  * This function, detects failures to malloc memory and zeros out the
  * This function, detects failures to malloc memory and zeros out the
@@ -43,13 +35,12 @@ extern int debug;
  */
  */
 
 
 void *
 void *
-_our_safe_malloc(size_t len, const char *funcname, const int line, const char *file)
+our_safe_malloc(size_t len, const char *funcname, int line, const char *file)
 {
 {
     u_char *ptr;
     u_char *ptr;
 
 
     if ((ptr = malloc(len)) == NULL) {
     if ((ptr = malloc(len)) == NULL) {
-        fprintf(stderr, "ERROR in %s:%s() line %d: Unable to malloc() %zu bytes/n",
-                file, funcname, line, len);
+        fprintf(stderr, "ERROR in %s:%s() line %d: Unable to malloc() %zu bytes/n", file, funcname, line, len);
         exit(-1);
         exit(-1);
     }
     }
 
 
@@ -70,11 +61,15 @@ _our_safe_malloc(size_t len, const char *funcname, const int line, const char *f
  * ptr = safe_realloc(ptr, size)
  * ptr = safe_realloc(ptr, size)
  */
  */
 void *
 void *
-_our_safe_realloc(void *ptr, size_t len, const char *funcname, const int line, const char *file)
+our_safe_realloc(void *ptr, size_t len, const char *funcname, int line, const char *file)
 {
 {
-
     if ((ptr = realloc(ptr, len)) == NULL) {
     if ((ptr = realloc(ptr, len)) == NULL) {
-        fprintf(stderr, "ERROR: in %s:%s() line %d: Unable to remalloc() buffer to %zu bytes", file, funcname, line, len);
+        fprintf(stderr,
+                "ERROR: in %s:%s() line %d: Unable to remalloc() buffer to %zu bytes",
+                file,
+                funcname,
+                line,
+                len);
         exit(-1);
         exit(-1);
     }
     }
 
 
@@ -88,7 +83,7 @@ _our_safe_realloc(void *ptr, size_t len, const char *funcname, const int line, c
  * This function, detects failures to realloc memory
  * This function, detects failures to realloc memory
  */
  */
 char *
 char *
-_our_safe_strdup(const char *str, const char *funcname, const int line, const char *file)
+our_safe_strdup(const char *str, const char *funcname, int line, const char *file)
 {
 {
     char *newstr;
     char *newstr;
 
 
@@ -100,14 +95,13 @@ _our_safe_strdup(const char *str, const char *funcname, const int line, const ch
     memcpy(newstr, str, strlen(str) + 1);
     memcpy(newstr, str, strlen(str) + 1);
 
 
     return newstr;
     return newstr;
-
 }
 }
 
 
 /**
 /**
  * calls free and sets to NULL.
  * calls free and sets to NULL.
  */
  */
 void
 void
-_our_safe_free(void *ptr, const char *funcname, const int line, const char *file)
+our_safe_free(void *ptr, const char *funcname, int line, const char *file)
 {
 {
     assert(funcname);
     assert(funcname);
     assert(line);
     assert(line);
@@ -122,28 +116,37 @@ _our_safe_free(void *ptr, const char *funcname, const int line, const char *file
 /**
 /**
  * get next packet in pcap file
  * get next packet in pcap file
  */
  */
-u_char *_our_safe_pcap_next(pcap_t *pcap,  struct pcap_pkthdr *pkthdr,
-        const char *funcname, const int line, const char *file)
+u_char *
+our_safe_pcap_next(pcap_t *pcap, struct pcap_pkthdr *pkthdr, const char *funcname, int line, const char *file)
 {
 {
     u_char *pktdata = (u_char *)pcap_next(pcap, pkthdr);
     u_char *pktdata = (u_char *)pcap_next(pcap, pkthdr);
 
 
     if (pktdata) {
     if (pktdata) {
         if (pkthdr->len > MAX_SNAPLEN) {
         if (pkthdr->len > MAX_SNAPLEN) {
-            fprintf(stderr, "safe_pcap_next ERROR: Invalid packet length in %s:%s() line %d: %u is greater than maximum %u\n",
-                    file, funcname, line, pkthdr->len, MAX_SNAPLEN);
+            fprintf(stderr,
+                    "safe_pcap_next ERROR: Invalid packet length in %s:%s() line %d: %u is greater than maximum %u\n",
+                    file,
+                    funcname,
+                    line,
+                    pkthdr->len,
+                    MAX_SNAPLEN);
             exit(-1);
             exit(-1);
         }
         }
 
 
         if (!pkthdr->len || !pkthdr->caplen) {
         if (!pkthdr->len || !pkthdr->caplen) {
-            fprintf(stderr, "safe_pcap_next ERROR: Invalid packet length in %s:%s() line %d: packet length=%u capture length=%u\n",
-                    file, funcname, line, pkthdr->len, pkthdr->caplen);
+            fprintf(stderr,
+                    "safe_pcap_next ERROR: Invalid packet length in %s:%s() line %d: packet length=%u capture length=%u\n",
+                    file,
+                    funcname,
+                    line,
+                    pkthdr->len,
+                    pkthdr->caplen);
             exit(-1);
             exit(-1);
         }
         }
 
 
         /* attempt to correct invalid captures */
         /* attempt to correct invalid captures */
         if (pkthdr->len < pkthdr->caplen) {
         if (pkthdr->len < pkthdr->caplen) {
-            dbgx(1, "Correcting invalid packet capture length %d: packet length=%u",
-                    pkthdr->caplen, pkthdr->len);
+            dbgx(1, "Correcting invalid packet capture length %d: packet length=%u", pkthdr->caplen, pkthdr->len);
             pkthdr->caplen = pkthdr->len;
             pkthdr->caplen = pkthdr->len;
         }
         }
     } else {
     } else {
@@ -157,34 +160,46 @@ u_char *_our_safe_pcap_next(pcap_t *pcap,  struct pcap_pkthdr *pkthdr,
 /**
 /**
  * get next packet in pcap file (extended)
  * get next packet in pcap file (extended)
  */
  */
-int _our_safe_pcap_next_ex(pcap_t *pcap, struct pcap_pkthdr **pkthdr,
-        const u_char **pktdata, const char *funcname,
-        const int line, const char *file)
+int
+our_safe_pcap_next_ex(pcap_t *pcap,
+                      struct pcap_pkthdr **pkthdr,
+                      const u_char **pktdata,
+                      const char *funcname,
+                      int line,
+                      const char *file)
 {
 {
     int res = pcap_next_ex(pcap, pkthdr, pktdata);
     int res = pcap_next_ex(pcap, pkthdr, pktdata);
 
 
     if (*pktdata && *pkthdr) {
     if (*pktdata && *pkthdr) {
         if ((*pkthdr)->len > MAXPACKET) {
         if ((*pkthdr)->len > MAXPACKET) {
-            fprintf(stderr, "safe_pcap_next_ex ERROR: Invalid packet length in %s:%s() line %d: %u is greater than maximum %u\n",
-                    file, funcname, line, (*pkthdr)->len, MAXPACKET);
+            fprintf(stderr,
+                    "safe_pcap_next_ex ERROR: Invalid packet length in %s:%s() line %d: %u is greater than maximum %u\n",
+                    file,
+                    funcname,
+                    line,
+                    (*pkthdr)->len,
+                    MAXPACKET);
             exit(-1);
             exit(-1);
         }
         }
 
 
         if (!(*pkthdr)->len || (*pkthdr)->len < (*pkthdr)->caplen) {
         if (!(*pkthdr)->len || (*pkthdr)->len < (*pkthdr)->caplen) {
-            fprintf(stderr, "safe_pcap_next_ex ERROR: Invalid packet length in %s:%s() line %d: packet length=%u capture length=%u\n",
-                    file, funcname, line, (*pkthdr)->len, (*pkthdr)->caplen);
+            fprintf(stderr,
+                    "safe_pcap_next_ex ERROR: Invalid packet length in %s:%s() line %d: packet length=%u capture length=%u\n",
+                    file,
+                    funcname,
+                    line,
+                    (*pkthdr)->len,
+                    (*pkthdr)->caplen);
             exit(-1);
             exit(-1);
         }
         }
 
 
         if ((*pkthdr)->len < (*pkthdr)->caplen) {
         if ((*pkthdr)->len < (*pkthdr)->caplen) {
-            dbgx(1, "Correcting invalid packet capture length %d: packet length=%u",
-                    (*pkthdr)->caplen, (*pkthdr)->len);
+            dbgx(1, "Correcting invalid packet capture length %d: packet length=%u", (*pkthdr)->caplen, (*pkthdr)->len);
             (*pkthdr)->caplen = (*pkthdr)->len;
             (*pkthdr)->caplen = (*pkthdr)->len;
         }
         }
     } else {
     } else {
         /* this will be reported as a failed packet in final report */
         /* this will be reported as a failed packet in final report */
-        dbgx(1, "No data found in packet 0x%p and/or header 0x%p",
-                *pktdata, *pkthdr);
+        dbgx(1, "No data found in packet 0x%p and/or header 0x%p", *pktdata, *pkthdr);
     }
     }
 
 
     return res;
     return res;
@@ -218,10 +233,10 @@ packet_stats(const tcpreplay_stats_t *stats)
         if (stats->bytes_sent > 1000 * 1000 * 1000 && diff_us > 1000 * 1000) {
         if (stats->bytes_sent > 1000 * 1000 * 1000 && diff_us > 1000 * 1000) {
             bytes_sec_X10 = (stats->bytes_sent * 10 * 1000) / (diff_us / 1000);
             bytes_sec_X10 = (stats->bytes_sent * 10 * 1000) / (diff_us / 1000);
             pkts_sec_X100 = (stats->pkts_sent * 100 * 1000) / (diff_us / 1000);
             pkts_sec_X100 = (stats->pkts_sent * 100 * 1000) / (diff_us / 1000);
-         } else {
+        } else {
             bytes_sec_X10 = (stats->bytes_sent * 10 * 1000 * 1000) / diff_us;
             bytes_sec_X10 = (stats->bytes_sent * 10 * 1000 * 1000) / diff_us;
             pkts_sec_X100 = (stats->pkts_sent * 100 * 1000 * 1000) / diff_us;
             pkts_sec_X100 = (stats->pkts_sent * 100 * 1000 * 1000) / diff_us;
-         }
+        }
 
 
         bytes_sec = bytes_sec_X10 / 10;
         bytes_sec = bytes_sec_X10 / 10;
         bytes_sec_10ths = bytes_sec_X10 % 10;
         bytes_sec_10ths = bytes_sec_X10 % 10;
@@ -238,23 +253,37 @@ packet_stats(const tcpreplay_stats_t *stats)
 
 
     if (diff_us >= 1000 * 1000)
     if (diff_us >= 1000 * 1000)
         printf("Actual: " COUNTER_SPEC " packets (" COUNTER_SPEC " bytes) sent in %zd.%02zd seconds\n",
         printf("Actual: " COUNTER_SPEC " packets (" COUNTER_SPEC " bytes) sent in %zd.%02zd seconds\n",
-                stats->pkts_sent, stats->bytes_sent, (ssize_t)diff.tv_sec, (ssize_t)(diff.tv_usec / (10 * 1000)));
+               stats->pkts_sent,
+               stats->bytes_sent,
+               (ssize_t)diff.tv_sec,
+               (ssize_t)(diff.tv_usec / (10 * 1000)));
     else
     else
         printf("Actual: " COUNTER_SPEC " packets (" COUNTER_SPEC " bytes) sent in %zd.%06zd seconds\n",
         printf("Actual: " COUNTER_SPEC " packets (" COUNTER_SPEC " bytes) sent in %zd.%06zd seconds\n",
-                stats->pkts_sent, stats->bytes_sent, (ssize_t)diff.tv_sec, (ssize_t)diff.tv_usec);
-
+               stats->pkts_sent,
+               stats->bytes_sent,
+               (ssize_t)diff.tv_sec,
+               (ssize_t)diff.tv_usec);
 
 
     if (mb_sec >= 1)
     if (mb_sec >= 1)
         printf("Rated: %llu.%1u Bps, %llu.%02u Mbps, %llu.%02u pps\n",
         printf("Rated: %llu.%1u Bps, %llu.%02u Mbps, %llu.%02u pps\n",
-               bytes_sec, bytes_sec_10ths, mb_sec, mb_sec_100ths, pkts_sec, pkts_sec_100ths);
+               bytes_sec,
+               bytes_sec_10ths,
+               mb_sec,
+               mb_sec_100ths,
+               pkts_sec,
+               pkts_sec_100ths);
     else
     else
         printf("Rated: %llu.%1u Bps, %llu.%03u Mbps, %llu.%02u pps\n",
         printf("Rated: %llu.%1u Bps, %llu.%03u Mbps, %llu.%02u pps\n",
-               bytes_sec, bytes_sec_10ths, mb_sec, mb_sec_1000ths, pkts_sec, pkts_sec_100ths);
+               bytes_sec,
+               bytes_sec_10ths,
+               mb_sec,
+               mb_sec_1000ths,
+               pkts_sec,
+               pkts_sec_100ths);
     fflush(NULL);
     fflush(NULL);
-    
+
     if (stats->failed)
     if (stats->failed)
-        printf("Failed write attempts: " COUNTER_SPEC "\n",
-                stats->failed);
+        printf("Failed write attempts: " COUNTER_SPEC "\n", stats->failed);
 }
 }
 
 
 /**
 /**
@@ -265,7 +294,8 @@ packet_stats(const tcpreplay_stats_t *stats)
  * @param len: length of the buffer
  * @param len: length of the buffer
  * @return: string containing date, or -1 on error
  * @return: string containing date, or -1 on error
  */
  */
-int format_date_time(struct timeval *when, char *buf, size_t len)
+int
+format_date_time(struct timeval *when, char *buf, size_t len)
 {
 {
     struct tm *tm;
     struct tm *tm;
     char tmp[64];
     char tmp[64];
@@ -286,7 +316,7 @@ int format_date_time(struct timeval *when, char *buf, size_t len)
  * it just calls errx() since all errors are fatal.
  * it just calls errx() since all errors are fatal.
  */
  */
 int
 int
-read_hexstring(const char *l2string, u_char *hex, const int hexlen)
+read_hexstring(const char *l2string, u_char *hex, int hexlen)
 {
 {
     int numbytes = 0;
     int numbytes = 0;
     unsigned int value;
     unsigned int value;
@@ -306,10 +336,12 @@ read_hexstring(const char *l2string, u_char *hex, const int hexlen)
 
 
     /* get the first byte */
     /* get the first byte */
     l2byte = strtok_r(string, ",", &token);
     l2byte = strtok_r(string, ",", &token);
-    sscanf(l2byte, "%x", &value);
+    if (l2byte == NULL)
+        err(-1, "Hex buffer must contain something");
+    value = strtol(l2byte, NULL, 16);
     if (value > 0xff)
     if (value > 0xff)
         errx(-1, "Invalid hex string byte: %s", l2byte);
         errx(-1, "Invalid hex string byte: %s", l2byte);
-    databyte = (u_char) value;
+    databyte = (u_char)value;
     memcpy(&hex[numbytes], &databyte, 1);
     memcpy(&hex[numbytes], &databyte, 1);
 
 
     /* get remaining bytes */
     /* get remaining bytes */
@@ -319,10 +351,10 @@ read_hexstring(const char *l2string, u_char *hex, const int hexlen)
             warn("Hex buffer too small for data- skipping data");
             warn("Hex buffer too small for data- skipping data");
             goto done;
             goto done;
         }
         }
-        sscanf(l2byte, "%x", &value);
+        value = strtol(l2byte, NULL, 16);
         if (value > 0xff)
         if (value > 0xff)
             errx(-1, "Invalid hex string byte: %s", l2byte);
             errx(-1, "Invalid hex string byte: %s", l2byte);
-        databyte = (u_char) value;
+        databyte = (u_char)value;
         memcpy(&hex[numbytes], &databyte, 1);
         memcpy(&hex[numbytes], &databyte, 1);
     }
     }
 
 
@@ -345,8 +377,9 @@ inet_aton(const char *name, struct in_addr *addr)
 }
 }
 #endif
 #endif
 
 
-#if SIZEOF_LONG  == 4
-uint32_t __div64_32(uint64_t *n, uint32_t base)
+#if SIZEOF_LONG == 4
+uint32_t
+__div64_32(uint64_t *n, uint32_t base)
 {
 {
     uint64_t rem = *n;
     uint64_t rem = *n;
     uint64_t b = base;
     uint64_t b = base;
@@ -357,13 +390,13 @@ uint32_t __div64_32(uint64_t *n, uint32_t base)
     res = 0;
     res = 0;
     if (high >= base) {
     if (high >= base) {
         high /= base;
         high /= base;
-        res = (uint64_t) high << 32;
-        rem -= (uint64_t) (high*base) << 32;
+        res = (uint64_t)high << 32;
+        rem -= (uint64_t)(high * base) << 32;
     }
     }
 
 
     while ((int64_t)b > 0 && b < rem) {
     while ((int64_t)b > 0 && b < rem) {
-        b = b+b;
-        d = d+d;
+        b = b + b;
+        d = d + d;
     }
     }
 
 
     do {
     do {
@@ -387,28 +420,29 @@ uint32_t __div64_32(uint64_t *n, uint32_t base)
  * @param: seed
  * @param: seed
  * @return: random number
  * @return: random number
  */
  */
-uint32_t tcpr_random(uint32_t *seed)
+uint32_t
+tcpr_random(uint32_t *seed)
 {
 {
-  unsigned int next = *seed;
-  int result;
+    unsigned int next = *seed;
+    int result;
 
 
-  next *= 1103515245;
-  next += 12345;
-  result = (unsigned int) (next / 65536) % 2048;
+    next *= 1103515245;
+    next += 12345;
+    result = (int)(next / 65536) % 2048;
 
 
-  next *= 1103515245;
-  next += 12345;
-  result <<= 10;
-  result ^= (unsigned int) (next / 65536) % 1024;
+    next *= 1103515245;
+    next += 12345;
+    result <<= 10;
+    result ^= (int)(next / 65536) % 1024;
 
 
-  next *= 1103515245;
-  next += 12345;
-  result <<= 10;
-  result ^= (unsigned int) (next / 65536) % 1024;
+    next *= 1103515245;
+    next += 12345;
+    result <<= 10;
+    result ^= (int)(next / 65536) % 1024;
 
 
-  *seed = next;
+    *seed = next;
 
 
-  return result;
+    return result;
 }
 }
 
 
 /**
 /**
@@ -416,7 +450,8 @@ uint32_t tcpr_random(uint32_t *seed)
  * a program. BSD and Unix derivatives should utilize `FIONBIO` due to known
  * a program. BSD and Unix derivatives should utilize `FIONBIO` due to known
  * issues with reading from tty with a 0 byte read returning -1 opposed to 0.
  * issues with reading from tty with a 0 byte read returning -1 opposed to 0.
  */
  */
-void restore_stdin(void)
+void
+restore_stdin(void)
 {
 {
 #ifdef FIONBIO
 #ifdef FIONBIO
     int nb = 0;
     int nb = 0;

+ 46 - 47
src/common/utils.h

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,12 +18,10 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#pragma once
 
 
-#ifndef _UTILS_H_
-#define _UTILS_H_
-
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
 
 
 typedef struct {
 typedef struct {
@@ -44,34 +42,36 @@ typedef struct {
     COUNTER flows_invalid_packets;
     COUNTER flows_invalid_packets;
 } tcpreplay_stats_t;
 } tcpreplay_stats_t;
 
 
-
-int read_hexstring(const char *l2string, u_char *hex, const int hexlen);
+int read_hexstring(const char *l2string, u_char *hex, int hexlen);
 void packet_stats(const tcpreplay_stats_t *stats);
 void packet_stats(const tcpreplay_stats_t *stats);
 int format_date_time(struct timeval *when, char *buf, size_t len);
 int format_date_time(struct timeval *when, char *buf, size_t len);
 uint32_t tcpr_random(uint32_t *seed);
 uint32_t tcpr_random(uint32_t *seed);
 void restore_stdin(void);
 void restore_stdin(void);
 
 
 /* our "safe" implimentations of functions which allocate memory */
 /* our "safe" implimentations of functions which allocate memory */
-#define safe_malloc(x) _our_safe_malloc(x, __FUNCTION__, __LINE__, __FILE__)
-void *_our_safe_malloc(size_t len, const char *, const int, const char *);
+#define safe_malloc(x) our_safe_malloc(x, __FUNCTION__, __LINE__, __FILE__)
+void *our_safe_malloc(size_t len, const char *, int, const char *);
 
 
-#define safe_realloc(x, y) _our_safe_realloc(x, y, __FUNCTION__, __LINE__, __FILE__)
-void *_our_safe_realloc(void *ptr, size_t len, const char *, const int, const char *);
+#define safe_realloc(x, y) our_safe_realloc(x, y, __FUNCTION__, __LINE__, __FILE__)
+void *our_safe_realloc(void *ptr, size_t len, const char *, int, const char *);
 
 
-#define safe_strdup(x) _our_safe_strdup(x, __FUNCTION__, __LINE__, __FILE__)
-char *_our_safe_strdup(const char *str, const char *, const int, const char *);
+#define safe_strdup(x) our_safe_strdup(x, __FUNCTION__, __LINE__, __FILE__)
+char *our_safe_strdup(const char *str, const char *, int, const char *);
 
 
-#define safe_free(x) _our_safe_free(x, __FUNCTION__, __LINE__, __FILE__)
-void _our_safe_free(void *ptr, const char *, const int, const char *);
+#define safe_free(x) our_safe_free(x, __FUNCTION__, __LINE__, __FILE__)
+void our_safe_free(void *ptr, const char *, int, const char *);
 
 
-#define safe_pcap_next(x, y) _our_safe_pcap_next(x, y, __FUNCTION__, __LINE__, __FILE__)
-u_char *_our_safe_pcap_next(pcap_t *pcap,  struct pcap_pkthdr *pkthdr,
-        const char *funcname, const int line, const char *file);
+#define safe_pcap_next(x, y) our_safe_pcap_next(x, y, __FUNCTION__, __LINE__, __FILE__)
+u_char *
+our_safe_pcap_next(pcap_t *pcap, struct pcap_pkthdr *pkthdr, const char *funcname, int line, const char *file);
 
 
-#define safe_pcap_next_ex(x, y, z) _our_safe_pcap_next_ex(x, y, z, __FUNCTION__, __LINE__, __FILE__)
-int _our_safe_pcap_next_ex(pcap_t *pcap, struct pcap_pkthdr **pkthdr,
-        const u_char **pktdata, const char *funcname,
-        const int line, const char *file);
+#define safe_pcap_next_ex(x, y, z) our_safe_pcap_next_ex(x, y, z, __FUNCTION__, __LINE__, __FILE__)
+int our_safe_pcap_next_ex(pcap_t *pcap,
+                           struct pcap_pkthdr **pkthdr,
+                           const u_char **pktdata,
+                           const char *funcname,
+                           int line,
+                           const char *file);
 
 
 #define MAX_ARGS 128
 #define MAX_ARGS 128
 
 
@@ -81,29 +81,28 @@ int _our_safe_pcap_next_ex(pcap_t *pcap, struct pcap_pkthdr **pkthdr,
 int inet_aton(const char *name, struct in_addr *addr);
 int inet_aton(const char *name, struct in_addr *addr);
 #endif
 #endif
 
 
-#if SIZEOF_LONG  == 8
-# define do_div(n,base) ({          \
-    uint32_t __base = (base);       \
-    uint32_t __rem;           \
-    __rem = ((uint64_t)(n)) % __base;     \
-    (n) = ((uint64_t)(n)) / __base;       \
-    __rem;              \
-   })
-#elif SIZEOF_LONG  == 4
+#if SIZEOF_LONG == 8
+#define do_div(n, base)                                                                                                \
+    ({                                                                                                                 \
+        uint32_t __base = (base);                                                                                      \
+        uint32_t __rem;                                                                                                \
+        __rem = ((uint64_t)(n)) % __base;                                                                              \
+        (n) = ((uint64_t)(n)) / __base;                                                                                \
+        __rem;                                                                                                         \
+    })
+#elif SIZEOF_LONG == 4
 extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
 extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
-# define do_div(n,base) ({        \
-    uint32_t __base = (base);     \
-    uint32_t __rem;         \
-    if (((n) >> 32) == 0) {     \
-        __rem = (uint32_t)(n) % __base;   \
-        (n) = (uint32_t)(n) / __base;   \
-    } else            \
-        __rem = __div64_32(&(n), __base);  \
-    __rem;            \
-   })
+#define do_div(n, base)                                                                                                \
+    ({                                                                                                                 \
+        uint32_t __base = (base);                                                                                      \
+        uint32_t __rem;                                                                                                \
+        if (((n) >> 32) == 0) {                                                                                        \
+            __rem = (uint32_t)(n) % __base;                                                                            \
+            (n) = (uint32_t)(n) / __base;                                                                              \
+        } else                                                                                                         \
+            __rem = __div64_32(&(n), __base);                                                                          \
+        __rem;                                                                                                         \
+    })
 #else /* SIZEOF_LONG == ?? */
 #else /* SIZEOF_LONG == ?? */
-# error do_div() does not yet support the C64
+#error do_div() does not yet support the C64
 #endif /* SIZEOF_LONG  */
 #endif /* SIZEOF_LONG  */
-
-#endif /* _UTILS_H_ */
-

+ 56 - 82
src/common/xX.c

@@ -4,9 +4,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -19,17 +19,15 @@
  */
  */
 
 
 /*
 /*
- * xX stands for "include or exclude" which is used with the 
+ * xX stands for "include or exclude" which is used with the
  * -x and -X flags
  * -x and -X flags
  *
  *
  * Functions for use to process args for or check data against in
  * Functions for use to process args for or check data against in
  * tcpreplay/do_packets and tcpprep.
  * tcpreplay/do_packets and tcpprep.
  */
  */
 
 
-#include <stdlib.h>
-
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
 #include <stdlib.h>
 #include <stdlib.h>
 
 
@@ -40,52 +38,52 @@
 int
 int
 parse_xX_str(tcpr_xX_t *xX, char *str, tcpr_bpf_t *bpf)
 parse_xX_str(tcpr_xX_t *xX, char *str, tcpr_bpf_t *bpf)
 {
 {
-    int out = 0;
+    int out;
 
 
     dbgx(1, "Parsing string: %s", str);
     dbgx(1, "Parsing string: %s", str);
     dbgx(1, "Switching on: %c", str[0]);
     dbgx(1, "Switching on: %c", str[0]);
 
 
     switch (str[0]) {
     switch (str[0]) {
-    case 'B':                  /* both ip's */
+    case 'B': /* both ip's */
         str = str + 2;
         str = str + 2;
         out = xXBoth;
         out = xXBoth;
         if (!parse_cidr(&(xX->cidr), str, ","))
         if (!parse_cidr(&(xX->cidr), str, ","))
             return xXError;
             return xXError;
         break;
         break;
 
 
-    case 'D':                  /* dst ip */
+    case 'D': /* dst ip */
         str = str + 2;
         str = str + 2;
         out = xXDest;
         out = xXDest;
         if (!parse_cidr(&(xX->cidr), str, ","))
         if (!parse_cidr(&(xX->cidr), str, ","))
             return xXError;
             return xXError;
         break;
         break;
 
 
-    case 'E':                  /* either ip */
+    case 'E': /* either ip */
         str = str + 2;
         str = str + 2;
         out = xXEither;
         out = xXEither;
         if (!parse_cidr(&(xX->cidr), str, ","))
         if (!parse_cidr(&(xX->cidr), str, ","))
             return xXError;
             return xXError;
         break;
         break;
-        
-    case 'F':                  /* bpf filter */
+
+    case 'F': /* bpf filter */
         str = str + 2;
         str = str + 2;
         out = xXBPF;
         out = xXBPF;
         bpf->filter = safe_strdup(str);
         bpf->filter = safe_strdup(str);
-        /* 
+        /*
          * note: it's temping to compile the BPF here, but we don't
          * note: it's temping to compile the BPF here, but we don't
-         * yet know what the link type is for the file, so we have 
+         * yet know what the link type is for the file, so we have
          * to compile the BPF once we open the pcap file
          * to compile the BPF once we open the pcap file
          */
          */
         break;
         break;
-        
-    case 'P':                  /* packet id */
+
+    case 'P': /* packet id */
         str = str + 2;
         str = str + 2;
         out = xXPacket;
         out = xXPacket;
         if (!parse_list(&(xX->list), str))
         if (!parse_list(&(xX->list), str))
             return xXError;
             return xXError;
         break;
         break;
 
 
-    case 'S':                  /* source ip */
+    case 'S': /* source ip */
         str = str + 2;
         str = str + 2;
         out = xXSource;
         out = xXSource;
         if (!parse_cidr(&(xX->cidr), str, ","))
         if (!parse_cidr(&(xX->cidr), str, ","))
@@ -94,13 +92,13 @@ parse_xX_str(tcpr_xX_t *xX, char *str, tcpr_bpf_t *bpf)
 
 
     default:
     default:
         errx(-1, "Invalid -%c option: %c", xX->mode, *str);
         errx(-1, "Invalid -%c option: %c", xX->mode, *str);
-        break;
     }
     }
 
 
-    if (xX->mode == 'X') {          /* run in exclude mode */
+    if (xX->mode == 'X') { /* run in exclude mode */
         out += xXExclude;
         out += xXExclude;
         if (bpf->filter != NULL)
         if (bpf->filter != NULL)
-            err(-1, "Using a BPF filter with -X doesn't work.\n"
+            err(-1,
+                "Using a BPF filter with -X doesn't work.\n"
                 "Try using -xF:\"not <filter>\" instead");
                 "Try using -xF:\"not <filter>\" instead");
     }
     }
 
 
@@ -108,78 +106,66 @@ parse_xX_str(tcpr_xX_t *xX, char *str, tcpr_bpf_t *bpf)
     return xX->mode;
     return xX->mode;
 }
 }
 
 
-
-
 /**
 /**
  * compare the source/destination IP address according to the mode
  * compare the source/destination IP address according to the mode
  * and return 1 if we should send the packet or 0 if not
  * and return 1 if we should send the packet or 0 if not
  */
  */
 int
 int
-process_xX_by_cidr_ipv4(int mode, tcpr_cidr_t * cidr, ipv4_hdr_t * ip_hdr)
+process_xX_by_cidr_ipv4(int mode, tcpr_cidr_t *cidr, ipv4_hdr_t *ip_hdr)
 {
 {
-
     if (mode & xXExclude) {
     if (mode & xXExclude) {
         /* Exclude mode */
         /* Exclude mode */
         switch (mode ^ xXExclude) {
         switch (mode ^ xXExclude) {
         case xXSource:
         case xXSource:
-            /* note: check_ip_cidr() returns TCPR_DIR_C2S for true, TCPR_DIR_S2C for false 
+            /* note: check_ip_cidr() returns TCPR_DIR_C2S for true, TCPR_DIR_S2C for false
              * and NOT true/false or 1/0, etc!
              * and NOT true/false or 1/0, etc!
              */
              */
             return check_ip_cidr(cidr, ip_hdr->ip_src.s_addr) ? DONT_SEND : SEND;
             return check_ip_cidr(cidr, ip_hdr->ip_src.s_addr) ? DONT_SEND : SEND;
-            break;
-
         case xXDest:
         case xXDest:
-            return check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr)  ? DONT_SEND : SEND;
+            return check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr) ? DONT_SEND : SEND;
 
 
         case xXBoth:
         case xXBoth:
-            return (check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr)  &&
-                    check_ip_cidr(cidr, ip_hdr->ip_src.s_addr) ) ? DONT_SEND : SEND;
-            break;
-
+            return (check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr) && check_ip_cidr(cidr, ip_hdr->ip_src.s_addr))
+                           ? DONT_SEND
+                           : SEND;
         case xXEither:
         case xXEither:
-            return (check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr)  ||
-                    check_ip_cidr(cidr, ip_hdr->ip_src.s_addr) ) ? DONT_SEND : SEND;
-            break;
+            return (check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr) || check_ip_cidr(cidr, ip_hdr->ip_src.s_addr))
+                           ? DONT_SEND
+                           : SEND;
         }
         }
-    }
-    else {
+    } else {
         /* Include Mode */
         /* Include Mode */
         switch (mode) {
         switch (mode) {
         case xXSource:
         case xXSource:
-            return check_ip_cidr(cidr, ip_hdr->ip_src.s_addr)  ? SEND : DONT_SEND;
-            break;
-
+            return check_ip_cidr(cidr, ip_hdr->ip_src.s_addr) ? SEND : DONT_SEND;
         case xXDest:
         case xXDest:
-            return check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr)  ? SEND : DONT_SEND;
-            break;
-
+            return check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr) ? SEND : DONT_SEND;
         case xXBoth:
         case xXBoth:
-            return (check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr)  &&
-                    check_ip_cidr(cidr, ip_hdr->ip_src.s_addr) ) ? SEND : DONT_SEND;
-            break;
-
+            return (check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr) && check_ip_cidr(cidr, ip_hdr->ip_src.s_addr))
+                           ? SEND
+                           : DONT_SEND;
         case xXEither:
         case xXEither:
-            return (check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr)  ||
-                    check_ip_cidr(cidr, ip_hdr->ip_src.s_addr) ) ? SEND : DONT_SEND;
-            break;
+            return (check_ip_cidr(cidr, ip_hdr->ip_dst.s_addr) || check_ip_cidr(cidr, ip_hdr->ip_src.s_addr))
+                           ? SEND
+                           : DONT_SEND;
+        default:
+            assert(false);
         }
         }
     }
     }
 
 
     /* total failure */
     /* total failure */
-    if (mode &xXExclude) {
+    if (mode & xXExclude) {
         warn("Unable to determine action in CIDR filter mode.  Default: Don't Send.");
         warn("Unable to determine action in CIDR filter mode.  Default: Don't Send.");
         return DONT_SEND;
         return DONT_SEND;
     } else {
     } else {
         warn("Unable to determine action in CIDR filter mode.  Default: Send.");
         warn("Unable to determine action in CIDR filter mode.  Default: Send.");
         return SEND;
         return SEND;
     }
     }
-
 }
 }
 
 
 int
 int
-process_xX_by_cidr_ipv6(int mode, tcpr_cidr_t * cidr, ipv6_hdr_t * ip6_hdr)
+process_xX_by_cidr_ipv6(int mode, tcpr_cidr_t *cidr, ipv6_hdr_t *ip6_hdr)
 {
 {
-
     if (mode & xXExclude) {
     if (mode & xXExclude) {
         /* Exclude mode */
         /* Exclude mode */
         switch (mode ^ xXExclude) {
         switch (mode ^ xXExclude) {
@@ -188,52 +174,40 @@ process_xX_by_cidr_ipv6(int mode, tcpr_cidr_t * cidr, ipv6_hdr_t * ip6_hdr)
              * and NOT true/false or 1/0, etc!
              * and NOT true/false or 1/0, etc!
              */
              */
             return check_ip6_cidr(cidr, &ip6_hdr->ip_src) ? DONT_SEND : SEND;
             return check_ip6_cidr(cidr, &ip6_hdr->ip_src) ? DONT_SEND : SEND;
-            break;
-
         case xXDest:
         case xXDest:
-            return check_ip6_cidr(cidr, &ip6_hdr->ip_dst)  ? DONT_SEND : SEND;
+            return check_ip6_cidr(cidr, &ip6_hdr->ip_dst) ? DONT_SEND : SEND;
 
 
         case xXBoth:
         case xXBoth:
-            return (check_ip6_cidr(cidr, &ip6_hdr->ip_dst)  &&
-                    check_ip6_cidr(cidr, &ip6_hdr->ip_src) ) ? DONT_SEND : SEND;
-            break;
-
+            return (check_ip6_cidr(cidr, &ip6_hdr->ip_dst) && check_ip6_cidr(cidr, &ip6_hdr->ip_src)) ? DONT_SEND
+                                                                                                      : SEND;
         case xXEither:
         case xXEither:
-            return (check_ip6_cidr(cidr, &ip6_hdr->ip_dst)  ||
-                    check_ip6_cidr(cidr, &ip6_hdr->ip_src) ) ? DONT_SEND : SEND;
-            break;
+            return (check_ip6_cidr(cidr, &ip6_hdr->ip_dst) || check_ip6_cidr(cidr, &ip6_hdr->ip_src)) ? DONT_SEND
+                                                                                                      : SEND;
         }
         }
-    }
-    else {
+    } else {
         /* Include Mode */
         /* Include Mode */
         switch (mode) {
         switch (mode) {
         case xXSource:
         case xXSource:
-            return check_ip6_cidr(cidr, &ip6_hdr->ip_src)  ? SEND : DONT_SEND;
-            break;
-
+            return check_ip6_cidr(cidr, &ip6_hdr->ip_src) ? SEND : DONT_SEND;
         case xXDest:
         case xXDest:
-            return check_ip6_cidr(cidr, &ip6_hdr->ip_dst)  ? SEND : DONT_SEND;
-            break;
-
+            return check_ip6_cidr(cidr, &ip6_hdr->ip_dst) ? SEND : DONT_SEND;
         case xXBoth:
         case xXBoth:
-            return (check_ip6_cidr(cidr, &ip6_hdr->ip_dst)  &&
-                    check_ip6_cidr(cidr, &ip6_hdr->ip_src) ) ? SEND : DONT_SEND;
-            break;
-
+            return (check_ip6_cidr(cidr, &ip6_hdr->ip_dst) && check_ip6_cidr(cidr, &ip6_hdr->ip_src)) ? SEND
+                                                                                                      : DONT_SEND;
         case xXEither:
         case xXEither:
-            return (check_ip6_cidr(cidr, &ip6_hdr->ip_dst)  ||
-                    check_ip6_cidr(cidr, &ip6_hdr->ip_src) ) ? SEND : DONT_SEND;
-            break;
+            return (check_ip6_cidr(cidr, &ip6_hdr->ip_dst) || check_ip6_cidr(cidr, &ip6_hdr->ip_src)) ? SEND
+                                                                                                      : DONT_SEND;
+        default:
+            assert(false);
         }
         }
     }
     }
 
 
     /* total failure */
     /* total failure */
-    if (mode &xXExclude) {
+    if (mode & xXExclude) {
         warn("Unable to determine action in CIDR filter mode.  Default: Don't Send.");
         warn("Unable to determine action in CIDR filter mode.  Default: Don't Send.");
         return DONT_SEND;
         return DONT_SEND;
     } else {
     } else {
         warn("Unable to determine action in CIDR filter mode.  Default: Send.");
         warn("Unable to determine action in CIDR filter mode.  Default: Send.");
         return SEND;
         return SEND;
     }
     }
-
 }
 }

+ 1 - 5
src/common/xX.h

@@ -18,8 +18,7 @@
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef __xX_H__
-#define __xX_H__
+#pragma once
 
 
 /*
 /*
  * Functions for processing args/data generated by -x and -X
  * Functions for processing args/data generated by -x and -X
@@ -40,6 +39,3 @@ int process_xX_by_cidr_ipv6(int, tcpr_cidr_t *, ipv6_hdr_t *);
 #define xXPacket 16
 #define xXPacket 16
 #define xXBPF 32
 #define xXBPF 32
 #define xXExclude 128           /* if exclude mode, add 128 to above value */
 #define xXExclude 128           /* if exclude mode, add 128 to above value */
-
-
-#endif

+ 128 - 142
src/defines.h

@@ -1,5 +1,4 @@
-#ifndef __DEFINES_H__
-#define __DEFINES_H__
+#pragma once
 
 
 #include "config.h"
 #include "config.h"
 
 
@@ -50,15 +49,15 @@
 #endif
 #endif
 
 
 #if defined INCLUDE_PCAP_BPF_H_FILE && !defined PCAP_DONT_INCLUDE_PCAP_BPF_H
 #if defined INCLUDE_PCAP_BPF_H_FILE && !defined PCAP_DONT_INCLUDE_PCAP_BPF_H
-#include "@INCLUDE_PCAP_BPF_HEADER@"
+#include <@INCLUDE_PCAP_BPF_HEADER@>
 #define PCAP_DONT_INCLUDE_PCAP_BPF_H 1 /* don't re-include it in pcap.h */
 #define PCAP_DONT_INCLUDE_PCAP_BPF_H 1 /* don't re-include it in pcap.h */
 #endif
 #endif
 
 
-#include "/Applications/Xcode_14.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pcap.h"
+#include </usr/include/pcap.h>
 
 
 /* include our own strlcat/strlcpy? */
 /* include our own strlcat/strlcpy? */
 #ifndef HAVE_STRLCPY
 #ifndef HAVE_STRLCPY
-#include "lib/strlcpy.h"
+#include <lib/strlcpy.h>
 #endif
 #endif
 
 
 /*
 /*
@@ -68,7 +67,7 @@
  * The result is that I stole the DLT types from pcap-bpf.h and
  * The result is that I stole the DLT types from pcap-bpf.h and
  * put them in here.
  * put them in here.
  */
  */
-#include "common/dlt_names.h"
+#include <common/dlt_names.h>
 
 
 #ifdef HAVE_BOOL_H
 #ifdef HAVE_BOOL_H
 #include <bool.h>
 #include <bool.h>
@@ -89,8 +88,8 @@
 #endif
 #endif
 #define COUNTER_OVERFLOW_RISK (((COUNTER)~0) >> 20)
 #define COUNTER_OVERFLOW_RISK (((COUNTER)~0) >> 20)
 
 
-#include "common/list.h"
-#include "common/cidr.h"
+#include <common/cidr.h>
+#include <common/list.h>
 
 
 
 
 typedef struct tcpr_ipv4_hdr ipv4_hdr_t;
 typedef struct tcpr_ipv4_hdr ipv4_hdr_t;
@@ -136,85 +135,75 @@ typedef struct tcpr_speed_s {
     /* speed modifiers */
     /* speed modifiers */
     int mode;
     int mode;
 #define SPEED_MULTIPLIER 1
 #define SPEED_MULTIPLIER 1
-#define SPEED_MBPSRATE   2
+#define SPEED_MBPSRATE 2
 #define SPEED_PACKETRATE 3
 #define SPEED_PACKETRATE 3
-#define SPEED_TOPSPEED   4
+#define SPEED_TOPSPEED 4
 #define SPEED_ONEATATIME 5
 #define SPEED_ONEATATIME 5
     COUNTER speed;
     COUNTER speed;
     float multiplier;
     float multiplier;
     int pps_multi;
     int pps_multi;
 } tcpr_speed_t;
 } tcpr_speed_t;
 
 
-#define MAX_FILES   1024        /* Max number of files we can pass to tcpreplay */
+#define MAX_FILES 1024 /* Max number of files we can pass to tcpreplay */
 
 
-#define DEFAULT_MTU 1500        /* Max Transmission Unit of standard ethernet
-                                 * don't forget *frames* are MTU + L2 header!
-                                 */
+/* Max Transmission Unit of standard ethernet  don't forget *frames* are MTU + L2 header! */
+#define DEFAULT_MTU 1500
 
 
-#define MAX_SNAPLEN 262144      /* tell libpcap to capture the entire packet
-                                 * this is the maximum size supported by libpcap
-                                 * (https://github.com/the-tcpdump-group/libpcap/blob/master/pcap-int.h#L99-L125)
-                                 */
+/* tell libpcap to capture the entire packet
+ * this is the maximum size supported by libpcap
+ * (https://github.com/the-tcpdump-group/libpcap/blob/master/pcap-int.h#L99-L125)
+ */
+#define MAX_SNAPLEN 262144
 
 
-#define MAXPACKET (MAX_SNAPLEN + 22)    /* snap length plus some room for adding a 
-                                         * couple VLAN headers or a L2 header
-                                         */
+/* snap length plus some room for adding a
+ * couple VLAN headers or a L2 header
+ */
+#define MAXPACKET (MAX_SNAPLEN + 22)
 
 
-#define PACKET_HEADROOM 512     /* additional headroom allocated for packets to accommodate editing */
+#define PACKET_HEADROOM 512 /* additional headroom allocated for packets to accommodate editing */
 
 
 #define DNS_RESOLVE 1
 #define DNS_RESOLVE 1
 #define DNS_DONT_RESOLVE 0
 #define DNS_DONT_RESOLVE 0
 
 
-#define RESOLVE 0               /* disable dns lookups */
-#define BPF_OPTIMIZE 1          /* default is to optimize bpf program */
-#define PCAP_TIMEOUT 100        /* 100ms pcap_open_live timeout */
+#define RESOLVE 0        /* disable dns lookups */
+#define BPF_OPTIMIZE 1   /* default is to optimize bpf program */
+#define PCAP_TIMEOUT 100 /* 100ms pcap_open_live timeout */
 
 
 #define DEFAULT_FUZZ_FACTOR 8
 #define DEFAULT_FUZZ_FACTOR 8
 
 
 /* HP-UX already defines TRUE/FALSE */
 /* HP-UX already defines TRUE/FALSE */
 #ifndef TRUE
 #ifndef TRUE
-typedef enum bool_e {
-    FALSE = 0,
-    TRUE
-} bool_t;
+typedef enum bool_e { FALSE = 0, TRUE } bool_t;
 #endif
 #endif
 
 
-#define EBUF_SIZE 1024           /* size of our error buffers */
-#define MAC_SIZE  7             /* size of the mac[] buffer */
+#define EBUF_SIZE 1024 /* size of our error buffers */
+#define MAC_SIZE 7     /* size of the mac[] buffer */
 
 
-typedef enum pad_e {
-    PAD_PACKET,
-    TRUNC_PACKET
-} pad_t;
+typedef enum pad_e { PAD_PACKET, TRUNC_PACKET } pad_t;
 
 
 #define DNS_QUERY_FLAG 0x8000
 #define DNS_QUERY_FLAG 0x8000
 
 
-typedef enum direction_e {
-    DIR_UNKNOWN = -1,
-    DIR_CLIENT  = 0,
-    DIR_SERVER  = 1,
-    DIR_ANY     = 2
-} direction_t;
+typedef enum direction_e { DIR_UNKNOWN = -1, DIR_CLIENT = 0, DIR_SERVER = 1, DIR_ANY = 2 } direction_t;
 
 
 typedef enum tcpprep_mode_e {
 typedef enum tcpprep_mode_e {
-    ERROR_MODE,     /* Some kind of error has occurred */
-    CIDR_MODE,      /* single pass, CIDR netblock */
-    REGEX_MODE,     /* single pass, regex */
-    PORT_MODE,      /* single pass, use src/dst ports to split */
-    MAC_MODE,       /* single pass, use src mac to split */
-    FIRST_MODE,     /* single pass, use first seen to split */
-    AUTO_MODE,      /* first pass through in auto mode */
-    ROUTER_MODE,    /* second pass through in router mode */
-    BRIDGE_MODE,    /* second pass through in bridge mode */
-    SERVER_MODE,    /* second pass through in server (router) mode */
-    CLIENT_MODE     /* second pass through in client (router) mode */
+    ERROR_MODE,  /* Some kind of error has occurred */
+    CIDR_MODE,   /* single pass, CIDR netblock */
+    REGEX_MODE,  /* single pass, regex */
+    PORT_MODE,   /* single pass, use src/dst ports to split */
+    MAC_MODE,    /* single pass, use src mac to split */
+    FIRST_MODE,  /* single pass, use first seen to split */
+    AUTO_MODE,   /* first pass through in auto mode */
+    ROUTER_MODE, /* second pass through in router mode */
+    BRIDGE_MODE, /* second pass through in bridge mode */
+    SERVER_MODE, /* second pass through in server (router) mode */
+    CLIENT_MODE  /* second pass through in client (router) mode */
 } tcpprep_mode_t;
 } tcpprep_mode_t;
 
 
-#define BROADCAST_MAC           "\xff\xff\xff\xff\xff\xff"
-#define IPV4_MULTICAST_MAC      "\x01\x00\x5e\x00\x00\x00"
-#define IPV6_MULTICAST_MAC      "\x33\x33\x00\x00\x00\x00"
-#define IPV4_VRRP               "\x00\x00\x50\x00\x01\x00"
-#define IPV6_VRRP               "\x00\x00\x50\x00\x02\x00"
+#define BROADCAST_MAC "\xff\xff\xff\xff\xff\xff"
+#define IPV4_MULTICAST_MAC "\x01\x00\x5e\x00\x00\x00"
+#define IPV6_MULTICAST_MAC "\x33\x33\x00\x00\x00\x00"
+#define IPV4_VRRP "\x00\x00\x50\x00\x01\x00"
+#define IPV6_VRRP "\x00\x00\x50\x00\x02\x00"
 
 
 /* MAC macros for printf */
 /* MAC macros for printf */
 #define MAC_FORMAT "%02X:%02X:%02X:%02X:%02X:%02X"
 #define MAC_FORMAT "%02X:%02X:%02X:%02X:%02X:%02X"
@@ -231,13 +220,11 @@ typedef enum tcpprep_mode_e {
 
 
 /* force a word or half-word swap on both Big and Little endian systems */
 /* force a word or half-word swap on both Big and Little endian systems */
 #ifndef SWAPLONG
 #ifndef SWAPLONG
-#define SWAPLONG(y) \
-((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
+#define SWAPLONG(y) ((((y)&0xff) << 24) | (((y)&0xff00) << 8) | (((y)&0xff0000) >> 8) | (((y) >> 24) & 0xff))
 #endif
 #endif
 
 
 #ifndef SWAPSHORT
 #ifndef SWAPSHORT
-#define SWAPSHORT(y) \
-( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )
+#define SWAPSHORT(y) ((((y)&0xff) << 8) | ((u_short)((y)&0xff00) >> 8))
 #endif
 #endif
 
 
 /* converts a 64bit int to network byte order */
 /* converts a 64bit int to network byte order */
@@ -248,21 +235,20 @@ typedef enum tcpprep_mode_e {
 #define htonll(x) (x)
 #define htonll(x) (x)
 #else
 #else
 /* stolen from http://www.codeproject.com/cpp/endianness.asp */
 /* stolen from http://www.codeproject.com/cpp/endianness.asp */
-#define ntohll(x) (((u_int64_t)(ntohl((int)((x << 32) >> 32))) << 32) | \
-                     (unsigned int)ntohl(((int)(x >> 32))))
+#define ntohll(x) (((u_int64_t)(ntohl((int)((x << 32) >> 32))) << 32) | (unsigned int)ntohl(((int)(x >> 32))))
 #define htonll(x) ntohll(x)
 #define htonll(x) ntohll(x)
 #endif /* WORDS_BIGENDIAN */
 #endif /* WORDS_BIGENDIAN */
 #endif /* HAVE_NTOHLL */
 #endif /* HAVE_NTOHLL */
 #endif /* !ntohll && !htonll */
 #endif /* !ntohll && !htonll */
 
 
-#define DEBUG_INFO   1          /* informational only, lessthan 1 line per packet */
-#define DEBUG_BASIC  2          /* limited debugging, one line per packet */
-#define DEBUG_DETAIL 3          /* more detailed, a few lines per packet */
-#define DEBUG_MORE   4          /* even more detail */
-#define DEBUG_CODE   5          /* examines code & values, many lines per packet */
+#define DEBUG_INFO 1   /* informational only, lessthan 1 line per packet */
+#define DEBUG_BASIC 2  /* limited debugging, one line per packet */
+#define DEBUG_DETAIL 3 /* more detailed, a few lines per packet */
+#define DEBUG_MORE 4   /* even more detail */
+#define DEBUG_CODE 5   /* examines code & values, many lines per packet */
 
 
 #if defined HAVE_IOPERM && defined __i386_
 #if defined HAVE_IOPERM && defined __i386_
-    #define HAVE_IOPORT_SLEEP
+#define HAVE_IOPORT_SLEEP
 #endif
 #endif
 
 
 /* Win32 doesn't know about PF_INET6 */
 /* Win32 doesn't know about PF_INET6 */
@@ -278,112 +264,112 @@ typedef enum tcpprep_mode_e {
 #define IPV6_EXTLEN_TO_BYTES(x) ((x * 4) + 8)
 #define IPV6_EXTLEN_TO_BYTES(x) ((x * 4) + 8)
 
 
 #ifndef HAVE_UINT8_T
 #ifndef HAVE_UINT8_T
-typedef u_int8_t uint8_t
-typedef u_int16_t uint16_t
-typedef u_int32_t uint32_t
+typedef u_int8_t uint8_t typedef u_int16_t uint16_t typedef u_int32_t uint32_t
 #endif
 #endif
 
 
 /* Support for flexible arrays. */
 /* Support for flexible arrays. */
 #undef __flexarr
 #undef __flexarr
 #if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97))
 #if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97))
 /* GCC 2.97 supports C99 flexible array members.  */
 /* GCC 2.97 supports C99 flexible array members.  */
-# define __flexarr      []
+#define __flexarr []
 #else
 #else
-# ifdef __GNUC__
-#  define __flexarr     [0]
-# else
-#  if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-#   define __flexarr    []
-#  elif defined(_WIN32)
+#ifdef __GNUC__
+#define __flexarr [0]
+#else
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#define __flexarr []
+#elif defined(_WIN32)
 /* MS VC++ */
 /* MS VC++ */
-#   define __flexarr    []
-#  else
+#define __flexarr []
+#else
 /* Some other non-C99 compiler. Approximate with [1]. */
 /* Some other non-C99 compiler. Approximate with [1]. */
-#   define __flexarr    [1]
-#  endif
-# endif
+#define __flexarr [1]
+#endif
+#endif
 #endif
 #endif
 
 
 
 
 /* Time converters */
 /* Time converters */
 #define SEC_TO_MILLISEC(x) (x * 1000)
 #define SEC_TO_MILLISEC(x) (x * 1000)
 #define SEC_TO_MICROSEC(x) (x * 1000000)
 #define SEC_TO_MICROSEC(x) (x * 1000000)
-#define SEC_TO_NANOSEC(x)  ((u_int64_t)x * 1000000000)
+#define SEC_TO_NANOSEC(x) ((u_int64_t)x * 1000000000)
 
 
 #define MILLISEC_TO_SEC(x) (x / 1000)
 #define MILLISEC_TO_SEC(x) (x / 1000)
 #define MICROSEC_TO_SEC(x) (x / 1000000)
 #define MICROSEC_TO_SEC(x) (x / 1000000)
-#define NANOSEC_TO_SEC(x)  ((u_int64_t)x / 1000000000)
+#define NANOSEC_TO_SEC(x) ((u_int64_t)x / 1000000000)
 
 
-#define TIMEVAL_TO_MILLISEC(x)  (((x)->tv_sec * 1000) + ((x)->tv_usec / 1000))
-#define TIMEVAL_TO_MICROSEC(x)  (((x)->tv_sec * 1000000) + (x)->tv_usec)
-#define TIMEVAL_TO_NANOSEC(x)   ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_usec * 1000))
+#define TIMEVAL_TO_MILLISEC(x) (((x)->tv_sec * 1000) + ((x)->tv_usec / 1000))
+#define TIMEVAL_TO_MICROSEC(x) (((x)->tv_sec * 1000000) + (x)->tv_usec)
+#define TIMEVAL_TO_NANOSEC(x) ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_usec * 1000))
 #define TIMSTAMP_TO_MICROSEC(x) (TIMEVAL_TO_MICROSEC(x))
 #define TIMSTAMP_TO_MICROSEC(x) (TIMEVAL_TO_MICROSEC(x))
 
 
-#define MILLISEC_TO_TIMEVAL(x, tv)          \
-    do {                                    \
-        (tv)->tv_sec = (x) / 1000;          \
-        (tv)->tv_usec = (x * 1000) - ((tv)->tv_sec * 1000000);   \
-    } while(0)
-
-#define MICROSEC_TO_TIMEVAL(x, tv)          \
-    do {                                    \
-        (tv)->tv_sec = (x) / 1000000;       \
-        (tv)->tv_usec = (x) - ((tv)->tv_sec * 1000000);   \
-    } while(0)
-
-#define NANOSEC_TO_TIMEVAL(x, tv)           \
-    do {                                    \
-        (tv)->tv_sec =  (x) / 1000000000;   \
-        (tv)->tv_usec = ((x) % 1000000000) / 1000;   \
-    } while(0)
-
-#define NANOSEC_TO_TIMESPEC(x, ts)          \
-    do {                                    \
-        (ts)->tv_sec = (x) / 1000000000;    \
-        (ts)->tv_nsec = (x) % 1000000000;   \
-    } while(0)
-
-#define TIMESPEC_TO_MILLISEC(x)  (((x)->tv_sec * 1000) + ((x)->tv_nsec / 1000000))
-#define TIMESPEC_TO_MICROSEC(x)  (((x)->tv_sec * 1000000) + (x)->tv_nsec / 1000)
+#define MILLISEC_TO_TIMEVAL(x, tv)                                                                                     \
+    do {                                                                                                               \
+        (tv)->tv_sec = (x) / 1000;                                                                                     \
+        (tv)->tv_usec = (x * 1000) - ((tv)->tv_sec * 1000000);                                                         \
+    } while (0)
+
+#define MICROSEC_TO_TIMEVAL(x, tv)                                                                                     \
+    do {                                                                                                               \
+        (tv)->tv_sec = (x) / 1000000;                                                                                  \
+        (tv)->tv_usec = (x) - ((tv)->tv_sec * 1000000);                                                                \
+    } while (0)
+
+#define NANOSEC_TO_TIMEVAL(x, tv)                                                                                      \
+    do {                                                                                                               \
+        (tv)->tv_sec = (x) / 1000000000;                                                                               \
+        (tv)->tv_usec = ((x) % 1000000000) / 1000;                                                                     \
+    } while (0)
+
+#define NANOSEC_TO_TIMESPEC(x, ts)                                                                                     \
+    do {                                                                                                               \
+        (ts)->tv_sec = (x) / 1000000000;                                                                               \
+        (ts)->tv_nsec = (x) % 1000000000;                                                                              \
+    } while (0)
+
+#define TIMESPEC_TO_MILLISEC(x) (((x)->tv_sec * 1000) + ((x)->tv_nsec / 1000000))
+#define TIMESPEC_TO_MICROSEC(x) (((x)->tv_sec * 1000000) + (x)->tv_nsec / 1000)
 #define TIMESPEC_TO_NANOSEC(x) ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_nsec))
 #define TIMESPEC_TO_NANOSEC(x) ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_nsec))
 
 
-#define TIMEVAL_SET(a, b)                  \
-    do {                                    \
-        (a)->tv_sec = (b)->tv_sec;          \
-        (a)->tv_usec = (b)->tv_usec;        \
-    } while(0)
+#define TIMEVAL_SET(a, b)                                                                                              \
+    do {                                                                                                               \
+        (a)->tv_sec = (b)->tv_sec;                                                                                     \
+        (a)->tv_usec = (b)->tv_usec;                                                                                   \
+    } while (0)
 
 
-#define TIMESPEC_SET(a, b)                 \
-    do {                                    \
-        (a)->tv_sec = (b)->tv_sec;          \
-        (a)->tv_nsec = (b)->tv_nsec;        \
-    } while(0)
+#define TIMESPEC_SET(a, b)                                                                                             \
+    do {                                                                                                               \
+        (a)->tv_sec = (b)->tv_sec;                                                                                     \
+        (a)->tv_nsec = (b)->tv_nsec;                                                                                   \
+    } while (0)
 
 
 /* 
 /* 
  * Help suppress some compiler warnings
  * Help suppress some compiler warnings
  * No problem if variable is actually used 
  * No problem if variable is actually used 
 */
 */
-#ifdef UNUSED 
-#elif defined(__GNUC__) 
-# define UNUSED(x) x __attribute__((unused))
-#elif defined(__LCLINT__) 
-# define UNUSED(x) /*@unused@*/ x 
-#else 
-# define UNUSED(x) x 
+#ifdef UNUSED
+#elif defined(__GNUC__)
+#define UNUSED(x) x __attribute__((unused))
+#elif defined(__LCLINT__)
+#define UNUSED(x) /*@unused@*/ x
+#else
+#define UNUSED(x) x
 #endif
 #endif
 
 
 #ifndef max
 #ifndef max
-#  define max(a,b) \
-       ({ __typeof__ (a) _a = (a); \
-           __typeof__ (b) _b = (b); \
-       _a > _b ? _a : _b; })
+#define max(a, b)                                                                                                      \
+    ({                                                                                                                 \
+        __typeof__(a) _a = (a);                                                                                        \
+        __typeof__(b) _b = (b);                                                                                        \
+        _a > _b ? _a : _b;                                                                                             \
+    })
 #endif
 #endif
 
 
 #ifndef min
 #ifndef min
-#  define min(a,b) \
-       ({ __typeof__ (a) _a = (a); \
-           __typeof__ (b) _b = (b); \
-       _a > _b ? _b : _a; })
+#define min(a, b)                                                                                                      \
+    ({                                                                                                                 \
+        __typeof__(a) _a = (a);                                                                                        \
+        __typeof__(b) _b = (b);                                                                                        \
+        _a > _b ? _b : _a;                                                                                             \
+    })
 #endif
 #endif
-
-#endif /* DEFINES */

+ 128 - 142
src/defines.h.in

@@ -1,5 +1,4 @@
-#ifndef __DEFINES_H__
-#define __DEFINES_H__
+#pragma once
 
 
 #include "config.h"
 #include "config.h"
 
 
@@ -50,15 +49,15 @@
 #endif
 #endif
 
 
 #if defined INCLUDE_PCAP_BPF_H_FILE && !defined PCAP_DONT_INCLUDE_PCAP_BPF_H
 #if defined INCLUDE_PCAP_BPF_H_FILE && !defined PCAP_DONT_INCLUDE_PCAP_BPF_H
-#include "@INCLUDE_PCAP_BPF_HEADER@"
+#include <@INCLUDE_PCAP_BPF_HEADER@>
 #define PCAP_DONT_INCLUDE_PCAP_BPF_H 1 /* don't re-include it in pcap.h */
 #define PCAP_DONT_INCLUDE_PCAP_BPF_H 1 /* don't re-include it in pcap.h */
 #endif
 #endif
 
 
-#include "@LPCAPINC@"
+#include <@LPCAPINC@>
 
 
 /* include our own strlcat/strlcpy? */
 /* include our own strlcat/strlcpy? */
 #ifndef HAVE_STRLCPY
 #ifndef HAVE_STRLCPY
-#include "lib/strlcpy.h"
+#include <lib/strlcpy.h>
 #endif
 #endif
 
 
 /*
 /*
@@ -68,7 +67,7 @@
  * The result is that I stole the DLT types from pcap-bpf.h and
  * The result is that I stole the DLT types from pcap-bpf.h and
  * put them in here.
  * put them in here.
  */
  */
-#include "common/dlt_names.h"
+#include <common/dlt_names.h>
 
 
 #ifdef HAVE_BOOL_H
 #ifdef HAVE_BOOL_H
 #include <bool.h>
 #include <bool.h>
@@ -89,8 +88,8 @@
 #endif
 #endif
 #define COUNTER_OVERFLOW_RISK (((COUNTER)~0) >> 20)
 #define COUNTER_OVERFLOW_RISK (((COUNTER)~0) >> 20)
 
 
-#include "common/list.h"
-#include "common/cidr.h"
+#include <common/cidr.h>
+#include <common/list.h>
 
 
 
 
 typedef struct tcpr_ipv4_hdr ipv4_hdr_t;
 typedef struct tcpr_ipv4_hdr ipv4_hdr_t;
@@ -136,85 +135,75 @@ typedef struct tcpr_speed_s {
     /* speed modifiers */
     /* speed modifiers */
     int mode;
     int mode;
 #define SPEED_MULTIPLIER 1
 #define SPEED_MULTIPLIER 1
-#define SPEED_MBPSRATE   2
+#define SPEED_MBPSRATE 2
 #define SPEED_PACKETRATE 3
 #define SPEED_PACKETRATE 3
-#define SPEED_TOPSPEED   4
+#define SPEED_TOPSPEED 4
 #define SPEED_ONEATATIME 5
 #define SPEED_ONEATATIME 5
     COUNTER speed;
     COUNTER speed;
     float multiplier;
     float multiplier;
     int pps_multi;
     int pps_multi;
 } tcpr_speed_t;
 } tcpr_speed_t;
 
 
-#define MAX_FILES   1024        /* Max number of files we can pass to tcpreplay */
+#define MAX_FILES 1024 /* Max number of files we can pass to tcpreplay */
 
 
-#define DEFAULT_MTU 1500        /* Max Transmission Unit of standard ethernet
-                                 * don't forget *frames* are MTU + L2 header!
-                                 */
+/* Max Transmission Unit of standard ethernet  don't forget *frames* are MTU + L2 header! */
+#define DEFAULT_MTU 1500
 
 
-#define MAX_SNAPLEN 262144      /* tell libpcap to capture the entire packet
-                                 * this is the maximum size supported by libpcap
-                                 * (https://github.com/the-tcpdump-group/libpcap/blob/master/pcap-int.h#L99-L125)
-                                 */
+/* tell libpcap to capture the entire packet
+ * this is the maximum size supported by libpcap
+ * (https://github.com/the-tcpdump-group/libpcap/blob/master/pcap-int.h#L99-L125)
+ */
+#define MAX_SNAPLEN 262144
 
 
-#define MAXPACKET (MAX_SNAPLEN + 22)    /* snap length plus some room for adding a 
-                                         * couple VLAN headers or a L2 header
-                                         */
+/* snap length plus some room for adding a
+ * couple VLAN headers or a L2 header
+ */
+#define MAXPACKET (MAX_SNAPLEN + 22)
 
 
-#define PACKET_HEADROOM 512     /* additional headroom allocated for packets to accommodate editing */
+#define PACKET_HEADROOM 512 /* additional headroom allocated for packets to accommodate editing */
 
 
 #define DNS_RESOLVE 1
 #define DNS_RESOLVE 1
 #define DNS_DONT_RESOLVE 0
 #define DNS_DONT_RESOLVE 0
 
 
-#define RESOLVE 0               /* disable dns lookups */
-#define BPF_OPTIMIZE 1          /* default is to optimize bpf program */
-#define PCAP_TIMEOUT 100        /* 100ms pcap_open_live timeout */
+#define RESOLVE 0        /* disable dns lookups */
+#define BPF_OPTIMIZE 1   /* default is to optimize bpf program */
+#define PCAP_TIMEOUT 100 /* 100ms pcap_open_live timeout */
 
 
 #define DEFAULT_FUZZ_FACTOR 8
 #define DEFAULT_FUZZ_FACTOR 8
 
 
 /* HP-UX already defines TRUE/FALSE */
 /* HP-UX already defines TRUE/FALSE */
 #ifndef TRUE
 #ifndef TRUE
-typedef enum bool_e {
-    FALSE = 0,
-    TRUE
-} bool_t;
+typedef enum bool_e { FALSE = 0, TRUE } bool_t;
 #endif
 #endif
 
 
-#define EBUF_SIZE 1024           /* size of our error buffers */
-#define MAC_SIZE  7             /* size of the mac[] buffer */
+#define EBUF_SIZE 1024 /* size of our error buffers */
+#define MAC_SIZE 7     /* size of the mac[] buffer */
 
 
-typedef enum pad_e {
-    PAD_PACKET,
-    TRUNC_PACKET
-} pad_t;
+typedef enum pad_e { PAD_PACKET, TRUNC_PACKET } pad_t;
 
 
 #define DNS_QUERY_FLAG 0x8000
 #define DNS_QUERY_FLAG 0x8000
 
 
-typedef enum direction_e {
-    DIR_UNKNOWN = -1,
-    DIR_CLIENT  = 0,
-    DIR_SERVER  = 1,
-    DIR_ANY     = 2
-} direction_t;
+typedef enum direction_e { DIR_UNKNOWN = -1, DIR_CLIENT = 0, DIR_SERVER = 1, DIR_ANY = 2 } direction_t;
 
 
 typedef enum tcpprep_mode_e {
 typedef enum tcpprep_mode_e {
-    ERROR_MODE,     /* Some kind of error has occurred */
-    CIDR_MODE,      /* single pass, CIDR netblock */
-    REGEX_MODE,     /* single pass, regex */
-    PORT_MODE,      /* single pass, use src/dst ports to split */
-    MAC_MODE,       /* single pass, use src mac to split */
-    FIRST_MODE,     /* single pass, use first seen to split */
-    AUTO_MODE,      /* first pass through in auto mode */
-    ROUTER_MODE,    /* second pass through in router mode */
-    BRIDGE_MODE,    /* second pass through in bridge mode */
-    SERVER_MODE,    /* second pass through in server (router) mode */
-    CLIENT_MODE     /* second pass through in client (router) mode */
+    ERROR_MODE,  /* Some kind of error has occurred */
+    CIDR_MODE,   /* single pass, CIDR netblock */
+    REGEX_MODE,  /* single pass, regex */
+    PORT_MODE,   /* single pass, use src/dst ports to split */
+    MAC_MODE,    /* single pass, use src mac to split */
+    FIRST_MODE,  /* single pass, use first seen to split */
+    AUTO_MODE,   /* first pass through in auto mode */
+    ROUTER_MODE, /* second pass through in router mode */
+    BRIDGE_MODE, /* second pass through in bridge mode */
+    SERVER_MODE, /* second pass through in server (router) mode */
+    CLIENT_MODE  /* second pass through in client (router) mode */
 } tcpprep_mode_t;
 } tcpprep_mode_t;
 
 
-#define BROADCAST_MAC           "\xff\xff\xff\xff\xff\xff"
-#define IPV4_MULTICAST_MAC      "\x01\x00\x5e\x00\x00\x00"
-#define IPV6_MULTICAST_MAC      "\x33\x33\x00\x00\x00\x00"
-#define IPV4_VRRP               "\x00\x00\x50\x00\x01\x00"
-#define IPV6_VRRP               "\x00\x00\x50\x00\x02\x00"
+#define BROADCAST_MAC "\xff\xff\xff\xff\xff\xff"
+#define IPV4_MULTICAST_MAC "\x01\x00\x5e\x00\x00\x00"
+#define IPV6_MULTICAST_MAC "\x33\x33\x00\x00\x00\x00"
+#define IPV4_VRRP "\x00\x00\x50\x00\x01\x00"
+#define IPV6_VRRP "\x00\x00\x50\x00\x02\x00"
 
 
 /* MAC macros for printf */
 /* MAC macros for printf */
 #define MAC_FORMAT "%02X:%02X:%02X:%02X:%02X:%02X"
 #define MAC_FORMAT "%02X:%02X:%02X:%02X:%02X:%02X"
@@ -231,13 +220,11 @@ typedef enum tcpprep_mode_e {
 
 
 /* force a word or half-word swap on both Big and Little endian systems */
 /* force a word or half-word swap on both Big and Little endian systems */
 #ifndef SWAPLONG
 #ifndef SWAPLONG
-#define SWAPLONG(y) \
-((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
+#define SWAPLONG(y) ((((y)&0xff) << 24) | (((y)&0xff00) << 8) | (((y)&0xff0000) >> 8) | (((y) >> 24) & 0xff))
 #endif
 #endif
 
 
 #ifndef SWAPSHORT
 #ifndef SWAPSHORT
-#define SWAPSHORT(y) \
-( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )
+#define SWAPSHORT(y) ((((y)&0xff) << 8) | ((u_short)((y)&0xff00) >> 8))
 #endif
 #endif
 
 
 /* converts a 64bit int to network byte order */
 /* converts a 64bit int to network byte order */
@@ -248,21 +235,20 @@ typedef enum tcpprep_mode_e {
 #define htonll(x) (x)
 #define htonll(x) (x)
 #else
 #else
 /* stolen from http://www.codeproject.com/cpp/endianness.asp */
 /* stolen from http://www.codeproject.com/cpp/endianness.asp */
-#define ntohll(x) (((u_int64_t)(ntohl((int)((x << 32) >> 32))) << 32) | \
-                     (unsigned int)ntohl(((int)(x >> 32))))
+#define ntohll(x) (((u_int64_t)(ntohl((int)((x << 32) >> 32))) << 32) | (unsigned int)ntohl(((int)(x >> 32))))
 #define htonll(x) ntohll(x)
 #define htonll(x) ntohll(x)
 #endif /* WORDS_BIGENDIAN */
 #endif /* WORDS_BIGENDIAN */
 #endif /* HAVE_NTOHLL */
 #endif /* HAVE_NTOHLL */
 #endif /* !ntohll && !htonll */
 #endif /* !ntohll && !htonll */
 
 
-#define DEBUG_INFO   1          /* informational only, lessthan 1 line per packet */
-#define DEBUG_BASIC  2          /* limited debugging, one line per packet */
-#define DEBUG_DETAIL 3          /* more detailed, a few lines per packet */
-#define DEBUG_MORE   4          /* even more detail */
-#define DEBUG_CODE   5          /* examines code & values, many lines per packet */
+#define DEBUG_INFO 1   /* informational only, lessthan 1 line per packet */
+#define DEBUG_BASIC 2  /* limited debugging, one line per packet */
+#define DEBUG_DETAIL 3 /* more detailed, a few lines per packet */
+#define DEBUG_MORE 4   /* even more detail */
+#define DEBUG_CODE 5   /* examines code & values, many lines per packet */
 
 
 #if defined HAVE_IOPERM && defined __i386_
 #if defined HAVE_IOPERM && defined __i386_
-    #define HAVE_IOPORT_SLEEP
+#define HAVE_IOPORT_SLEEP
 #endif
 #endif
 
 
 /* Win32 doesn't know about PF_INET6 */
 /* Win32 doesn't know about PF_INET6 */
@@ -278,112 +264,112 @@ typedef enum tcpprep_mode_e {
 #define IPV6_EXTLEN_TO_BYTES(x) ((x * 4) + 8)
 #define IPV6_EXTLEN_TO_BYTES(x) ((x * 4) + 8)
 
 
 #ifndef HAVE_UINT8_T
 #ifndef HAVE_UINT8_T
-typedef u_int8_t uint8_t
-typedef u_int16_t uint16_t
-typedef u_int32_t uint32_t
+typedef u_int8_t uint8_t typedef u_int16_t uint16_t typedef u_int32_t uint32_t
 #endif
 #endif
 
 
 /* Support for flexible arrays. */
 /* Support for flexible arrays. */
 #undef __flexarr
 #undef __flexarr
 #if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97))
 #if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97))
 /* GCC 2.97 supports C99 flexible array members.  */
 /* GCC 2.97 supports C99 flexible array members.  */
-# define __flexarr      []
+#define __flexarr []
 #else
 #else
-# ifdef __GNUC__
-#  define __flexarr     [0]
-# else
-#  if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-#   define __flexarr    []
-#  elif defined(_WIN32)
+#ifdef __GNUC__
+#define __flexarr [0]
+#else
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#define __flexarr []
+#elif defined(_WIN32)
 /* MS VC++ */
 /* MS VC++ */
-#   define __flexarr    []
-#  else
+#define __flexarr []
+#else
 /* Some other non-C99 compiler. Approximate with [1]. */
 /* Some other non-C99 compiler. Approximate with [1]. */
-#   define __flexarr    [1]
-#  endif
-# endif
+#define __flexarr [1]
+#endif
+#endif
 #endif
 #endif
 
 
 
 
 /* Time converters */
 /* Time converters */
 #define SEC_TO_MILLISEC(x) (x * 1000)
 #define SEC_TO_MILLISEC(x) (x * 1000)
 #define SEC_TO_MICROSEC(x) (x * 1000000)
 #define SEC_TO_MICROSEC(x) (x * 1000000)
-#define SEC_TO_NANOSEC(x)  ((u_int64_t)x * 1000000000)
+#define SEC_TO_NANOSEC(x) ((u_int64_t)x * 1000000000)
 
 
 #define MILLISEC_TO_SEC(x) (x / 1000)
 #define MILLISEC_TO_SEC(x) (x / 1000)
 #define MICROSEC_TO_SEC(x) (x / 1000000)
 #define MICROSEC_TO_SEC(x) (x / 1000000)
-#define NANOSEC_TO_SEC(x)  ((u_int64_t)x / 1000000000)
+#define NANOSEC_TO_SEC(x) ((u_int64_t)x / 1000000000)
 
 
-#define TIMEVAL_TO_MILLISEC(x)  (((x)->tv_sec * 1000) + ((x)->tv_usec / 1000))
-#define TIMEVAL_TO_MICROSEC(x)  (((x)->tv_sec * 1000000) + (x)->tv_usec)
-#define TIMEVAL_TO_NANOSEC(x)   ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_usec * 1000))
+#define TIMEVAL_TO_MILLISEC(x) (((x)->tv_sec * 1000) + ((x)->tv_usec / 1000))
+#define TIMEVAL_TO_MICROSEC(x) (((x)->tv_sec * 1000000) + (x)->tv_usec)
+#define TIMEVAL_TO_NANOSEC(x) ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_usec * 1000))
 #define TIMSTAMP_TO_MICROSEC(x) (TIMEVAL_TO_MICROSEC(x))
 #define TIMSTAMP_TO_MICROSEC(x) (TIMEVAL_TO_MICROSEC(x))
 
 
-#define MILLISEC_TO_TIMEVAL(x, tv)          \
-    do {                                    \
-        (tv)->tv_sec = (x) / 1000;          \
-        (tv)->tv_usec = (x * 1000) - ((tv)->tv_sec * 1000000);   \
-    } while(0)
-
-#define MICROSEC_TO_TIMEVAL(x, tv)          \
-    do {                                    \
-        (tv)->tv_sec = (x) / 1000000;       \
-        (tv)->tv_usec = (x) - ((tv)->tv_sec * 1000000);   \
-    } while(0)
-
-#define NANOSEC_TO_TIMEVAL(x, tv)           \
-    do {                                    \
-        (tv)->tv_sec =  (x) / 1000000000;   \
-        (tv)->tv_usec = ((x) % 1000000000) / 1000;   \
-    } while(0)
-
-#define NANOSEC_TO_TIMESPEC(x, ts)          \
-    do {                                    \
-        (ts)->tv_sec = (x) / 1000000000;    \
-        (ts)->tv_nsec = (x) % 1000000000;   \
-    } while(0)
-
-#define TIMESPEC_TO_MILLISEC(x)  (((x)->tv_sec * 1000) + ((x)->tv_nsec / 1000000))
-#define TIMESPEC_TO_MICROSEC(x)  (((x)->tv_sec * 1000000) + (x)->tv_nsec / 1000)
+#define MILLISEC_TO_TIMEVAL(x, tv)                                                                                     \
+    do {                                                                                                               \
+        (tv)->tv_sec = (x) / 1000;                                                                                     \
+        (tv)->tv_usec = (x * 1000) - ((tv)->tv_sec * 1000000);                                                         \
+    } while (0)
+
+#define MICROSEC_TO_TIMEVAL(x, tv)                                                                                     \
+    do {                                                                                                               \
+        (tv)->tv_sec = (x) / 1000000;                                                                                  \
+        (tv)->tv_usec = (x) - ((tv)->tv_sec * 1000000);                                                                \
+    } while (0)
+
+#define NANOSEC_TO_TIMEVAL(x, tv)                                                                                      \
+    do {                                                                                                               \
+        (tv)->tv_sec = (x) / 1000000000;                                                                               \
+        (tv)->tv_usec = ((x) % 1000000000) / 1000;                                                                     \
+    } while (0)
+
+#define NANOSEC_TO_TIMESPEC(x, ts)                                                                                     \
+    do {                                                                                                               \
+        (ts)->tv_sec = (x) / 1000000000;                                                                               \
+        (ts)->tv_nsec = (x) % 1000000000;                                                                              \
+    } while (0)
+
+#define TIMESPEC_TO_MILLISEC(x) (((x)->tv_sec * 1000) + ((x)->tv_nsec / 1000000))
+#define TIMESPEC_TO_MICROSEC(x) (((x)->tv_sec * 1000000) + (x)->tv_nsec / 1000)
 #define TIMESPEC_TO_NANOSEC(x) ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_nsec))
 #define TIMESPEC_TO_NANOSEC(x) ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_nsec))
 
 
-#define TIMEVAL_SET(a, b)                  \
-    do {                                    \
-        (a)->tv_sec = (b)->tv_sec;          \
-        (a)->tv_usec = (b)->tv_usec;        \
-    } while(0)
+#define TIMEVAL_SET(a, b)                                                                                              \
+    do {                                                                                                               \
+        (a)->tv_sec = (b)->tv_sec;                                                                                     \
+        (a)->tv_usec = (b)->tv_usec;                                                                                   \
+    } while (0)
 
 
-#define TIMESPEC_SET(a, b)                 \
-    do {                                    \
-        (a)->tv_sec = (b)->tv_sec;          \
-        (a)->tv_nsec = (b)->tv_nsec;        \
-    } while(0)
+#define TIMESPEC_SET(a, b)                                                                                             \
+    do {                                                                                                               \
+        (a)->tv_sec = (b)->tv_sec;                                                                                     \
+        (a)->tv_nsec = (b)->tv_nsec;                                                                                   \
+    } while (0)
 
 
 /* 
 /* 
  * Help suppress some compiler warnings
  * Help suppress some compiler warnings
  * No problem if variable is actually used 
  * No problem if variable is actually used 
 */
 */
-#ifdef UNUSED 
-#elif defined(__GNUC__) 
-# define UNUSED(x) x __attribute__((unused))
-#elif defined(__LCLINT__) 
-# define UNUSED(x) /*@unused@*/ x 
-#else 
-# define UNUSED(x) x 
+#ifdef UNUSED
+#elif defined(__GNUC__)
+#define UNUSED(x) x __attribute__((unused))
+#elif defined(__LCLINT__)
+#define UNUSED(x) /*@unused@*/ x
+#else
+#define UNUSED(x) x
 #endif
 #endif
 
 
 #ifndef max
 #ifndef max
-#  define max(a,b) \
-       ({ __typeof__ (a) _a = (a); \
-           __typeof__ (b) _b = (b); \
-       _a > _b ? _a : _b; })
+#define max(a, b)                                                                                                      \
+    ({                                                                                                                 \
+        __typeof__(a) _a = (a);                                                                                        \
+        __typeof__(b) _b = (b);                                                                                        \
+        _a > _b ? _a : _b;                                                                                             \
+    })
 #endif
 #endif
 
 
 #ifndef min
 #ifndef min
-#  define min(a,b) \
-       ({ __typeof__ (a) _a = (a); \
-           __typeof__ (b) _b = (b); \
-       _a > _b ? _b : _a; })
+#define min(a, b)                                                                                                      \
+    ({                                                                                                                 \
+        __typeof__(a) _a = (a);                                                                                        \
+        __typeof__(b) _b = (b);                                                                                        \
+        _a > _b ? _b : _a;                                                                                             \
+    })
 #endif
 #endif
-
-#endif /* DEFINES */

+ 119 - 41
src/fragroute/Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.16.3 from Makefile.am.
 # @configure_input@
 # @configure_input@
 
 
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 
 # This Makefile.in is free software; the Free Software Foundation
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # gives unlimited permission to copy and/or distribute it,
@@ -150,7 +150,30 @@ am__v_at_0 = @
 am__v_at_1 = 
 am__v_at_1 = 
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
-am__depfiles_maybe = depfiles
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = ./$(DEPDIR)/libfragroute_a-argv.Po \
+	./$(DEPDIR)/libfragroute_a-bget.Po \
+	./$(DEPDIR)/libfragroute_a-fragroute.Po \
+	./$(DEPDIR)/libfragroute_a-iputil.Po \
+	./$(DEPDIR)/libfragroute_a-mod.Po \
+	./$(DEPDIR)/libfragroute_a-mod_delay.Po \
+	./$(DEPDIR)/libfragroute_a-mod_drop.Po \
+	./$(DEPDIR)/libfragroute_a-mod_dup.Po \
+	./$(DEPDIR)/libfragroute_a-mod_echo.Po \
+	./$(DEPDIR)/libfragroute_a-mod_ip6_opt.Po \
+	./$(DEPDIR)/libfragroute_a-mod_ip6_qos.Po \
+	./$(DEPDIR)/libfragroute_a-mod_ip_chaff.Po \
+	./$(DEPDIR)/libfragroute_a-mod_ip_frag.Po \
+	./$(DEPDIR)/libfragroute_a-mod_ip_opt.Po \
+	./$(DEPDIR)/libfragroute_a-mod_ip_tos.Po \
+	./$(DEPDIR)/libfragroute_a-mod_ip_ttl.Po \
+	./$(DEPDIR)/libfragroute_a-mod_order.Po \
+	./$(DEPDIR)/libfragroute_a-mod_print.Po \
+	./$(DEPDIR)/libfragroute_a-mod_tcp_chaff.Po \
+	./$(DEPDIR)/libfragroute_a-mod_tcp_opt.Po \
+	./$(DEPDIR)/libfragroute_a-mod_tcp_seg.Po \
+	./$(DEPDIR)/libfragroute_a-pkt.Po \
+	./$(DEPDIR)/libfragroute_a-randutil.Po
 am__mv = mv -f
 am__mv = mv -f
 AM_V_lt = $(am__v_lt_@AM_V@)
 AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@@ -319,6 +342,7 @@ build_alias = @build_alias@
 build_asan = @build_asan@
 build_asan = @build_asan@
 build_cpu = @build_cpu@
 build_cpu = @build_cpu@
 build_os = @build_os@
 build_os = @build_os@
+build_tsan = @build_tsan@
 build_vendor = @build_vendor@
 build_vendor = @build_vendor@
 builddir = @builddir@
 builddir = @builddir@
 datadir = @datadir@
 datadir = @datadir@
@@ -355,6 +379,7 @@ prefix = @prefix@
 program_transform_name = @program_transform_name@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
 psdir = @psdir@
 rmmod = @rmmod@
 rmmod = @rmmod@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
 srcdir = @srcdir@
@@ -406,8 +431,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	  *config.status*) \
 	  *config.status*) \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
 	  *) \
 	  *) \
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
 	esac;
 	esac;
 
 
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
@@ -433,29 +458,35 @@ mostlyclean-compile:
 distclean-compile:
 distclean-compile:
 	-rm -f *.tab.c
 	-rm -f *.tab.c
 
 
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-argv.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-bget.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-fragroute.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-iputil.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_delay.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_drop.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_dup.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_echo.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip6_opt.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip6_qos.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip_chaff.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip_frag.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip_opt.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip_tos.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip_ttl.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_order.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_print.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_tcp_chaff.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_tcp_opt.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_tcp_seg.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-pkt.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-randutil.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-argv.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-bget.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-fragroute.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-iputil.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_delay.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_drop.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_dup.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_echo.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip6_opt.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip6_qos.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip_chaff.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip_frag.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip_opt.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip_tos.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_ip_ttl.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_order.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_print.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_tcp_chaff.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_tcp_opt.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-mod_tcp_seg.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-pkt.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfragroute_a-randutil.Po@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+	@$(MKDIR_P) $(@D)
+	@echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
 
 
 .c.o:
 .c.o:
 @am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
 @am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@@ -861,7 +892,10 @@ cscopelist-am: $(am__tagged_files)
 distclean-tags:
 distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 
 
-distdir: $(DISTFILES)
+distdir: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	list='$(DISTFILES)'; \
 	list='$(DISTFILES)'; \
@@ -933,7 +967,29 @@ clean-am: clean-generic clean-libtool clean-noinstLIBRARIES \
 	mostlyclean-am
 	mostlyclean-am
 
 
 distclean: distclean-am
 distclean: distclean-am
-	-rm -rf ./$(DEPDIR)
+		-rm -f ./$(DEPDIR)/libfragroute_a-argv.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-bget.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-fragroute.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-iputil.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_delay.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_drop.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_dup.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_echo.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip6_opt.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip6_qos.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip_chaff.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip_frag.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip_opt.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip_tos.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip_ttl.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_order.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_print.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_tcp_chaff.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_tcp_opt.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_tcp_seg.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-pkt.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-randutil.Po
 	-rm -f Makefile
 	-rm -f Makefile
 distclean-am: clean-am distclean-compile distclean-generic \
 distclean-am: clean-am distclean-compile distclean-generic \
 	distclean-tags
 	distclean-tags
@@ -979,7 +1035,29 @@ install-ps-am:
 installcheck-am:
 installcheck-am:
 
 
 maintainer-clean: maintainer-clean-am
 maintainer-clean: maintainer-clean-am
-	-rm -rf ./$(DEPDIR)
+		-rm -f ./$(DEPDIR)/libfragroute_a-argv.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-bget.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-fragroute.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-iputil.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_delay.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_drop.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_dup.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_echo.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip6_opt.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip6_qos.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip_chaff.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip_frag.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip_opt.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip_tos.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_ip_ttl.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_order.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_print.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_tcp_chaff.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_tcp_opt.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-mod_tcp_seg.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-pkt.Po
+	-rm -f ./$(DEPDIR)/libfragroute_a-randutil.Po
 	-rm -f Makefile
 	-rm -f Makefile
 maintainer-clean-am: distclean-am maintainer-clean-generic
 maintainer-clean-am: distclean-am maintainer-clean-generic
 
 
@@ -1000,16 +1078,16 @@ uninstall-am:
 
 
 .MAKE: install-am install-strip
 .MAKE: install-am install-strip
 
 
-.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
-	clean-libtool clean-noinstLIBRARIES cscopelist-am ctags \
-	ctags-am distclean distclean-compile distclean-generic \
-	distclean-libtool distclean-tags distdir dvi dvi-am html \
-	html-am info info-am install install-am 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 \
+.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
+	clean-generic clean-libtool clean-noinstLIBRARIES \
+	cscopelist-am ctags ctags-am distclean distclean-compile \
+	distclean-generic distclean-libtool distclean-tags distdir dvi \
+	dvi-am html html-am info info-am install install-am \
+	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 \
 	maintainer-clean-generic mostlyclean mostlyclean-compile \
 	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
 	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
 	tags tags-am uninstall uninstall-am
 	tags tags-am uninstall uninstall-am

+ 1 - 3
src/fragroute/argv.c

@@ -6,15 +6,13 @@
  * $Id$
  * $Id$
  */
  */
 
 
+#include "argv.h"
 #include "config.h"
 #include "config.h"
-
 #include <ctype.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "argv.h"
-
 int
 int
 argv_create(char *p, int argc, char *argv[])
 argv_create(char *p, int argc, char *argv[])
 {
 {

+ 1 - 4
src/fragroute/argv.h

@@ -6,10 +6,7 @@
  * $Id$
  * $Id$
  */
  */
 
 
-#ifndef ARGV_H
-#define ARGV_H
+#pragma once
 
 
 int argv_create(char *p, int argc, char *argv[]);
 int argv_create(char *p, int argc, char *argv[]);
 char *argv_copy(char *argv[]);
 char *argv_copy(char *argv[]);
-
-#endif /* ARGV_H */

+ 222 - 221
src/fragroute/bget.c

@@ -399,55 +399,62 @@
 */
 */
 
 
 #if 0
 #if 0
-#define TestProg    20000          /* Generate built-in test program
-                     if defined.  The value specifies
-                     how many buffer allocation attempts
-                     the test program should make. */
+#define TestProg                                                                                                       \
+    20000 /* Generate built-in test program                                                                            \
+if defined.  The value specifies                                                                                       \
+how many buffer allocation attempts                                                                                    \
+the test program should make. */
 #endif
 #endif
-#define SizeQuant   4              /* Buffer allocation size quantum:
-                     all buffers allocated are a
-                     multiple of this size.  This
-                     MUST be a power of two. */
+#define SizeQuant                                                                                                      \
+    4 /* Buffer allocation size quantum:                                                                               \
+all buffers allocated are a                                                                                            \
+multiple of this size.  This                                                                                           \
+MUST be a power of two. */
 #if 0
 #if 0
-#define BufDump     1              /* Define this symbol to enable the
-                     bpoold() function which dumps the
-                     buffers in a buffer pool. */
-
-#define BufValid    1              /* Define this symbol to enable the
-                     bpoolv() function for validating
-                     a buffer pool. */
-
-#define DumpData    1              /* Define this symbol to enable the
-                     bufdump() function which allows
-                     dumping the contents of an allocated
-                     or free buffer. */
-
-#define BufStats    1              /* Define this symbol to enable the
-                     bstats() function which calculates
-                     the total free space in the buffer
-                     pool, the largest available
-                     buffer, and the total space
-                     currently allocated. */
-
-#define FreeWipe    1              /* Wipe free buffers to a guaranteed
-                     pattern of garbage to trip up
-                     miscreants who attempt to use
-                     pointers into released buffers. */
-
-#define BestFit     1              /* Use a best fit algorithm when
-                     searching for space for an
-                     allocation request.  This uses
-                     memory more efficiently, but
-                     allocation will be much slower. */
+#define BufDump                                                                                                        \
+    1 /* Define this symbol to enable the                                                                              \
+bpoold() function which dumps the                                                                                      \
+buffers in a buffer pool. */
+
+#define BufValid                                                                                                       \
+    1 /* Define this symbol to enable the                                                                              \
+bpoolv() function for validating                                                                                       \
+a buffer pool. */
+
+#define DumpData                                                                                                       \
+    1 /* Define this symbol to enable the                                                                              \
+bufdump() function which allows                                                                                        \
+dumping the contents of an allocated                                                                                   \
+or free buffer. */
+
+#define BufStats                                                                                                       \
+    1 /* Define this symbol to enable the                                                                              \
+bstats() function which calculates                                                                                     \
+the total free space in the buffer                                                                                     \
+pool, the largest available                                                                                            \
+buffer, and the total space                                                                                            \
+currently allocated. */
+
+#define FreeWipe                                                                                                       \
+    1 /* Wipe free buffers to a guaranteed                                                                             \
+pattern of garbage to trip up                                                                                          \
+miscreants who attempt to use                                                                                          \
+pointers into released buffers. */
+
+#define BestFit                                                                                                        \
+    1 /* Use a best fit algorithm when                                                                                 \
+searching for space for an                                                                                             \
+allocation request.  This uses                                                                                         \
+memory more efficiently, but                                                                                           \
+allocation will be much slower. */
 #endif
 #endif
-#define BECtl        1              /* Define this symbol to enable the
-                     bectl() function for automatic
-                     pool space control.  */
-
-#include <stdio.h>
+#define BECtl                                                                                                          \
+    1 /* Define this symbol to enable the                                                                              \
+bectl() function for automatic                                                                                         \
+pool space control.  */
 
 
 #ifdef lint
 #ifdef lint
-#define NDEBUG                  /* Exits in asserts confuse lint */
+#define NDEBUG /* Exits in asserts confuse lint */
 /* LINTLIBRARY */                     /* Don't complain about def, no ref */
 /* LINTLIBRARY */                     /* Don't complain about def, no ref */
 extern char *sprintf();               /* Sun includes don't define sprintf */
 extern char *sprintf();               /* Sun includes don't define sprintf */
 #endif
 #endif
@@ -455,9 +462,9 @@ extern char *sprintf();               /* Sun includes don't define sprintf */
 #include <assert.h>
 #include <assert.h>
 #include <memory.h>
 #include <memory.h>
 
 
-#ifdef BufDump                  /* BufDump implies DumpData */
+#ifdef BufDump /* BufDump implies DumpData */
 #ifndef DumpData
 #ifndef DumpData
-#define DumpData    1
+#define DumpData 1
 #endif
 #endif
 #endif
 #endif
 
 
@@ -470,48 +477,47 @@ extern char *sprintf();               /* Sun includes don't define sprintf */
 
 
 #include "bget.h"
 #include "bget.h"
 
 
-#define MemSize     int           /* Type for size arguments to memxxx()
-                     functions such as memcmp(). */
+#define MemSize                                                                                                        \
+    int /* Type for size arguments to memxxx()                                                                         \
+functions such as memcmp(). */
 
 
 /* Queue links */
 /* Queue links */
 
 
 struct qlinks {
 struct qlinks {
-    struct bfhead *flink;          /* Forward link */
-    struct bfhead *blink;          /* Backward link */
+    struct bfhead *flink; /* Forward link */
+    struct bfhead *blink; /* Backward link */
 };
 };
 
 
 /* Header in allocated and free buffers */
 /* Header in allocated and free buffers */
 
 
 struct bhead {
 struct bhead {
-    bufsize prevfree;              /* Relative link back to previous
-                     free buffer in memory or 0 if
-                     previous buffer is allocated.    */
-    bufsize bsize;              /* Buffer size: positive if free,
-                     negative if allocated. */
+    bufsize prevfree; /* Relative link back to previous
+        free buffer in memory or 0 if
+        previous buffer is allocated.    */
+    bufsize bsize;    /* Buffer size: positive if free,
+           negative if allocated. */
 };
 };
-#define BH(p)    ((struct bhead *) (p))
+#define BH(p) ((struct bhead *)(p))
 
 
 /*  Header in directly allocated buffers (by acqfcn) */
 /*  Header in directly allocated buffers (by acqfcn) */
 
 
 struct bdhead {
 struct bdhead {
-    bufsize tsize;              /* Total size, including overhead */
-    struct bhead bh;              /* Common header */
+    bufsize tsize;   /* Total size, including overhead */
+    struct bhead bh; /* Common header */
 };
 };
-#define BDH(p)    ((struct bdhead *) (p))
+#define BDH(p) ((struct bdhead *)(p))
 
 
 /* Header in free buffers */
 /* Header in free buffers */
 
 
 struct bfhead {
 struct bfhead {
-    struct bhead bh;              /* Common allocated/free header */
-    struct qlinks ql;              /* Links on free list */
-};
-#define BFH(p)    ((struct bfhead *) (p))
-
-static struct bfhead freelist = {     /* List of free buffers */
-    {0, 0},
-    {&freelist, &freelist}
+    struct bhead bh;  /* Common allocated/free header */
+    struct qlinks ql; /* Links on free list */
 };
 };
+#define BFH(p) ((struct bfhead *)(p))
 
 
+static struct bfhead freelist = {/* List of free buffers */
+                                 {0, 0},
+                                 {&freelist, &freelist}};
 
 
 #ifdef BufStats
 #ifdef BufStats
 static bufsize totalloc = 0;          /* Total space currently allocated */
 static bufsize totalloc = 0;          /* Total space currently allocated */
@@ -542,20 +548,21 @@ static bufsize pool_len = 0;          /*  0: no bpool calls have been made
 
 
 /*  Minimum allocation quantum: */
 /*  Minimum allocation quantum: */
 
 
-#define QLSize    (sizeof(struct qlinks))
-#define SizeQ    ((SizeQuant > QLSize) ? SizeQuant : QLSize)
+#define QLSize (sizeof(struct qlinks))
+#define SizeQ ((SizeQuant > QLSize) ? SizeQuant : QLSize)
 
 
-#define V   (void)              /* To denote unwanted returned values */
+#define V (void)/* To denote unwanted returned values */
 
 
 /* End sentinel: value placed in bsize field of dummy block delimiting
 /* End sentinel: value placed in bsize field of dummy block delimiting
    end of pool block.  The most negative number which will  fit  in  a
    end of pool block.  The most negative number which will  fit  in  a
    bufsize, defined in a way that the compiler will accept. */
    bufsize, defined in a way that the compiler will accept. */
 
 
-#define ESent    ((bufsize) (-(((1L << (sizeof(bufsize) * 8 - 2)) - 1) * 2) - 2))
+#define ESent ((bufsize)(-(((1L << (sizeof(bufsize) * 8 - 2)) - 1) * 2) - 2))
 
 
 /*  BGET  --  Allocate a buffer.  */
 /*  BGET  --  Allocate a buffer.  */
 
 
-void *bget(requested_size)
+void *
+bget(requested_size)
 bufsize requested_size;
 bufsize requested_size;
 {
 {
     bufsize size = requested_size;
     bufsize size = requested_size;
@@ -570,8 +577,8 @@ bufsize requested_size;
 
 
     assert(size > 0);
     assert(size > 0);
 
 
-    if (size < (bufsize)SizeQ) {           /* Need at least room for the */
-        size = SizeQ;              /*    queue links.  */
+    if (size < (bufsize)SizeQ) { /* Need at least room for the */
+        size = SizeQ;            /*    queue links.  */
     }
     }
 #ifdef SizeQuant
 #ifdef SizeQuant
 #if SizeQuant > 1
 #if SizeQuant > 1
@@ -579,9 +586,9 @@ bufsize requested_size;
 #endif
 #endif
 #endif
 #endif
 
 
-    size += sizeof(struct bhead);     /* Add overhead in allocated buffer
-                                       * to size required.
-                                       */
+    size += sizeof(struct bhead); /* Add overhead in allocated buffer
+                                   * to size required.
+                                   */
 
 
 #ifdef BECtl
 #ifdef BECtl
     /* If a compact function was provided in the call to bectl(), wrap
     /* If a compact function was provided in the call to bectl(), wrap
@@ -591,14 +598,13 @@ bufsize requested_size;
 
 
     while (1) {
     while (1) {
 #endif
 #endif
-        b = freelist.ql.flink;
+    b = freelist.ql.flink;
 #ifdef BestFit
 #ifdef BestFit
         best = &freelist;
         best = &freelist;
 #endif
 #endif
 
 
-
-        /* Scan the free list searching for the first buffer big enough
-       to hold the requested size buffer. */
+    /* Scan the free list searching for the first buffer big enough
+   to hold the requested size buffer. */
 
 
 #ifdef BestFit
 #ifdef BestFit
         while (b != &freelist) {
         while (b != &freelist) {
@@ -612,74 +618,73 @@ bufsize requested_size;
         b = best;
         b = best;
 #endif /* BestFit */
 #endif /* BestFit */
 
 
-        while (b != &freelist) {
-            if ((bufsize) b->bh.bsize >= size) {
-
-                /* Buffer  is big enough to satisfy  the request.  Allocate it
-                 * to the caller.  We must decide whether the buffer is  large
-                 * enough  to  split  into  the part given to the caller and a
-                 * free buffer that remains on the free list, or  whether  the
-                 * entire  buffer  should  be  removed from the free list and
-                 * given to the caller in its entirety.  We  only  split  the
-                 * buffer if enough room remains for a header plus the minimum
-                 * quantum of allocation.
-                 */
+    while (b != &freelist) {
+        if ((bufsize)b->bh.bsize >= size) {
+            /* Buffer  is big enough to satisfy  the request.  Allocate it
+             * to the caller.  We must decide whether the buffer is  large
+             * enough  to  split  into  the part given to the caller and a
+             * free buffer that remains on the free list, or  whether  the
+             * entire  buffer  should  be  removed from the free list and
+             * given to the caller in its entirety.  We  only  split  the
+             * buffer if enough room remains for a header plus the minimum
+             * quantum of allocation.
+             */
 
 
-                if ((b->bh.bsize - size) > (bufsize)(SizeQ + (sizeof(struct bhead)))) {
-                    struct bhead *ba, *bn;
-
-                    ba = BH(((char *) b) + (b->bh.bsize - size));
-                    bn = BH(((char *) ba) + size);
-                    assert(bn->prevfree == b->bh.bsize);
-                    /* Subtract size from length of free block. */
-                    b->bh.bsize -= size;
-                    /* Link allocated buffer to the previous free buffer. */
-                    ba->prevfree = b->bh.bsize;
-                    /* Plug negative size into user buffer. */
-                    ba->bsize = -(bufsize) size;
-                    /* Mark buffer after this one not preceded by free block. */
-                    bn->prevfree = 0;
+            if ((b->bh.bsize - size) > (bufsize)(SizeQ + (sizeof(struct bhead)))) {
+                struct bhead *ba, *bn;
+
+                ba = BH(((char *)b) + (b->bh.bsize - size));
+                bn = BH(((char *)ba) + size);
+                assert(bn->prevfree == b->bh.bsize);
+                /* Subtract size from length of free block. */
+                b->bh.bsize -= size;
+                /* Link allocated buffer to the previous free buffer. */
+                ba->prevfree = b->bh.bsize;
+                /* Plug negative size into user buffer. */
+                ba->bsize = -(bufsize)size;
+                /* Mark buffer after this one not preceded by free block. */
+                bn->prevfree = 0;
 
 
 #ifdef BufStats
 #ifdef BufStats
                     totalloc += size;
                     totalloc += size;
                     numget++;          /* Increment number of bget() calls */
                     numget++;          /* Increment number of bget() calls */
 #endif
 #endif
-                    buf = (void *) ((((char *) ba) + sizeof(struct bhead)));
-                    return buf;
-                } else {
-                    struct bhead *ba;
+                buf = (void *)((((char *)ba) + sizeof(struct bhead)));
+                return buf;
+            } else {
+                struct bhead *ba;
 
 
-                    ba = BH(((char *) b) + b->bh.bsize);
-                    assert(ba->prevfree == b->bh.bsize);
+                ba = BH(((char *)b) + b->bh.bsize);
+                assert(ba->prevfree == b->bh.bsize);
 
 
-                    /* The buffer isn't big enough to split.  Give  the  whole
-                     * shebang to the caller and remove it from the free list.
-                     */
+                /* The buffer isn't big enough to split.  Give  the  whole
+                 * shebang to the caller and remove it from the free list.
+                 */
 
 
-                    assert(b->ql.blink->ql.flink == b);
-                    assert(b->ql.flink->ql.blink == b);
-                    b->ql.blink->ql.flink = b->ql.flink;
-                    b->ql.flink->ql.blink = b->ql.blink;
+                assert(b->ql.blink->ql.flink == b);
+                assert(b->ql.flink->ql.blink == b);
+                b->ql.blink->ql.flink = b->ql.flink;
+                b->ql.flink->ql.blink = b->ql.blink;
 
 
 #ifdef BufStats
 #ifdef BufStats
                     totalloc += b->bh.bsize;
                     totalloc += b->bh.bsize;
                     numget++;          /* Increment number of bget() calls */
                     numget++;          /* Increment number of bget() calls */
 #endif
 #endif
-                    /* Negate size to mark buffer allocated. */
-                    b->bh.bsize = -(b->bh.bsize);
+                /* Negate size to mark buffer allocated. */
+                b->bh.bsize = -(b->bh.bsize);
 
 
-                    /* Zero the back pointer in the next buffer in memory
-                     * to indicate that this buffer is allocated.
-                     */
-                    ba->prevfree = 0;
+                /* Zero the back pointer in the next buffer in memory
+                 * to indicate that this buffer is allocated.
+                 */
+                ba->prevfree = 0;
 
 
-                    /* Give user buffer starting at queue links. */
-                    buf =  (void *) &(b->ql);
-                    return buf;
-                }
+                /* Give user buffer starting at queue links. */
+                buf = (void *)&(b->ql);
+                return buf;
             }
             }
-            b = b->ql.flink;          /* Link to next buffer */
         }
         }
+        b = b->ql.flink; /* Link to next buffer */
+    }
 #ifdef BECtl
 #ifdef BECtl
 
 
         /* We failed to find a buffer.  If there's a compact  function
         /* We failed to find a buffer.  If there's a compact  function
@@ -749,29 +754,30 @@ bufsize requested_size;
            the  entire  contents  of  the buffer to zero, not just the
            the  entire  contents  of  the buffer to zero, not just the
            region requested by the caller. */
            region requested by the caller. */
 
 
-void *bgetz(size)
-  bufsize size;
+void *
+bgetz(size)
+bufsize size;
 {
 {
-    char *buf = (char *) bget(size);
+    char *buf = (char *)bget(size);
 
 
     if (buf != NULL) {
     if (buf != NULL) {
-    struct bhead *b;
-    bufsize rsize;
+        struct bhead *b;
+        bufsize rsize;
 
 
-    b = BH(buf - sizeof(struct bhead));
-    rsize = -(b->bsize);
-    if (rsize == 0) {
-        struct bdhead *bd;
+        b = BH(buf - sizeof(struct bhead));
+        rsize = -(b->bsize);
+        if (rsize == 0) {
+            struct bdhead *bd;
 
 
-        bd = BDH(buf - sizeof(struct bdhead));
-        rsize = bd->tsize - sizeof(struct bdhead);
-    } else {
-        rsize -= sizeof(struct bhead);
-    }
-    assert(rsize >= size);
-    V memset(buf, 0, (MemSize) rsize);
+            bd = BDH(buf - sizeof(struct bdhead));
+            rsize = bd->tsize - sizeof(struct bdhead);
+        } else {
+            rsize -= sizeof(struct bhead);
+        }
+        assert(rsize >= size);
+        V memset(buf, 0, (MemSize)rsize);
     }
     }
-    return ((void *) buf);
+    return ((void *)buf);
 }
 }
 
 
 /*  BGETR  --  Reallocate a buffer.  This is a minimal implementation,
 /*  BGETR  --  Reallocate a buffer.  This is a minimal implementation,
@@ -779,12 +785,11 @@ void *bgetz(size)
            enhanced to allow the buffer to grow into adjacent free
            enhanced to allow the buffer to grow into adjacent free
            blocks and to avoid moving data unnecessarily.  */
            blocks and to avoid moving data unnecessarily.  */
 
 
-void *bgetr(buf, size)
-  void *buf;
-  bufsize size;
+void *bgetr(buf, size) void *buf;
+bufsize size;
 {
 {
     void *nbuf;
     void *nbuf;
-    bufsize osize;              /* Old size of buffer */
+    bufsize osize; /* Old size of buffer */
     struct bhead *b;
     struct bhead *b;
 
 
     if ((nbuf = bget(size)) == NULL) { /* Acquire new buffer */
     if ((nbuf = bget(size)) == NULL) { /* Acquire new buffer */
@@ -793,7 +798,7 @@ void *bgetr(buf, size)
     if (buf == NULL) {
     if (buf == NULL) {
         return nbuf;
         return nbuf;
     }
     }
-    b = BH(((char *) buf) - sizeof(struct bhead));
+    b = BH(((char *)buf) - sizeof(struct bhead));
     osize = -b->bsize;
     osize = -b->bsize;
 #ifdef BECtl
 #ifdef BECtl
     if (osize == 0) {
     if (osize == 0) {
@@ -804,10 +809,11 @@ void *bgetr(buf, size)
         osize = bd->tsize - sizeof(struct bdhead);
         osize = bd->tsize - sizeof(struct bdhead);
     } else
     } else
 #endif
 #endif
-        osize -= sizeof(struct bhead);
+    osize -= sizeof(struct bhead);
     assert(osize > 0);
     assert(osize > 0);
-    V memcpy((char *) nbuf, (char *) buf, /* Copy the data */
-            (MemSize) ((size < osize) ? size : osize));
+    V memcpy((char *)nbuf,
+             (char *)buf, /* Copy the data */
+             (MemSize)((size < osize) ? size : osize));
 
 
     brel(buf);
     brel(buf);
     return nbuf;
     return nbuf;
@@ -815,13 +821,12 @@ void *bgetr(buf, size)
 
 
 /*  BREL  --  Release a buffer.  */
 /*  BREL  --  Release a buffer.  */
 
 
-void brel(buf)
-  void *buf;
+void brel(buf) void *buf;
 {
 {
     struct bfhead *b, *bn;
     struct bfhead *b, *bn;
 
 
     assert(buf != NULL);
     assert(buf != NULL);
-    b = BFH(((char *) buf) - sizeof(struct bhead));
+    b = BFH(((char *)buf) - sizeof(struct bhead));
 #ifdef BufStats
 #ifdef BufStats
     numrel++;                  /* Increment number of brel() calls */
     numrel++;                  /* Increment number of brel() calls */
 #endif
 #endif
@@ -851,14 +856,14 @@ void brel(buf)
        allocated. */
        allocated. */
 
 
     if (b->bh.bsize >= 0) {
     if (b->bh.bsize >= 0) {
-    bn = NULL;
+        bn = NULL;
     }
     }
     assert(b->bh.bsize < 0);
     assert(b->bh.bsize < 0);
 
 
     /*    Back pointer in next buffer must be zero, indicating the
     /*    Back pointer in next buffer must be zero, indicating the
     same thing: */
     same thing: */
 
 
-    assert(BH((char *) b - b->bh.bsize)->prevfree == 0);
+    assert(BH((char *)b - b->bh.bsize)->prevfree == 0);
 
 
 #ifdef BufStats
 #ifdef BufStats
     totalloc += b->bh.bsize;
     totalloc += b->bh.bsize;
@@ -868,31 +873,29 @@ void brel(buf)
     /* If the back link is nonzero, the previous buffer is free.  */
     /* If the back link is nonzero, the previous buffer is free.  */
 
 
     if (b->bh.prevfree != 0) {
     if (b->bh.prevfree != 0) {
+        /* The previous buffer is free.  Consolidate this buffer  with    it
+           by  adding  the  length  of    this  buffer  to the previous free
+           buffer.  Note that we subtract the size  in    the  buffer  being
+               released,  since  it's  negative to indicate that the buffer is
+           allocated. */
 
 
-    /* The previous buffer is free.  Consolidate this buffer  with    it
-       by  adding  the  length  of    this  buffer  to the previous free
-       buffer.  Note that we subtract the size  in    the  buffer  being
-           released,  since  it's  negative to indicate that the buffer is
-       allocated. */
-
-    register bufsize size = b->bh.bsize;
+        register bufsize size = b->bh.bsize;
 
 
         /* Make the previous buffer the one we're working on. */
         /* Make the previous buffer the one we're working on. */
-    assert(BH((char *) b - b->bh.prevfree)->bsize == b->bh.prevfree);
-    b = BFH(((char *) b) - b->bh.prevfree);
-    b->bh.bsize -= size;
+        assert(BH((char *)b - b->bh.prevfree)->bsize == b->bh.prevfree);
+        b = BFH(((char *)b) - b->bh.prevfree);
+        b->bh.bsize -= size;
     } else {
     } else {
-
         /* The previous buffer isn't allocated.  Insert this buffer
         /* The previous buffer isn't allocated.  Insert this buffer
        on the free list as an isolated free block. */
        on the free list as an isolated free block. */
 
 
-    assert(freelist.ql.blink->ql.flink == &freelist);
-    assert(freelist.ql.flink->ql.blink == &freelist);
-    b->ql.flink = &freelist;
-    b->ql.blink = freelist.ql.blink;
-    freelist.ql.blink = b;
-    b->ql.blink->ql.flink = b;
-    b->bh.bsize = -b->bh.bsize;
+        assert(freelist.ql.blink->ql.flink == &freelist);
+        assert(freelist.ql.flink->ql.blink == &freelist);
+        b->ql.flink = &freelist;
+        b->ql.blink = freelist.ql.blink;
+        freelist.ql.blink = b;
+        b->ql.blink->ql.flink = b;
+        b->bh.bsize = -b->bh.bsize;
     }
     }
 
 
     /* Now we look at the next buffer in memory, located by advancing from
     /* Now we look at the next buffer in memory, located by advancing from
@@ -900,27 +903,26 @@ void brel(buf)
        free.  If it is, we combine  this  buffer  with    the  next  one    in
        free.  If it is, we combine  this  buffer  with    the  next  one    in
        memory, dechaining the second buffer from the free list. */
        memory, dechaining the second buffer from the free list. */
 
 
-    bn =  BFH(((char *) b) + b->bh.bsize);
+    bn = BFH(((char *)b) + b->bh.bsize);
     if (bn->bh.bsize > 0) {
     if (bn->bh.bsize > 0) {
-
-    /* The buffer is free.    Remove it from the free list and add
-       its size to that of our buffer. */
-
-    assert(BH((char *) bn + bn->bh.bsize)->prevfree == bn->bh.bsize);
-    assert(bn->ql.blink->ql.flink == bn);
-    assert(bn->ql.flink->ql.blink == bn);
-    bn->ql.blink->ql.flink = bn->ql.flink;
-    bn->ql.flink->ql.blink = bn->ql.blink;
-    b->bh.bsize += bn->bh.bsize;
-
-    /* Finally,  advance  to   the    buffer    that   follows    the  newly
-       consolidated free block.  We must set its  backpointer  to  the
-       head  of  the  consolidated free block.  We know the next block
-       must be an allocated block because the process of recombination
-       guarantees  that  two  free    blocks will never be contiguous in
-       memory.  */
-
-    bn = BFH(((char *) b) + b->bh.bsize);
+        /* The buffer is free.    Remove it from the free list and add
+           its size to that of our buffer. */
+
+        assert(BH((char *)bn + bn->bh.bsize)->prevfree == bn->bh.bsize);
+        assert(bn->ql.blink->ql.flink == bn);
+        assert(bn->ql.flink->ql.blink == bn);
+        bn->ql.blink->ql.flink = bn->ql.flink;
+        bn->ql.flink->ql.blink = bn->ql.blink;
+        b->bh.bsize += bn->bh.bsize;
+
+        /* Finally,  advance  to   the    buffer    that   follows    the  newly
+           consolidated free block.  We must set its  backpointer  to  the
+           head  of  the  consolidated free block.  We know the next block
+           must be an allocated block because the process of recombination
+           guarantees  that  two  free    blocks will never be contiguous in
+           memory.  */
+
+        bn = BFH(((char *)b) + b->bh.bsize);
     }
     }
 #ifdef FreeWipe
 #ifdef FreeWipe
     V memset(((char *) b) + sizeof(struct bfhead), 0x55,
     V memset(((char *) b) + sizeof(struct bfhead), 0x55,
@@ -979,9 +981,8 @@ void bectl(compact, acquire, release, pool_incr)
 
 
 /*  BPOOL  --  Add a region of memory to the buffer pool.  */
 /*  BPOOL  --  Add a region of memory to the buffer pool.  */
 
 
-void bpool(buf, len)
-  void *buf;
-  bufsize len;
+void bpool(buf, len) void *buf;
+bufsize len;
 {
 {
     struct bfhead *b = BFH(buf);
     struct bfhead *b = BFH(buf);
     struct bhead *bn;
     struct bhead *bn;
@@ -1006,7 +1007,7 @@ void bpool(buf, len)
        it  had    better    not  be  (much) larger than the largest buffer
        it  had    better    not  be  (much) larger than the largest buffer
        whose size we can store in bhead.bsize. */
        whose size we can store in bhead.bsize. */
 
 
-    assert(len - sizeof(struct bhead) <= -((bufsize) ESent + 1));
+    assert(len - sizeof(struct bhead) <= -((bufsize)ESent + 1));
 
 
     /* Clear  the  backpointer at  the start of the block to indicate that
     /* Clear  the  backpointer at  the start of the block to indicate that
        there  is  no  free  block  prior  to  this   one.    That   blocks
        there  is  no  free  block  prior  to  this   one.    That   blocks
@@ -1032,13 +1033,13 @@ void bpool(buf, len)
        allocation and release functions). */
        allocation and release functions). */
 
 
     len -= sizeof(struct bhead);
     len -= sizeof(struct bhead);
-    b->bh.bsize = (bufsize) len;
+    b->bh.bsize = (bufsize)len;
 #ifdef FreeWipe
 #ifdef FreeWipe
     V memset(((char *) b) + sizeof(struct bfhead), 0x55,
     V memset(((char *) b) + sizeof(struct bfhead), 0x55,
          (MemSize) (len - sizeof(struct bfhead)));
          (MemSize) (len - sizeof(struct bfhead)));
 #endif
 #endif
-    bn = BH(((char *) b) + len);
-    bn->prevfree = (bufsize) len;
+    bn = BH(((char *)b) + len);
+    bn->prevfree = (bufsize)len;
     /* Definition of ESent assumes two's complement! */
     /* Definition of ESent assumes two's complement! */
     assert((~0) == -1);
     assert((~0) == -1);
     bn->bsize = ESent;
     bn->bsize = ESent;
@@ -1245,34 +1246,34 @@ int bpoolv(buf)
 }
 }
 #endif /* BufValid */
 #endif /* BufValid */
 
 
-        /***********************\
-    *            *
-    * Built-in test program *
-    *            *
-        \***********************/
+/***********************\
+*            *
+* Built-in test program *
+*            *
+\***********************/
 
 
 #ifdef TestProg
 #ifdef TestProg
 
 
-#define Repeatable  1              /* Repeatable pseudorandom sequence */
+#define Repeatable 1 /* Repeatable pseudorandom sequence */
                       /* If Repeatable is not defined, a
                       /* If Repeatable is not defined, a
                      time-seeded pseudorandom sequence
                      time-seeded pseudorandom sequence
                      is generated, exercising BGET with
                      is generated, exercising BGET with
                      a different pattern of calls on each
                      a different pattern of calls on each
                      run. */
                      run. */
-#define OUR_RAND              /* Use our own built-in version of
-                     rand() to guarantee the test is
-                     100% repeatable. */
+#define OUR_RAND     /* Use our own built-in version of                                                                \
+            rand() to guarantee the test is                                                                            \
+            100% repeatable. */
 
 
 #ifdef BECtl
 #ifdef BECtl
-#define PoolSize    300000          /* Test buffer pool size */
+#define PoolSize 300000 /* Test buffer pool size */
 #else
 #else
-#define PoolSize    50000          /* Test buffer pool size */
+#define PoolSize 50000 /* Test buffer pool size */
 #endif
 #endif
-#define ExpIncr     32768          /* Test expansion block size */
-#define CompactTries 10           /* Maximum tries at compacting */
+#define ExpIncr 32768   /* Test expansion block size */
+#define CompactTries 10 /* Maximum tries at compacting */
 
 
-#define dumpAlloc   0              /* Dump allocated buffers ? */
-#define dumpFree    0              /* Dump free buffers ? */
+#define dumpAlloc 0 /* Dump allocated buffers ? */
+#define dumpFree 0  /* Dump free buffers ? */
 
 
 #ifndef Repeatable
 #ifndef Repeatable
 extern long time();
 extern long time();

+ 2 - 0
src/fragroute/bget.h

@@ -4,6 +4,8 @@
 
 
 */
 */
 
 
+#pragma once
+
 #ifndef _
 #ifndef _
 #ifdef PROTOTYPES
 #ifdef PROTOTYPES
 #define  _(x)  x              /* If compiler knows prototypes */
 #define  _(x)  x              /* If compiler knows prototypes */

+ 14 - 24
src/fragroute/fragroute.c

@@ -7,16 +7,13 @@
  * $Id$
  * $Id$
  */
  */
 
 
-#include "config.h"
-#include "lib/queue.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
-#include <signal.h>
+#include "lib/queue.h"
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
-#include <unistd.h>
 
 
 #ifdef HAVE_LIBDNET
 #ifdef HAVE_LIBDNET
 /* need to undef these which are pulled in via defines.h, prior to importing dnet.h */
 /* need to undef these which are pulled in via defines.h, prior to importing dnet.h */
@@ -33,9 +30,8 @@
 #endif
 #endif
 
 
 #include "fragroute.h"
 #include "fragroute.h"
-#include "pkt.h"
 #include "mod.h"
 #include "mod.h"
-// #include "tun.h"
+#include "pkt.h"
 
 
 void
 void
 fragroute_close(fragroute_t *ctx)
 fragroute_close(fragroute_t *ctx)
@@ -46,27 +42,22 @@ fragroute_close(fragroute_t *ctx)
     pkt_close();
     pkt_close();
 }
 }
 
 
-
 int
 int
 fragroute_process(fragroute_t *ctx, void *buf, size_t len)
 fragroute_process(fragroute_t *ctx, void *buf, size_t len)
 {
 {
     struct pkt *pkt;
     struct pkt *pkt;
     assert(ctx);
     assert(ctx);
     assert(buf);
     assert(buf);
-    
+
     ctx->first_packet = 0;
     ctx->first_packet = 0;
     /* save the l2 header of the original packet for later */
     /* save the l2 header of the original packet for later */
-    ctx->l2len = get_l2len(buf, len, ctx->dlt);
+    ctx->l2len = get_l2len(buf, (int)len, ctx->dlt);
     memcpy(ctx->l2header, buf, ctx->l2len);
     memcpy(ctx->l2header, buf, ctx->l2len);
 
 
     if ((pkt = pkt_new(len)) == NULL) {
     if ((pkt = pkt_new(len)) == NULL) {
         strcpy(ctx->errbuf, "unable to pkt_new()");
         strcpy(ctx->errbuf, "unable to pkt_new()");
         return -1;
         return -1;
     }
     }
-//    if (len > PKT_BUF_LEN) {
-//        sprintf(ctx->errbuf, "skipping oversized packet: %zu", len);
-//        return -1;
-//    }
 
 
     memcpy(pkt->pkt_data, buf, len);
     memcpy(pkt->pkt_data, buf, len);
     pkt->pkt_end = pkt->pkt_data + len;
     pkt->pkt_end = pkt->pkt_data + len;
@@ -77,11 +68,11 @@ fragroute_process(fragroute_t *ctx, void *buf, size_t len)
         strcpy(ctx->errbuf, "skipping non-IP packet");
         strcpy(ctx->errbuf, "skipping non-IP packet");
         return -1;
         return -1;
     }
     }
-/*  Don't always checksum packets before being fragged
-    if (pkt->pkt_eth && htons(pkt->pkt_eth->eth_type) == ETH_TYPE_IP) {
-        ip_checksum(pkt->pkt_ip, len);
-    }
-*/
+    /*  Don't always checksum packets before being fragged
+        if (pkt->pkt_eth && htons(pkt->pkt_eth->eth_type) == ETH_TYPE_IP) {
+            ip_checksum(pkt->pkt_ip, len);
+        }
+    */
 
 
     TAILQ_INIT(ctx->pktq);
     TAILQ_INIT(ctx->pktq);
     TAILQ_INSERT_TAIL(ctx->pktq, pkt, pkt_next);
     TAILQ_INSERT_TAIL(ctx->pktq, pkt, pkt_next);
@@ -103,23 +94,23 @@ fragroute_getfragment(fragroute_t *ctx, char **packet)
     static struct pkt *next = NULL;
     static struct pkt *next = NULL;
     char *pkt_data = *packet;
     char *pkt_data = *packet;
     u_int32_t length;
     u_int32_t length;
-    
+
     if (ctx->first_packet != 0) {
     if (ctx->first_packet != 0) {
         pkt = next;
         pkt = next;
     } else {
     } else {
         ctx->first_packet = 1;
         ctx->first_packet = 1;
         pkt = TAILQ_FIRST(ctx->pktq);
         pkt = TAILQ_FIRST(ctx->pktq);
     }
     }
-    
+
     if (pkt != TAILQ_END(&(ctx->pktq))) {
     if (pkt != TAILQ_END(&(ctx->pktq))) {
         next = TAILQ_NEXT(pkt, pkt_next);
         next = TAILQ_NEXT(pkt, pkt_next);
         memcpy(pkt_data, pkt->pkt_data, pkt->pkt_end - pkt->pkt_data);
         memcpy(pkt_data, pkt->pkt_data, pkt->pkt_end - pkt->pkt_data);
-        
+
         /* return the original L2 header */
         /* return the original L2 header */
         memcpy(pkt_data, ctx->l2header, ctx->l2len);
         memcpy(pkt_data, ctx->l2header, ctx->l2len);
         length = pkt->pkt_end - pkt->pkt_data;
         length = pkt->pkt_end - pkt->pkt_data;
         pkt = next;
         pkt = next;
-        return length;
+        return (int)length;
     }
     }
 
 
     return 0; // nothing
     return 0; // nothing
@@ -134,7 +125,6 @@ fragroute_init(const int mtu, const int dlt, const char *config, char *errbuf)
         sprintf(errbuf, "Fragroute only supports DLT_EN10MB pcap files");
         sprintf(errbuf, "Fragroute only supports DLT_EN10MB pcap files");
         return NULL;
         return NULL;
     }
     }
-        
 
 
     ctx = (fragroute_t *)safe_malloc(sizeof(fragroute_t));
     ctx = (fragroute_t *)safe_malloc(sizeof(fragroute_t));
     ctx->pktq = (struct pktq *)safe_malloc(sizeof(struct pktq));
     ctx->pktq = (struct pktq *)safe_malloc(sizeof(struct pktq));

+ 16 - 25
src/fragroute/fragroute.h

@@ -5,9 +5,9 @@
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *   Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  *
  *
- *   The Tcpreplay Suite of tools is free software: you can redistribute it 
- *   and/or modify it under the terms of the GNU General Public License as 
- *   published by the Free Software Foundation, either version 3 of the 
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it
+ *   and/or modify it under the terms of the GNU General Public License as
+ *   published by the Free Software Foundation, either version 3 of the
  *   License, or with the authors permission any later version.
  *   License, or with the authors permission any later version.
  *
  *
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
@@ -18,33 +18,26 @@
  *   You should have received a copy of the GNU General Public License
  *   You should have received a copy of the GNU General Public License
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
- 
+
+#pragma once
 
 
 #include "config.h"
 #include "config.h"
 #include "pkt.h"
 #include "pkt.h"
 
 
-#ifndef __FRAGROUTE_H__
-#define __FRAGROUTE_H__
-
 #define FRAGROUTE_ERRBUF_LEN 1024
 #define FRAGROUTE_ERRBUF_LEN 1024
 
 
 /* Fragroute context. */
 /* Fragroute context. */
 struct fragroute_s {
 struct fragroute_s {
-    struct addr     src;
-    struct addr     dst;
-    struct addr     smac;
-    struct addr     dmac;
-    int     dlt;
-    int        mtu;
-    int     first_packet; /* have we called getfragment() yet after process()? */
-    int     l2len;
-    u_char  l2header[50];
-//    arp_t        *arp;
-//    eth_t        *eth;
-//    intf_t        *intf;
-//    route_t        *route;
-//    tun_t        *tun;
-    char        errbuf[FRAGROUTE_ERRBUF_LEN];
+    struct addr src;
+    struct addr dst;
+    struct addr smac;
+    struct addr dmac;
+    int dlt;
+    int mtu;
+    int first_packet; /* have we called getfragment() yet after process()? */
+    int l2len;
+    u_char l2header[50];
+    char errbuf[FRAGROUTE_ERRBUF_LEN];
     struct pktq *pktq; /* packet chain */
     struct pktq *pktq; /* packet chain */
 };
 };
 
 
@@ -52,7 +45,5 @@ typedef struct fragroute_s fragroute_t;
 
 
 int fragroute_process(fragroute_t *ctx, void *buf, size_t len);
 int fragroute_process(fragroute_t *ctx, void *buf, size_t len);
 int fragroute_getfragment(fragroute_t *ctx, char **packet);
 int fragroute_getfragment(fragroute_t *ctx, char **packet);
-fragroute_t * fragroute_init(const int mtu, const int dlt, const char *config, char *errbuf);
+fragroute_t *fragroute_init(const int mtu, const int dlt, const char *config, char *errbuf);
 void fragroute_close(fragroute_t *ctx);
 void fragroute_close(fragroute_t *ctx);
-
-#endif /* __FRAGROUTE_H__ */

+ 10 - 18
src/fragroute/iputil.c

@@ -1,7 +1,6 @@
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-#include "iputil.h"
 #ifdef HAVE_DNET_H
 #ifdef HAVE_DNET_H
 #include <dnet.h>
 #include <dnet.h>
 #endif
 #endif
@@ -12,12 +11,10 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <string.h>
 #include <string.h>
 
 
-static ssize_t
-inet_add_option_6(void *buf, size_t len, int proto, const void *optbuf, size_t optlen);
+static ssize_t inet_add_option_6(void *buf, size_t len, int proto, const void *optbuf, size_t optlen);
 
 
 ssize_t
 ssize_t
-inet_add_option(uint16_t eth_type, void *buf, size_t len,
-                int proto, const void *optbuf, size_t optlen)
+inet_add_option(uint16_t eth_type, void *buf, size_t len, int proto, const void *optbuf, size_t optlen)
 {
 {
     if (eth_type == ETH_TYPE_IP) {
     if (eth_type == ETH_TYPE_IP) {
         return ip_add_option(buf, len, proto, optbuf, optlen);
         return ip_add_option(buf, len, proto, optbuf, optlen);
@@ -52,15 +49,14 @@ inet_add_option_6(void *buf, size_t len, int proto, const void *optbuf, size_t o
     hl = tcp->th_off << 2;
     hl = tcp->th_off << 2;
     p = (u_char *)tcp + hl;
     p = (u_char *)tcp + hl;
 
 
-    datalen = ntohs(ip6->ip6_plen) + IP6_HDR_LEN - (p - (u_char *)buf);
+    datalen = ntohs(ip6->ip6_plen) + IP6_HDR_LEN - (int)(p - (u_char *)buf);
 
 
     /* Compute padding to next word boundary. */
     /* Compute padding to next word boundary. */
-    if ((padlen = 4 - (optlen % 4)) == 4)
+    if ((padlen = 4 - (int)(optlen % 4)) == 4)
         padlen = 0;
         padlen = 0;
 
 
     /* XXX - IP_HDR_LEN_MAX == TCP_HDR_LEN_MAX */
     /* XXX - IP_HDR_LEN_MAX == TCP_HDR_LEN_MAX */
-    if (hl + optlen + padlen > IP_HDR_LEN_MAX ||
-            ntohs(ip6->ip6_plen) + IP6_HDR_LEN + optlen + padlen > len) {
+    if (hl + optlen + padlen > IP_HDR_LEN_MAX || ntohs(ip6->ip6_plen) + IP6_HDR_LEN + optlen + padlen > len) {
         errno = EINVAL;
         errno = EINVAL;
         return (-1);
         return (-1);
     }
     }
@@ -82,10 +78,9 @@ inet_add_option_6(void *buf, size_t len, int proto, const void *optbuf, size_t o
 
 
     ip6->ip6_plen = htons(ntohs(ip6->ip6_plen) + optlen);
     ip6->ip6_plen = htons(ntohs(ip6->ip6_plen) + optlen);
 
 
-    return (optlen);
+    return (ssize_t)optlen;
 }
 }
 
 
-
 void
 void
 inet_checksum(uint16_t eth_type, void *buf, size_t len)
 inet_checksum(uint16_t eth_type, void *buf, size_t len)
 {
 {
@@ -97,8 +92,7 @@ inet_checksum(uint16_t eth_type, void *buf, size_t len)
 }
 }
 
 
 int
 int
-raw_ip_opt_parse(int argc, char *argv[], uint8_t *opt_type, uint8_t *opt_len,
-        uint8_t *buff, int buff_len)
+raw_ip_opt_parse(int argc, char *argv[], uint8_t *opt_type, uint8_t *opt_len, uint8_t *buff, int buff_len)
 {
 {
     int i, j;
     int i, j;
 
 
@@ -118,16 +112,14 @@ raw_ip_opt_parse(int argc, char *argv[], uint8_t *opt_type, uint8_t *opt_len,
         }
         }
     }
     }
     if (*opt_len != j + 2) {
     if (*opt_len != j + 2) {
-        warnx("invalid opt->len (%d) doesn't match data length (%d)",
-                *opt_len, j);
+        warnx("invalid opt->len (%d) doesn't match data length (%d)", *opt_len, j);
         return -1;
         return -1;
     }
     }
     return 0;
     return 0;
 }
 }
 
 
 int
 int
-raw_ip6_opt_parse(int argc, char *argv[], uint8_t *proto, int *len,
-        uint8_t *buff, int buff_len)
+raw_ip6_opt_parse(int argc, char *argv[], uint8_t *proto, int *len, uint8_t *buff, int buff_len)
 {
 {
     int i, j;
     int i, j;
 
 

+ 3 - 4
src/fragroute/iputil.h

@@ -1,5 +1,6 @@
-#ifndef IPUTIL_H
-#define IPUTIL_H
+#pragma once
+
+#include "defines.h"
 
 
 ssize_t inet_add_option(uint16_t eth_type, void *buf, size_t len,
 ssize_t inet_add_option(uint16_t eth_type, void *buf, size_t len,
                 int proto, const void *optbuf, size_t optlen);
                 int proto, const void *optbuf, size_t optlen);
@@ -9,5 +10,3 @@ int raw_ip_opt_parse(int argc, char *argv[], uint8_t *type, uint8_t *len,
         uint8_t *buff, int buff_len);
         uint8_t *buff, int buff_len);
 int raw_ip6_opt_parse(int argc, char *argv[], uint8_t *proto, int *len,
 int raw_ip6_opt_parse(int argc, char *argv[], uint8_t *proto, int *len,
         uint8_t *buff, int buff_len);
         uint8_t *buff, int buff_len);
-
-#endif /* IPUTIL_H */

+ 51 - 55
src/fragroute/mod.c

@@ -7,66 +7,62 @@
  * $Id$
  * $Id$
  */
  */
 
 
-#include "config.h"
-#include "lib/queue.h"
+#include "mod.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
+#include "argv.h"
+#include "lib/queue.h"
 #include <ctype.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "argv.h"
-#include "mod.h"
-
-#define MAX_ARGS         128
+#define MAX_ARGS 128
 
 
 struct rule {
 struct rule {
-    struct mod        *mod;
-    void            *data;
-    TAILQ_ENTRY(rule)     next;
+    struct mod *mod;
+    void *data;
+    TAILQ_ENTRY(rule) next;
 };
 };
 
 
 /*
 /*
  * new modules must be registered here.
  * new modules must be registered here.
  */
  */
-extern struct mod     mod_delay;
-extern struct mod     mod_drop;
-extern struct mod     mod_dup;
-extern struct mod     mod_echo;
-extern struct mod     mod_ip_chaff;
-extern struct mod     mod_ip_frag;
-extern struct mod     mod_ip_opt;
-extern struct mod     mod_ip_ttl;
-extern struct mod     mod_ip_tos;
-extern struct mod     mod_ip6_qos;
-extern struct mod     mod_ip6_opt;
-extern struct mod     mod_order;
-extern struct mod     mod_print;
-extern struct mod     mod_tcp_chaff;
-extern struct mod     mod_tcp_opt;
-extern struct mod     mod_tcp_seg;
-
-static struct mod *mods[] = {
-    &mod_delay,
-    &mod_drop,
-    &mod_dup,
-    &mod_echo,
-    &mod_ip_chaff,
-    &mod_ip_frag,
-    &mod_ip_opt,
-    &mod_ip_ttl,
-    &mod_ip_tos,
-    &mod_ip6_qos,
-    &mod_ip6_opt,
-    &mod_order,
-    &mod_print,
-    &mod_tcp_chaff,
-    &mod_tcp_opt,
-    &mod_tcp_seg,
-    NULL
-};
+extern struct mod mod_delay;
+extern struct mod mod_drop;
+extern struct mod mod_dup;
+extern struct mod mod_echo;
+extern struct mod mod_ip_chaff;
+extern struct mod mod_ip_frag;
+extern struct mod mod_ip_opt;
+extern struct mod mod_ip_ttl;
+extern struct mod mod_ip_tos;
+extern struct mod mod_ip6_qos;
+extern struct mod mod_ip6_opt;
+extern struct mod mod_order;
+extern struct mod mod_print;
+extern struct mod mod_tcp_chaff;
+extern struct mod mod_tcp_opt;
+extern struct mod mod_tcp_seg;
+
+static struct mod *mods[] = {&mod_delay,
+                             &mod_drop,
+                             &mod_dup,
+                             &mod_echo,
+                             &mod_ip_chaff,
+                             &mod_ip_frag,
+                             &mod_ip_opt,
+                             &mod_ip_ttl,
+                             &mod_ip_tos,
+                             &mod_ip6_qos,
+                             &mod_ip6_opt,
+                             &mod_order,
+                             &mod_print,
+                             &mod_tcp_chaff,
+                             &mod_tcp_opt,
+                             &mod_tcp_seg,
+                             NULL};
 
 
 static TAILQ_HEAD(head, rule) rules;
 static TAILQ_HEAD(head, rule) rules;
 
 
@@ -99,7 +95,6 @@ mod_open(const char *script, char *errbuf)
     dbg(1, "opened config file...");
     dbg(1, "opened config file...");
     /* read the file, one line at a time... */
     /* read the file, one line at a time... */
     for (i = 1; fgets(buf, sizeof(buf), fp) != NULL; i++) {
     for (i = 1; fgets(buf, sizeof(buf), fp) != NULL; i++) {
-
         /* skip comments & blank lines */
         /* skip comments & blank lines */
         if (*buf == '#' || *buf == '\r' || *buf == '\n')
         if (*buf == '#' || *buf == '\r' || *buf == '\n')
             continue;
             continue;
@@ -136,10 +131,8 @@ mod_open(const char *script, char *errbuf)
         rule->mod = *m;
         rule->mod = *m;
 
 
         /* pass the remaining args to the rule */
         /* pass the remaining args to the rule */
-        if (rule->mod->open != NULL &&
-            (rule->data = rule->mod->open(argc, argv)) == NULL) {
-            sprintf(errbuf, "invalid argument to directive '%s' (line %d)",
-                rule->mod->name, i);
+        if (rule->mod->open != NULL && (rule->data = rule->mod->open(argc, argv)) == NULL) {
+            sprintf(errbuf, "invalid argument to directive '%s' (line %d)", rule->mod->name, i);
             ret = -1;
             ret = -1;
             break;
             break;
         }
         }
@@ -150,10 +143,11 @@ mod_open(const char *script, char *errbuf)
     /* close the file */
     /* close the file */
     fclose(fp);
     fclose(fp);
     dbg(1, "close file...");
     dbg(1, "close file...");
-    
+
     if (ret == 0) {
     if (ret == 0) {
         buf[0] = '\0';
         buf[0] = '\0';
-        TAILQ_FOREACH(rule, &rules, next) {
+        TAILQ_FOREACH(rule, &rules, next)
+        {
             strlcat(buf, rule->mod->name, sizeof(buf));
             strlcat(buf, rule->mod->name, sizeof(buf));
             strlcat(buf, " -> ", sizeof(buf));
             strlcat(buf, " -> ", sizeof(buf));
         }
         }
@@ -172,7 +166,8 @@ mod_apply(struct pktq *pktq)
 {
 {
     struct rule *rule;
     struct rule *rule;
 
 
-    TAILQ_FOREACH(rule, &rules, next) {
+    TAILQ_FOREACH(rule, &rules, next)
+    {
         rule->mod->apply(rule->data, pktq);
         rule->mod->apply(rule->data, pktq);
     }
     }
 }
 }
@@ -182,7 +177,8 @@ mod_close(void)
 {
 {
     struct rule *rule;
     struct rule *rule;
 
 
-    TAILQ_FOREACH_REVERSE(rule, &rules, next, head) {
+    TAILQ_FOREACH_REVERSE(rule, &rules, next, head)
+    {
         if (rule->mod->close != NULL)
         if (rule->mod->close != NULL)
             rule->data = rule->mod->close(rule->data);
             rule->data = rule->mod->close(rule->data);
         TAILQ_REMOVE(&rules, rule, next);
         TAILQ_REMOVE(&rules, rule, next);

+ 1 - 4
src/fragroute/mod.h

@@ -6,8 +6,7 @@
  * $Id$
  * $Id$
  */
  */
 
 
-#ifndef MOD_H
-#define MOD_H
+#pragma once
 
 
 #include "pkt.h"
 #include "pkt.h"
 
 
@@ -23,5 +22,3 @@ void    mod_usage(void);
 int     mod_open(const char *script, char *errbuf);
 int     mod_open(const char *script, char *errbuf);
 void    mod_apply(struct pktq *pktq);
 void    mod_apply(struct pktq *pktq);
 void    mod_close(void);
 void    mod_close(void);
-
-#endif /* MOD_H */

+ 16 - 19
src/fragroute/mod_delay.c

@@ -7,22 +7,19 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
-#include <stdio.h>
+#include "mod.h"
+#include "pkt.h"
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "pkt.h"
-#include "mod.h"
-
-#define DELAY_FIRST    1
-#define DELAY_LAST    2
-#define DELAY_RANDOM    3
+#define DELAY_FIRST 1
+#define DELAY_LAST 2
+#define DELAY_RANDOM 3
 
 
 struct delay_data {
 struct delay_data {
-    rand_t        *rnd;
-    int         which;
-    struct timeval     tv;
+    rand_t *rnd;
+    int which;
+    struct timeval tv;
 };
 };
 
 
 void *
 void *
@@ -60,12 +57,12 @@ delay_open(int argc, char *argv[])
     else
     else
         return (delay_close(data));
         return (delay_close(data));
 
 
-    if ((usec = atoi(argv[2])) == 0)
+    if ((usec = strtol(argv[2], NULL, 10)) == 0)
         return (delay_close(data));
         return (delay_close(data));
 
 
     usec *= 1000;
     usec *= 1000;
-    data->tv.tv_sec = usec / 1000000;
-    data->tv.tv_usec = usec % 1000000;
+    data->tv.tv_sec = (time_t)(usec / 1000000);
+    data->tv.tv_usec = (suseconds_t)(usec % 1000000);
 
 
     return (data);
     return (data);
 }
 }
@@ -89,9 +86,9 @@ delay_apply(void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_delay = {
 struct mod mod_delay = {
-    "delay",            /* name */
-    "delay first|last|random <ms>",    /* usage */
-    delay_open,            /* open */
-    delay_apply,           /* apply */
-    delay_close            /* close */
+        "delay",                        /* name */
+        "delay first|last|random <ms>", /* usage */
+        delay_open,                     /* open */
+        delay_apply,                    /* apply */
+        delay_close                     /* close */
 };
 };

+ 15 - 19
src/fragroute/mod_drop.c

@@ -7,22 +7,19 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
-#include <stdio.h>
+#include "mod.h"
+#include "pkt.h"
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "pkt.h"
-#include "mod.h"
-
-#define DROP_FIRST    1
-#define DROP_LAST    2
-#define DROP_RANDOM    3
+#define DROP_FIRST 1
+#define DROP_LAST 2
+#define DROP_RANDOM 3
 
 
 struct drop_data {
 struct drop_data {
-    rand_t    *rnd;
-    int     which;
-    int     percent;
+    rand_t *rnd;
+    int which;
+    int percent;
 };
 };
 
 
 void *
 void *
@@ -59,7 +56,7 @@ drop_open(int argc, char *argv[])
     else
     else
         return (drop_close(data));
         return (drop_close(data));
 
 
-    if ((data->percent = atoi(argv[2])) <= 0 || data->percent > 100)
+    if ((data->percent = (int)strtol(argv[2], NULL, 10)) <= 0 || data->percent > 100)
         return (drop_close(data));
         return (drop_close(data));
 
 
     return (data);
     return (data);
@@ -71,8 +68,7 @@ drop_apply(void *d, struct pktq *pktq)
     struct drop_data *data = (struct drop_data *)d;
     struct drop_data *data = (struct drop_data *)d;
     struct pkt *pkt;
     struct pkt *pkt;
 
 
-    if (data->percent < 100 &&
-        (rand_uint16(data->rnd) % 100) > data->percent)
+    if (data->percent < 100 && (rand_uint16(data->rnd) % 100) > data->percent)
         return (0);
         return (0);
 
 
     if (data->which == DROP_FIRST)
     if (data->which == DROP_FIRST)
@@ -91,9 +87,9 @@ drop_apply(void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_drop = {
 struct mod mod_drop = {
-    "drop",                    /* name */
-    "drop first|last|random <prob-%>",    /* usage */
-    drop_open,                /* open */
-    drop_apply,               /* apply */
-    drop_close                /* close */
+        "drop",                            /* name */
+        "drop first|last|random <prob-%>", /* usage */
+        drop_open,                         /* open */
+        drop_apply,                        /* apply */
+        drop_close                         /* close */
 };
 };

+ 15 - 19
src/fragroute/mod_dup.c

@@ -7,22 +7,19 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
-#include <stdio.h>
+#include "mod.h"
+#include "pkt.h"
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "pkt.h"
-#include "mod.h"
-
-#define DUP_FIRST    1
-#define DUP_LAST    2
-#define DUP_RANDOM    3
+#define DUP_FIRST 1
+#define DUP_LAST 2
+#define DUP_RANDOM 3
 
 
 struct dup_data {
 struct dup_data {
-    rand_t    *rnd;
-    int     which;
-    int     percent;
+    rand_t *rnd;
+    int which;
+    int percent;
 };
 };
 
 
 void *
 void *
@@ -59,7 +56,7 @@ dup_open(int argc, char *argv[])
     else
     else
         return (dup_close(data));
         return (dup_close(data));
 
 
-    if ((data->percent = atoi(argv[2])) <= 0 || data->percent > 100)
+    if ((data->percent = (int)strtol(argv[2], NULL, 10)) <= 0 || data->percent > 100)
         return (dup_close(data));
         return (dup_close(data));
 
 
     return (data);
     return (data);
@@ -71,8 +68,7 @@ dup_apply(void *d, struct pktq *pktq)
     struct dup_data *data = (struct dup_data *)d;
     struct dup_data *data = (struct dup_data *)d;
     struct pkt *pkt, *new;
     struct pkt *pkt, *new;
 
 
-    if (data->percent < 100 &&
-        (rand_uint16(data->rnd) % 100) > data->percent)
+    if (data->percent < 100 && (rand_uint16(data->rnd) % 100) > data->percent)
         return (0);
         return (0);
 
 
     if (data->which == DUP_FIRST)
     if (data->which == DUP_FIRST)
@@ -95,9 +91,9 @@ dup_apply(void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_dup = {
 struct mod mod_dup = {
-    "dup",                    /* name */
-    "dup first|last|random <prob-%>",    /* usage */
-    dup_open,                /* open */
-    dup_apply,               /* apply */
-    dup_close                /* close */
+        "dup",                            /* name */
+        "dup first|last|random <prob-%>", /* usage */
+        dup_open,                         /* open */
+        dup_apply,                        /* apply */
+        dup_close                         /* close */
 };
 };

+ 7 - 11
src/fragroute/mod_echo.c

@@ -7,16 +7,12 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
-#include <sys/types.h>
-
+#include "argv.h"
+#include "mod.h"
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "argv.h"
-#include "mod.h"
-
 void *
 void *
 echo_open(int argc, char *argv[])
 echo_open(int argc, char *argv[])
 {
 {
@@ -49,9 +45,9 @@ echo_close(void *d)
 }
 }
 
 
 struct mod mod_echo = {
 struct mod mod_echo = {
-    "echo",                /* name */
-    "echo <string> ...",        /* usage */
-    echo_open,            /* open */
-    echo_apply,            /* apply */
-    echo_close            /* close */
+        "echo",              /* name */
+        "echo <string> ...", /* usage */
+        echo_open,           /* open */
+        echo_apply,          /* apply */
+        echo_close           /* close */
 };
 };

+ 32 - 36
src/fragroute/mod_ip6_opt.c

@@ -6,39 +6,33 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
+#include "iputil.h"
+#include "mod.h"
+#include "pkt.h"
 #include <err.h>
 #include <err.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "pkt.h"
-#include "mod.h"
-#include "iputil.h"
-
 #define MAX_ADDRS 32
 #define MAX_ADDRS 32
 
 
-#define OPT6_TYPE_ROUTE     1
-#define OPT6_TYPE_RAW     2
+#define OPT6_TYPE_ROUTE 1
+#define OPT6_TYPE_RAW 2
 
 
-struct ip6_opt_data_route
-{
+struct ip6_opt_data_route {
     int segments;
     int segments;
     struct addr addr[MAX_ADDRS];
     struct addr addr[MAX_ADDRS];
 };
 };
 
 
-struct ip6_opt_data_raw
-{
+struct ip6_opt_data_raw {
     int len;
     int len;
     uint8_t proto;
     uint8_t proto;
     uint8_t data8[512];
     uint8_t data8[512];
 };
 };
 
 
-struct ip6_opt_data
-{
+struct ip6_opt_data {
     int type;
     int type;
-    union
-    {
+    union {
         struct ip6_opt_data_route route;
         struct ip6_opt_data_route route;
         struct ip6_opt_data_raw raw;
         struct ip6_opt_data_raw raw;
     } u;
     } u;
@@ -67,8 +61,7 @@ ip6_opt_open(int argc, char *argv[])
         int i, j;
         int i, j;
 
 
         opt->type = OPT6_TYPE_ROUTE;
         opt->type = OPT6_TYPE_ROUTE;
-        if ((opt->u.route.segments = atoi(argv[2])) < 1 ||
-                opt->u.route.segments > MAX_ADDRS) {
+        if ((opt->u.route.segments = (int)strtol(argv[2], NULL, 10)) < 1 || opt->u.route.segments > MAX_ADDRS) {
             warnx("<segments> must be >= 1");
             warnx("<segments> must be >= 1");
             return (ip6_opt_close(opt));
             return (ip6_opt_close(opt));
         }
         }
@@ -81,17 +74,19 @@ ip6_opt_open(int argc, char *argv[])
         }
         }
 
 
         for (; j < argc; i++, j++) {
         for (; j < argc; i++, j++) {
-            if (addr_aton(argv[j], &opt->u.route.addr[i]) < 0 ||
-                    opt->u.route.addr[i].addr_type != ADDR_TYPE_IP6) {
+            if (addr_aton(argv[j], &opt->u.route.addr[i]) < 0 || opt->u.route.addr[i].addr_type != ADDR_TYPE_IP6) {
                 return (ip6_opt_close(opt));
                 return (ip6_opt_close(opt));
             }
             }
         }
         }
     } else if (strcasecmp(argv[1], "raw") == 0) {
     } else if (strcasecmp(argv[1], "raw") == 0) {
         opt->type = OPT6_TYPE_RAW;
         opt->type = OPT6_TYPE_RAW;
 
 
-        if (raw_ip6_opt_parse(argc - 2, &argv[2],
-                    &opt->u.raw.proto, &opt->u.raw.len,
-                    &opt->u.raw.data8[2], sizeof(opt->u.raw.data8) - 2) != 0)
+        if (raw_ip6_opt_parse(argc - 2,
+                              &argv[2],
+                              &opt->u.raw.proto,
+                              &opt->u.raw.len,
+                              &opt->u.raw.data8[2],
+                              sizeof(opt->u.raw.data8) - 2) != 0)
             return (ip6_opt_close(opt));
             return (ip6_opt_close(opt));
         opt->u.raw.len += 2;
         opt->u.raw.len += 2;
         opt->u.raw.data8[0] = 0;
         opt->u.raw.data8[0] = 0;
@@ -107,14 +102,15 @@ int
 ip6_opt_apply(void *d, struct pktq *pktq)
 ip6_opt_apply(void *d, struct pktq *pktq)
 {
 {
     struct ip6_opt_data *opt = (struct ip6_opt_data *)d;
     struct ip6_opt_data *opt = (struct ip6_opt_data *)d;
-    struct ip6_ext_hdr* ext;
+    struct ip6_ext_hdr *ext;
     int offset, len;
     int offset, len;
     struct pkt *pkt;
     struct pkt *pkt;
     uint8_t nxt, iph_nxt;
     uint8_t nxt, iph_nxt;
-    uint8_t* p;
+    uint8_t *p;
     int i;
     int i;
 
 
-    TAILQ_FOREACH(pkt, pktq, pkt_next) {
+    TAILQ_FOREACH(pkt, pktq, pkt_next)
+    {
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
 
 
         if (eth_type != ETH_TYPE_IPV6) {
         if (eth_type != ETH_TYPE_IPV6) {
@@ -122,11 +118,11 @@ ip6_opt_apply(void *d, struct pktq *pktq)
         }
         }
 
 
         nxt = pkt->pkt_ip6->ip6_nxt;
         nxt = pkt->pkt_ip6->ip6_nxt;
-        ext = (struct ip6_ext_hdr*)(((u_char*)pkt->pkt_ip6) + IP6_HDR_LEN);
+        ext = (struct ip6_ext_hdr *)(((u_char *)pkt->pkt_ip6) + IP6_HDR_LEN);
 
 
         if (opt->type == OPT6_TYPE_ROUTE) {
         if (opt->type == OPT6_TYPE_ROUTE) {
             offset = 8 + IP6_ADDR_LEN * opt->u.route.segments;
             offset = 8 + IP6_ADDR_LEN * opt->u.route.segments;
-            memmove(((u_char*)ext) + offset, ext, pkt->pkt_end - (u_char*)ext);
+            memmove(((u_char *)ext) + offset, ext, pkt->pkt_end - (u_char *)ext);
 
 
             pkt->pkt_end += offset;
             pkt->pkt_end += offset;
             pkt->pkt_ip_data += offset;
             pkt->pkt_ip_data += offset;
@@ -135,11 +131,11 @@ ip6_opt_apply(void *d, struct pktq *pktq)
 
 
             ext->ext_data.routing.type = 0;
             ext->ext_data.routing.type = 0;
             ext->ext_data.routing.segleft = opt->u.route.segments;
             ext->ext_data.routing.segleft = opt->u.route.segments;
-            ((uint32_t*)ext)[1] = 0; /* reserved */
+            ((uint32_t *)ext)[1] = 0; /* reserved */
 
 
             iph_nxt = IP_PROTO_ROUTING;
             iph_nxt = IP_PROTO_ROUTING;
 
 
-            p = (uint8_t*)(ext) + 8;
+            p = (uint8_t *)(ext) + 8;
 
 
             for (i = 0; i < opt->u.route.segments; ++i, p += IP6_ADDR_LEN) {
             for (i = 0; i < opt->u.route.segments; ++i, p += IP6_ADDR_LEN) {
                 memcpy(p, opt->u.route.addr[i].addr_data8, IP6_ADDR_LEN);
                 memcpy(p, opt->u.route.addr[i].addr_data8, IP6_ADDR_LEN);
@@ -147,14 +143,14 @@ ip6_opt_apply(void *d, struct pktq *pktq)
 
 
         } else if (opt->type == OPT6_TYPE_RAW) {
         } else if (opt->type == OPT6_TYPE_RAW) {
             offset = opt->u.raw.len;
             offset = opt->u.raw.len;
-            memmove(((u_char*)ext) + offset, ext, pkt->pkt_end - (u_char*)ext);
+            memmove(((u_char *)ext) + offset, ext, pkt->pkt_end - (u_char *)ext);
 
 
             pkt->pkt_end += offset;
             pkt->pkt_end += offset;
             pkt->pkt_ip_data += offset;
             pkt->pkt_ip_data += offset;
 
 
             iph_nxt = opt->u.raw.proto;
             iph_nxt = opt->u.raw.proto;
 
 
-            p = (uint8_t*)ext;
+            p = (uint8_t *)ext;
             memcpy(p, opt->u.raw.data8, opt->u.raw.len);
             memcpy(p, opt->u.raw.data8, opt->u.raw.len);
 
 
 #if 0
 #if 0
@@ -185,9 +181,9 @@ ip6_opt_apply(void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_ip6_opt = {
 struct mod mod_ip6_opt = {
-    "ip6_opt",                    /* name */
-    "ip6_opt [route <segments> <ip6-addr> ...] | [raw <type> <byte stream>]",        /* usage */
-    ip6_opt_open,                    /* open */
-    ip6_opt_apply,                    /* apply */
-    ip6_opt_close                    /* close */
+        "ip6_opt",                                                                /* name */
+        "ip6_opt [route <segments> <ip6-addr> ...] | [raw <type> <byte stream>]", /* usage */
+        ip6_opt_open,                                                             /* open */
+        ip6_opt_apply,                                                            /* apply */
+        ip6_opt_close                                                             /* close */
 };
 };

+ 15 - 21
src/fragroute/mod_ip6_qos.c

@@ -6,19 +6,15 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
+#include "mod.h"
+#include "pkt.h"
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "argv.h"
-#include "mod.h"
-#include "pkt.h"
-
-struct ip6_qos_data
-{
-    int    ip6_tc;
-    int    ip6_fl;
+struct ip6_qos_data {
+    int ip6_tc;
+    int ip6_fl;
 };
 };
 
 
 static void *
 static void *
@@ -41,12 +37,10 @@ ip6_qos_open(int argc, char *argv[])
     if ((data = calloc(1, sizeof(*data))) == NULL)
     if ((data = calloc(1, sizeof(*data))) == NULL)
         return (NULL);
         return (NULL);
 
 
-    if (sscanf(argv[1], "%x", (unsigned int*)&data->ip6_tc) != 1 ||
-            data->ip6_tc < 0 || data->ip6_tc > 255)
+    if (sscanf(argv[1], "%x", (unsigned int *)&data->ip6_tc) != 1 || data->ip6_tc < 0 || data->ip6_tc > 255)
         return (ip6_qos_close(data));
         return (ip6_qos_close(data));
 
 
-    if (sscanf(argv[2], "%x", (unsigned int*)&data->ip6_fl) != 1 ||
-            data->ip6_fl < 0 || data->ip6_fl > 0x100000)
+    if (sscanf(argv[2], "%x", (unsigned int *)&data->ip6_fl) != 1 || data->ip6_fl < 0 || data->ip6_fl > 0x100000)
         return (ip6_qos_close(data));
         return (ip6_qos_close(data));
 
 
     printf("init: %x\n", data->ip6_fl);
     printf("init: %x\n", data->ip6_fl);
@@ -60,13 +54,13 @@ ip6_qos_apply(void *d, struct pktq *pktq)
     struct ip6_qos_data *data = (struct ip6_qos_data *)d;
     struct ip6_qos_data *data = (struct ip6_qos_data *)d;
     struct pkt *pkt;
     struct pkt *pkt;
 
 
-    TAILQ_FOREACH(pkt, pktq, pkt_next) {
+    TAILQ_FOREACH(pkt, pktq, pkt_next)
+    {
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
 
 
         if (eth_type == ETH_TYPE_IPV6) {
         if (eth_type == ETH_TYPE_IPV6) {
             if (data->ip6_tc || data->ip6_fl) {
             if (data->ip6_tc || data->ip6_fl) {
-                pkt->pkt_ip6->ip6_flow = htonl((uint32_t)data->ip6_tc << 20 |
-                        data->ip6_fl);
+                pkt->pkt_ip6->ip6_flow = htonl((uint32_t)data->ip6_tc << 20 | data->ip6_fl);
                 pkt->pkt_ip6->ip6_vfc = (IP6_VERSION | (data->ip6_tc >> 4));
                 pkt->pkt_ip6->ip6_vfc = (IP6_VERSION | (data->ip6_tc >> 4));
             }
             }
         }
         }
@@ -75,9 +69,9 @@ ip6_qos_apply(void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_ip6_qos = {
 struct mod mod_ip6_qos = {
-    "ip6_qos",            /* name */
-    "ip6_qos <tc> <fl>",            /* usage */
-    ip6_qos_open,            /* open */
-    ip6_qos_apply,            /* apply */
-    ip6_qos_close            /* close */
+        "ip6_qos",           /* name */
+        "ip6_qos <tc> <fl>", /* usage */
+        ip6_qos_open,        /* open */
+        ip6_qos_apply,       /* apply */
+        ip6_qos_close        /* close */
 };
 };

+ 30 - 38
src/fragroute/mod_ip_chaff.c

@@ -7,24 +7,22 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "mod.h"
 #include "mod.h"
 #include "pkt.h"
 #include "pkt.h"
 #include "randutil.h"
 #include "randutil.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 
-#define CHAFF_TYPE_DUP     1
-#define CHAFF_TYPE_OPT     2
-#define CHAFF_TYPE_TTL     3
+#define CHAFF_TYPE_DUP 1
+#define CHAFF_TYPE_OPT 2
+#define CHAFF_TYPE_TTL 3
 
 
 struct ip_chaff_data {
 struct ip_chaff_data {
-    rand_t        *rnd;
-    int         type;
-    int         ttl;
-    struct pktq    *pktq;
+    rand_t *rnd;
+    int type;
+    int ttl;
+    struct pktq *pktq;
 };
 };
 
 
 void *
 void *
@@ -56,8 +54,8 @@ ip_chaff_open(int argc, char *argv[])
         data->type = CHAFF_TYPE_DUP;
         data->type = CHAFF_TYPE_DUP;
     } else if (strcasecmp(argv[1], "opt") == 0) {
     } else if (strcasecmp(argv[1], "opt") == 0) {
         data->type = CHAFF_TYPE_OPT;
         data->type = CHAFF_TYPE_OPT;
-    } else if ((data->ttl = atoi(argv[1])) >= 0 && data->ttl < 256) {
-                data->type = CHAFF_TYPE_TTL;
+    } else if ((data->ttl = strtol(argv[1], NULL, 10)) >= 0 && data->ttl < 256) {
+        data->type = CHAFF_TYPE_TTL;
     } else
     } else
         return (ip_chaff_close(data));
         return (ip_chaff_close(data));
 
 
@@ -80,39 +78,33 @@ ip_chaff_apply(void *d, struct pktq *pktq)
             continue;
             continue;
 
 
         new = pkt_dup(pkt);
         new = pkt_dup(pkt);
-        rand_strset(data->rnd, new->pkt_ip_data,
-            new->pkt_end - new->pkt_ip_data + 1);
+        rand_strset(data->rnd, new->pkt_ip_data, new->pkt_end - new->pkt_ip_data + 1);
 
 
         switch (data->type) {
         switch (data->type) {
         case CHAFF_TYPE_DUP:
         case CHAFF_TYPE_DUP:
             new->pkt_ts.tv_usec = 1;
             new->pkt_ts.tv_usec = 1;
             if (eth_type == ETH_TYPE_IP) {
             if (eth_type == ETH_TYPE_IP) {
-            ip_checksum(new->pkt_ip, new->pkt_ip_data -
-                new->pkt_eth_data);
+                ip_checksum(new->pkt_ip, new->pkt_ip_data - new->pkt_eth_data);
             }
             }
             break;
             break;
         case CHAFF_TYPE_OPT:
         case CHAFF_TYPE_OPT:
             if (eth_type == ETH_TYPE_IP) {
             if (eth_type == ETH_TYPE_IP) {
-            opt.opt_type = 0x42;
-            opt.opt_len = IP_OPT_LEN;
-            i = ip_add_option(new->pkt_ip,
-                new->pkt_buf_size - ETH_HDR_LEN, IP_PROTO_IP,
-                &opt, opt.opt_len);
-            /* XXX - whack opt with random crap */
-            *(uint32_t *)new->pkt_ip_data = rand_uint32(data->rnd);
-            new->pkt_ip_data += i;
-            new->pkt_end += i;
-            ip_checksum(new->pkt_ip, new->pkt_ip_data -
-                new->pkt_eth_data);
+                opt.opt_type = 0x42;
+                opt.opt_len = IP_OPT_LEN;
+                i = ip_add_option(new->pkt_ip, new->pkt_buf_size - ETH_HDR_LEN, IP_PROTO_IP, &opt, opt.opt_len);
+                /* XXX - whack opt with random crap */
+                *(uint32_t *)new->pkt_ip_data = rand_uint32(data->rnd);
+                new->pkt_ip_data += i;
+                new->pkt_end += i;
+                ip_checksum(new->pkt_ip, new->pkt_ip_data - new->pkt_eth_data);
             } else if (eth_type == ETH_TYPE_IPV6) {
             } else if (eth_type == ETH_TYPE_IPV6) {
                 continue;
                 continue;
             }
             }
-            /* no break */
+            /* fall through */
         case CHAFF_TYPE_TTL:
         case CHAFF_TYPE_TTL:
             if (eth_type == ETH_TYPE_IP) {
             if (eth_type == ETH_TYPE_IP) {
-            new->pkt_ip->ip_ttl = data->ttl;
-            ip_checksum(new->pkt_ip, new->pkt_ip_data -
-                new->pkt_eth_data);
+                new->pkt_ip->ip_ttl = data->ttl;
+                ip_checksum(new->pkt_ip, new->pkt_ip_data - new->pkt_eth_data);
             } else if (eth_type == ETH_TYPE_IPV6) {
             } else if (eth_type == ETH_TYPE_IPV6) {
                 pkt->pkt_ip6->ip6_hlim = data->ttl;
                 pkt->pkt_ip6->ip6_hlim = data->ttl;
             }
             }
@@ -129,9 +121,9 @@ ip_chaff_apply(void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_ip_chaff = {
 struct mod mod_ip_chaff = {
-    "ip_chaff",                /* name */
-    "ip_chaff dup|opt|<ttl>",        /* usage */
-    ip_chaff_open,                /* open */
-    ip_chaff_apply,                /* apply */
-    ip_chaff_close                /* close */
+        "ip_chaff",               /* name */
+        "ip_chaff dup|opt|<ttl>", /* usage */
+        ip_chaff_open,            /* open */
+        ip_chaff_apply,           /* apply */
+        ip_chaff_close            /* close */
 };
 };

+ 42 - 62
src/fragroute/mod_ip_frag.c

@@ -6,37 +6,32 @@
  * $Id$
  * $Id$
  */
  */
 
 
-#include "config.h"
-#include "lib/queue.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
+#include "lib/queue.h"
 #include "mod.h"
 #include "mod.h"
 #include "pkt.h"
 #include "pkt.h"
 #include "randutil.h"
 #include "randutil.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 
 #ifndef MAX
 #ifndef MAX
-#define MAX(a,b)    (((a)>(b))?(a):(b))
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
 #endif
 #endif
 
 
-#define FAVOR_OLD    1
-#define FAVOR_NEW    2
+#define FAVOR_OLD 1
+#define FAVOR_NEW 2
 
 
-static int
-ip_frag_apply_ipv4(void *d, struct pktq *pktq);
+static int ip_frag_apply_ipv4(void *d, struct pktq *pktq);
 
 
-static int
-ip_frag_apply_ipv6(void *d, struct pktq *pktq);
+static int ip_frag_apply_ipv6(void *d, struct pktq *pktq);
 
 
-static struct ip_frag_data
-{
-    rand_t    *rnd;
-    int     size;
-    int     overlap;
+static struct ip_frag_data {
+    rand_t *rnd;
+    int size;
+    int overlap;
     uint32_t ident;
     uint32_t ident;
 } ip_frag_data;
 } ip_frag_data;
 
 
@@ -57,18 +52,16 @@ ip_frag_open(int argc, char *argv[])
         return (NULL);
         return (NULL);
     }
     }
     ip_frag_data.rnd = rand_open();
     ip_frag_data.rnd = rand_open();
-    ip_frag_data.size = atoi(argv[1]);
+    ip_frag_data.size = (int)strtol(argv[1], NULL, 10);
 
 
     if (ip_frag_data.size == 0 || (ip_frag_data.size % 8) != 0) {
     if (ip_frag_data.size == 0 || (ip_frag_data.size % 8) != 0) {
         warn("fragment size must be a multiple of 8");
         warn("fragment size must be a multiple of 8");
         return (ip_frag_close(&ip_frag_data));
         return (ip_frag_close(&ip_frag_data));
     }
     }
     if (argc == 3) {
     if (argc == 3) {
-        if (strcmp(argv[2], "old") == 0 ||
-            strcmp(argv[2], "win32") == 0)
+        if (strcmp(argv[2], "old") == 0 || strcmp(argv[2], "win32") == 0)
             ip_frag_data.overlap = FAVOR_OLD;
             ip_frag_data.overlap = FAVOR_OLD;
-        else if (strcmp(argv[2], "new") == 0 ||
-            strcmp(argv[2], "unix") == 0)
+        else if (strcmp(argv[2], "new") == 0 || strcmp(argv[2], "unix") == 0)
             ip_frag_data.overlap = FAVOR_NEW;
             ip_frag_data.overlap = FAVOR_NEW;
         else
         else
             return (ip_frag_close(&ip_frag_data));
             return (ip_frag_close(&ip_frag_data));
@@ -126,8 +119,7 @@ ip_frag_apply_ipv4(_U_ void *d, struct pktq *pktq)
             fraglen = MAX(UDP_HDR_LEN, ip_frag_data.size);
             fraglen = MAX(UDP_HDR_LEN, ip_frag_data.size);
             break;
             break;
         case IP_PROTO_TCP:
         case IP_PROTO_TCP:
-            fraglen = MAX(pkt->pkt_tcp->th_off << 2,
-                ip_frag_data.size);
+            fraglen = MAX(pkt->pkt_tcp->th_off << 2, ip_frag_data.size);
             break;
             break;
         default:
         default:
             fraglen = ip_frag_data.size;
             fraglen = ip_frag_data.size;
@@ -139,24 +131,22 @@ ip_frag_apply_ipv4(_U_ void *d, struct pktq *pktq)
         if (pkt->pkt_end - pkt->pkt_ip_data < fraglen)
         if (pkt->pkt_end - pkt->pkt_ip_data < fraglen)
             continue;
             continue;
 
 
-        for (p = pkt->pkt_ip_data; p < pkt->pkt_end; ) {
+        for (p = pkt->pkt_ip_data; p < pkt->pkt_end;) {
             new = pkt_new(pkt->pkt_buf_size);
             new = pkt_new(pkt->pkt_buf_size);
-            memcpy(new->pkt_eth, pkt->pkt_eth, (u_char*)pkt->pkt_eth_data - (u_char*)pkt->pkt_eth);
+            memcpy(new->pkt_eth, pkt->pkt_eth, (u_char *)pkt->pkt_eth_data - (u_char *)pkt->pkt_eth);
             memcpy(new->pkt_ip, pkt->pkt_ip, hl);
             memcpy(new->pkt_ip, pkt->pkt_ip, hl);
             new->pkt_ip_data = new->pkt_eth_data + hl;
             new->pkt_ip_data = new->pkt_eth_data + hl;
 
 
             p1 = p, p2 = NULL;
             p1 = p, p2 = NULL;
             off = (p - pkt->pkt_ip_data) >> 3;
             off = (p - pkt->pkt_ip_data) >> 3;
 
 
-            if (ip_frag_data.overlap != 0 && (off & 1) != 0 &&
-                    p + (fraglen << 1) < pkt->pkt_end) {
+            if (ip_frag_data.overlap != 0 && (off & 1) != 0 && p + (fraglen << 1) < pkt->pkt_end) {
                 struct pkt tmp;
                 struct pkt tmp;
                 u_char tmp_buf[pkt->pkt_buf_size];
                 u_char tmp_buf[pkt->pkt_buf_size];
 
 
                 tmp.pkt_buf = tmp_buf;
                 tmp.pkt_buf = tmp_buf;
                 tmp.pkt_buf_size = pkt->pkt_buf_size;
                 tmp.pkt_buf_size = pkt->pkt_buf_size;
-                rand_strset(ip_frag_data.rnd, tmp.pkt_buf,
-                        fraglen);
+                rand_strset(ip_frag_data.rnd, tmp.pkt_buf, fraglen);
                 if (ip_frag_data.overlap == FAVOR_OLD) {
                 if (ip_frag_data.overlap == FAVOR_OLD) {
                     p1 = p + fraglen;
                     p1 = p + fraglen;
                     p2 = tmp.pkt_buf;
                     p2 = tmp.pkt_buf;
@@ -164,11 +154,9 @@ ip_frag_apply_ipv4(_U_ void *d, struct pktq *pktq)
                     p1 = tmp.pkt_buf;
                     p1 = tmp.pkt_buf;
                     p2 = p + fraglen;
                     p2 = p + fraglen;
                 }
                 }
-                new->pkt_ip->ip_off = htons(IP_MF |
-                    (off + (fraglen >> 3)));
+                new->pkt_ip->ip_off = htons(IP_MF | (off + (fraglen >> 3)));
             } else {
             } else {
-                new->pkt_ip->ip_off = htons(off |
-                    ((p + fraglen < pkt->pkt_end) ? IP_MF: 0));
+                new->pkt_ip->ip_off = htons(off | ((p + fraglen < pkt->pkt_end) ? IP_MF : 0));
             }
             }
             new->pkt_ip->ip_len = htons(hl + fraglen);
             new->pkt_ip->ip_len = htons(hl + fraglen);
             ip_checksum(new->pkt_ip, hl + fraglen);
             ip_checksum(new->pkt_ip, hl + fraglen);
@@ -181,12 +169,12 @@ ip_frag_apply_ipv4(_U_ void *d, struct pktq *pktq)
                 new = pkt_dup(new);
                 new = pkt_dup(new);
                 new->pkt_ts.tv_usec = 1;
                 new->pkt_ts.tv_usec = 1;
                 new->pkt_ip->ip_off = htons(IP_MF | off);
                 new->pkt_ip->ip_off = htons(IP_MF | off);
-                new->pkt_ip->ip_len = htons(hl + (fraglen<<1));
-                ip_checksum(new->pkt_ip, hl + (fraglen<<1));
+                new->pkt_ip->ip_len = htons(hl + (fraglen << 1));
+                ip_checksum(new->pkt_ip, hl + (fraglen << 1));
 
 
                 memcpy(new->pkt_ip_data, p, fraglen);
                 memcpy(new->pkt_ip_data, p, fraglen);
-                memcpy(new->pkt_ip_data+fraglen, p2, fraglen);
-                new->pkt_end = new->pkt_ip_data + (fraglen<<1);
+                memcpy(new->pkt_ip_data + fraglen, p2, fraglen);
+                new->pkt_end = new->pkt_ip_data + (fraglen << 1);
                 TAILQ_INSERT_BEFORE(pkt, new, pkt_next);
                 TAILQ_INSERT_BEFORE(pkt, new, pkt_next);
                 p += (fraglen << 1);
                 p += (fraglen << 1);
             } else
             } else
@@ -201,7 +189,6 @@ ip_frag_apply_ipv4(_U_ void *d, struct pktq *pktq)
     return (0);
     return (0);
 }
 }
 
 
-
 static int
 static int
 ip_frag_apply_ipv6(_U_ void *d, struct pktq *pktq)
 ip_frag_apply_ipv6(_U_ void *d, struct pktq *pktq)
 {
 {
@@ -233,8 +220,7 @@ ip_frag_apply_ipv6(_U_ void *d, struct pktq *pktq)
             fraglen = MAX(UDP_HDR_LEN, ip_frag_data.size);
             fraglen = MAX(UDP_HDR_LEN, ip_frag_data.size);
             break;
             break;
         case IP_PROTO_TCP:
         case IP_PROTO_TCP:
-            fraglen = MAX(pkt->pkt_tcp->th_off << 2,
-                ip_frag_data.size);
+            fraglen = MAX(pkt->pkt_tcp->th_off << 2, ip_frag_data.size);
             break;
             break;
         default:
         default:
             fraglen = ip_frag_data.size;
             fraglen = ip_frag_data.size;
@@ -248,32 +234,28 @@ ip_frag_apply_ipv6(_U_ void *d, struct pktq *pktq)
 
 
         next_hdr = pkt->pkt_ip6->ip6_nxt;
         next_hdr = pkt->pkt_ip6->ip6_nxt;
 
 
-        for (p = pkt->pkt_ip_data; p < pkt->pkt_end; ) {
+        for (p = pkt->pkt_ip_data; p < pkt->pkt_end;) {
             new = pkt_new(pkt->pkt_buf_size);
             new = pkt_new(pkt->pkt_buf_size);
-            memcpy(new->pkt_eth, pkt->pkt_eth, (u_char*)pkt->pkt_eth_data - (u_char*)pkt->pkt_eth);
+            memcpy(new->pkt_eth, pkt->pkt_eth, (u_char *)pkt->pkt_eth_data - (u_char *)pkt->pkt_eth);
             memcpy(new->pkt_ip, pkt->pkt_ip, hl);
             memcpy(new->pkt_ip, pkt->pkt_ip, hl);
-            ext = (struct ip6_ext_hdr *)((u_char*)new->pkt_eth_data + hl);
-            new->pkt_ip_data = (u_char *)(ext) + 2 +
-                sizeof(struct ip6_ext_data_fragment);
+            ext = (struct ip6_ext_hdr *)((u_char *)new->pkt_eth_data + hl);
+            new->pkt_ip_data = (u_char *)(ext) + 2 + sizeof(struct ip6_ext_data_fragment);
             new->pkt_ip6->ip6_nxt = IP_PROTO_FRAGMENT;
             new->pkt_ip6->ip6_nxt = IP_PROTO_FRAGMENT;
 
 
             ext->ext_nxt = next_hdr;
             ext->ext_nxt = next_hdr;
             ext->ext_len = 0; /* ip6 fragf reserved */
             ext->ext_len = 0; /* ip6 fragf reserved */
             ext->ext_data.fragment.ident = ip_frag_data.ident;
             ext->ext_data.fragment.ident = ip_frag_data.ident;
 
 
-
             p1 = p, p2 = NULL;
             p1 = p, p2 = NULL;
             off = (p - pkt->pkt_ip_data) >> 3;
             off = (p - pkt->pkt_ip_data) >> 3;
 
 
-            if (ip_frag_data.overlap != 0 && (off & 1) != 0 &&
-                p + (fraglen << 1) < pkt->pkt_end) {
+            if (ip_frag_data.overlap != 0 && (off & 1) != 0 && p + (fraglen << 1) < pkt->pkt_end) {
                 struct pkt tmp;
                 struct pkt tmp;
                 u_char tmp_buf[pkt->pkt_buf_size];
                 u_char tmp_buf[pkt->pkt_buf_size];
 
 
                 tmp.pkt_buf = tmp_buf;
                 tmp.pkt_buf = tmp_buf;
                 tmp.pkt_buf_size = pkt->pkt_buf_size;
                 tmp.pkt_buf_size = pkt->pkt_buf_size;
-                rand_strset(ip_frag_data.rnd, tmp.pkt_buf,
-                    fraglen);
+                rand_strset(ip_frag_data.rnd, tmp.pkt_buf, fraglen);
                 if (ip_frag_data.overlap == FAVOR_OLD) {
                 if (ip_frag_data.overlap == FAVOR_OLD) {
                     p1 = p + fraglen;
                     p1 = p + fraglen;
                     p2 = tmp.pkt_buf;
                     p2 = tmp.pkt_buf;
@@ -281,11 +263,9 @@ ip_frag_apply_ipv6(_U_ void *d, struct pktq *pktq)
                     p1 = tmp.pkt_buf;
                     p1 = tmp.pkt_buf;
                     p2 = p + fraglen;
                     p2 = p + fraglen;
                 }
                 }
-                ext->ext_data.fragment.offlg =
-                    htons((off /*+ (fraglen >> 3)*/) << 3) | IP6_MORE_FRAG;
+                ext->ext_data.fragment.offlg = htons((off /*+ (fraglen >> 3)*/) << 3) | IP6_MORE_FRAG;
             } else {
             } else {
-                ext->ext_data.fragment.offlg = htons(off << 3) |
-                        ((p + fraglen < pkt->pkt_end) ? IP6_MORE_FRAG : 0);
+                ext->ext_data.fragment.offlg = htons(off << 3) | ((p + fraglen < pkt->pkt_end) ? IP6_MORE_FRAG : 0);
             }
             }
             new->pkt_ip6->ip6_plen = htons(fraglen + 8);
             new->pkt_ip6->ip6_plen = htons(fraglen + 8);
 
 
@@ -319,9 +299,9 @@ ip_frag_apply_ipv6(_U_ void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_ip_frag = {
 struct mod mod_ip_frag = {
-    "ip_frag",                /* name */
-    "ip_frag <size> [old|new]",        /* usage */
-    ip_frag_open,                /* open */
-    ip_frag_apply,                /* apply */
-    ip_frag_close                /* close */
+        "ip_frag",                  /* name */
+        "ip_frag <size> [old|new]", /* usage */
+        ip_frag_open,               /* open */
+        ip_frag_apply,              /* apply */
+        ip_frag_close               /* close */
 };
 };

+ 24 - 23
src/fragroute/mod_ip_opt.c

@@ -6,18 +6,16 @@
  * $Id$
  * $Id$
  */
  */
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
+#include "iputil.h"
+#include "mod.h"
+#include "pkt.h"
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "pkt.h"
-#include "mod.h"
-#include "iputil.h"
-
 void *
 void *
 ip_opt_close(void *d)
 ip_opt_close(void *d)
 {
 {
@@ -44,14 +42,18 @@ ip_opt_open(int argc, char *argv[])
     } else if (strcasecmp(argv[1], "ssrr") == 0) {
     } else if (strcasecmp(argv[1], "ssrr") == 0) {
         opt->opt_type = IP_OPT_SSRR;
         opt->opt_type = IP_OPT_SSRR;
     } else if (strcasecmp(argv[1], "raw") == 0) {
     } else if (strcasecmp(argv[1], "raw") == 0) {
-        if (raw_ip_opt_parse(argc - 2, &argv[2], &opt->opt_type, &opt->opt_len,
-                    &opt->opt_data.data8[0], sizeof(opt->opt_data.data8)) != 0)
+        if (raw_ip_opt_parse(argc - 2,
+                             &argv[2],
+                             &opt->opt_type,
+                             &opt->opt_len,
+                             &opt->opt_data.data8[0],
+                             sizeof(opt->opt_data.data8)) != 0)
             return (ip_opt_close(opt));
             return (ip_opt_close(opt));
         return opt;
         return opt;
     } else
     } else
         return (ip_opt_close(opt));
         return (ip_opt_close(opt));
 
 
-    if ((i = atoi(argv[2])) < 4 || i > 0xff) {
+    if ((i = (int)strtol(argv[2], NULL, 10)) < 4 || i > 0xff) {
         warn("<ptr> must be >= 4, and should be a multiple of 4");
         warn("<ptr> must be >= 4, and should be a multiple of 4");
         return (ip_opt_close(opt));
         return (ip_opt_close(opt));
     }
     }
@@ -75,28 +77,27 @@ ip_opt_apply(void *d, struct pktq *pktq)
     struct pkt *pkt;
     struct pkt *pkt;
     size_t len;
     size_t len;
 
 
-    TAILQ_FOREACH(pkt, pktq, pkt_next) {
+    TAILQ_FOREACH(pkt, pktq, pkt_next)
+    {
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
 
 
         if (eth_type == ETH_TYPE_IP) {
         if (eth_type == ETH_TYPE_IP) {
-        len = ip_add_option(pkt->pkt_ip, PKT_BUF_LEN - ETH_HDR_LEN,
-            IP_PROTO_IP, opt, opt->opt_len);
+            len = ip_add_option(pkt->pkt_ip, PKT_BUF_LEN - ETH_HDR_LEN, IP_PROTO_IP, opt, opt->opt_len);
 
 
-        if (len > 0) {
-            pkt->pkt_end += len;
-            pkt_decorate(pkt);
-            ip_checksum(pkt->pkt_ip,
-                pkt->pkt_end - pkt->pkt_eth_data);
+            if (len > 0) {
+                pkt->pkt_end += len;
+                pkt_decorate(pkt);
+                ip_checksum(pkt->pkt_ip, pkt->pkt_end - pkt->pkt_eth_data);
+            }
         }
         }
     }
     }
-    }
     return (0);
     return (0);
 }
 }
 
 
 struct mod mod_ip_opt = {
 struct mod mod_ip_opt = {
-    "ip_opt",                    /* name */
-    "ip_opt [lsrr|ssrr <ptr> <ip-addr> ...] | [raw <byte stream>]",        /* usage */
-    ip_opt_open,                    /* open */
-    ip_opt_apply,                    /* apply */
-    ip_opt_close                    /* close */
+        "ip_opt",                                                       /* name */
+        "ip_opt [lsrr|ssrr <ptr> <ip-addr> ...] | [raw <byte stream>]", /* usage */
+        ip_opt_open,                                                    /* open */
+        ip_opt_apply,                                                   /* apply */
+        ip_opt_close                                                    /* close */
 };
 };

+ 16 - 18
src/fragroute/mod_ip_tos.c

@@ -7,17 +7,15 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "argv.h"
 #include "argv.h"
 #include "mod.h"
 #include "mod.h"
 #include "pkt.h"
 #include "pkt.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 
 struct ip_tos_data {
 struct ip_tos_data {
-    int    tos;
+    int tos;
 };
 };
 
 
 void *
 void *
@@ -39,8 +37,7 @@ ip_tos_open(int argc, char *argv[])
     if ((data = calloc(1, sizeof(*data))) == NULL)
     if ((data = calloc(1, sizeof(*data))) == NULL)
         return (NULL);
         return (NULL);
 
 
-    if (sscanf(argv[1], "%i", &data->tos) != 1 ||
-        data->tos < 0 || data->tos > 255)
+    if (sscanf(argv[1], "%i", &data->tos) != 1 || data->tos < 0 || data->tos > 255)
         return (ip_tos_close(data));
         return (ip_tos_close(data));
 
 
     return (data);
     return (data);
@@ -52,22 +49,23 @@ ip_tos_apply(void *d, struct pktq *pktq)
     struct ip_tos_data *data = (struct ip_tos_data *)d;
     struct ip_tos_data *data = (struct ip_tos_data *)d;
     struct pkt *pkt;
     struct pkt *pkt;
 
 
-    TAILQ_FOREACH(pkt, pktq, pkt_next) {
+    TAILQ_FOREACH(pkt, pktq, pkt_next)
+    {
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
 
 
         if (eth_type == ETH_TYPE_IP) {
         if (eth_type == ETH_TYPE_IP) {
-        pkt->pkt_ip->ip_tos = data->tos;
-        /* XXX - do incremental checksum */
-        ip_checksum(pkt->pkt_ip, pkt->pkt_ip_data - pkt->pkt_eth_data);
-    }
+            pkt->pkt_ip->ip_tos = data->tos;
+            /* XXX - do incremental checksum */
+            ip_checksum(pkt->pkt_ip, pkt->pkt_ip_data - pkt->pkt_eth_data);
+        }
     }
     }
     return (0);
     return (0);
 }
 }
 
 
 struct mod mod_ip_tos = {
 struct mod mod_ip_tos = {
-    "ip_tos",            /* name */
-    "ip_tos <tos>",            /* usage */
-    ip_tos_open,            /* open */
-    ip_tos_apply,            /* apply */
-    ip_tos_close            /* close */
+        "ip_tos",       /* name */
+        "ip_tos <tos>", /* usage */
+        ip_tos_open,    /* open */
+        ip_tos_apply,   /* apply */
+        ip_tos_close    /* close */
 };
 };

+ 18 - 19
src/fragroute/mod_ip_ttl.c

@@ -7,17 +7,15 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "argv.h"
 #include "argv.h"
 #include "mod.h"
 #include "mod.h"
 #include "pkt.h"
 #include "pkt.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 
 struct ip_ttl_data {
 struct ip_ttl_data {
-    int    ttl;
+    int ttl;
 };
 };
 
 
 void *
 void *
@@ -39,7 +37,7 @@ ip_ttl_open(int argc, char *argv[])
     if ((data = calloc(1, sizeof(*data))) == NULL)
     if ((data = calloc(1, sizeof(*data))) == NULL)
         return (NULL);
         return (NULL);
 
 
-    if ((data->ttl = atoi(argv[1])) <= 0 || data->ttl > 255)
+    if ((data->ttl = strtol(argv[1], NULL, 10)) <= 0 || data->ttl > 255)
         return (ip_ttl_close(data));
         return (ip_ttl_close(data));
 
 
     return (data);
     return (data);
@@ -52,17 +50,18 @@ ip_ttl_apply(void *d, struct pktq *pktq)
     struct pkt *pkt;
     struct pkt *pkt;
     int ttldec;
     int ttldec;
 
 
-    TAILQ_FOREACH(pkt, pktq, pkt_next) {
+    TAILQ_FOREACH(pkt, pktq, pkt_next)
+    {
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
 
 
         if (eth_type == ETH_TYPE_IP) {
         if (eth_type == ETH_TYPE_IP) {
-        ttldec = pkt->pkt_ip->ip_ttl - data->ttl;
-        pkt->pkt_ip->ip_ttl = data->ttl;
+            ttldec = pkt->pkt_ip->ip_ttl - data->ttl;
+            pkt->pkt_ip->ip_ttl = data->ttl;
 
 
-        if (pkt->pkt_ip->ip_sum >= htons(0xffff - (ttldec << 8)))
-            pkt->pkt_ip->ip_sum += htons(ttldec << 8) + 1;
-        else
-            pkt->pkt_ip->ip_sum += htons(ttldec << 8);
+            if (pkt->pkt_ip->ip_sum >= htons(0xffff - (ttldec << 8)))
+                pkt->pkt_ip->ip_sum += htons(ttldec << 8) + 1;
+            else
+                pkt->pkt_ip->ip_sum += htons(ttldec << 8);
         } else if (eth_type == ETH_TYPE_IPV6) {
         } else if (eth_type == ETH_TYPE_IPV6) {
             pkt->pkt_ip6->ip6_hlim = data->ttl;
             pkt->pkt_ip6->ip6_hlim = data->ttl;
         }
         }
@@ -71,9 +70,9 @@ ip_ttl_apply(void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_ip_ttl = {
 struct mod mod_ip_ttl = {
-    "ip_ttl",            /* name */
-    "ip_ttl <ttl>",            /* usage */
-    ip_ttl_open,            /* open */
-    ip_ttl_apply,            /* apply */
-    ip_ttl_close            /* close */
+        "ip_ttl",       /* name */
+        "ip_ttl <ttl>", /* usage */
+        ip_ttl_open,    /* open */
+        ip_ttl_apply,   /* apply */
+        ip_ttl_close    /* close */
 };
 };

+ 10 - 12
src/fragroute/mod_order.c

@@ -7,19 +7,17 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
+#include "mod.h"
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "mod.h"
-
-#define ORDER_RANDOM    1
-#define ORDER_REVERSE    2
+#define ORDER_RANDOM 1
+#define ORDER_REVERSE 2
 
 
 struct order_data {
 struct order_data {
-    rand_t    *rnd;
-    int     type;
+    rand_t *rnd;
+    int type;
 };
 };
 
 
 void *
 void *
@@ -71,9 +69,9 @@ order_apply(void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_order = {
 struct mod mod_order = {
-    "order",            /* name */
-    "order random|reverse",        /* usage */
-    order_open,            /* open */
-    order_apply,            /* apply */
-    order_close            /* close */
+        "order",                /* name */
+        "order random|reverse", /* usage */
+        order_open,             /* open */
+        order_apply,            /* apply */
+        order_close             /* close */
 };
 };

+ 100 - 96
src/fragroute/mod_print.c

@@ -7,25 +7,23 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
+#include "mod.h"
+#include "pkt.h"
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "mod.h"
-#include "pkt.h"
-
 #ifndef INET6_ADDRSTRLEN
 #ifndef INET6_ADDRSTRLEN
 #define INET6_ADDRSTRLEN 46
 #define INET6_ADDRSTRLEN 46
 #endif
 #endif
 
 
-#define EXTRACT_16BITS(p)    ((uint16_t)ntohs(*(uint16_t *)(p)))
-#define EXTRACT_32BITS(p)    ((uint32_t)ntohl(*(uint32_t *)(p)))
+#define EXTRACT_16BITS(p) ((uint16_t)ntohs(*(uint16_t *)(p)))
+#define EXTRACT_32BITS(p) ((uint32_t)ntohl(*(uint32_t *)(p)))
 
 
 /* XXX - _print_* routines adapted from tcpdump */
 /* XXX - _print_* routines adapted from tcpdump */
 
 
 static void
 static void
-_print_icmp(u_char *p, _U_ int length)
+print_icmp(u_char *p, _U_ int length)
 {
 {
     struct ip_hdr *ip;
     struct ip_hdr *ip;
     struct icmp_hdr *icmp;
     struct icmp_hdr *icmp;
@@ -39,7 +37,7 @@ _print_icmp(u_char *p, _U_ int length)
 }
 }
 
 
 static void
 static void
-_print_icmp6(u_char *p, _U_ int length)
+print_icmp6(u_char *p, _U_ int length)
 {
 {
     struct ip6_hdr *ip6;
     struct ip6_hdr *ip6;
     struct icmp_hdr *icmp;
     struct icmp_hdr *icmp;
@@ -53,7 +51,7 @@ _print_icmp6(u_char *p, _U_ int length)
 }
 }
 
 
 void
 void
-_print_tcp(int family, unsigned char *p, int length)
+print_tcp(int family, unsigned char *p, int length)
 {
 {
     struct tcp_hdr *tcp;
     struct tcp_hdr *tcp;
     u_short sport, dport, win, urp;
     u_short sport, dport, win, urp;
@@ -64,21 +62,21 @@ _print_tcp(int family, unsigned char *p, int length)
     char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN];
     char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN];
 
 
     if (family == AF_INET6) {
     if (family == AF_INET6) {
-            struct ip6_hdr *ip6 = (struct ip6_hdr *)p;
-            tcp = (struct tcp_hdr *)(p + IP6_HDR_LEN);
-            len = length;
+        struct ip6_hdr *ip6 = (struct ip6_hdr *)p;
+        tcp = (struct tcp_hdr *)(p + IP6_HDR_LEN);
+        len = length;
 
 
-            ip6_ntop(&ip6->ip6_src, src, sizeof(src));
-            ip6_ntop(&ip6->ip6_dst, dst, sizeof(dst));
+        ip6_ntop(&ip6->ip6_src, src, sizeof(src));
+        ip6_ntop(&ip6->ip6_dst, dst, sizeof(dst));
     } else {
     } else {
-            struct ip_hdr *ip;
+        struct ip_hdr *ip;
 
 
-    ip = (struct ip_hdr *)p;
-    tcp = (struct tcp_hdr *)(p + (ip->ip_hl * 4));
-    len = length - (ip->ip_hl * 4);
+        ip = (struct ip_hdr *)p;
+        tcp = (struct tcp_hdr *)(p + (ip->ip_hl * 4));
+        len = length - (ip->ip_hl * 4);
 
 
-            ip_ntop(&ip->ip_src, src, sizeof(src));
-            ip_ntop(&ip->ip_dst, dst, sizeof(dst));
+        ip_ntop(&ip->ip_src, src, sizeof(src));
+        ip_ntop(&ip->ip_dst, dst, sizeof(dst));
     }
     }
 
 
     if (len < TCP_HDR_LEN) {
     if (len < TCP_HDR_LEN) {
@@ -95,11 +93,15 @@ _print_tcp(int family, unsigned char *p, int length)
 
 
     printf("%s.%d > %s.%d: ", src, sport, dst, dport);
     printf("%s.%d > %s.%d: ", src, sport, dst, dport);
 
 
-    if (tcp->th_flags & (TH_SYN|TH_FIN|TH_RST|TH_PUSH)) {
-        if (tcp->th_flags & TH_SYN)    putchar('S');
-        if (tcp->th_flags & TH_FIN)    putchar('F');
-        if (tcp->th_flags & TH_RST)    putchar('R');
-        if (tcp->th_flags & TH_PUSH)    putchar('P');
+    if (tcp->th_flags & (TH_SYN | TH_FIN | TH_RST | TH_PUSH)) {
+        if (tcp->th_flags & TH_SYN)
+            putchar('S');
+        if (tcp->th_flags & TH_FIN)
+            putchar('F');
+        if (tcp->th_flags & TH_RST)
+            putchar('R');
+        if (tcp->th_flags & TH_PUSH)
+            putchar('P');
     } else
     } else
         putchar('.');
         putchar('.');
 
 
@@ -133,16 +135,20 @@ _print_tcp(int family, unsigned char *p, int length)
             if (TCP_OPT_TYPEONLY(opt)) {
             if (TCP_OPT_TYPEONLY(opt)) {
                 len = 1;
                 len = 1;
             } else {
             } else {
-                len = *cp++;    /* total including type, len */
+                len = *cp++; /* total including type, len */
                 if (len < 2 || len > tcp_hl)
                 if (len < 2 || len > tcp_hl)
                     goto bad;
                     goto bad;
-                --tcp_hl;         /* account for length byte */
+                --tcp_hl; /* account for length byte */
             }
             }
-            --tcp_hl;           /* account for type byte */
+            --tcp_hl; /* account for type byte */
             datalen = 0;
             datalen = 0;
 
 
 /* Bail if "l" bytes of data are not left or were not captured  */
 /* Bail if "l" bytes of data are not left or were not captured  */
-#define LENCHECK(l) { if ((l) > tcp_hl) goto bad; }
+#define LENCHECK(l)                                                                                                    \
+    {                                                                                                                  \
+        if ((l) > tcp_hl)                                                                                              \
+            goto bad;                                                                                                  \
+    }
 
 
             switch (opt) {
             switch (opt) {
             case TCP_OPT_MSS:
             case TCP_OPT_MSS:
@@ -170,8 +176,7 @@ _print_tcp(int family, unsigned char *p, int length)
                 break;
                 break;
             case TCP_OPT_SACK:
             case TCP_OPT_SACK:
                 datalen = len - 2;
                 datalen = len - 2;
-                if ((datalen % 8) != 0 ||
-                    !(tcp->th_flags & TH_ACK)) {
+                if ((datalen % 8) != 0 || !(tcp->th_flags & TH_ACK)) {
                     printf("malformed sack ");
                     printf("malformed sack ");
                     printf("[len %d] ", datalen);
                     printf("[len %d] ", datalen);
                     break;
                     break;
@@ -230,9 +235,9 @@ _print_tcp(int family, unsigned char *p, int length)
             tcp_hl -= datalen;
             tcp_hl -= datalen;
 
 
             /* Check specification against observed length */
             /* Check specification against observed length */
-            ++datalen;                /* option octet */
+            ++datalen; /* option octet */
             if (!TCP_OPT_TYPEONLY(opt))
             if (!TCP_OPT_TYPEONLY(opt))
-                ++datalen;              /* size octet */
+                ++datalen; /* size octet */
             if (datalen != len)
             if (datalen != len)
                 printf("[len %d]", len);
                 printf("[len %d]", len);
             ch = ',';
             ch = ',';
@@ -242,7 +247,7 @@ _print_tcp(int family, unsigned char *p, int length)
         putchar('>');
         putchar('>');
     }
     }
     return;
     return;
- bad:
+bad:
     fputs("[bad opt]", stdout);
     fputs("[bad opt]", stdout);
     if (ch != '\0')
     if (ch != '\0')
         putchar('>');
         putchar('>');
@@ -250,35 +255,34 @@ _print_tcp(int family, unsigned char *p, int length)
 }
 }
 
 
 static void
 static void
-_print_udp(int family, u_char *p, _U_ int length)
+print_udp(int family, u_char *p, _U_ int length)
 {
 {
     struct udp_hdr *udp;
     struct udp_hdr *udp;
     char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN];
     char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN];
 
 
     if (family == AF_INET6) {
     if (family == AF_INET6) {
-            struct ip6_hdr *ip6 = (struct ip6_hdr *)p;
-            udp = (struct udp_hdr *)(p + IP6_HDR_LEN);
+        struct ip6_hdr *ip6 = (struct ip6_hdr *)p;
+        udp = (struct udp_hdr *)(p + IP6_HDR_LEN);
 
 
-            ip6_ntop(&ip6->ip6_src, src, sizeof(src));
-            ip6_ntop(&ip6->ip6_dst, dst, sizeof(dst));
+        ip6_ntop(&ip6->ip6_src, src, sizeof(src));
+        ip6_ntop(&ip6->ip6_dst, dst, sizeof(dst));
     } else {
     } else {
-            struct ip_hdr *ip;
+        struct ip_hdr *ip;
 
 
-    ip = (struct ip_hdr *)p;
-    udp = (struct udp_hdr *)(p + (ip->ip_hl * 4));
+        ip = (struct ip_hdr *)p;
+        udp = (struct udp_hdr *)(p + (ip->ip_hl * 4));
 
 
-            ip_ntop(&ip->ip_src, src, sizeof(src));
-            ip_ntop(&ip->ip_dst, dst, sizeof(dst));
+        ip_ntop(&ip->ip_src, src, sizeof(src));
+        ip_ntop(&ip->ip_dst, dst, sizeof(dst));
     }
     }
 
 
     /* XXX - truncation? */
     /* XXX - truncation? */
-    printf("%s.%d > %s.%d:", src, ntohs(udp->uh_sport),
-        dst, ntohs(udp->uh_dport));
+    printf("%s.%d > %s.%d:", src, ntohs(udp->uh_sport), dst, ntohs(udp->uh_dport));
     printf(" udp %d", ntohs(udp->uh_ulen) - UDP_HDR_LEN);
     printf(" udp %d", ntohs(udp->uh_ulen) - UDP_HDR_LEN);
 }
 }
 
 
 static void
 static void
-_print_frag6(u_char *p, _U_ int length)
+print_frag6(u_char *p, _U_ int length)
 {
 {
     struct ip6_hdr *ip6;
     struct ip6_hdr *ip6;
     struct ip6_ext_hdr *ext;
     struct ip6_ext_hdr *ext;
@@ -291,13 +295,14 @@ _print_frag6(u_char *p, _U_ int length)
 
 
     printf("%s > %s:", ip6_ntoa(&ip6->ip6_src), ip6_ntoa(&ip6->ip6_dst));
     printf("%s > %s:", ip6_ntoa(&ip6->ip6_src), ip6_ntoa(&ip6->ip6_dst));
     printf(" fragment: next %hhu offset %d%s ident 0x%08x",
     printf(" fragment: next %hhu offset %d%s ident 0x%08x",
-        ext->ext_nxt, off,
-        (ext->ext_data.fragment.offlg & IP6_MORE_FRAG) ? " MF" : "",
-        htonl(ext->ext_data.fragment.ident));
+           ext->ext_nxt,
+           off,
+           (ext->ext_data.fragment.offlg & IP6_MORE_FRAG) ? " MF" : "",
+           htonl(ext->ext_data.fragment.ident));
 }
 }
 
 
 static void
 static void
-_print_ip(u_char *p, int length)
+print_ip(u_char *p, int length)
 {
 {
     struct ip_hdr *ip;
     struct ip_hdr *ip;
     int ip_off, ip_hl, ip_len;
     int ip_off, ip_hl, ip_len;
@@ -321,28 +326,29 @@ _print_ip(u_char *p, int length)
     if ((ip_off & IP_OFFMASK) == 0) {
     if ((ip_off & IP_OFFMASK) == 0) {
         switch (ip->ip_p) {
         switch (ip->ip_p) {
         case IP_PROTO_TCP:
         case IP_PROTO_TCP:
-            _print_tcp(AF_INET, p, ip_len);
+            print_tcp(AF_INET, p, ip_len);
             break;
             break;
         case IP_PROTO_UDP:
         case IP_PROTO_UDP:
-            _print_udp(AF_INET, p, ip_len);
+            print_udp(AF_INET, p, ip_len);
             break;
             break;
         case IP_PROTO_ICMP:
         case IP_PROTO_ICMP:
-            _print_icmp(p, ip_len);
+            print_icmp(p, ip_len);
             break;
             break;
         default:
         default:
-            printf("%s > %s:", ip_ntoa(&ip->ip_src),
-                ip_ntoa(&ip->ip_dst));
+            printf("%s > %s:", ip_ntoa(&ip->ip_src), ip_ntoa(&ip->ip_dst));
             printf(" ip-proto-%d %d", ip->ip_p, ip_len);
             printf(" ip-proto-%d %d", ip->ip_p, ip_len);
             break;
             break;
         }
         }
     }
     }
     /* Handle more frags. */
     /* Handle more frags. */
-    if (ip_off & (IP_MF|IP_OFFMASK)) {
+    if (ip_off & (IP_MF | IP_OFFMASK)) {
         if (ip_off & IP_OFFMASK)
         if (ip_off & IP_OFFMASK)
-            printf("%s > %s:", ip_ntoa(&ip->ip_src),
-                ip_ntoa(&ip->ip_dst));
-        printf(" (frag %d:%d@%d%s)", ntohs(ip->ip_id), ip_len - ip_hl,
-            (ip_off & IP_OFFMASK) << 3, (ip_off & IP_MF) ? "+" : "");
+            printf("%s > %s:", ip_ntoa(&ip->ip_src), ip_ntoa(&ip->ip_dst));
+        printf(" (frag %d:%d@%d%s)",
+               ntohs(ip->ip_id),
+               ip_len - ip_hl,
+               (ip_off & IP_OFFMASK) << 3,
+               (ip_off & IP_MF) ? "+" : "");
     } else if (ip_off & IP_DF)
     } else if (ip_off & IP_DF)
         printf(" (DF)");
         printf(" (DF)");
 
 
@@ -353,7 +359,7 @@ _print_ip(u_char *p, int length)
 }
 }
 
 
 static void
 static void
-_print_ip6(u_char *p, int length)
+print_ip6(u_char *p, int length)
 {
 {
     struct ip6_hdr *ip6;
     struct ip6_hdr *ip6;
     int plen;
     int plen;
@@ -368,24 +374,22 @@ _print_ip6(u_char *p, int length)
     plen = htons(ip6->ip6_plen);
     plen = htons(ip6->ip6_plen);
 
 
     switch (ip6->ip6_nxt) {
     switch (ip6->ip6_nxt) {
-        case IP_PROTO_TCP:
-            _print_tcp(AF_INET6, p, plen);
-            break;
-        case IP_PROTO_UDP:
-            _print_udp(AF_INET6, p, plen);
-            break;
-        case IP_PROTO_ICMPV6:
-            _print_icmp6(p, plen);
-            break;
-        case IP_PROTO_FRAGMENT:
-            _print_frag6(p, plen);
-            break;
-        default:
-            printf("%s > %s:", ip6_ntoa(&ip6->ip6_src),
-                ip6_ntoa(&ip6->ip6_dst));
-            printf(" ip-proto-%hhu ttl %hhu  payload len %d", ip6->ip6_nxt,
-                ip6->ip6_hlim, plen);
-            break;
+    case IP_PROTO_TCP:
+        print_tcp(AF_INET6, p, plen);
+        break;
+    case IP_PROTO_UDP:
+        print_udp(AF_INET6, p, plen);
+        break;
+    case IP_PROTO_ICMPV6:
+        print_icmp6(p, plen);
+        break;
+    case IP_PROTO_FRAGMENT:
+        print_frag6(p, plen);
+        break;
+    default:
+        printf("%s > %s:", ip6_ntoa(&ip6->ip6_src), ip6_ntoa(&ip6->ip6_dst));
+        printf(" ip-proto-%hhu ttl %hhu  payload len %d", ip6->ip6_nxt, ip6->ip6_hlim, plen);
+        break;
     }
     }
 
 
     if (ip6->ip6_hlim <= 1)
     if (ip6->ip6_hlim <= 1)
@@ -393,13 +397,13 @@ _print_ip6(u_char *p, int length)
 }
 }
 
 
 static void
 static void
-_print_eth(struct eth_hdr* e, int length)
+print_eth(struct eth_hdr *e, int length)
 {
 {
-        char d[20], s[20];
-        eth_ntop(&e->eth_dst, &d[0], sizeof(d));
-        eth_ntop(&e->eth_src, &s[0], sizeof(s));
+    char d[20], s[20];
+    eth_ntop(&e->eth_dst, &d[0], sizeof(d));
+    eth_ntop(&e->eth_src, &s[0], sizeof(s));
 
 
-        printf("%s > %s type 0x%04hx length %d", d, s, htons(e->eth_type), length);
+    printf("%s > %s type 0x%04hx length %d", d, s, htons(e->eth_type), length);
 }
 }
 
 
 static char *
 static char *
@@ -410,8 +414,7 @@ timerntoa(struct timeval *tv)
 
 
     usec = (tv->tv_sec * 1000000) + tv->tv_usec;
     usec = (tv->tv_sec * 1000000) + tv->tv_usec;
 
 
-    snprintf(buf, sizeof(buf), "%d.%03d ms",
-        (int)(usec / 1000), (int)(usec % 1000));
+    snprintf(buf, sizeof(buf), "%d.%03d ms", (int)(usec / 1000), (int)(usec % 1000));
 
 
     return (buf);
     return (buf);
 }
 }
@@ -421,15 +424,16 @@ print_apply(_U_ void *d, struct pktq *pktq)
 {
 {
     struct pkt *pkt;
     struct pkt *pkt;
 
 
-    TAILQ_FOREACH(pkt, pktq, pkt_next) {
+    TAILQ_FOREACH(pkt, pktq, pkt_next)
+    {
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
 
 
         if (eth_type == ETH_TYPE_IP)
         if (eth_type == ETH_TYPE_IP)
-        _print_ip(pkt->pkt_eth_data, pkt->pkt_end - pkt->pkt_eth_data);
+            print_ip(pkt->pkt_eth_data, pkt->pkt_end - pkt->pkt_eth_data);
         else if (eth_type == ETH_TYPE_IPV6)
         else if (eth_type == ETH_TYPE_IPV6)
-          _print_ip6(pkt->pkt_eth_data, pkt->pkt_end - pkt->pkt_eth_data);
+            print_ip6(pkt->pkt_eth_data, pkt->pkt_end - pkt->pkt_eth_data);
         else
         else
-            _print_eth(pkt->pkt_eth, pkt->pkt_end - pkt->pkt_data);
+            print_eth(pkt->pkt_eth, pkt->pkt_end - pkt->pkt_data);
         if (timerisset(&pkt->pkt_ts))
         if (timerisset(&pkt->pkt_ts))
             printf(" [delay %s]", timerntoa(&pkt->pkt_ts));
             printf(" [delay %s]", timerntoa(&pkt->pkt_ts));
         printf("\n");
         printf("\n");
@@ -438,9 +442,9 @@ print_apply(_U_ void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_print = {
 struct mod mod_print = {
-    "print",        /* name */
-    "print",        /* usage */
-    NULL,            /* init */
-    print_apply,        /* apply */
-    NULL            /* close */
+        "print",     /* name */
+        "print",     /* usage */
+        NULL,        /* init */
+        print_apply, /* apply */
+        NULL         /* close */
 };
 };

+ 39 - 49
src/fragroute/mod_tcp_chaff.c

@@ -7,28 +7,26 @@
  */
  */
 
 
 #include "config.h"
 #include "config.h"
-
+#include "iputil.h"
+#include "mod.h"
+#include "pkt.h"
+#include "randutil.h"
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "pkt.h"
-#include "mod.h"
-#include "randutil.h"
-#include "iputil.h"
-
-#define CHAFF_TYPE_CKSUM    1
-#define CHAFF_TYPE_NULL        2
-#define CHAFF_TYPE_PAWS        3
-#define CHAFF_TYPE_REXMIT    4
-#define CHAFF_TYPE_SEQ        5
-#define CHAFF_TYPE_SYN        6
-#define CHAFF_TYPE_TTL        7
+#define CHAFF_TYPE_CKSUM 1
+#define CHAFF_TYPE_NULL 2
+#define CHAFF_TYPE_PAWS 3
+#define CHAFF_TYPE_REXMIT 4
+#define CHAFF_TYPE_SEQ 5
+#define CHAFF_TYPE_SYN 6
+#define CHAFF_TYPE_TTL 7
 
 
 struct tcp_chaff_data {
 struct tcp_chaff_data {
-    rand_t        *rnd;
-    int         type;
-    int         ttl;
+    rand_t *rnd;
+    int type;
+    int ttl;
 };
 };
 
 
 void *
 void *
@@ -68,7 +66,7 @@ tcp_chaff_open(int argc, char *argv[])
         data->type = CHAFF_TYPE_SEQ;
         data->type = CHAFF_TYPE_SEQ;
     else if (strcasecmp(argv[1], "syn") == 0)
     else if (strcasecmp(argv[1], "syn") == 0)
         data->type = CHAFF_TYPE_SYN;
         data->type = CHAFF_TYPE_SYN;
-    else if ((data->ttl = atoi(argv[1])) > 0 && data->ttl < 256)
+    else if ((data->ttl = (int)strtol(argv[1], NULL, 10)) > 0 && data->ttl < 256)
         data->type = CHAFF_TYPE_TTL;
         data->type = CHAFF_TYPE_TTL;
     else
     else
         return (tcp_chaff_close(data));
         return (tcp_chaff_close(data));
@@ -101,61 +99,56 @@ tcp_chaff_apply(void *d, struct pktq *pktq)
             continue;
             continue;
         }
         }
 
 
-        if (nxt != IP_PROTO_TCP ||
-                pkt->pkt_tcp == NULL || pkt->pkt_tcp_data == NULL ||
-                (pkt->pkt_tcp->th_flags & TH_ACK) == 0)
+        if (nxt != IP_PROTO_TCP || pkt->pkt_tcp == NULL || pkt->pkt_tcp_data == NULL ||
+            (pkt->pkt_tcp->th_flags & TH_ACK) == 0)
             continue;
             continue;
 
 
         new = pkt_dup(pkt);
         new = pkt_dup(pkt);
-        rand_strset(data->rnd, new->pkt_tcp_data, new->pkt_end -
-            new->pkt_tcp_data + 1);
+        rand_strset(data->rnd, new->pkt_tcp_data, new->pkt_end - new->pkt_tcp_data + 1);
 
 
         switch (data->type) {
         switch (data->type) {
         case CHAFF_TYPE_CKSUM:
         case CHAFF_TYPE_CKSUM:
-            inet_checksum(eth_type, new->pkt_ip,
-                new->pkt_ip_data - new->pkt_eth_data);
+            inet_checksum(eth_type, new->pkt_ip, new->pkt_ip_data - new->pkt_eth_data);
             new->pkt_tcp->th_sum = rand_uint16(data->rnd);
             new->pkt_tcp->th_sum = rand_uint16(data->rnd);
             break;
             break;
         case CHAFF_TYPE_NULL:
         case CHAFF_TYPE_NULL:
             new->pkt_tcp->th_flags = 0;
             new->pkt_tcp->th_flags = 0;
-            inet_checksum(eth_type, new->pkt_ip,
-                    new->pkt_ip_data - new->pkt_eth_data);
+            inet_checksum(eth_type, new->pkt_ip, new->pkt_ip_data - new->pkt_eth_data);
             break;
             break;
         case CHAFF_TYPE_PAWS:
         case CHAFF_TYPE_PAWS:
             /* Delete any existing TCP options. */
             /* Delete any existing TCP options. */
             i = (new->pkt_tcp->th_off << 2) - TCP_HDR_LEN;
             i = (new->pkt_tcp->th_off << 2) - TCP_HDR_LEN;
             new->pkt_tcp->th_off = 5;
             new->pkt_tcp->th_off = 5;
             new->pkt_end -= i;
             new->pkt_end -= i;
-            new->pkt_ip->ip_len = htons(new->pkt_end -
-                new->pkt_eth_data);
+            new->pkt_ip->ip_len = htons(new->pkt_end - new->pkt_eth_data);
 
 
             /* Insert initial timestamp, for PAWS elimination. */
             /* Insert initial timestamp, for PAWS elimination. */
             opt.opt_type = TCP_OPT_TIMESTAMP;
             opt.opt_type = TCP_OPT_TIMESTAMP;
             opt.opt_len = TCP_OPT_LEN + 8;
             opt.opt_len = TCP_OPT_LEN + 8;
             opt.opt_data.timestamp[0] = 0;
             opt.opt_data.timestamp[0] = 0;
             opt.opt_data.timestamp[1] = 0;
             opt.opt_data.timestamp[1] = 0;
-            if ((i = inet_add_option(eth_type, new->pkt_ip,
-                PKT_BUF_LEN - ETH_HDR_LEN,
-                IP_PROTO_TCP, &opt, opt.opt_len)) < 0) {
+            if ((i = (int)inet_add_option(eth_type,
+                                          new->pkt_ip,
+                                          PKT_BUF_LEN - ETH_HDR_LEN,
+                                          IP_PROTO_TCP,
+                                          &opt,
+                                          opt.opt_len)) < 0) {
                 pkt_free(new);
                 pkt_free(new);
                 continue;
                 continue;
             }
             }
             new->pkt_end += i;
             new->pkt_end += i;
-            inet_checksum(eth_type, new->pkt_ip,
-                    new->pkt_ip_data - new->pkt_eth_data);
+            inet_checksum(eth_type, new->pkt_ip, new->pkt_ip_data - new->pkt_eth_data);
             pkt_decorate(new);
             pkt_decorate(new);
             break;
             break;
         case CHAFF_TYPE_REXMIT:
         case CHAFF_TYPE_REXMIT:
             new->pkt_ts.tv_usec = 1;
             new->pkt_ts.tv_usec = 1;
-            inet_checksum(eth_type, new->pkt_ip,
-                    new->pkt_ip_data - new->pkt_eth_data);
+            inet_checksum(eth_type, new->pkt_ip, new->pkt_ip_data - new->pkt_eth_data);
             break;
             break;
         case CHAFF_TYPE_SEQ:
         case CHAFF_TYPE_SEQ:
             /* XXX - dunno recv window? */
             /* XXX - dunno recv window? */
             new->pkt_tcp->th_seq = htonl(666);
             new->pkt_tcp->th_seq = htonl(666);
             new->pkt_tcp->th_ack = htonl(666);
             new->pkt_tcp->th_ack = htonl(666);
-            inet_checksum(eth_type, new->pkt_ip,
-                    new->pkt_ip_data - new->pkt_eth_data);
+            inet_checksum(eth_type, new->pkt_ip, new->pkt_ip_data - new->pkt_eth_data);
             break;
             break;
         case CHAFF_TYPE_SYN:
         case CHAFF_TYPE_SYN:
             new->pkt_tcp->th_flags = TH_SYN;
             new->pkt_tcp->th_flags = TH_SYN;
@@ -163,16 +156,13 @@ tcp_chaff_apply(void *d, struct pktq *pktq)
             new->pkt_tcp->th_ack = 0;
             new->pkt_tcp->th_ack = 0;
             new->pkt_end = new->pkt_tcp_data;
             new->pkt_end = new->pkt_tcp_data;
             new->pkt_tcp_data = NULL;
             new->pkt_tcp_data = NULL;
-            new->pkt_ip->ip_len = htons(new->pkt_end -
-                new->pkt_eth_data);
-            inet_checksum(eth_type, new->pkt_ip,
-                    new->pkt_ip_data - new->pkt_eth_data);
+            new->pkt_ip->ip_len = htons(new->pkt_end - new->pkt_eth_data);
+            inet_checksum(eth_type, new->pkt_ip, new->pkt_ip_data - new->pkt_eth_data);
             break;
             break;
         case CHAFF_TYPE_TTL:
         case CHAFF_TYPE_TTL:
             if (eth_type == ETH_TYPE_IP) {
             if (eth_type == ETH_TYPE_IP) {
-            new->pkt_ip->ip_ttl = data->ttl;
-                ip_checksum(new->pkt_ip,
-                        new->pkt_ip_data - new->pkt_eth_data);
+                new->pkt_ip->ip_ttl = data->ttl;
+                ip_checksum(new->pkt_ip, new->pkt_ip_data - new->pkt_eth_data);
             } else if (eth_type == ETH_TYPE_IPV6) {
             } else if (eth_type == ETH_TYPE_IPV6) {
                 new->pkt_ip6->ip6_hlim = data->ttl;
                 new->pkt_ip6->ip6_hlim = data->ttl;
             }
             }
@@ -188,9 +178,9 @@ tcp_chaff_apply(void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_tcp_chaff = {
 struct mod mod_tcp_chaff = {
-    "tcp_chaff",                        /* name */
-    "tcp_chaff cksum|null|paws|rexmit|seq|syn|<ttl>",    /* usage */
-    tcp_chaff_open,                        /* open */
-    tcp_chaff_apply,                    /* apply */
-    tcp_chaff_close                        /* close */
+        "tcp_chaff",                                      /* name */
+        "tcp_chaff cksum|null|paws|rexmit|seq|syn|<ttl>", /* usage */
+        tcp_chaff_open,                                   /* open */
+        tcp_chaff_apply,                                  /* apply */
+        tcp_chaff_close                                   /* close */
 };
 };

+ 25 - 19
src/fragroute/mod_tcp_opt.c

@@ -6,18 +6,16 @@
  * $Id$
  * $Id$
  */
  */
 
 
-#include "config.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
+#include "iputil.h"
+#include "mod.h"
+#include "pkt.h"
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
-#include "pkt.h"
-#include "mod.h"
-#include "iputil.h"
-
 void *
 void *
 tcp_opt_close(void *d)
 tcp_opt_close(void *d)
 {
 {
@@ -42,7 +40,7 @@ tcp_opt_open(int argc, char *argv[])
         opt->opt_type = TCP_OPT_MSS;
         opt->opt_type = TCP_OPT_MSS;
         opt->opt_len = TCP_OPT_LEN + 2;
         opt->opt_len = TCP_OPT_LEN + 2;
 
 
-        if ((i = atoi(argv[2])) <= 0 || i > 0xffff) {
+        if ((i = (int)strtol(argv[2], NULL, 10)) <= 0 || i > 0xffff) {
             warn("mss <size> must be from 0-65535");
             warn("mss <size> must be from 0-65535");
             return (tcp_opt_close(opt));
             return (tcp_opt_close(opt));
         }
         }
@@ -51,14 +49,18 @@ tcp_opt_open(int argc, char *argv[])
         opt->opt_type = TCP_OPT_WSCALE;
         opt->opt_type = TCP_OPT_WSCALE;
         opt->opt_len = TCP_OPT_LEN + 2;
         opt->opt_len = TCP_OPT_LEN + 2;
 
 
-        if ((i = atoi(argv[2])) <= 0 || i > 0xff) {
+        if ((i = (int)strtol(argv[2], NULL, 10)) <= 0 || i > 0xff) {
             warn("wscale <size> must be from 0-255");
             warn("wscale <size> must be from 0-255");
             return (tcp_opt_close(opt));
             return (tcp_opt_close(opt));
         }
         }
         opt->opt_data.wscale = i;
         opt->opt_data.wscale = i;
     } else if (strcasecmp(argv[1], "raw") == 0) {
     } else if (strcasecmp(argv[1], "raw") == 0) {
-        if (raw_ip_opt_parse(argc - 2, &argv[2], &opt->opt_type, &opt->opt_len,
-                    &opt->opt_data.data8[0], sizeof(opt->opt_data.data8)) != 0)
+        if (raw_ip_opt_parse(argc - 2,
+                             &argv[2],
+                             &opt->opt_type,
+                             &opt->opt_len,
+                             &opt->opt_data.data8[0],
+                             sizeof(opt->opt_data.data8)) != 0)
             return (tcp_opt_close(opt));
             return (tcp_opt_close(opt));
     } else
     } else
         return (tcp_opt_close(opt));
         return (tcp_opt_close(opt));
@@ -72,13 +74,17 @@ tcp_opt_apply(void *d, struct pktq *pktq)
     struct tcp_opt *opt = (struct tcp_opt *)d;
     struct tcp_opt *opt = (struct tcp_opt *)d;
     struct pkt *pkt;
     struct pkt *pkt;
 
 
-    TAILQ_FOREACH(pkt, pktq, pkt_next) {
+    TAILQ_FOREACH(pkt, pktq, pkt_next)
+    {
         size_t len;
         size_t len;
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
         uint16_t eth_type = htons(pkt->pkt_eth->eth_type);
 
 
-        len = inet_add_option(eth_type, pkt->pkt_ip,
-            sizeof(pkt->pkt_data) - ETH_HDR_LEN,
-            IP_PROTO_TCP, opt, opt->opt_len);
+        len = inet_add_option(eth_type,
+                              pkt->pkt_ip,
+                              sizeof(pkt->pkt_data) - ETH_HDR_LEN,
+                              IP_PROTO_TCP,
+                              opt,
+                              opt->opt_len);
 
 
         if (len > 0) {
         if (len > 0) {
             pkt->pkt_end += len;
             pkt->pkt_end += len;
@@ -90,9 +96,9 @@ tcp_opt_apply(void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_tcp_opt = {
 struct mod mod_tcp_opt = {
-    "tcp_opt",                    /* name */
-    "tcp_opt mss|wscale <size>|raw <byte stream>",            /* usage */
-    tcp_opt_open,                    /* open */
-    tcp_opt_apply,                    /* apply */
-    tcp_opt_close                    /* close */
+        "tcp_opt",                                     /* name */
+        "tcp_opt mss|wscale <size>|raw <byte stream>", /* usage */
+        tcp_opt_open,                                  /* open */
+        tcp_opt_apply,                                 /* apply */
+        tcp_opt_close                                  /* close */
 };
 };

+ 28 - 35
src/fragroute/mod_tcp_seg.c

@@ -6,31 +6,29 @@
  * $Id$
  * $Id$
  */
  */
 
 
-#include "config.h"
-#include "lib/queue.h"
 #include "defines.h"
 #include "defines.h"
+#include "config.h"
 #include "common.h"
 #include "common.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
+#include "iputil.h"
+#include "lib/queue.h"
 #include "mod.h"
 #include "mod.h"
 #include "pkt.h"
 #include "pkt.h"
 #include "randutil.h"
 #include "randutil.h"
-#include "iputil.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 
 #ifndef MIN
 #ifndef MIN
-#define MIN(a,b)    (((a)<(b))?(a):(b))
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
 #endif
 #endif
 
 
-#define FAVOR_OLD    1
-#define FAVOR_NEW    2
+#define FAVOR_OLD 1
+#define FAVOR_NEW 2
 
 
 static struct tcp_seg_data {
 static struct tcp_seg_data {
-    rand_t    *rnd;
-    int     size;
-    int     overlap;
+    rand_t *rnd;
+    int size;
+    int overlap;
 } tcp_seg_data;
 } tcp_seg_data;
 
 
 void *
 void *
@@ -51,16 +49,14 @@ tcp_seg_open(int argc, char *argv[])
     }
     }
     tcp_seg_data.rnd = rand_open();
     tcp_seg_data.rnd = rand_open();
 
 
-    if ((tcp_seg_data.size = atoi(argv[1])) == 0) {
+    if ((tcp_seg_data.size = (int)strtol(argv[1], NULL, 10)) == 0) {
         warnx("invalid segment size '%s'", argv[1]);
         warnx("invalid segment size '%s'", argv[1]);
         return (tcp_seg_close(&tcp_seg_data));
         return (tcp_seg_close(&tcp_seg_data));
     }
     }
     if (argc == 3) {
     if (argc == 3) {
-        if (strcmp(argv[2], "old") == 0 ||
-            strcmp(argv[2], "win32") == 0)
+        if (strcmp(argv[2], "old") == 0 || strcmp(argv[2], "win32") == 0)
             tcp_seg_data.overlap = FAVOR_OLD;
             tcp_seg_data.overlap = FAVOR_OLD;
-        else if (strcmp(argv[2], "new") == 0 ||
-            strcmp(argv[2], "unix") == 0)
+        else if (strcmp(argv[2], "new") == 0 || strcmp(argv[2], "unix") == 0)
             tcp_seg_data.overlap = FAVOR_NEW;
             tcp_seg_data.overlap = FAVOR_NEW;
         else
         else
             return (tcp_seg_close(&tcp_seg_data));
             return (tcp_seg_close(&tcp_seg_data));
@@ -95,14 +91,12 @@ tcp_seg_apply(_U_ void *d, struct pktq *pktq)
             continue;
             continue;
         }
         }
 
 
-        if (nxt != IP_PROTO_TCP ||
-            pkt->pkt_tcp == NULL || pkt->pkt_tcp_data == NULL ||
-            (pkt->pkt_tcp->th_flags & TH_ACK) == 0 ||
-            pkt->pkt_end - pkt->pkt_tcp_data <= tcp_seg_data.size)
+        if (nxt != IP_PROTO_TCP || pkt->pkt_tcp == NULL || pkt->pkt_tcp_data == NULL ||
+            (pkt->pkt_tcp->th_flags & TH_ACK) == 0 || pkt->pkt_end - pkt->pkt_tcp_data <= tcp_seg_data.size)
             continue;
             continue;
 
 
         if (eth_type == ETH_TYPE_IP) {
         if (eth_type == ETH_TYPE_IP) {
-        hl = pkt->pkt_ip->ip_hl << 2;
+            hl = pkt->pkt_ip->ip_hl << 2;
         } else if (eth_type == ETH_TYPE_IPV6) {
         } else if (eth_type == ETH_TYPE_IPV6) {
             hl = IP6_HDR_LEN;
             hl = IP6_HDR_LEN;
         } else {
         } else {
@@ -116,18 +110,17 @@ tcp_seg_apply(_U_ void *d, struct pktq *pktq)
             u_char *p1, *p2;
             u_char *p1, *p2;
 
 
             new = pkt_new(pkt->pkt_buf_size);
             new = pkt_new(pkt->pkt_buf_size);
-            memcpy(new->pkt_eth, pkt->pkt_eth, (u_char*)pkt->pkt_eth_data - (u_char*)pkt->pkt_eth);
+            memcpy(new->pkt_eth, pkt->pkt_eth, (u_char *)pkt->pkt_eth_data - (u_char *)pkt->pkt_eth);
             p1 = p, p2 = NULL;
             p1 = p, p2 = NULL;
             len = MIN(pkt->pkt_end - p, tcp_seg_data.size);
             len = MIN(pkt->pkt_end - p, tcp_seg_data.size);
 
 
-            if (tcp_seg_data.overlap != 0 &&
-                p + (len << 1) < pkt->pkt_end) {
+            if (tcp_seg_data.overlap != 0 && p + (len << 1) < pkt->pkt_end) {
                 struct pkt tmp;
                 struct pkt tmp;
                 u_char tmp_buf[pkt->pkt_buf_size];
                 u_char tmp_buf[pkt->pkt_buf_size];
 
 
                 tmp.pkt_buf = tmp_buf;
                 tmp.pkt_buf = tmp_buf;
                 tmp.pkt_buf_size = pkt->pkt_buf_size;
                 tmp.pkt_buf_size = pkt->pkt_buf_size;
-                rand_strset(tcp_seg_data.rnd, tmp.pkt_buf,len);
+                rand_strset(tcp_seg_data.rnd, tmp.pkt_buf, len);
 
 
                 if (tcp_seg_data.overlap == FAVOR_OLD) {
                 if (tcp_seg_data.overlap == FAVOR_OLD) {
                     p1 = p + len;
                     p1 = p + len;
@@ -146,8 +139,8 @@ tcp_seg_apply(_U_ void *d, struct pktq *pktq)
             new->pkt_end = new->pkt_tcp_data + len;
             new->pkt_end = new->pkt_tcp_data + len;
 
 
             if (eth_type == ETH_TYPE_IP) {
             if (eth_type == ETH_TYPE_IP) {
-            new->pkt_ip->ip_id = rand_uint16(tcp_seg_data.rnd);
-            new->pkt_ip->ip_len = htons(hl + tl + len);
+                new->pkt_ip->ip_id = rand_uint16(tcp_seg_data.rnd);
+                new->pkt_ip->ip_len = htons(hl + tl + len);
             } else {
             } else {
                 new->pkt_ip6->ip6_plen = htons(tl + len);
                 new->pkt_ip6->ip6_plen = htons(tl + len);
             }
             }
@@ -183,9 +176,9 @@ tcp_seg_apply(_U_ void *d, struct pktq *pktq)
 }
 }
 
 
 struct mod mod_tcp_seg = {
 struct mod mod_tcp_seg = {
-    "tcp_seg",                /* name */
-    "tcp_seg <size> [old|new]",        /* usage */
-    tcp_seg_open,                /* open */
-    tcp_seg_apply,                /* apply */
-    tcp_seg_close                /* close */
+        "tcp_seg",                  /* name */
+        "tcp_seg <size> [old|new]", /* usage */
+        tcp_seg_open,               /* open */
+        tcp_seg_apply,              /* apply */
+        tcp_seg_close               /* close */
 };
 };

+ 0 - 0
src/fragroute/pkt.c


Some files were not shown because too many files changed in this diff