1
2dnl $Id$
3
4AC_PREREQ([2.69])
5
6dnl Set version info here!
7AC_INIT([tcpreplay],[4.3.4],[https://github.com/appneta/tcpreplay/issues],[tcpreplay],[http://tcpreplay.sourceforge.net/])
8AC_CONFIG_SRCDIR([src/tcpreplay.c])
9AC_CONFIG_HEADERS([src/config.h])
10AC_CONFIG_AUX_DIR(config)
11AM_MAINTAINER_MODE([enable])
12AM_WITH_DMALLOC
13
14dnl People building from GitHub need the same version of Autogen as I'm using
15dnl or specify --disable-local-libopts to force using the locally-installed
16dnl copy of libopts rather than the source in the `./libopts/` directory.
17MAINTAINER_AUTOGEN_VERSION=5.18.12
18
19AC_CONFIG_MACRO_DIR([m4])
20
21TCPREPLAY_VERSION=$PACKAGE_VERSION
22
23dnl Release is only used for the RPM spec file
24TCPREPLAY_RELEASE=1
25
26AC_SUBST(TCPREPLAY_VERSION)
27AC_SUBST(TCPREPLAY_RELEASE)
28
29dnl Determine OS
30AC_CANONICAL_BUILD
31AC_CANONICAL_HOST
32AC_CANONICAL_TARGET
33AC_SUBST(host)
34AC_SUBST(build)
35AC_SUBST(target)
36
37CROSS_ARCH=
38CROSS_LD=
39build_arch=$(echo $MACHTYPE | cut -d'-' -f1)
40if test "$cross_compiling" = "yes" ; then
41    CROSS_ARCH="ARCH=$host_cpu"
42    CROSS_LD="LD=$LD"
43fi
44AC_SUBST(CROSS_ARCH)
45AC_SUBST(CROSS_LD)
46
47dnl ============================================
48dnl MacOSX build and runtime environment options
49dnl ============================================
50
51AC_ARG_WITH(macosx-sdk,
52    AS_HELP_STRING([--with-macosx-sdk],
53        [Use a specific SDK for building.])
54    [
55                          Usage:     --with-macosx-sdk=<version>
56                          e. g.: --with-macosx-sdk=10.8
57    ],
58,)
59
60
61dnl ===========================
62dnl Check OS X SDK and compiler
63dnl ===========================
64
65case "$host_os" in
66    darwin*) # Mac OS X or iOS
67        # If no --with-macosx-sdk option is given, look for one
68
69        # The intent is that for "most" Mac-based developers, a suitable
70        # SDK will be found automatically without any configure options.
71
72        # For developers with a current Xcode, the lowest-numbered SDK
73        # higher than or equal to the minimum required should be found.
74
75        # To find a list of available version run `xcodebuild -showsdks`
76
77        MULTIARCH=${host_cpu}-${host_os}
78        AC_MSG_CHECKING([what macOS compiler to use])
79
80        for _macosx_sdk in $with_macosx_sdk 10.8 10.9 10.10 10.11 10.12 10.13 10.14 10.15 10.16 10.17 10.18 10.19 10.20 11.0 11.1 11.2 11.3 11.4 11.5; do
81            MACOSX_SDK_PATH=$(xcrun --sdk macosx${_macosx_sdk} --show-sdk-path 2> /dev/null)
82            if test -d "$MACOSX_SDK_PATH"; then
83                with_macosx_sdk="${_macosx_sdk}"
84                break
85            else
86                MACOSX_SDK_PATH=$(xcode-select -print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${_macosx_sdk}.sdk
87                if test -d "$MACOSX_SDK_PATH"; then
88                    with_macosx_sdk="${_macosx_sdk}"
89                    break
90                fi
91            fi
92        done
93        if test -d "$MACOSX_SDK_PATH"; then
94            CC="$(xcrun -find clang) -m64 -isysroot $MACOSX_SDK_PATH"
95            INSTALL_NAME_TOOL=$(xcrun -find install_name_tool)
96            AR=$(xcrun -find ar)
97            NM=$(xcrun -find nm)
98            STRIP=$(xcrun -find strip)
99            LIBTOOL=$(xcrun -find libtool)
100            RANLIB=$(xcrun -find ranlib)
101            AC_MSG_RESULT([$CC])
102        else
103            AC_MSG_RESULT([legacy])
104        fi
105        ;;
106    Linux*)
107        dnl ============================================
108        dnl Some libraries are in /usr/lib/i386-linux-gnu
109        dnl but host is i686-linux-gnu
110        dnl ============================================
111        MULTIARCH=$(dpkg-architecture -qDEB_HOST_MULTIARCH) 2> /dev/null || ${host_cpu}-${host_os}
112        ;;
113    *)
114        MULTIARCH=${host_cpu}-${host_os}
115        ;;
116esac
117
118AC_SUBST(MACOSX_SDK_PATH)
119AC_SUBST(LIBTOOL) # Note that the OS X libtool command is unrelated to GNU libtool
120
121dnl ============================================
122dnl PF_RING library option
123dnl ============================================
124
125AC_ARG_WITH(pfring-lib,
126    AS_HELP_STRING([--with-pfring-lib],
127        [Use a specific PF_RING static library when using PF_RING libpcap.])
128    [
129                          Usage:     --with-pfring-lib=<library>
130                          e. g.: --with-pfring-lib=/usr/lib/libpfring_zc_x86_64.a
131    ],
132,)
133
134
135have_cygwin=no
136AC_MSG_CHECKING([for cygwin development environment])
137if test $(echo $target | grep -c cygwin) -gt 0 ; then
138    AC_DEFINE([HAVE_WIN32], [1], [Windows/Cygwin])
139    AC_MSG_RESULT(yes)
140    have_cygwin=yes
141else
142    AC_MSG_RESULT(no)
143fi
144
145
146AM_INIT_AUTOMAKE([1.15 foreign subdir-objects -Wall -Wno-override])
147m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
148
149dnl Checks for programs.
150AM_PROG_AR
151AC_PROG_INSTALL
152LT_INIT
153AC_PROG_CC
154AC_PROG_CXX
155AC_PROG_CPP
156AC_PROG_LN_S
157LT_INIT
158AC_PROG_AWK
159AC_PROG_SED
160AC_PROG_MAKE_SET
161AC_EXEEXT
162AC_PATH_PROG(PRINTF, printf)
163AC_PATH_PROG(ECHO, echo)
164AC_PATH_PROG(CUT, cut)
165AC_PATH_PROG(AUTOGEN, autogen)
166AC_PATH_PROG(GROFF, groff)
167AC_PATH_PROG(depmod, depmod, /sbin/depmod, $PATH:/sbin)
168AC_PATH_PROG(insmod, insmod, /sbin/insmod, $PATH:/sbin)
169AC_PATH_PROG(rmmod, rmmod, /sbin/rmmod, $PATH:/sbin)
170
171
172dnl tcpreplay has (so far) been relying on leading-edge autogen.
173dnl Therefore, by default:
174dnl - use the version we ship with
175dnl - do not install it
176dnl - build a static copy (AC_DISABLE_SHARED - implicitly done earlier)
177case "${enable_local_libopts+set}" in
178 set) ;;
179 *) enable_local_libopts=yes ;;
180esac
181
182case "${enable_libopts_install+set}" in
183 set) ;;
184 *) enable_libopts_install=no ;;
185esac
186
187dnl check autogen version
188AUTOGEN_VERSION="unknown - man pages will not be built"
189if test -n "${AUTOGEN}" ; then
190    AC_MSG_CHECKING(for autogen version >= ${MAINTAINER_AUTOGEN_VERSION})
191    AUTOGEN_VERSION=$(${AUTOGEN} -v | ${CUT} -d' ' -f 4)
192    AUTOGEN_MAJOR=$(echo ${AUTOGEN_VERSION} | ${CUT} -d '.' -f 1)
193    AUTOGEN_MINOR=$(echo ${AUTOGEN_VERSION} | ${CUT} -d '.' -f 2)
194    AUTOGEN_BUILD=$(echo ${AUTOGEN_VERSION} | ${CUT} -d '.' -f 3)
195    if test -z "$AUTOGEN_BUILD"; then
196        AUTOGEN_BUILD=0
197    fi
198    if (test ${AUTOGEN_MAJOR} -eq 5 && test ${AUTOGEN_MINOR} -eq 18 && test ${AUTOGEN_BUILD} -lt 4) ||
199            (test ${AUTOGEN_MAJOR} -eq 5 && test ${AUTOGEN_MINOR} -lt 18) ||
200            test ${AUTOGEN_MAJOR} -lt 5 ; then
201        AC_MSG_RESULT(no)
202        if test ! "x$enable_local_libopts" = "xyes"; then
203            AC_MSG_ERROR([${AUTOGEN} is too old (${AUTOGEN_VERSION}) for building from source code. Upgrade to 5.18.4 or higher])
204        fi
205        AUTOGEN_VERSION="${AUTOGEN_VERSION} - downlevel"
206    else
207        AC_MSG_RESULT(yes)
208    fi
209
210    dnl Compare the installed version with the maintainer version if building from GitHub and not using system libopts
211    if test ! -f src/tcpreplay_opts.c && test "x$enable_local_libopts" = "xyes" ; then
212        if test $MAINTAINER_AUTOGEN_VERSION != $AUTOGEN_VERSION ; then
213            AC_MSG_ERROR([Your version of autogen ($AUTOGEN_VERSION) != libopts tear off ($MAINTAINER_AUTOGEN_VERSION)  Either install the correct version or specify --disable-local-libopts])
214        fi
215    fi
216else
217    if test ! -f src/tcpreplay_opts.c ; then
218        AC_MSG_ERROR([Please install GNU autogen $MAINTAINER_AUTOGEN_VERSION or higher if you are building from GitHub. To avoid this message download source from https://github.com/appneta/tcpreplay/releases/latest])
219    fi
220fi
221AC_DEFINE([AUTOGEN_VERSION], [${AUTOGEN_VERSION}], [What version of autogen is installed on this system])
222
223if test "x$enable_local_libopts" = "xyes" ; then
224    AC_MSG_NOTICE([Using included libopts tearoff])
225else
226    AC_MSG_NOTICE([Using system libopts])
227fi
228
229AC_PROG_EGREP
230AC_HEADER_MAJOR
231
232dnl Checks for typedefs, structures, and compiler characteristics.
233AC_CHECK_HEADER_STDBOOL
234AC_C_INLINE
235AC_TYPE_INT16_T
236AC_TYPE_INT32_T
237AC_TYPE_INT64_T
238AC_TYPE_INT8_T
239AC_TYPE_OFF_T
240AC_TYPE_PID_T
241AC_TYPE_SIZE_T
242AC_TYPE_SSIZE_T
243AC_TYPE_UINT16_T
244AC_TYPE_UINT32_T
245AC_TYPE_UINT64_T
246AC_TYPE_UINT8_T
247AC_CHECK_HEADERS_ONCE([sys/time.h])
248AC_C_CONST
249AC_C_INLINE
250AC_SYS_LARGEFILE
251
252dnl Check for functions
253AC_FUNC_FSEEKO
254
255dnl Check for types.
256AC_CHECK_TYPE(u_int8_t, uint8_t)
257AC_CHECK_TYPE(u_int16_t, uint16_t)
258AC_CHECK_TYPE(u_int32_t, uint32_t)
259AC_CHECK_TYPE(u_int64_t, uint64_t)
260
261dnl OS X SDK 10.11 throws lots of unnecessary macro warnings
262wno_format=""
263wno_macro_redefined=""
264case $host in
265    *-apple-darwin*)
266        AC_MSG_CHECKING(for $CC -Wno-macro-redefined)
267        OLD_CFLAGS=$CFLAGS
268        CFLAGS="$CFLAGS -Wno-macro-redefined -Werror"
269        AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
270            int main(int argc, char *argv[]) { return(0); }]])],
271            [ AC_MSG_RESULT(yes)
272              wno_macro_redefined="-Wno-macro-redefined" ],
273            [ AC_MSG_RESULT(no) ])
274        AC_MSG_CHECKING(for $CC -Wno-format)
275        CFLAGS="$OLD_CFLAGS $wno_macro_redefined"
276        CFLAGS="$CFLAGS -Wno-format -Werror"
277        AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
278            int main(int argc, char *argv[]) { return(0); }]])],
279        [ AC_MSG_RESULT(yes)
280          wno_format="-Wno-format" ],
281        [ AC_MSG_RESULT(no) ])
282        CFLAGS="$OLD_CFLAGS $wno_format"
283    ;;
284esac
285
286dnl Older versions of GCC don't support these options
287AC_MSG_CHECKING(for $CC -Wextra support)
288OLD_CFLAGS=$CFLAGS
289CFLAGS="$CFLAGS -Wextra -Werror"
290wextra=""
291AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
292    int main(int argc, char *argv[]) { return(0); }]])],
293    [ AC_MSG_RESULT(yes)
294      wextra="-Wextra" ],
295    [ AC_MSG_RESULT(no) ])
296CFLAGS="$OLD_CFLAGS $wextra"
297
298AC_MSG_CHECKING(for $CC -Wno-variadic-macros support)
299OLD_CFLAGS=$CFLAGS
300CFLAGS="$CFLAGS -Wno-variadic-macros -Werror"
301wno_variadic_macros=""
302AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
303    int main(int argc, char *argv[]) { return(0); }]])],
304    [ AC_MSG_RESULT(yes)
305      wno_variadic_macros="-Wno-variadic-macros" ],
306    [ AC_MSG_RESULT(no) ])
307CFLAGS="$OLD_CFLAGS $wno_variadic_macros"
308
309AC_MSG_CHECKING(for $CC -Wfatal-errors support)
310OLD_CFLAGS=$CFLAGS
311CFLAGS="$CFLAGS -Wfatal-errors -Werror"
312wfatal_errors=""
313AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
314    int main(int argc, char *argv[]) { return(0); }]])],
315    [ AC_MSG_RESULT(yes)
316      wfatal_errors="-Wfatal-errors" ],
317    [ AC_MSG_RESULT(no) ])
318CFLAGS="$OLD_CFLAGS $wfatal_errors"
319
320AC_MSG_CHECKING(for $CC -Wno-format-contains-nul support)
321OLD_CFLAGS=$CFLAGS
322CFLAGS="$CFLAGS -Wno-format-contains-nul -Werror"
323wno_format_contains_nul=""
324AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
325    int main(int argc, char *argv[]) { return(0); }]])],
326    [ AC_MSG_RESULT(yes)
327      wno_format_contains_nul="-Wno-format-contains-nul" ],
328    [ AC_MSG_RESULT(no) ])
329CFLAGS="$OLD_CFLAGS $wno_format_contains_nul"
330
331dnl Check for other header files
332AC_CHECK_HEADERS([fcntl.h stddef.h sys/socket.h  arpa/inet.h sys/time.h])
333AC_CHECK_HEADERS([signal.h string.h strings.h sys/types.h stdint.h sys/select.h])
334AC_CHECK_HEADERS([netinet/in.h netinet/in_systm.h poll.h sys/poll.h unistd.h sys/param.h])
335AC_CHECK_HEADERS([inttypes.h libintl.h sys/file.h sys/ioctl.h sys/systeminfo.h])
336AC_CHECK_HEADERS([sys/io.h architecture/i386/pio.h sched.h])
337AC_HEADER_STDBOOL
338
339dnl OpenBSD has special requirements
340AC_CHECK_HEADERS([sys/sysctl.h net/route.h], [], [], [
341[#if HAVE_SYS_PARAM_H
342#include <sys/param.h>
343#endif
344#if HAVE_SYS_TYPES_H
345#include <sys/types.h>
346#endif
347#if HAVE_SYS_SOCKET_H
348#include <sys/socket.h>
349#endif
350]])
351
352
353dnl Checks for libraries.
354AC_CHECK_LIB(socket, socket)
355AC_CHECK_LIB(nsl, gethostbyname)
356AC_CHECK_LIB(rt, nanosleep)
357AC_CHECK_LIB(resolv, resolv)
358
359dnl Checks for library functions.
360AC_FUNC_FORK
361AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
362AC_FUNC_MEMCMP
363AC_FUNC_VPRINTF
364AC_FUNC_MKTIME
365AC_FUNC_MMAP
366AC_CHECK_MEMBERS([struct timeval.tv_sec])
367AC_CHECK_FUNCS([alarm atexit bzero dup2 gethostbyname getpagesize gettimeofday])
368AC_CHECK_FUNCS([ctime inet_ntoa memmove memset munmap pow putenv realpath])
369AC_CHECK_FUNCS([regcomp strdup select socket strcasecmp strchr strcspn strdup])
370AC_CHECK_FUNCS([strerror strtol strncpy strtoull poll ntohll mmap snprintf])
371AC_CHECK_FUNCS([vsnprintf strsignal strpbrk strrchr strspn strstr strtoul])
372AC_CHECK_FUNCS([ioperm])
373
374dnl Look for strlcpy since some BSD's have it
375AC_CHECK_FUNCS([strlcpy],have_strlcpy=true,have_strlcpy=false)
376AM_CONDITIONAL(SYSTEM_STRLCPY, [test x$have_strlcpy = xtrue])
377
378AC_C_BIGENDIAN
379AM_CONDITIONAL([WORDS_BIGENDIAN], [ test x$ac_cv_c_bigendian = xyes ])
380
381AC_ARG_ENABLE([asan],
382    AS_HELP_STRING([--enable-asan],[Enable Address Sanitizer support]))
383if test "x$enable_asan" = "xyes"; then
384        build_asan=yes
385        AC_CHECK_LIB([asan], [__asan_report_error], ,
386                [AC_MSG_ERROR([libasan.so not found, this is required for --enable-asan])])
387        CFLAGS="${CFLAGS} -O1 -g -fsanitize=address -fno-omit-frame-pointer"
388        dnl -lasan always need to be the first library
389        LDFLAGS="-lasan ${LDFLAGS}"
390else
391        build_asan=no
392fi
393AC_SUBST(build_asan)
394
395dnl Enable debugging in code/compiler options
396debug=no
397debug_flag=NDEBUG
398debug_run_time_flag=
399AC_ARG_ENABLE(debug,
400    AS_HELP_STRING([--enable-debug],[Enable debugging code and support for the -d option]),
401    [ if test x$enableval = xyes; then
402        debug=yes
403        dnl replace '-0X' and add '-g' flags
404        changequote({,})
405        CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9s]*//g'`
406        changequote([,])
407        CFLAGS="${CFLAGS} -g -O0 -Wall $wextra $wfatal_errors $wno_variadic_macros $wno_format_contains_nul $wno_format"
408# We may also want to add:
409#         -Wformat-security -Wswitch-default -Wunused-paramter -Wpadded"
410        debug_flag=DEBUG
411        debug_run_time_flag=--dbug=1
412        AC_DEFINE([DEBUG], [1], [Enable debugging code and support for the -d option])
413    fi])
414AC_SUBST(debug_flag)
415AC_SUBST(debug_run_time_flag)
416
417dnl Enable extra debugging in code/compiler options - may slow down performance
418extra_debug=no
419extra_debug_flag=NEXTRA_DBUG
420AC_ARG_ENABLE(extra-debug,
421    AS_HELP_STRING([--enable-extra-debug],[Enable additional debugging code (may affect performance)]),
422    [ if test x$enableval = xyes; then
423        extra_debug=yes
424        extra_debug_flag=EXTRA_DEBUG
425        AC_DEFINE([EXTRA_DEBUG], [1], [Enable additional debugging code (may affect performance)])
426    fi])
427AC_SUBST(extra_debug_flag)
428
429dnl Enable timestamp_trace in code/compiler options
430timestamp_trace=no
431AC_ARG_ENABLE(timestamp-trace,
432    AS_HELP_STRING([--timestamp-trace],[Enable dumping of trace timestamps at the end of a test]),
433    [ if test x$enableval = xyes; then
434        timestamp_trace=yes
435        CFLAGS="${CFLAGS} -DTIMESTAMP_TRACE"
436        AC_DEFINE([TIMESTAMP_TRACE], [1], [Enable dumping of trace timestamps at the end of a test])
437    fi])
438AC_SUBST(timestamp_trace_flag)
439
440
441AC_ARG_ENABLE(dmalloc,
442    AS_HELP_STRING([--enable-dmalloc],[Enable linking to dmalloc for better memory debugging]),
443    [ if test x$enableval = xyes ; then
444        dmalloc=yes
445        AC_DEFINE([ENABLE_DMALLOC], [1], [Enable dmalloc])
446        AC_DEFINE([DMALLOC_FUNC_CHECK], [1], [Enable dmalloc function arg checking])
447        CFLAGS="${CFLAGS} -I/opt/local/include"
448        DMALLOC_LIB="/opt/local/lib/libdmalloc.a"
449        AC_SUBST(DMALLOC_LIB)
450    fi])
451
452
453AC_ARG_ENABLE(pedantic,
454    AS_HELP_STRING([--enable-pedantic],[Enable gcc's -pedantic option]),
455    [ if test x$enableval = xyes; then
456        CFLAGS="$CFLAGS -pedantic"
457      fi ])
458
459dnl Enable Efense
460AC_ARG_ENABLE(efence,
461    AS_HELP_STRING([--enable-efence],[Enable Electric Fence memory debugger]),
462    [ if test x$enableval = xyes; then
463          CFLAGS="$CFLAGS -lefence"
464          AC_DEFINE([EFENCE], [1], [Enable Electric Fence memory debugger])
465      fi])
466
467dnl Enable Gprof
468AC_ARG_ENABLE(gprof,
469    AS_HELP_STRING([--enable-gprof],[Enable GNU Profiler]),
470    [ if test x$enableval = xyes; then
471          if test $debug = yes; then
472              CFLAGS="$CFLAGS -pg"
473          else
474              # GPROF requires gdb
475              CFLAGS="$CFLAGS -ggdb -pg -fprofile-arcs"
476          fi
477          AC_DEFINE([GPROF], [1], [Enable GNU Profiler])
478      fi])
479
480dnl Enable libpcap auto discovery via pcap-config
481enable_pcap_config=no
482AC_ARG_ENABLE(pcapconfig,
483    AS_HELP_STRING([--enable-pcapconfig],[Enable automatic libpcap config, reverting to system scanning]),
484    [
485        if test $enableval = yes; then
486            enable_pcap_config=yes
487            AC_MSG_NOTICE([Enabling libpcap discovery via pcap_config])
488        else
489            enable_pcap_config=no
490            AC_MSG_NOTICE([Disabling libpcap discovery via pcap_config])
491        fi
492    ],
493    [
494        AC_MSG_NOTICE([Bypassing libpcap discovery via pcap_config])
495    ])
496
497dnl Use 64bits for packet counters
498use64bit_counters=yes
499AC_ARG_ENABLE(64bits,
500    AS_HELP_STRING([--disable-64bits],[Do not use 64bit packet counters]),
501    [
502         AC_MSG_NOTICE([Using u_int32_t for packet counters])
503    ],
504    [
505         AC_DEFINE([ENABLE_64BITS], [1], [Use 64bit packet counters])
506         AC_MSG_NOTICE([Using u_int64_t for packet counters])
507    ])
508
509
510# If we're running gcc add '-D_U_="__attribute__((unused))"' to CFLAGS as well,
511# so we can use _U_ to flag unused function arguments and not get warnings
512# about them. Otherwise, add '-D_U_=""', so that _U_ used to flag an unused
513# function argument will compile with non-GCC compilers.
514#
515if test "x$GCC" = "xyes" ; then
516    CFLAGS="-D_U_=\"__attribute__((unused))\" $CFLAGS"
517else
518    CFLAGS="-D_U_=\"\" $CFLAGS"
519fi
520
521
522AC_ARG_ENABLE(force-bpf,
523    AS_HELP_STRING([--enable-force-bpf],[Force using BPF for sending packets]),
524    [ AC_DEFINE([FORCE_INJECT_BPF], [1], [Force using BPF for sending packet])])
525
526AC_ARG_ENABLE(force-pf,
527    AS_HELP_STRING([--enable-force-pf],[Force using Linux's PF_PACKET for sending packets]),
528    [ AC_DEFINE([FORCE_INJECT_PF], [1], [Force using Linux's PF_PACKET for sending packets])])
529
530AC_ARG_ENABLE(force-libdnet,
531    AS_HELP_STRING([--enable-force-libdnet],[Force using libdnet for sending packets]),
532    [ AC_DEFINE([FORCE_INJECT_LIBDNET], [1], [Force using libdnet for sending packets])])
533
534AC_ARG_ENABLE(force-inject,
535    AS_HELP_STRING([--enable-force-inject],[Force using libpcap's pcap_inject() for sending packets]),
536    [ AC_DEFINE([FORCE_INJECT_PCAP_INJECT],[1], [Force using libpcap's pcap_inject() for sending packets])])
537
538AC_ARG_ENABLE(force-sendpacket,
539    AS_HELP_STRING([--enable-force-sendpacket],[Force using libpcap's pcap_sendpacket() for sending packets]),
540    [ AC_DEFINE([FORCE_INJECT_PCAP_SENDPACKET], [1], [Force using libpcap's pcap_sendpacket() for sending packets])])
541
542dnl Static link libraries
543static_link=no
544dynamic_link=yes
545AC_ARG_ENABLE(static-link,
546    AS_HELP_STRING([--enable-static-link],[Use static libraries ( .a  or .A.tbd ) - default no]),
547    [
548    if test $enableval = yes; then
549        static_link=yes
550        dynamic_link=no
551    fi
552    ])
553
554dnl Dynamic link libraries
555AC_ARG_ENABLE(dynamic-link,
556    AS_HELP_STRING([--enable-dynamic-link],[Use shared libraries ( .so .dylib or .tbd ) - default yes]),
557    [
558    if test $enableval = no; then
559        dynamic_link=no
560        static_link=yes
561    elif test $static_link = yes; then
562        AC_MSG_ERROR([Cannot specify both --enable-dynamic-link and --enable-static-link])
563    fi
564    ])
565
566if test $static_link = yes; then
567    AC_DEFINE([ENABLE_STATIC_LINK], [1], [Use static libraries ( .a or .A.tbd )])
568else
569    AC_DEFINE([ENABLE_DYNAMIC_LINK], [1], [Use shared libraries ( .so .dylib or .tbd )])
570fi
571
572dnl Check for inet_aton and inet_pton
573AC_CHECK_FUNC(inet_aton,
574    AC_DEFINE([HAVE_INET_ATON], [1], [Do we have inet_aton?])
575    inet_aton=yes,
576    inet_aton=no)
577AC_CHECK_FUNC(inet_pton,
578    AC_DEFINE([HAVE_INET_PTON], [1], [Do we have inet_pton?])
579    inet_pton=yes,
580    inet_pton=no)
581AC_CHECK_FUNC(inet_ntop,
582    AC_DEFINE([HAVE_INET_NTOP], [1], [Do we have inet_ntop?])
583    inet_ntop=yes,
584    inet_ntop=no)
585
586if test "$inet_ntop" = "no" -a "$inet_pton" = "no" ; then
587    AC_MSG_ERROR([We need either inet_ntop or inet_pton])
588fi
589
590AC_CHECK_FUNC(inet_addr,
591    AC_DEFINE([HAVE_INET_ADDR], [1], [Do we have inet_addr?])
592    inet_addr=yes,
593    inet_addr=no)
594
595if test x$inet_addr = no ; then
596    AC_MSG_ERROR([We need inet_addr.  See bug 26])
597fi
598
599dnl #####################################################
600dnl Checks for tuntap device support
601dnl #####################################################
602have_tuntap=no
603AC_ARG_ENABLE([tuntap],
604  AS_HELP_STRING([--disable-tuntap], [Disable tuntap support]), [:],
605  [case "$build_os" in
606    linux*)
607      AC_CHECK_HEADER([linux/if_tun.h], [have_tuntap=yes])
608      ;;
609    *)
610      AC_CHECK_HEADER([net/if_tun.h], [have_tuntap=yes])
611      ;;
612  esac])
613
614if test $have_tuntap = yes ; then
615    AC_DEFINE([HAVE_TUNTAP], [1],
616            [Do we have TUNTAP device support?])
617fi
618
619dnl #####################################################
620dnl Checks for libpcap
621dnl #####################################################
622foundpcap=no
623pf_ring_found=no
624pf_ring_lib=${with_pfring_lib}
625using_pcap_config=no
626AC_MSG_CHECKING(for libpcap)
627AC_ARG_WITH(libpcap,
628    AS_HELP_STRING([--with-libpcap=DIR],[Use libpcap in DIR]),
629[
630    testdir=$withval
631    for incl in ${testdir}/include/pcap.h ${testdir}/pcap.h ${testdir}/pcap/pcap.h; do
632        if ! test -f "${incl}"; then
633            continue
634        fi
635        LPCAPINC=${incl}
636        LPCAPINCDIR=${testdir}
637        if test $dynamic_link = yes; then
638            for ext in .dylib .so .tbd ; do
639                for dir in . lib lib64 lib/${host_cpu}-${host_os} ${host_cpu}-${host_os} lib/${MULTIARCH} ${MULTIARCH}; do
640                    sharefile=$(ls ${testdir}/$dir/libpcap${ext}* 2> /dev/null | sort | head -n1)
641                    if test -n "${sharefile}"; then
642                        LPCAPLIB="-L$(dirname ${sharefile}) -lpcap"
643                        foundpcap=$testdir
644                        break
645                    fi
646                done
647
648                if ! test $foundpcap = no; then
649                    break
650                fi
651            done
652        else
653            dnl
654            dnl If dynamic library not found, try static
655            dnl
656            for ext in ${libext} .a .A.tbd ; do
657                for dir in . lib lib64 lib/${host_cpu}-${host_os} ${host_cpu}-${host_os} lib/${MULTIARCH} ${MULTIARCH}; do
658                    staticfile=$(ls ${testdir}/$dir/libpcap${ext} 2> /dev/null | sort | head -n1)
659                    if test -n "${staticfile}"; then
660                        LPCAPLIB="${staticfile}"
661                        foundpcap=${testdir}
662                        break
663                    fi
664                done
665
666                if ! test $foundpcap = no; then
667                    ## could be PF_RING
668                    #
669                    #  library is static and in PF_RING build tree
670                    #
671                    #  Need access to libpfring library
672                    #  and must find an associated libpfring.a
673                    if test -n "${with_pfring_lib}"; then
674                        if test -f ${with_pfring_lib}; then
675                            pf_ring_lib=${with_pfring_lib}
676                            pf_ring_found=yes
677                        else
678                            AC_MSG_ERROR(["Unable to find PF_RING library ${with_pfring_lib}"])
679                        fi
680                    else
681                        ## search locally for most likely PF_RING library
682                        for lib in ${foundpcap}/../lib/libs/libpfring_zc_${host_cpu}.a \
683                                ${foundpcap}/../lib/libs/libpfring_dna_${host_cpu}.a \
684                                ${foundpcap}/../lib/libs/libpfring_zero_${host_cpu}.a \
685                                ${foundpcap}/../lib/libs/libpfring_nt_${host_cpu}.a \
686                                ${foundpcap}/../lib/libpfring.a; do
687                            if test -f "${lib}"; then
688                                pf_ring_lib=${lib}
689                                pf_ring_found=yes
690                                break
691                            fi
692                        done
693                    fi
694                    break
695                fi
696            done
697        fi
698
699        if test $foundpcap = no; then
700            AC_MSG_ERROR("Unable to find matching library for header file in ${testdir}")
701        fi
702
703        break
704    done
705],[
706    #
707    # Look for pcap-config.
708    #
709    # I wish this option could be the default, but it is only enabled with --enable-pcapconfig
710    #
711    # The issue is that libpcap is one of those libraries that is nearly impossible to set up
712    # properly across all platforms. The 'pcap-config' script is shipped with new versions of libpcap,
713    # and was created to address portability issues. Unfortunately, the script is not updated properly
714    # outside of the base distribution. Examples: PF_RING requires 'pthreads', 'numa' and 'rt', but
715    # this is not reflect that in the script. OS X Xcode 10.11 SDK creates its own very broken
716    # 'pcap-config' script that only occasionally works for dynamic definitions, and defintely
717    # does not work for static.
718    #
719    # The ability to enable this script exists for corner cases where libpcap distributions starts
720    # using even more libraries than I am currently not aware of. Originally, you only had to worry
721    # about 'nl', but now we have to be prepared to add 'nl-3', 'nl-genl-3' and 'dbus-1' to make
722    # libpcap fucntional. In the future, there may be more.
723    #
724    # (sigh)
725    #
726    # So, in the future if libpcap changes and stops working, try setting --enable-pcapconfig. It
727    # it may work for you.
728    if test $enable_pcap_config = yes; then
729        AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
730            if test -n "$PCAP_CONFIG"; then
731            #
732            # Found - use it to get the include flags for
733            # libpcap and the flags to link with libpcap.
734            #
735            # Please read section 11.6 "Shell Substitutions"
736            # in the autoconf manual before doing anything
737            # to this that involves quoting.  Especially note
738            # the statement "There is just no portable way to use
739            # double-quoted strings inside double-quoted back-quoted
740            # expressions (pfew!)."
741            #
742
743            if test $dynamic_link = yes; then
744                LPCAPLIB=$($PCAP_CONFIG --libs)
745            else
746                LPCAPLIB=$($PCAP_CONFIG --libs --static)
747            fi
748            CFLAGS="$CFLAGS $($PCAP_CONFIG --cflags)"
749            if test -n "$LPCAPLIB"; then
750                foundpcap=yes
751                using_pcap_config=yes
752            else
753                AC_MSG_WARN(Unable to find libpcap using pcap-config)
754            fi
755        fi
756    fi
757
758    if test ! $foundpcap = yes; then
759        #
760        # Not found; look for pcap.
761        #
762        for testdir in /usr/local /opt/local /usr /wpdpack $MACOSX_SDK_PATH/usr /usr/local/opt/libpcap ; do
763            if test -f "${testdir}/include/pcap.h"; then
764                LPCAPINC="${testdir}/include/pcap.h"
765                LPCAPINCDIR="${testdir}/include"
766                if test $dynamic_link = yes; then
767                    for ext in .dylib .so .tbd; do
768                        for dir in . lib lib64 ${host_cpu} lib/${host_cpu} ${host_cpu}-${host_os} lib/${host_cpu}-${host_os} ${MULTIARCH} lib/${MULTIARCH}; do
769                            sharefile=$(ls "${testdir}/$dir/libpcap${ext}" 2> /dev/null | sort | head -n1)
770                            if test -n "${sharefile}"; then
771                                LPCAPLIB="-L$(dirname ${sharefile}) -lpcap"
772                                foundpcap=$testdir
773                                break
774                            fi
775                        done
776
777                        if ! test $foundpcap = no; then
778                            break
779                        fi
780                    done
781                fi
782                if test $foundpcap = no ; then
783                    dnl
784                    dnl If dynamic library not found, try static
785                    dnl
786                    for ext in ${libext} .a .A.tbd ; do
787                        for dir in . lib lib64 lib/${host_cpu}-${host_os} ${host_cpu}-${host_os} lib/${MULTIARCH} ${MULTIARCH}; do
788                            staticfile=$(ls "${testdir}/$dir/libpcap${ext}" 2> /dev/null | sort | head -n1)
789                            if test -n "${staticfile}"; then
790                                LPCAPLIB="${staticfile}"
791                                foundpcap=$testdir
792                                break
793                            fi
794                        done
795
796                        if ! test $foundpcap = no; then
797                            break
798                        fi
799                    done
800                fi
801                if test $foundpcap = no -a -f "${testdir}/lib/libwpcap.${libext}" ; then
802                    LPCAPLIB="${testdir}/lib/libwpcap.${libext}"
803                    AC_DEFINE([HAVE_WINPCAP], [1], [Do we have WinPcap?])
804                    foundpcap=$testdir
805                fi
806            fi
807
808            if ! test $foundpcap = no; then
809                break
810            fi
811        done
812    fi
813    ])
814
815if test $foundpcap = no ; then
816    AC_MSG_RESULT(no)
817    AC_MSG_ERROR(libpcap not found)
818else
819    AC_MSG_RESULT($foundpcap)
820fi
821
822# libpcap can require libnl
823AC_SEARCH_LIBS([nl_handle_alloc], [nl],
824        [AC_MSG_NOTICE([Unable to find nl library - may be needed by libpcap])])
825
826##
827## If not automatically configured,
828## check for newer and full-featured libpcap's
829##
830if ! test $using_pcap_config = yes; then
831    ## newer libpcap requires dbus and latest nl (e.g. -lnl-genl-3 -lnl-3  -ldbus-1)
832    AC_CHECK_LIB(nl, nl_cache_alloc, [nl_found=yes])
833    AC_CHECK_LIB(nl-genl-3, genl_connect, [nl_genl_3_found=yes])
834    AC_CHECK_LIB(nl-3, nl_cache_alloc, [nl_3_found=yes])
835    AC_CHECK_LIB(dbus-1, dbus_malloc, [dbus_1_found=yes])
836    if test "$nl_found" = "yes"; then
837        LPCAPLIB="$LPCAPLIB -lnl"
838    fi
839    if test "$nl_genl_3_found" = "yes"; then
840        LPCAPLIB="$LPCAPLIB -lnl-genl-3"
841    fi
842    if test "$nl_3_found" = "yes"; then
843        LPCAPLIB="$LPCAPLIB -lnl-3"
844    fi
845    if test "$dbus_1_found" = "yes"; then
846        LPCAPLIB="$LPCAPLIB -ldbus-1"
847    fi
848
849    ## See if prereqs for PF_RING exist
850    AC_CHECK_LIB(numa, numa_available, [numa_found=yes])
851    AC_CHECK_LIB(pthread, pthread_create, [pthread_found=yes])
852    if test $pf_ring_found = yes; then
853        if ! test "${numa_found}" = "yes"; then
854            AC_MSG_ERROR([PF_RING requires libnuma and/or libnuma-dev])
855        fi
856        if ! test "${pthread_found}" = "yes"; then
857            AC_MSG_ERROR([PF_RING requires libpthread])
858        fi
859        LPCAPLIB="$LPCAPLIB ${pf_ring_lib} -lnuma -lpthread -lrt"
860    fi
861fi
862
863OLDLIBS="$LIBS"
864if test -n "$LPCAPINCDIR"; then
865    OLDCFLAGS="$CFLAGS -I$LPCAPINCDIR"
866    CFLAGS="$CFLAGS -I$LPCAPINCDIR"
867else
868    OLDCFLAGS="$CFLAGS"
869    LPCAPINCDIR=$(echo $CFLAGS | sed -e 's/^\-I//')
870    LPCAPINC="$LPCAPINCDIR/pcap.h"
871fi
872
873LIBS="$LPCAPLIB"
874AC_SEARCH_LIBS([pcap_get_pfring_id], [pcap], AC_DEFINE([HAVE_PF_RING_PCAP], [1], [Do we have PF_RING libpcap support?]))
875
876## Does libpcap work with selected libraries?
877AC_SEARCH_LIBS([pcap_close], [pcap],
878    , AC_MSG_ERROR(Unable to link libpcap in ${foundpcap}),)
879
880AC_SUBST(LPCAPINC)
881AC_SUBST(LPCAPLIB)
882
883
884dnl Check to see what version of libpcap
885dnl this code has been reduced a lot, but probably still could be
886dnl reduced quite a bit more if we chose too
887AC_MSG_CHECKING(for libpcap version)
888
889dnl 0.9.6 (which is still thinks it is 0.9.5 due to a bug) introduces an important
890dnl fix for OSX.  See: http://tcpreplay.synfin.net/trac/ticket/167
891AC_RUN_IFELSE([AC_LANG_PROGRAM([[
892#include <string.h>
893#include <stdlib.h>
894#include <stdio.h>
895#include "$LPCAPINC"
896#define PCAP_TEST "0.9.6"
897]], [[
898/*
899 * simple proggy to test the version of libpcap
900 * returns zero if version >= 0.9.6
901 * or one otherwise
902 */
903    if (strncmp(pcap_lib_version(), PCAP_TEST, 3) >= 0)
904        exit(0);
905
906    if (strncmp(pcap_lib_version(), PCAP_TEST, 5) >= 0) {
907        printf("%s ", pcap_lib_version());
908        exit(0);
909    }
910
911    exit(1);
912]])],
913 [libpcap_version_096=yes],
914 [libpcap_version_096=no],
915 [libpcap_version_096=yes]
916)
917
918AC_RUN_IFELSE([AC_LANG_PROGRAM([[
919#include <string.h>
920#include <stdlib.h>
921#include <stdio.h>
922#include "$LPCAPINC"
923#define PCAP_TEST "0.8"
924]], [[
925/*
926 * simple proggy to test the version of libpcap
927 * returns zero if version >= 0.8.0
928 * or one otherwise
929 */
930    if (strncmp(pcap_lib_version(), PCAP_TEST, 3) >= 0)
931        exit(0);
932
933    /* winpcap? */
934    if (strncmp(pcap_lib_version(), "WinPcap", 7) == 0)
935        exit(0);
936
937    exit(1);
938]])],
939 [libpcap_ver8=yes],
940 [libpcap_ver8=no],
941 [libpcap_ver8=yes]
942)
943
944AC_RUN_IFELSE([AC_LANG_PROGRAM([[
945#include <string.h>
946#include <stdlib.h>
947#include <stdio.h>
948#include "$LPCAPINC"
949#define PCAP_TEST "0.7.2"
950extern const char pcap_version[[]]; /* double up since autoconf escapes things */
951]], [[
952/*
953 * simple proggy to test the version of libpcap
954 * returns zero if version >= 0.7.2
955 * or one otherwise
956 */
957    if (strncmp(pcap_lib_version(), PCAP_TEST, 3) >= 0)
958        exit(0);
959
960    if (strncmp(pcap_version, PCAP_TEST, 5) >= 0)
961            exit(0);
962
963    exit(1);
964]])],
965 [libpcap_ver7=yes],
966 [libpcap_ver7=no],
967 [libpcap_ver7=yes]
968)
969
970if test x$libpcap_ver8 = xyes ; then
971    AC_MSG_RESULT(>= 0.8.0)
972elif test x$libpcap_ver7 = xyes ; then
973    AC_MSG_RESULT(>= 0.7.2)
974else
975    AC_MSG_ERROR([Libpcap versions < 0.7.2 are not supported
976    Please upgrade to version 0.7.2 or better])
977fi
978
979libpcap_version=unknown
980if test x$libpcap_version_096 = xyes ; then
981    libpcap_version=">= 0.9.6"
982elif test x$libpcap_ver8 = xyes ; then
983    libpcap_version=">= 0.8.0"
984elif test x$libcap_ver7 = xyes ; then
985    libpcap_version=">= 0.7.0"
986fi
987
988dnl Check for pcap_setnonblock()
989AC_MSG_CHECKING(for pcap_setnonblock)
990AC_LINK_IFELSE([AC_LANG_PROGRAM([[
991#include <stdio.h>
992#include <stdlib.h>
993#include <string.h>
994#include "$LPCAPINC"
995]],[[
996    pcap_t *p;
997    char *errbuf;
998
999    pcap_setnonblock(p, 1, errbuf);
1000    exit(0);
1001]])], [
1002    have_pcap_setnonblock=yes
1003    AC_MSG_RESULT(yes)
1004], [
1005    have_pcap_setnonblock=no
1006    AC_MSG_RESULT(no)
1007])
1008
1009if test $have_pcap_setnonblock = yes ; then
1010    AC_DEFINE([HAVE_PCAP_SETNONBLOCK], [1],
1011              [Does libpcap have pcap_setnonblock?])
1012fi
1013
1014dnl Check to see if we've got pcap_datalink_val_to_name()
1015AC_MSG_CHECKING(for pcap_datalink_val_to_description)
1016AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1017#include <stdio.h>
1018#include <stdlib.h>
1019#include <string.h>
1020#include "$LPCAPINC"
1021]],[[
1022    if (strcmp(pcap_datalink_val_to_description(1), "Ethernet (10Mb)") == 0)
1023        exit(0);
1024    exit(1);
1025]])],[
1026    have_dlt_to_desc=yes
1027    AC_MSG_RESULT(yes)
1028], [
1029    have_dlt_to_desc=no
1030    AC_MSG_RESULT(no)
1031])
1032
1033if test $have_dlt_to_desc = yes ; then
1034    AC_DEFINE([HAVE_DLT_VAL_TO_DESC], [1],
1035              [Does libpcap have pcap_datalink_val_to_description?])
1036fi
1037
1038dnl Check for pcap_get_selectable_fd()
1039AC_MSG_CHECKING(for pcap_get_selectable_fd)
1040AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1041#include <stdio.h>
1042#include <stdlib.h>
1043#include <string.h>
1044#include "$LPCAPINC"
1045]], [[
1046    int f;
1047    pcap_t *p;
1048    f = pcap_get_selectable_fd(p);
1049    exit(0);
1050]])], [
1051    have_pcap_get_selectable_fd=yes
1052    AC_MSG_RESULT(yes)
1053], [
1054    have_pcap_get_selectable_fd=no
1055    AC_MSG_RESULT(no)
1056])
1057
1058if test x$have_pcap_get_selectable_fd = xyes ; then
1059    AC_DEFINE([HAVE_PCAP_GET_SELECTABLE_FD], [1],
1060        [Does libpcap have pcap_get_selectable_fd?])
1061fi
1062
1063dnl Important: winpcap apparently defines functions in it's header files
1064dnl which aren't actually in the library.  Totally fucked up.  Hence, we
1065dnl must actually LINK the code, not just compile it.
1066
1067dnl Check to see if we've got pcap_dump_fopen()
1068AC_MSG_CHECKING(for pcap_dump_fopen)
1069AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1070#include <stdio.h>
1071#include <stdlib.h>
1072#include <string.h>
1073#include "$LPCAPINC"
1074]],[[
1075    pcap_dumper_t *dump;
1076    pcap_t *pcap;
1077    FILE *foo;
1078    dump = pcap_dump_fopen(pcap, foo);
1079]])],[
1080    have_pcap_dump_fopen=yes
1081    AC_MSG_RESULT(yes)
1082], [
1083    have_pcap_dump_fopen=no
1084    AC_MSG_RESULT(no)
1085])
1086
1087if test $have_pcap_dump_fopen = yes ; then
1088    AC_DEFINE([HAVE_PCAP_DUMP_FOPEN], [1],
1089              [Does libpcap have pcap_dump_fopen?])
1090else
1091    AC_MSG_NOTICE([--verbose mode requires libpcap >= 0.9.0])
1092fi
1093
1094have_pcap_inject=no
1095dnl Check to see if we've got pcap_inject()
1096AC_MSG_CHECKING(for pcap_inject sending support)
1097AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1098#include <stdio.h>
1099#include <stdlib.h>
1100#include <string.h>
1101#include "$LPCAPINC"
1102]],[[
1103    pcap_t *pcap;
1104    char *buf;
1105    pcap_inject(pcap, (void *)buf, 0);
1106]])],[
1107    have_pcap_inject=yes
1108    AC_MSG_RESULT(yes)
1109], [
1110    have_pcap_inject=no
1111    AC_MSG_RESULT(no)
1112])
1113
1114if test $have_pcap_inject = yes ; then
1115    AC_DEFINE([HAVE_PCAP_INJECT], [1], [Does libpcap have pcap_inject?])
1116fi
1117
1118have_pcap_sendpacket=no
1119dnl Check to see if we've got pcap_sendpacket()
1120AC_MSG_CHECKING(for pcap_sendpacket sending support)
1121AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1122#include <stdio.h>
1123#include <stdlib.h>
1124#include <string.h>
1125#include "$LPCAPINC"
1126]],[[
1127    pcap_t *pcap;
1128    u_char *buf;
1129    pcap_sendpacket(pcap, buf, 0);
1130]])],[
1131    have_pcap_sendpacket=yes
1132    AC_MSG_RESULT(yes)
1133], [
1134    have_pcap_sendpacket=no
1135    AC_MSG_RESULT(no)
1136])
1137
1138if test $have_pcap_sendpacket = yes ; then
1139    AC_DEFINE([HAVE_PCAP_SENDPACKET], [1], [Does libpcap have pcap_sendpacket?])
1140fi
1141
1142have_pcap_breakloop=no
1143AC_MSG_CHECKING(for pcap_breakloop)
1144AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1145#include <stdio.h>
1146#include <stdlib.h>
1147#include <string.h>
1148#include "$LPCAPINC"
1149]],[[
1150    pcap_t *pcap;
1151    pcap_sendpacket(pcap);
1152]])],[
1153    have_pcap_breakloop=yes
1154    AC_MSG_RESULT(yes)
1155], [
1156    have_pcap_breakloop=no
1157    AC_MSG_RESULT(no)
1158])
1159
1160if test $have_pcap_breakloop = yes ; then
1161    AC_DEFINE([HAVE_PCAP_BREAKLOOP], [1], [Does libpcap have pcap_breakloop?])
1162fi
1163
1164
1165have_pcap_version=no
1166dnl Check to see if we have pcap_version[]
1167AC_MSG_CHECKING(for pcap_version[])
1168AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1169#include <stdio.h>
1170#include <stdlib.h>
1171#include <string.h>
1172#include "$LPCAPINC"
1173extern char pcap_version[];
1174]], [[
1175    printf("%s", pcap_version);
1176]])],[
1177    AC_DEFINE([HAVE_PCAP_VERSION],[1], [Does libpcap have pcap_version[]])
1178    AC_MSG_RESULT(yes)
1179],[
1180    AC_MSG_RESULT(no)
1181])
1182
1183have_pcap_snapshot=no
1184dnl Check for pcap_snapshot()
1185AC_MSG_CHECKING(for pcap_snapshot)
1186AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1187#include <stdio.h>
1188#include <stdlib.h>
1189#include <string.h>
1190#include "$LPCAPINC"
1191]],[[
1192    pcap_t *p;
1193    int len;
1194
1195    len = pcap_snapshot(p);
1196    exit(0);
1197]])], [
1198    have_pcap_snapshot=yes
1199    AC_MSG_RESULT(yes)
1200], [
1201    have_pcap_snapshot=no
1202    AC_MSG_RESULT(no)
1203])
1204
1205if test $have_pcap_snapshot = yes ; then
1206    AC_DEFINE([HAVE_PCAP_SNAPSHOT], [1],
1207              [Does libpcap have pcap_snapshot?])
1208fi
1209
1210
1211# Tcpbridge requires libpcap and pcap_sendpacket()
1212enable_tcpbridge=no
1213if test x$foundpcap != xno -a x$have_pcap_sendpacket = xyes ; then
1214
1215    # if we have pcap_sendpacket() then we can build tcpbridge on non-BPF systems
1216    if test x$have_bpf = xno; then
1217        AC_DEFINE(ENABLE_TCPBRIDGE, [1], [Compile tcpbridge])
1218        enable_tcpbridge=yes
1219        AC_MSG_NOTICE([Building tcpbridge])
1220
1221    # BPF systems need to also have pcap_setnonblock()
1222    elif test x$have_pcap_setnonblock = xyes ; then
1223        AC_DEFINE(ENABLE_TCPBRIDGE, [1], [Compile tcpbridge])
1224        enable_tcpbridge=yes
1225        AC_MSG_NOTICE([Building tcpbridge])
1226    else
1227        AC_MSG_WARN([Unable to build tcpbridge.  Try installing latest libpcap!])
1228    fi
1229fi
1230AM_CONDITIONAL(COMPILE_TCPBRIDGE, [test x$enable_tcpbridge = xyes ])
1231
1232
1233
1234# tcpliveplay requires linux OS to function properly
1235enable_tcpliveplay=no
1236case $host in
1237    *-*-linux*)
1238    AC_DEFINE(ENABLE_TCPLIVEPLAY, [1], [Compile tcpliveplay])
1239    enable_tcpliveplay=yes
1240    AC_MSG_NOTICE([Building tcpliveplay])
1241    ;;
1242
1243    *)
1244    AC_MSG_WARN([Unable to build tcpliveplay.  This tool is only enabled on linux environments.])
1245    ;;
1246esac
1247
1248AM_CONDITIONAL(COMPILE_TCPLIVEPLAY, [test x$enable_tcpliveplay = xyes ])
1249
1250
1251
1252dnl #####################################################
1253dnl Check for netmap support
1254dnl #####################################################
1255have_netmap=no
1256enable_netmap=no
1257trynetmapdir=
1258AC_MSG_CHECKING(for netmap socket sending support)
1259AC_ARG_WITH(netmap,
1260    AS_HELP_STRING([--with-netmap=DIR],[Use netmap in DIR]),
1261    [trynetmapdir=$withval])
1262
1263NETMAP_SEARCH_DIRS=
1264if test "$cross_compiling" = yes; then
1265    if test "x$trynetmapdir" != "x"; then
1266        NETMAP_SEARCH_DIRS=$trynetmapdir
1267    fi
1268else
1269    NETMAP_SEARCH_DIRS="$trynetmapdir /opt/netmap /usr/src/netmap-release /usr/src/netmap /usr/local/src/netmap-release /usr/local/src/netmap /usr/include"
1270fi
1271
1272for testdir in $NETMAP_SEARCH_DIRS; do
1273    if test -f "${testdir}/sys/net/netmap.h" ; then
1274        NETMAPINC="${testdir}/sys/net/netmap.h"
1275        NETMAPUSERINC="${testdir}/sys/net/netmap_user.h"
1276        NETMAPINCDIR="${testdir}/sys"
1277        have_netmap="yes $testdir"
1278        enable_netmap=yes
1279    else
1280        if test -f "${testdir}/net/netmap.h" ; then
1281            NETMAPINC="${testdir}/net/netmap.h"
1282            NETMAPUSERINC="${testdir}/net/netmap_user.h"
1283            NETMAPINCDIR="${testdir}"
1284            have_netmap="yes $testdir"
1285            enable_netmap=yes
1286        fi
1287    fi
1288
1289    if test "$have_netmap" != no ; then
1290        NETMAPFLAGS="-DHAVE_NETMAP"
1291        OLDCFLAGS="$CFLAGS -I$NETMAPINCDIR"
1292        CFLAGS="$CFLAGS -DNETMAP_WITH_LIBS -DND -I$NETMAPINCDIR"
1293
1294        AC_SUBST(NETMAPINC)
1295        AC_SUBST(NETMAPUSERINC)
1296        AC_SUBST(NETMAPINCDIR)
1297        AC_SUBST(NETMAPFLAGS)
1298        AC_DEFINE([HAVE_NETMAP], [1],
1299               [Do we have netmap support?])
1300        have_netmap="yes $testdir"
1301        enable_netmap=yes
1302        break;
1303    fi
1304done
1305
1306AC_MSG_RESULT($have_netmap)
1307AM_CONDITIONAL(COMPILE_NETMAP, [test x$enable_netmap = xyes ])
1308
1309
1310dnl ###########################################################
1311dnl Check for nm_open() function available in netmap version 5
1312dnl Also check for other version-specific netmap definitions and structures
1313dnl ###########################################################
1314
1315if test "x$NETMAPINCDIR" != "x"; then
1316    OLDCPPFLAGS="$CPPFLAGS"
1317    CPPFLAGS="$CPPFLAGS -DNETMAP_WITH_LIBS -DND -I$NETMAPINCDIR"
1318
1319    have_nm_open=no
1320    have_nm_nr_reg_mask=no
1321    have_nm_nr_flags=no
1322    have_nmring_head_tail=no
1323    if test "$have_netmap" != no ; then
1324        dnl check for nm_open()
1325        AC_CHECK_DECL([nm_open],[have_nm_open=yes], , [[
1326            #include <stdio.h>
1327            #include "${NETMAPUSERINC}"
1328        ]])
1329
1330        dnl check for #define NR_REG_MASK
1331        AC_MSG_CHECKING(for netmap NR_REG_MASK definition)
1332        AC_COMPILE_IFELSE(
1333            [AC_LANG_PROGRAM([[
1334                    #include <stdint.h>
1335                    #include <sys/socket.h>
1336                    #include <net/if.h>
1337                    #include <net/netmap.h>
1338                ]],
1339                [[
1340                    #ifdef NR_REG_MASK
1341                        /* OK */
1342                    #else
1343                        # error NR_REG_MASK not found
1344                    #endif
1345                ]])
1346            ],
1347            [have_nm_nr_reg_mask=yes],
1348            [])
1349        AC_MSG_RESULT($have_nm_nr_reg_mask)
1350
1351        dnl check for nr_flags in struct nmreq
1352        AC_MSG_CHECKING(for netmap nr_flags definition)
1353        AC_COMPILE_IFELSE(
1354            [AC_LANG_PROGRAM([[
1355                    #include <stdint.h>
1356                    #include <sys/socket.h>
1357                    #include <net/if.h>
1358                    #include <net/netmap.h>
1359                ]],
1360                [[
1361                    struct nmreq nmr;
1362                    nmr.nr_flags = 0;
1363                ]])
1364            ],
1365            [have_nm_nr_flags=yes],
1366            [])
1367        AC_MSG_RESULT($have_nm_nr_flags)
1368
1369        dnl check for head/tail in struct netmap_ring
1370        AC_MSG_CHECKING(for netmap ring head/tail definitions)
1371        AC_COMPILE_IFELSE(
1372            [AC_LANG_PROGRAM([[
1373                    #include <stdint.h>
1374                    #include <sys/socket.h>
1375                    #include <net/if.h>
1376                    #include <net/netmap.h>
1377                ]],
1378                [[
1379                    struct netmap_ring r;
1380                    r.head = r.tail = 0;
1381                ]])
1382            ],
1383            [have_nmring_head_tail=yes],
1384            [])
1385        AC_MSG_RESULT($have_nmring_head_tail)
1386
1387    fi
1388
1389    if test "$have_nm_open" = yes ; then
1390        AC_DEFINE([HAVE_NETMAP_NM_OPEN], [1], [Does netmap have nm_open function?])
1391    fi
1392    if test "$have_nm_nr_reg_mask" = yes ; then
1393        AC_DEFINE([HAVE_NETMAP_NR_REG], [1], [Does netmap have NR_REG_MASK defined?])
1394    fi
1395    if test "$have_nm_nr_flags" = yes ; then
1396        AC_DEFINE([HAVE_NETMAP_NR_FLAGS], [1], [Does netmap struct nmreq have nr_flags defined?])
1397    fi
1398    if test "$have_nmring_head_tail" = yes ; then
1399        AC_DEFINE([HAVE_NETMAP_RING_HEAD_TAIL], [1], [Does structure netmap_ring have head/tail defined?])
1400    fi
1401
1402    CPPFLAGS="$OLDCPPFLAGS"
1403fi
1404
1405have_pf=no
1406dnl Check for linux PF_PACKET support
1407AC_MSG_CHECKING(for PF_PACKET socket sending support)
1408AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1409#include <sys/socket.h>
1410#include <netpacket/packet.h>
1411#include <net/ethernet.h>     /* the L2 protocols */
1412#include <netinet/in.h>       /* htons */
1413]], [[
1414    int pf_socket;
1415    pf_socket = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
1416]])],[
1417    AC_DEFINE([HAVE_PF_PACKET], [1],
1418            [Do we have Linux PF_PACKET socket support?])
1419    AC_MSG_RESULT(yes)
1420    have_pf=yes
1421],[
1422    AC_MSG_RESULT(no)
1423])
1424
1425have_tx_ring=no
1426dnl Check for older Linux TX_RING support
1427AC_MSG_CHECKING(for TX_RING socket sending support)
1428AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1429#include <sys/socket.h>
1430#include <netpacket/packet.h>
1431#include <net/ethernet.h>     /* the L2 protocols */
1432#include <netinet/in.h>       /* htons */
1433#include <linux/if_packet.h>
1434]], [[
1435    int test;
1436    test = TP_STATUS_WRONG_FORMAT
1437]])],[
1438    AC_DEFINE([HAVE_TX_RING], [1],
1439            [Do we have Linux TX_RING socket support?])
1440    AC_MSG_RESULT(yes)
1441    have_tx_ring=yes
1442],[
1443    AC_MSG_RESULT(no)
1444])
1445
1446
1447AC_CHECK_HEADERS([net/bpf.h], [have_bpf=yes], [have_bpf=no])
1448if test $have_bpf = yes ; then
1449    AC_DEFINE([HAVE_BPF], [1],
1450            [Do we have BPF device support?])
1451fi
1452
1453dnl ##################################################
1454dnl # Check for libdnet, but only if not Cygwin!
1455dnl #
1456dnl # if your version of libdnet doesn't compile, try
1457dnl # getting it from ...
1458dnl # http://libdnet.sourceforge.net/
1459dnl # ... or ...
1460dnl # https://github.com/jncornett/libdnet
1461dnl # ... or ...
1462dnl # on Linux try 'apt-get install libdumbnet-dev'
1463dnl ##################################################
1464founddnet=no
1465have_libdnet=no
1466libdnet_version=
1467enable_fragroute=no
1468trydnetdir=/usr/local
1469
1470if test $have_cygwin = no ; then
1471    AC_MSG_CHECKING(for libdnet)
1472    AC_ARG_WITH(libdnet,
1473        AS_HELP_STRING([--with-libdnet=DIR],[Use libdnet in DIR]),
1474        [trydnetdir=$withval])
1475
1476    if test $trydnetdir != no; then
1477        case "$build_os" in
1478        linux*)
1479            dnl # Debian/Ubuntu already have a package called libdnet
1480            dnl # so you the package you want to install libdumbnet-dev
1481            for testdir in $trydnetdir /usr/local /opt/local /usr ; do
1482                if test -x ${testdir}/bin/dumbnet-config -a $founddnet = no ; then
1483                    LDNETINC="$($testdir/bin/dumbnet-config --cflags)"
1484                    LDNETLIB="$($testdir/bin/dumbnet-config --libs)"
1485                    libdnet_version="$($testdir/bin/dumbnet-config --version) (libdumbnet)"
1486                    founddnet=$testdir
1487                fi
1488            done
1489            ;;
1490        esac
1491
1492        if test $founddnet = no ; then
1493            for testdir in $trydnetdir /usr/local /opt/local $MACOSX_SDK_PATH/usr /usr ; do
1494                if test -x ${testdir}/bin/dnet-config -a $founddnet = no ; then
1495                    LDNETINC="$($testdir/bin/dnet-config --cflags)"
1496                    LDNETLIB="$($testdir/bin/dnet-config --libs)"
1497                    libdnet_version="$($testdir/bin/dnet-config --version)"
1498                    founddnet=$testdir
1499                fi
1500            done
1501        fi
1502    fi
1503
1504    if test $founddnet = no ; then
1505        AC_MSG_RESULT(no)
1506        AC_MSG_WARN([libdnet not found, disabling fragroute feature])
1507    else
1508        AC_MSG_RESULT($founddnet)
1509        enable_fragroute=yes
1510        have_libdnet=yes
1511        AC_DEFINE([HAVE_LIBDNET], [1], [Do we have libdnet?])
1512        dnl Debian uses dumbnet.h instead of dnet.h due to naming conflict
1513        old_cflags=$CFLAGS
1514        CFLAGS=$LDNETINC
1515        AC_CHECK_HEADERS([dumbnet.h dnet.h])
1516        CFLAGS=$old_cflags
1517    fi
1518
1519else
1520    AC_MSG_NOTICE([Skipping libdnet check under Cygwin for compatibility reasons])
1521fi
1522
1523
1524AC_SUBST(LDNETINC)
1525AC_SUBST(LDNETLIB)
1526AC_DEFINE_UNQUOTED([LIBDNET_VERSION], "$libdnet_version", [Version of libdnet])
1527
1528AM_CONDITIONAL(COMPILE_FRAGROUTE, [test x$founddnet != xno])
1529if test x$founddnet != xno ; then
1530    AC_DEFINE(ENABLE_FRAGROUTE, [1], [Enable fragroute module])
1531fi
1532
1533
1534dnl Make sure we have a valid packet injection mechanisim
1535if test $have_bpf = no -a $have_pcap_inject = no -a $have_pcap_sendpacket = no \
1536    -a $have_libdnet = no -a $have_pf = no ; then
1537    AC_MSG_ERROR([Unable to find a supported method to send packets.  Please upgrade your libpcap or enable libdnet])
1538fi
1539
1540dnl Older versions of libpcap are missing some DLT types
1541dnl If doesn't exist, we'll define them in src/common/fakepcap.h
1542AC_MSG_CHECKING(for DLT_LINUX_SLL in libpcap)
1543AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "$LPCAPINC"]], [[ int foo;
1544                 foo = DLT_LINUX_SLL
1545               ]])],[ AC_DEFINE([HAVE_DLT_LINUX_SLL], [1],
1546                           [Does pcap.h include a header with DLT_LINUX_SLL?])
1547                 AC_MSG_RESULT(yes)
1548               ],[AC_MSG_RESULT(no)
1549               ])
1550
1551AC_MSG_CHECKING(for DLT_C_HDLC in libpcap)
1552AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "$LPCAPINC"]], [[ int foo;
1553                 foo = DLT_C_HDLC ]])],[ AC_DEFINE([HAVE_DLT_C_HDLC], [1],
1554                            [Does pcap.h include a header with DLT_C_HDLC?])
1555                  AC_MSG_RESULT(yes)
1556                ],[AC_MSG_RESULT(no)
1557               ])
1558
1559PCAP_BPF_H_FILE="$LPCAPINCDIR/pcap-bpf.h"
1560AC_MSG_CHECKING(for $PCAP_BPF_H_FILE)
1561AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
1562                #include <sys/time.h>
1563                #include <stdint.h>
1564                #include "$PCAP_BPF_H_FILE"]], [[ int foo;
1565                 foo = BPF_MAJOR_VERSION; ]])],[ AC_DEFINE([INCLUDE_PCAP_BPF_HEADER], [1],
1566                           [What is the path (if any) to the pcap-bpf.h
1567                            header?])
1568                 AC_MSG_RESULT(yes)
1569                 AC_SUBST(PCAP_BPF_H_FILE)
1570               ],[AC_MSG_RESULT(no)
1571               ])
1572
1573foundbpfheader=no
1574AC_MSG_CHECKING(for libpcap bpf header)
1575for testfile in $LPCAPINCDIR/pcap/bpf.h $LPCAPINCDIR/pcap-bpf.h ; do
1576    if test -f "${testfile}" -a $foundbpfheader = no ; then
1577        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1578            #include <sys/types.h>
1579            #include <sys/time.h>
1580            #include <stdint.h>
1581            #include "$testfile"]], [[
1582                int foo;
1583                foo = BPF_MAJOR_VERSION;
1584            ]])],[
1585                foundbpfheader=yes
1586                PCAP_BPF_H_FILE=$testfile
1587                AC_SUBST(PCAP_BPF_H_FILE)
1588                AC_DEFINE([INCLUDE_PCAP_BPF_HEADER], [1],
1589                        [What is the path (if any) to the libpcap bpf header file?])
1590            ],[])
1591    fi
1592done
1593
1594if test $foundbpfheader != no; then
1595    AC_MSG_RESULT($testfile)
1596else
1597    AC_MSG_RESULT(no)
1598fi
1599
1600dnl ## Test for netmap-libpcap
1601have_pcap_netmap=no
1602if test $foundpcap != no ; then
1603	AC_MSG_CHECKING(for netmap libpcap)
1604    PCAP_NETMAP_C_FILE="$LPCAPINCDIR/pcap-netmap.c"
1605    if test -f "${PCAP_NETMAP_C_FILE}" ; then
1606        AC_DEFINE([HAVE_LIBPCAP_NETMAP], [1],
1607                                   [Does this version of libpcap support netmap?])
1608        have_pcap_netmap=yes
1609        AC_MSG_RESULT(yes)
1610    else
1611        AC_MSG_RESULT(no)
1612    fi
1613fi
1614
1615dnl restore LIBS & CFLAGS
1616LIBS="$OLDLIBS"
1617CFLAGS="$OLDCFLAGS"
1618
1619
1620dnl ##################################################
1621dnl # Check for pcapnav
1622dnl ##################################################
1623pcapnav_ver=no
1624pcncfg=no
1625AC_ARG_WITH(pcapnav-config,
1626    AS_HELP_STRING([--with-pcapnav-config=FILE],[Use given pcapnav-config]),
1627    [ AC_MSG_CHECKING(for pcapnav-config)
1628    if test -x $withval ; then
1629        pcncfg=$withval
1630        AC_MSG_RESULT($pcncfg)
1631    elif test x$withval = xno ; then
1632        AC_MSG_RESULT(no)
1633    else
1634        AC_MSG_RESULT([Can't find pcapnav-config: disabling offset jump feature])
1635    fi ],
1636    [ AC_PATH_PROG(pcncfg,[pcapnav-config], [no] ) ]
1637)
1638
1639if test $pcncfg != no ; then
1640    LNAVLIB=$($pcncfg --libs)
1641    LNAV_CFLAGS=$($pcncfg --cflags)
1642    PCAPNAV_VERSION=$($pcncfg --version)
1643    AC_SUBST(LNAVLIB)
1644    AC_SUBST(LNAV_CFLAGS)
1645    AC_DEFINE_UNQUOTED(PCAPNAV_VERSION, "$PCAPNAV_VERSION",
1646                       [libpcapnav's version?])
1647
1648dnl Check to see what version of libpcapnav
1649dnl this code has been reduced a lot, but probably still could be
1650dnl reduced quite a bit more if we chose too
1651    AC_MSG_CHECKING(for libpcapnav version)
1652    AC_RUN_IFELSE([AC_LANG_SOURCE([[
1653#include <string.h>
1654#define PCAPNAV_TEST "0.4"
1655/*
1656 * simple proggy to test the version of libpcapnav
1657 * returns zero if version >= 0.4
1658 * or one otherwise
1659 */
1660
1661int
1662main (int argc, char *argv[])
1663{
1664    if (strncmp(PCAPNAV_VERSION, PCAPNAV_TEST, 3) >= 0)
1665        exit(0);
1666    exit(1);
1667}           ]])],[libpcapnav_ver=yes
1668            AC_MSG_RESULT(>= 0.4)],[libpcapnav_ver=no
1669            AC_MSG_RESULT(< 0.4)],[libpcapnav_ver=no
1670    ])
1671
1672
1673if test x$libpcapnav_ver = xno ; then
1674    AC_MSG_WARN([Libpcapnav versions < 0.4 are not supported.
1675    Please upgrade to version 0.4 or better.
1676    Disabling offset jump feature.])
1677else
1678    AC_DEFINE([HAVE_PCAPNAV], [1], [Do we have libpcapnav?])
1679fi
1680
1681fi # checking pcapnav version
1682
1683
1684dnl (shamelessly ripped off from libpcap)
1685dnl Checks to see if unaligned memory accesses fail
1686dnl
1687dnl     FORCE_ALIGN (DEFINED)
1688dnl
1689AC_MSG_CHECKING(for requires strict byte alignment)
1690AC_CACHE_VAL(unaligned_cv_fail,
1691        [case "$host_cpu" in
1692
1693        # XXX: should also check that they don't do weird things (like on arm)
1694        alpha*|arm*|hp*|mips*|sparc*|ia64)
1695                unaligned_cv_fail=yes
1696                ;;
1697
1698        *)
1699        cat >conftest.c <<EOF
1700        #include <sys/types.h>
1701        #include <sys/wait.h>
1702        #include <stdio.h>
1703        unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
1704        main() {
1705            unsigned int i;
1706            pid_t pid;
1707            int status;
1708            /* avoid "core dumped" message */
1709            pid = fork();
1710            if (pid <  0)
1711                exit(2);
1712            if (pid > 0) {
1713                /* parent */
1714                pid = waitpid(pid, &status, 0);
1715                if (pid < 0)
1716                        exit(3);
1717                exit(!WIFEXITED(status));
1718            }
1719            /* child */
1720            i = *(unsigned int *)&a[[1]];
1721            printf("%d\n", i);
1722            exit(0);
1723        }
1724EOF
1725        ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
1726            conftest.c $LIBS >/dev/null 2>&1
1727        if test ! -x conftest ; then
1728            dnl failed to compile for some reason
1729            unaligned_cv_fail=yes
1730        else
1731            ./conftest >conftest.out
1732            if test ! -s conftest.out ; then
1733                unaligned_cv_fail=yes
1734            else
1735                unaligned_cv_fail=no
1736            fi
1737        fi
1738        rm -f conftest* core core.conftest
1739        ;;
1740
1741        esac
1742    ])
1743AC_MSG_RESULT($unaligned_cv_fail)
1744if test $unaligned_cv_fail = yes ; then
1745    AC_DEFINE([FORCE_ALIGN], [1], [Are we strictly aligned?])
1746fi
1747
1748dnl ##################################################
1749dnl # Check for tcpdump.
1750dnl ##################################################
1751
1752tcpdump_path=no
1753AC_ARG_WITH(tcpdump,
1754    AS_HELP_STRING([--with-tcpdump=FILE],[Path to tcpdump binary]),
1755    [ if test -x $withval ; then
1756          tcpdump_path=$withval
1757          AC_MSG_RESULT([Using tcpdump in $tcpdump_path])
1758      else
1759          AC_MSG_RESULT([Error: $withval does not exist or is not executable])
1760      fi ],
1761    [ AC_PATH_PROG(tcpdump_path, tcpdump, "no", [$PATH:/usr/sbin:/sbin:/usr/local/sbin]) ])
1762
1763
1764if test "$tcpdump_path" = "no"; then
1765    AC_MSG_WARN([Unable to find tcpdump.  Please specify --with-tcpdump.
1766                 Disabling --verbose])
1767else
1768    AC_DEFINE([HAVE_TCPDUMP], [1], [Do we have tcpdump?])
1769    AC_DEFINE_UNQUOTED(TCPDUMP_BINARY, "$tcpdump_path", [The tcpdump binary initially used])
1770fi
1771
1772
1773AM_CONDITIONAL([ENABLE_TCPDUMP], test "$tcpdump_path" != "no" -a x$have_pcap_dump_fopen = xyes)
1774if test x$tcpdump_path != xno -a x$have_pcap_dump_fopen = xyes ; then
1775    AC_DEFINE([ENABLE_VERBOSE], [1], [Do we have tcpdump and pcap_dump_fopen()?])
1776else
1777    AC_MSG_WARN([Your version of libpcap does not support --verbose])
1778fi
1779
1780dnl No 'make test' when cross compile
1781
1782AC_MSG_CHECKING(for 'make test' profile)
1783if test "$host" == "$build" ; then
1784    AC_MSG_RESULT([yes])
1785else
1786    AC_MSG_WARN(Unable to do tests when cross-compiling)
1787    AC_MSG_RESULT([Unable to do tests when cross-compiling])
1788fi
1789
1790dnl Allows user to choose which nic to use for testing purposes
1791AC_ARG_WITH(testnic,
1792    AS_HELP_STRING([--with-testnic=NIC],[Select which network card to use for testing]),
1793    [ nic1=$withval
1794      nic2=$withval
1795      AC_MSG_RESULT([Using --with-testnic=$withval])],
1796    [
1797case $host in
1798    *-*-linux*)
1799    nic1=eth0
1800    nic2=eth0
1801    ;;
1802
1803    *-*-solaris*)
1804    nic1=hme0
1805    nic2=hme0
1806    ;;
1807
1808    *-*-sunos*)
1809    nic1=hme0
1810    nic2=hme0
1811    ;;
1812
1813    *-apple-darwin*)
1814    nic1=en0
1815    nic2=en0
1816    ;;
1817
1818    *-*-openbsd*)
1819    nic1=xl0
1820    nic2=xl0
1821    ;;
1822
1823    *-*-freebsd*)
1824    nic1=em0
1825    nic2=em0
1826    ;;
1827
1828    *-*-cygwin)
1829    nic1=%0
1830    nic2=%0
1831    ;;
1832
1833    *)
1834    AC_MSG_RESULT([$host is unknown!  Using first non-loopback interface])
1835    nic1=%0
1836    nic2=%0
1837    ;;
1838esac])
1839
1840dnl There's a bug in OS X which causes pcap_findalldevs() to make the wifi NIC to disassociate
1841dnl so under OSX we disable the interface list feature
1842disable_pcap_findalldevs=no
1843osx_frameworks=no
1844
1845AC_MSG_CHECKING([for OS version])
1846dnl these need to be dynamic based on OS
1847case $host in
1848    *-*-linux*)
1849    AC_DEFINE([HAVE_LINUX], [1], [Building Linux])
1850    AC_MSG_RESULT(Linux)
1851    ;;
1852
1853    *-*-solaris*)
1854    AC_DEFINE([HAVE_SOLARIS], [1], [Building Solaris])
1855    AC_MSG_RESULT(Solaris)
1856    ;;
1857
1858    *-*-sunos*)
1859    AC_DEFINE([HAVE_SUNOS], [1], [Building SunOS])
1860    AC_MSG_RESULT(SunOS)
1861    ;;
1862
1863    *-apple-darwin*)
1864    if test x$libpcap_version_096 = xno ; then
1865        disable_pcap_findalldevs=yes
1866    fi
1867    osx_frameworks=yes
1868    AC_DEFINE([HAVE_DARWIN], [1], [Building Apple/Darwin])
1869    AC_MSG_RESULT(Apple macOS)
1870    ;;
1871
1872    *-*-openbsd*)
1873    AC_DEFINE([HAVE_OPENBSD], [1], [Building Open BSD])
1874    AC_MSG_RESULT(OpenBSD)
1875    ;;
1876
1877    *-*-freebsd*)
1878    AC_DEFINE([HAVE_FREEBSD], [1], [Building Free BSD])
1879    AC_MSG_RESULT(FreeBSD)
1880    ;;
1881
1882    *-*-cygwin)
1883    AC_MSG_RESULT(Win32/Cygwin)
1884    AC_DEFINE([HAVE_CYGWIN], [1], [Building Cygwin])
1885    ;;
1886
1887    *)
1888    AC_MSG_RESULT([$host is unknown!])
1889    ;;
1890esac
1891AM_CONDITIONAL([ENABLE_OSX_FRAMEWORKS], test "$osx_frameworks" = "yes")
1892
1893AC_ARG_WITH(testnic2,
1894    AS_HELP_STRING([--with-testnic2=NIC2],[Select an optional 2nd network card to use for testing]),
1895    [ nic2=$withval ])
1896
1897AC_MSG_NOTICE([Using $nic1 for 1st test network interface card])
1898AC_MSG_NOTICE([Using $nic2 for 2nd test network interface card])
1899AC_SUBST(nic1)
1900AC_SUBST(nic2)
1901
1902
1903AC_MSG_CHECKING([if it's ok to use pcap_findalldevs()])
1904if test x$disable_pcap_findalldevs = xno ; then
1905    AC_DEFINE([ENABLE_PCAP_FINDALLDEVS], [1], [Enable use of pcap_findalldevs()])
1906    AC_MSG_RESULT(yes)
1907else
1908    AC_MSG_RESULT(no)
1909fi
1910
1911LIBOPTS_CHECK(libopts)
1912
1913
1914AC_CONFIG_FILES([Makefile
1915           doxygen.cfg
1916           lib/Makefile
1917           docs/Makefile
1918           src/Makefile
1919           src/tcpedit/Makefile
1920           src/fragroute/Makefile
1921           src/common/Makefile
1922           src/defines.h
1923           test/Makefile
1924           test/config
1925           scripts/Makefile])
1926
1927AC_OUTPUT
1928
1929# Configuration results
1930AC_MSG_RESULT([
1931##########################################################################
1932             TCPREPLAY Suite Configuration Results (${TCPREPLAY_VERSION})
1933##########################################################################
1934libpcap:                    ${foundpcap} (${libpcap_version})
1935PF_RING libpcap             ${pf_ring_found}   ${pf_ring_lib}
1936libdnet:                    ${founddnet}   ${libdnet_version}
1937autogen:                    ${AUTOGEN} (${AUTOGEN_VERSION})
1938Use libopts tearoff:        ${enable_local_libopts}
193964bit counter support:      ${use64bit_counters}
1940tcpdump binary path:        ${tcpdump_path}
1941fragroute support:          ${enable_fragroute}
1942tcpbridge support:          ${enable_tcpbridge}
1943tcpliveplay support:        ${enable_tcpliveplay}
1944
1945Supported Packet Injection Methods (*):
1946Linux TX_RING:              ${have_tx_ring}
1947Linux PF_PACKET:            ${have_pf}
1948BSD BPF:                    ${have_bpf}
1949libdnet:                    ${have_libdnet}
1950pcap_inject:                ${have_pcap_inject}
1951pcap_sendpacket:            ${have_pcap_sendpacket} **
1952pcap_netmap                 ${have_pcap_netmap}
1953Linux/BSD netmap:           ${have_netmap}
1954Tuntap device support:      ${have_tuntap}
1955
1956* In order of preference; see configure --help to override
1957** Required for tcpbridge
1958])
1959
1960
1961case $host in
1962    *-*-cygwin)
1963        AC_MSG_WARN([Windows/Cygwin support is still somewhat experimental.
1964Please report any bugs! https://github.com/appneta/tcpreplay/issues])
1965    ;;
1966esac
1967
1968