configure.ac 60 KB

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