configure.ac 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995
  1. dnl $Id$
  2. AC_PREREQ([2.69])
  3. dnl Set version info here!
  4. AC_INIT([tcpreplay],[4.4.2],[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.12
  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. LPCAPLIB="-L$(dirname ${sharefile}) -lpcap"
  580. foundpcap=$testdir
  581. break
  582. fi
  583. done
  584. if ! test $foundpcap = no; then
  585. break
  586. fi
  587. done
  588. else
  589. dnl
  590. dnl If dynamic library not found, try static
  591. dnl
  592. for ext in ${libext} .a .A.tbd ; do
  593. for dir in . lib lib64 lib/${host_cpu}-${host_os} ${host_cpu}-${host_os} lib/${MULTIARCH} ${MULTIARCH}; do
  594. staticfile=$(ls ${testdir}/$dir/libpcap${ext} 2> /dev/null | sort | head -n1)
  595. if test -n "${staticfile}"; then
  596. LPCAPLIB="${staticfile}"
  597. foundpcap=${testdir}
  598. break
  599. fi
  600. done
  601. if ! test $foundpcap = no; then
  602. ## could be PF_RING
  603. #
  604. # library is static and in PF_RING build tree
  605. #
  606. # Need access to libpfring library
  607. # and must find an associated libpfring.a
  608. if test -n "${with_pfring_lib}"; then
  609. if test -f ${with_pfring_lib}; then
  610. pf_ring_lib=${with_pfring_lib}
  611. pf_ring_found=yes
  612. else
  613. AC_MSG_ERROR(["Unable to find PF_RING library ${with_pfring_lib}"])
  614. fi
  615. else
  616. ## search locally for most likely PF_RING library
  617. for lib in ${foundpcap}/../lib/libs/libpfring_zc_${host_cpu}.a \
  618. ${foundpcap}/../lib/libs/libpfring_dna_${host_cpu}.a \
  619. ${foundpcap}/../lib/libs/libpfring_zero_${host_cpu}.a \
  620. ${foundpcap}/../lib/libs/libpfring_nt_${host_cpu}.a \
  621. ${foundpcap}/../lib/libpfring.a; do
  622. if test -f "${lib}"; then
  623. pf_ring_lib=${lib}
  624. pf_ring_found=yes
  625. break
  626. fi
  627. done
  628. fi
  629. break
  630. fi
  631. done
  632. fi
  633. if test $foundpcap = no; then
  634. AC_MSG_ERROR("Unable to find matching library for header file in ${testdir}")
  635. fi
  636. break
  637. done
  638. ],[
  639. #
  640. # Look for pcap-config.
  641. #
  642. # I wish this option could be the default, but it is only enabled with --enable-pcapconfig
  643. #
  644. # The issue is that libpcap is one of those libraries that is nearly impossible to set up
  645. # properly across all platforms. The 'pcap-config' script is shipped with new versions of libpcap,
  646. # and was created to address portability issues. Unfortunately, the script is not updated properly
  647. # outside of the base distribution. Examples: PF_RING requires 'pthreads', 'numa' and 'rt', but
  648. # this is not reflect that in the script. OS X Xcode 10.11 SDK creates its own very broken
  649. # 'pcap-config' script that only occasionally works for dynamic definitions, and defintely
  650. # does not work for static.
  651. #
  652. # The ability to enable this script exists for corner cases where libpcap distributions starts
  653. # using even more libraries than I am currently not aware of. Originally, you only had to worry
  654. # about 'nl', but now we have to be prepared to add 'nl-3', 'nl-genl-3' and 'dbus-1' to make
  655. # libpcap fucntional. In the future, there may be more.
  656. #
  657. # (sigh)
  658. #
  659. # So, in the future if libpcap changes and stops working, try setting --enable-pcapconfig. It
  660. # it may work for you.
  661. if test $enable_pcap_config = yes; then
  662. AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
  663. if test -n "$PCAP_CONFIG"; then
  664. #
  665. # Found - use it to get the include flags for
  666. # libpcap and the flags to link with libpcap.
  667. #
  668. # Please read section 11.6 "Shell Substitutions"
  669. # in the autoconf manual before doing anything
  670. # to this that involves quoting. Especially note
  671. # the statement "There is just no portable way to use
  672. # double-quoted strings inside double-quoted back-quoted
  673. # expressions (pfew!)."
  674. #
  675. if test $dynamic_link = yes; then
  676. LPCAPLIB=$($PCAP_CONFIG --libs)
  677. else
  678. LPCAPLIB=$($PCAP_CONFIG --libs --static)
  679. fi
  680. CFLAGS="$CFLAGS $($PCAP_CONFIG --cflags)"
  681. if test -n "$LPCAPLIB"; then
  682. foundpcap=yes
  683. using_pcap_config=yes
  684. else
  685. AC_MSG_WARN(Unable to find libpcap using pcap-config)
  686. fi
  687. fi
  688. fi
  689. if test ! $foundpcap = yes; then
  690. #
  691. # Not found; look for pcap.
  692. #
  693. for testdir in /usr/local /opt/local /usr /wpdpack $MACOSX_SDK_PATH/usr /usr/local/opt/libpcap ; do
  694. if test -f "${testdir}/include/pcap.h"; then
  695. LPCAPINC="${testdir}/include/pcap.h"
  696. LPCAPINCDIR="${testdir}/include"
  697. if test $dynamic_link = yes; then
  698. for ext in .dylib .so .tbd; do
  699. for dir in . lib lib64 ${host_cpu} lib/${host_cpu} ${host_cpu}-${host_os} lib/${host_cpu}-${host_os} ${MULTIARCH} lib/${MULTIARCH}; do
  700. sharefile=$(ls "${testdir}/$dir/libpcap${ext}" 2> /dev/null | sort | head -n1)
  701. if test -n "${sharefile}"; then
  702. LPCAPLIB="-L$(dirname ${sharefile}) -lpcap"
  703. foundpcap=$testdir
  704. break
  705. fi
  706. done
  707. if ! test $foundpcap = no; then
  708. break
  709. fi
  710. done
  711. fi
  712. if test $foundpcap = no ; then
  713. dnl
  714. dnl If dynamic library not found, try static
  715. dnl
  716. for ext in ${libext} .a .A.tbd ; do
  717. for dir in . lib lib64 lib/${host_cpu}-${host_os} ${host_cpu}-${host_os} lib/${MULTIARCH} ${MULTIARCH}; do
  718. staticfile=$(ls "${testdir}/$dir/libpcap${ext}" 2> /dev/null | sort | head -n1)
  719. if test -n "${staticfile}"; then
  720. LPCAPLIB="${staticfile}"
  721. foundpcap=$testdir
  722. break
  723. fi
  724. done
  725. if ! test $foundpcap = no; then
  726. break
  727. fi
  728. done
  729. fi
  730. if test $foundpcap = no -a -f "${testdir}/lib/libwpcap.${libext}" ; then
  731. LPCAPLIB="${testdir}/lib/libwpcap.${libext}"
  732. AC_DEFINE([HAVE_WINPCAP], [1], [Do we have WinPcap?])
  733. foundpcap=$testdir
  734. fi
  735. fi
  736. if ! test $foundpcap = no; then
  737. break
  738. fi
  739. done
  740. fi
  741. ])
  742. if test $foundpcap = no ; then
  743. AC_MSG_RESULT(no)
  744. AC_MSG_ERROR(libpcap not found)
  745. else
  746. AC_MSG_RESULT($foundpcap)
  747. fi
  748. # libpcap can require libnl
  749. AC_SEARCH_LIBS([nl_handle_alloc], [nl],
  750. [AC_MSG_NOTICE([Unable to find nl library - may be needed by libpcap])])
  751. ##
  752. ## If not automatically configured,
  753. ## check for newer and full-featured libpcap's
  754. ##
  755. if ! test $using_pcap_config = yes; then
  756. ## newer libpcap requires dbus and latest nl (e.g. -lnl-genl-3 -lnl-3 -ldbus-1)
  757. AC_CHECK_LIB(nl, nl_cache_alloc, [nl_found=yes])
  758. AC_CHECK_LIB(nl-genl-3, genl_connect, [nl_genl_3_found=yes])
  759. AC_CHECK_LIB(nl-3, nl_cache_alloc, [nl_3_found=yes])
  760. AC_CHECK_LIB(dbus-1, dbus_malloc, [dbus_1_found=yes])
  761. if test "$nl_found" = "yes"; then
  762. LPCAPLIB="$LPCAPLIB -lnl"
  763. fi
  764. if test "$nl_genl_3_found" = "yes"; then
  765. LPCAPLIB="$LPCAPLIB -lnl-genl-3"
  766. fi
  767. if test "$nl_3_found" = "yes"; then
  768. LPCAPLIB="$LPCAPLIB -lnl-3"
  769. fi
  770. if test "$dbus_1_found" = "yes"; then
  771. LPCAPLIB="$LPCAPLIB -ldbus-1"
  772. fi
  773. ## See if prereqs for PF_RING exist
  774. AC_CHECK_LIB(numa, numa_available, [numa_found=yes])
  775. AC_CHECK_LIB(pthread, pthread_create, [pthread_found=yes])
  776. if test $pf_ring_found = yes; then
  777. if ! test "${numa_found}" = "yes"; then
  778. AC_MSG_ERROR([PF_RING requires libnuma and/or libnuma-dev])
  779. fi
  780. if ! test "${pthread_found}" = "yes"; then
  781. AC_MSG_ERROR([PF_RING requires libpthread])
  782. fi
  783. LPCAPLIB="$LPCAPLIB ${pf_ring_lib} -lnuma -lpthread -lrt"
  784. fi
  785. fi
  786. OLDLIBS="$LIBS"
  787. if test -n "$LPCAPINCDIR"; then
  788. OLDCFLAGS="$CFLAGS -I$LPCAPINCDIR"
  789. CFLAGS="$CFLAGS -I$LPCAPINCDIR"
  790. else
  791. OLDCFLAGS="$CFLAGS"
  792. LPCAPINCDIR=$(echo $CFLAGS | sed -e 's/^\-I//')
  793. LPCAPINC="$LPCAPINCDIR/pcap.h"
  794. fi
  795. LIBS="$LPCAPLIB"
  796. AC_SEARCH_LIBS([pcap_get_pfring_id], [pcap], AC_DEFINE([HAVE_PF_RING_PCAP], [1], [Do we have PF_RING libpcap support?]))
  797. ## Does libpcap work with selected libraries?
  798. AC_SEARCH_LIBS([pcap_close], [pcap],
  799. , AC_MSG_ERROR(Unable to link libpcap in ${foundpcap}),)
  800. AC_SUBST(LPCAPINC)
  801. AC_SUBST(LPCAPLIB)
  802. dnl Check to see what version of libpcap
  803. dnl this code has been reduced a lot, but probably still could be
  804. dnl reduced quite a bit more if we chose too
  805. AC_MSG_CHECKING(for libpcap version)
  806. dnl 0.9.6 (which is still thinks it is 0.9.5 due to a bug) introduces an important
  807. dnl fix for OSX. See: http://tcpreplay.synfin.net/trac/ticket/167
  808. AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  809. #include <string.h>
  810. #include <stdlib.h>
  811. #include <stdio.h>
  812. #include "$LPCAPINC"
  813. #define PCAP_TEST "0.9.6"
  814. ]], [[
  815. /*
  816. * simple proggy to test the version of libpcap
  817. * returns zero if version >= 0.9.6
  818. * or one otherwise
  819. */
  820. if (strncmp(pcap_lib_version(), PCAP_TEST, 3) >= 0)
  821. exit(0);
  822. if (strncmp(pcap_lib_version(), PCAP_TEST, 5) >= 0) {
  823. printf("%s ", pcap_lib_version());
  824. exit(0);
  825. }
  826. exit(1);
  827. ]])],
  828. [libpcap_version_096=yes],
  829. [libpcap_version_096=no],
  830. [libpcap_version_096=yes]
  831. )
  832. AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  833. #include <string.h>
  834. #include <stdlib.h>
  835. #include <stdio.h>
  836. #include "$LPCAPINC"
  837. #define PCAP_TEST "0.8"
  838. ]], [[
  839. /*
  840. * simple proggy to test the version of libpcap
  841. * returns zero if version >= 0.8.0
  842. * or one otherwise
  843. */
  844. if (strncmp(pcap_lib_version(), PCAP_TEST, 3) >= 0)
  845. exit(0);
  846. /* winpcap? */
  847. if (strncmp(pcap_lib_version(), "WinPcap", 7) == 0)
  848. exit(0);
  849. exit(1);
  850. ]])],
  851. [libpcap_ver8=yes],
  852. [libpcap_ver8=no],
  853. [libpcap_ver8=yes]
  854. )
  855. AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  856. #include <string.h>
  857. #include <stdlib.h>
  858. #include <stdio.h>
  859. #include "$LPCAPINC"
  860. #define PCAP_TEST "0.7.2"
  861. extern const char pcap_version[[]]; /* double up since autoconf escapes things */
  862. ]], [[
  863. /*
  864. * simple proggy to test the version of libpcap
  865. * returns zero if version >= 0.7.2
  866. * or one otherwise
  867. */
  868. if (strncmp(pcap_lib_version(), PCAP_TEST, 3) >= 0)
  869. exit(0);
  870. if (strncmp(pcap_version, PCAP_TEST, 5) >= 0)
  871. exit(0);
  872. exit(1);
  873. ]])],
  874. [libpcap_ver7=yes],
  875. [libpcap_ver7=no],
  876. [libpcap_ver7=yes]
  877. )
  878. if test x$libpcap_ver8 = xyes ; then
  879. AC_MSG_RESULT(>= 0.8.0)
  880. elif test x$libpcap_ver7 = xyes ; then
  881. AC_MSG_RESULT(>= 0.7.2)
  882. else
  883. AC_MSG_ERROR([Libpcap versions < 0.7.2 are not supported
  884. Please upgrade to version 0.7.2 or better])
  885. fi
  886. libpcap_version=unknown
  887. if test x$libpcap_version_096 = xyes ; then
  888. libpcap_version=">= 0.9.6"
  889. elif test x$libpcap_ver8 = xyes ; then
  890. libpcap_version=">= 0.8.0"
  891. elif test x$libcap_ver7 = xyes ; then
  892. libpcap_version=">= 0.7.0"
  893. fi
  894. dnl Check for pcap_setnonblock()
  895. AC_MSG_CHECKING(for pcap_setnonblock)
  896. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  897. #include <stdio.h>
  898. #include <stdlib.h>
  899. #include <string.h>
  900. #include "$LPCAPINC"
  901. ]],[[
  902. pcap_t *p;
  903. char *errbuf;
  904. pcap_setnonblock(p, 1, errbuf);
  905. exit(0);
  906. ]])], [
  907. have_pcap_setnonblock=yes
  908. AC_MSG_RESULT(yes)
  909. ], [
  910. have_pcap_setnonblock=no
  911. AC_MSG_RESULT(no)
  912. ])
  913. if test $have_pcap_setnonblock = yes ; then
  914. AC_DEFINE([HAVE_PCAP_SETNONBLOCK], [1],
  915. [Does libpcap have pcap_setnonblock?])
  916. fi
  917. dnl Check to see if we've got pcap_datalink_val_to_name()
  918. AC_MSG_CHECKING(for pcap_datalink_val_to_description)
  919. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  920. #include <stdio.h>
  921. #include <stdlib.h>
  922. #include <string.h>
  923. #include "$LPCAPINC"
  924. ]],[[
  925. if (strcmp(pcap_datalink_val_to_description(1), "Ethernet (10Mb)") == 0)
  926. exit(0);
  927. exit(1);
  928. ]])],[
  929. have_dlt_to_desc=yes
  930. AC_MSG_RESULT(yes)
  931. ], [
  932. have_dlt_to_desc=no
  933. AC_MSG_RESULT(no)
  934. ])
  935. if test $have_dlt_to_desc = yes ; then
  936. AC_DEFINE([HAVE_DLT_VAL_TO_DESC], [1],
  937. [Does libpcap have pcap_datalink_val_to_description?])
  938. fi
  939. dnl Check for pcap_get_selectable_fd()
  940. AC_MSG_CHECKING(for pcap_get_selectable_fd)
  941. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  942. #include <stdio.h>
  943. #include <stdlib.h>
  944. #include <string.h>
  945. #include "$LPCAPINC"
  946. ]], [[
  947. int f;
  948. pcap_t *p;
  949. f = pcap_get_selectable_fd(p);
  950. exit(0);
  951. ]])], [
  952. have_pcap_get_selectable_fd=yes
  953. AC_MSG_RESULT(yes)
  954. ], [
  955. have_pcap_get_selectable_fd=no
  956. AC_MSG_RESULT(no)
  957. ])
  958. if test x$have_pcap_get_selectable_fd = xyes ; then
  959. AC_DEFINE([HAVE_PCAP_GET_SELECTABLE_FD], [1],
  960. [Does libpcap have pcap_get_selectable_fd?])
  961. fi
  962. dnl Important: winpcap apparently defines functions in it's header files
  963. dnl which aren't actually in the library. Totally fucked up. Hence, we
  964. dnl must actually LINK the code, not just compile it.
  965. dnl Check to see if we've got pcap_dump_fopen()
  966. AC_MSG_CHECKING(for pcap_dump_fopen)
  967. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  968. #include <stdio.h>
  969. #include <stdlib.h>
  970. #include <string.h>
  971. #include "$LPCAPINC"
  972. ]],[[
  973. pcap_dumper_t *dump;
  974. pcap_t *pcap;
  975. FILE *foo;
  976. dump = pcap_dump_fopen(pcap, foo);
  977. ]])],[
  978. have_pcap_dump_fopen=yes
  979. AC_MSG_RESULT(yes)
  980. ], [
  981. have_pcap_dump_fopen=no
  982. AC_MSG_RESULT(no)
  983. ])
  984. if test $have_pcap_dump_fopen = yes ; then
  985. AC_DEFINE([HAVE_PCAP_DUMP_FOPEN], [1],
  986. [Does libpcap have pcap_dump_fopen?])
  987. else
  988. AC_MSG_NOTICE([--verbose mode requires libpcap >= 0.9.0])
  989. fi
  990. have_pcap_inject=no
  991. dnl Check to see if we've got pcap_inject()
  992. AC_MSG_CHECKING(for pcap_inject sending support)
  993. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  994. #include <stdio.h>
  995. #include <stdlib.h>
  996. #include <string.h>
  997. #include "$LPCAPINC"
  998. ]],[[
  999. pcap_t *pcap;
  1000. char *buf;
  1001. pcap_inject(pcap, (void *)buf, 0);
  1002. ]])],[
  1003. have_pcap_inject=yes
  1004. AC_MSG_RESULT(yes)
  1005. ], [
  1006. have_pcap_inject=no
  1007. AC_MSG_RESULT(no)
  1008. ])
  1009. if test $have_pcap_inject = yes ; then
  1010. AC_DEFINE([HAVE_PCAP_INJECT], [1], [Does libpcap have pcap_inject?])
  1011. fi
  1012. have_pcap_sendpacket=no
  1013. dnl Check to see if we've got pcap_sendpacket()
  1014. AC_MSG_CHECKING(for pcap_sendpacket sending support)
  1015. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  1016. #include <stdio.h>
  1017. #include <stdlib.h>
  1018. #include <string.h>
  1019. #include "$LPCAPINC"
  1020. ]],[[
  1021. pcap_t *pcap;
  1022. u_char *buf;
  1023. pcap_sendpacket(pcap, buf, 0);
  1024. ]])],[
  1025. have_pcap_sendpacket=yes
  1026. AC_MSG_RESULT(yes)
  1027. ], [
  1028. have_pcap_sendpacket=no
  1029. AC_MSG_RESULT(no)
  1030. ])
  1031. if test $have_pcap_sendpacket = yes ; then
  1032. AC_DEFINE([HAVE_PCAP_SENDPACKET], [1], [Does libpcap have pcap_sendpacket?])
  1033. fi
  1034. have_pcap_breakloop=no
  1035. AC_MSG_CHECKING(for pcap_breakloop)
  1036. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  1037. #include <stdio.h>
  1038. #include <stdlib.h>
  1039. #include <string.h>
  1040. #include "$LPCAPINC"
  1041. ]],[[
  1042. pcap_t *pcap;
  1043. pcap_sendpacket(pcap);
  1044. ]])],[
  1045. have_pcap_breakloop=yes
  1046. AC_MSG_RESULT(yes)
  1047. ], [
  1048. have_pcap_breakloop=no
  1049. AC_MSG_RESULT(no)
  1050. ])
  1051. if test $have_pcap_breakloop = yes ; then
  1052. AC_DEFINE([HAVE_PCAP_BREAKLOOP], [1], [Does libpcap have pcap_breakloop?])
  1053. fi
  1054. have_pcap_version=no
  1055. dnl Check to see if we have pcap_version[]
  1056. AC_MSG_CHECKING(for pcap_version[])
  1057. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  1058. #include <stdio.h>
  1059. #include <stdlib.h>
  1060. #include <string.h>
  1061. #include "$LPCAPINC"
  1062. extern char pcap_version[];
  1063. ]], [[
  1064. printf("%s", pcap_version);
  1065. ]])],[
  1066. AC_DEFINE([HAVE_PCAP_VERSION],[1], [Does libpcap have pcap_version[]])
  1067. AC_MSG_RESULT(yes)
  1068. ],[
  1069. AC_MSG_RESULT(no)
  1070. ])
  1071. have_pcap_snapshot=no
  1072. dnl Check for pcap_snapshot()
  1073. AC_MSG_CHECKING(for pcap_snapshot)
  1074. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  1075. #include <stdio.h>
  1076. #include <stdlib.h>
  1077. #include <string.h>
  1078. #include "$LPCAPINC"
  1079. ]],[[
  1080. pcap_t *p;
  1081. int len;
  1082. len = pcap_snapshot(p);
  1083. exit(0);
  1084. ]])], [
  1085. have_pcap_snapshot=yes
  1086. AC_MSG_RESULT(yes)
  1087. ], [
  1088. have_pcap_snapshot=no
  1089. AC_MSG_RESULT(no)
  1090. ])
  1091. if test $have_pcap_snapshot = yes ; then
  1092. AC_DEFINE([HAVE_PCAP_SNAPSHOT], [1],
  1093. [Does libpcap have pcap_snapshot?])
  1094. fi
  1095. # Tcpbridge requires libpcap and pcap_sendpacket()
  1096. enable_tcpbridge=no
  1097. if test x$foundpcap != xno -a x$have_pcap_sendpacket = xyes ; then
  1098. # if we have pcap_sendpacket() then we can build tcpbridge on non-BPF systems
  1099. if test x$have_bpf = xno; then
  1100. AC_DEFINE(ENABLE_TCPBRIDGE, [1], [Compile tcpbridge])
  1101. enable_tcpbridge=yes
  1102. AC_MSG_NOTICE([Building tcpbridge])
  1103. # BPF systems need to also have pcap_setnonblock()
  1104. elif test x$have_pcap_setnonblock = xyes ; then
  1105. AC_DEFINE(ENABLE_TCPBRIDGE, [1], [Compile tcpbridge])
  1106. enable_tcpbridge=yes
  1107. AC_MSG_NOTICE([Building tcpbridge])
  1108. else
  1109. AC_MSG_WARN([Unable to build tcpbridge. Try installing latest libpcap!])
  1110. fi
  1111. fi
  1112. AM_CONDITIONAL(COMPILE_TCPBRIDGE, [test x$enable_tcpbridge = xyes ])
  1113. # tcpliveplay requires linux OS to function properly
  1114. enable_tcpliveplay=no
  1115. case $host in
  1116. *-*-linux*)
  1117. AC_DEFINE(ENABLE_TCPLIVEPLAY, [1], [Compile tcpliveplay])
  1118. enable_tcpliveplay=yes
  1119. AC_MSG_NOTICE([Building tcpliveplay])
  1120. ;;
  1121. *)
  1122. AC_MSG_WARN([Unable to build tcpliveplay. This tool is only enabled on linux environments.])
  1123. ;;
  1124. esac
  1125. AM_CONDITIONAL(COMPILE_TCPLIVEPLAY, [test x$enable_tcpliveplay = xyes ])
  1126. dnl #####################################################
  1127. dnl Check for netmap support
  1128. dnl #####################################################
  1129. have_netmap=no
  1130. enable_netmap=no
  1131. trynetmapdir=
  1132. AC_MSG_CHECKING(for netmap socket sending support)
  1133. AC_ARG_WITH(netmap,
  1134. AS_HELP_STRING([--with-netmap=DIR],[Use netmap in DIR]),
  1135. [trynetmapdir=$withval])
  1136. NETMAP_SEARCH_DIRS=
  1137. if test "$cross_compiling" = yes; then
  1138. if test "x$trynetmapdir" != "x"; then
  1139. NETMAP_SEARCH_DIRS=$trynetmapdir
  1140. fi
  1141. else
  1142. 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"
  1143. fi
  1144. for testdir in $NETMAP_SEARCH_DIRS; do
  1145. if test -f "${testdir}/sys/net/netmap.h" ; then
  1146. NETMAPINC="${testdir}/sys/net/netmap.h"
  1147. NETMAPUSERINC="${testdir}/sys/net/netmap_user.h"
  1148. NETMAPINCDIR="${testdir}/sys"
  1149. have_netmap="yes $testdir"
  1150. enable_netmap=yes
  1151. else
  1152. if test -f "${testdir}/net/netmap.h" ; then
  1153. NETMAPINC="${testdir}/net/netmap.h"
  1154. NETMAPUSERINC="${testdir}/net/netmap_user.h"
  1155. NETMAPINCDIR="${testdir}"
  1156. have_netmap="yes $testdir"
  1157. enable_netmap=yes
  1158. fi
  1159. fi
  1160. if test "$have_netmap" != no ; then
  1161. NETMAPFLAGS="-DHAVE_NETMAP"
  1162. OLDCFLAGS="$CFLAGS -I$NETMAPINCDIR"
  1163. CFLAGS="$CFLAGS -DNETMAP_WITH_LIBS -DND -I$NETMAPINCDIR"
  1164. AC_SUBST(NETMAPINC)
  1165. AC_SUBST(NETMAPUSERINC)
  1166. AC_SUBST(NETMAPINCDIR)
  1167. AC_SUBST(NETMAPFLAGS)
  1168. AC_DEFINE([HAVE_NETMAP], [1],
  1169. [Do we have netmap support?])
  1170. have_netmap="yes $testdir"
  1171. enable_netmap=yes
  1172. break;
  1173. fi
  1174. done
  1175. AC_MSG_RESULT($have_netmap)
  1176. AM_CONDITIONAL(COMPILE_NETMAP, [test x$enable_netmap = xyes ])
  1177. dnl ###########################################################
  1178. dnl Check for nm_open() function available in netmap version 5
  1179. dnl Also check for other version-specific netmap definitions and structures
  1180. dnl ###########################################################
  1181. if test "x$NETMAPINCDIR" != "x"; then
  1182. OLDCPPFLAGS="$CPPFLAGS"
  1183. CPPFLAGS="$CPPFLAGS -DNETMAP_WITH_LIBS -DND -I$NETMAPINCDIR"
  1184. have_nm_open=no
  1185. have_nm_nr_reg_mask=no
  1186. have_nm_nr_flags=no
  1187. have_nmring_head_tail=no
  1188. if test "$have_netmap" != no ; then
  1189. dnl check for nm_open()
  1190. AC_CHECK_DECL([nm_open],[have_nm_open=yes], , [[
  1191. #include <stdio.h>
  1192. #include "${NETMAPUSERINC}"
  1193. ]])
  1194. dnl check for #define NR_REG_MASK
  1195. AC_MSG_CHECKING(for netmap NR_REG_MASK definition)
  1196. AC_COMPILE_IFELSE(
  1197. [AC_LANG_PROGRAM([[
  1198. #include <stdint.h>
  1199. #include <sys/socket.h>
  1200. #include <net/if.h>
  1201. #include <net/netmap.h>
  1202. ]],
  1203. [[
  1204. #ifdef NR_REG_MASK
  1205. /* OK */
  1206. #else
  1207. # error NR_REG_MASK not found
  1208. #endif
  1209. ]])
  1210. ],
  1211. [have_nm_nr_reg_mask=yes],
  1212. [])
  1213. AC_MSG_RESULT($have_nm_nr_reg_mask)
  1214. dnl check for nr_flags in struct nmreq
  1215. AC_MSG_CHECKING(for netmap nr_flags definition)
  1216. AC_COMPILE_IFELSE(
  1217. [AC_LANG_PROGRAM([[
  1218. #include <stdint.h>
  1219. #include <sys/socket.h>
  1220. #include <net/if.h>
  1221. #include <net/netmap.h>
  1222. ]],
  1223. [[
  1224. struct nmreq nmr;
  1225. nmr.nr_flags = 0;
  1226. ]])
  1227. ],
  1228. [have_nm_nr_flags=yes],
  1229. [])
  1230. AC_MSG_RESULT($have_nm_nr_flags)
  1231. dnl check for head/tail in struct netmap_ring
  1232. AC_MSG_CHECKING(for netmap ring head/tail definitions)
  1233. AC_COMPILE_IFELSE(
  1234. [AC_LANG_PROGRAM([[
  1235. #include <stdint.h>
  1236. #include <sys/socket.h>
  1237. #include <net/if.h>
  1238. #include <net/netmap.h>
  1239. ]],
  1240. [[
  1241. struct netmap_ring r;
  1242. r.head = r.tail = 0;
  1243. ]])
  1244. ],
  1245. [have_nmring_head_tail=yes],
  1246. [])
  1247. AC_MSG_RESULT($have_nmring_head_tail)
  1248. fi
  1249. if test "$have_nm_open" = yes ; then
  1250. AC_DEFINE([HAVE_NETMAP_NM_OPEN], [1], [Does netmap have nm_open function?])
  1251. fi
  1252. if test "$have_nm_nr_reg_mask" = yes ; then
  1253. AC_DEFINE([HAVE_NETMAP_NR_REG], [1], [Does netmap have NR_REG_MASK defined?])
  1254. fi
  1255. if test "$have_nm_nr_flags" = yes ; then
  1256. AC_DEFINE([HAVE_NETMAP_NR_FLAGS], [1], [Does netmap struct nmreq have nr_flags defined?])
  1257. fi
  1258. if test "$have_nmring_head_tail" = yes ; then
  1259. AC_DEFINE([HAVE_NETMAP_RING_HEAD_TAIL], [1], [Does structure netmap_ring have head/tail defined?])
  1260. fi
  1261. CPPFLAGS="$OLDCPPFLAGS"
  1262. fi
  1263. have_pf=no
  1264. dnl Check for linux PF_PACKET support
  1265. AC_MSG_CHECKING(for PF_PACKET socket sending support)
  1266. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1267. #include <sys/socket.h>
  1268. #include <netpacket/packet.h>
  1269. #include <net/ethernet.h> /* the L2 protocols */
  1270. #include <netinet/in.h> /* htons */
  1271. ]], [[
  1272. int pf_socket;
  1273. pf_socket = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  1274. ]])],[
  1275. AC_DEFINE([HAVE_PF_PACKET], [1],
  1276. [Do we have Linux PF_PACKET socket support?])
  1277. AC_MSG_RESULT(yes)
  1278. have_pf=yes
  1279. ],[
  1280. AC_MSG_RESULT(no)
  1281. ])
  1282. have_tx_ring=no
  1283. dnl Check for older Linux TX_RING support
  1284. AC_MSG_CHECKING(for TX_RING socket sending support)
  1285. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1286. #include <sys/socket.h>
  1287. #include <netpacket/packet.h>
  1288. #include <net/ethernet.h> /* the L2 protocols */
  1289. #include <netinet/in.h> /* htons */
  1290. #include <linux/if_packet.h>
  1291. ]], [[
  1292. int test;
  1293. test = TP_STATUS_WRONG_FORMAT
  1294. ]])],[
  1295. AC_DEFINE([HAVE_TX_RING], [1],
  1296. [Do we have Linux TX_RING socket support?])
  1297. AC_MSG_RESULT(yes)
  1298. have_tx_ring=yes
  1299. ],[
  1300. AC_MSG_RESULT(no)
  1301. ])
  1302. AC_CHECK_HEADERS([net/bpf.h], [have_bpf=yes], [have_bpf=no])
  1303. if test $have_bpf = yes ; then
  1304. AC_DEFINE([HAVE_BPF], [1],
  1305. [Do we have BPF device support?])
  1306. fi
  1307. dnl ##################################################
  1308. dnl # Check for libdnet, but only if not Cygwin!
  1309. dnl #
  1310. dnl # if your version of libdnet doesn't compile, try
  1311. dnl # getting it from ...
  1312. dnl # http://libdnet.sourceforge.net/
  1313. dnl # ... or ...
  1314. dnl # https://github.com/jncornett/libdnet
  1315. dnl # ... or ...
  1316. dnl # on Linux try 'apt-get install libdumbnet-dev'
  1317. dnl ##################################################
  1318. founddnet=no
  1319. have_libdnet=no
  1320. libdnet_version=
  1321. enable_fragroute=no
  1322. trydnetdir=/usr/local
  1323. if test $have_cygwin = no ; then
  1324. AC_MSG_CHECKING(for libdnet)
  1325. AC_ARG_WITH(libdnet,
  1326. AS_HELP_STRING([--with-libdnet=DIR],[Use libdnet in DIR]),
  1327. [trydnetdir=$withval])
  1328. if test $trydnetdir != no; then
  1329. case "$build_os" in
  1330. linux*)
  1331. dnl # Debian/Ubuntu already have a package called libdnet
  1332. dnl # so you the package you want to install libdumbnet-dev
  1333. for testdir in $trydnetdir /usr/local /opt/local /usr ; do
  1334. if test -x ${testdir}/bin/dumbnet-config -a $founddnet = no ; then
  1335. LDNETINC="$($testdir/bin/dumbnet-config --cflags)"
  1336. LDNETLIB="$($testdir/bin/dumbnet-config --libs)"
  1337. libdnet_version="$($testdir/bin/dumbnet-config --version) (libdumbnet)"
  1338. founddnet=$testdir
  1339. fi
  1340. done
  1341. ;;
  1342. esac
  1343. if test $founddnet = no ; then
  1344. for testdir in $trydnetdir /usr/local /opt/local $MACOSX_SDK_PATH/usr /usr ; do
  1345. if test -x ${testdir}/bin/dnet-config -a $founddnet = no ; then
  1346. LDNETINC="$($testdir/bin/dnet-config --cflags)"
  1347. LDNETLIB="$($testdir/bin/dnet-config --libs)"
  1348. libdnet_version="$($testdir/bin/dnet-config --version)"
  1349. founddnet=$testdir
  1350. fi
  1351. done
  1352. fi
  1353. fi
  1354. if test $founddnet = no ; then
  1355. AC_MSG_RESULT(no)
  1356. AC_MSG_WARN([libdnet not found, disabling fragroute feature])
  1357. else
  1358. AC_MSG_RESULT($founddnet)
  1359. enable_fragroute=yes
  1360. have_libdnet=yes
  1361. AC_DEFINE([HAVE_LIBDNET], [1], [Do we have libdnet?])
  1362. dnl Debian uses dumbnet.h instead of dnet.h due to naming conflict
  1363. old_cflags=$CFLAGS
  1364. CFLAGS=$LDNETINC
  1365. AC_CHECK_HEADERS([dumbnet.h dnet.h])
  1366. CFLAGS=$old_cflags
  1367. fi
  1368. else
  1369. AC_MSG_NOTICE([Skipping libdnet check under Cygwin for compatibility reasons])
  1370. fi
  1371. AC_SUBST(LDNETINC)
  1372. AC_SUBST(LDNETLIB)
  1373. AC_DEFINE_UNQUOTED([LIBDNET_VERSION], "$libdnet_version", [Version of libdnet])
  1374. AM_CONDITIONAL(COMPILE_FRAGROUTE, [test x$founddnet != xno])
  1375. if test x$founddnet != xno ; then
  1376. AC_DEFINE(ENABLE_FRAGROUTE, [1], [Enable fragroute module])
  1377. fi
  1378. dnl Make sure we have a valid packet injection mechanisim
  1379. if test $have_bpf = no -a $have_pcap_inject = no -a $have_pcap_sendpacket = no \
  1380. -a $have_libdnet = no -a $have_pf = no ; then
  1381. AC_MSG_ERROR([Unable to find a supported method to send packets. Please upgrade your libpcap or enable libdnet])
  1382. fi
  1383. dnl Older versions of libpcap are missing some DLT types
  1384. dnl If doesn't exist, we'll define them in src/common/fakepcap.h
  1385. AC_MSG_CHECKING(for DLT_LINUX_SLL in libpcap)
  1386. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "$LPCAPINC"]], [[ int foo;
  1387. foo = DLT_LINUX_SLL
  1388. ]])],[ AC_DEFINE([HAVE_DLT_LINUX_SLL], [1],
  1389. [Does pcap.h include a header with DLT_LINUX_SLL?])
  1390. AC_MSG_RESULT(yes)
  1391. ],[AC_MSG_RESULT(no)
  1392. ])
  1393. AC_MSG_CHECKING(for DLT_C_HDLC in libpcap)
  1394. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "$LPCAPINC"]], [[ int foo;
  1395. foo = DLT_C_HDLC ]])],[ AC_DEFINE([HAVE_DLT_C_HDLC], [1],
  1396. [Does pcap.h include a header with DLT_C_HDLC?])
  1397. AC_MSG_RESULT(yes)
  1398. ],[AC_MSG_RESULT(no)
  1399. ])
  1400. PCAP_BPF_H_FILE="$LPCAPINCDIR/pcap-bpf.h"
  1401. AC_MSG_CHECKING(for $PCAP_BPF_H_FILE)
  1402. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
  1403. #include <sys/time.h>
  1404. #include <stdint.h>
  1405. #include "$PCAP_BPF_H_FILE"]], [[ int foo;
  1406. foo = BPF_MAJOR_VERSION; ]])],[ AC_DEFINE([INCLUDE_PCAP_BPF_HEADER], [1],
  1407. [What is the path (if any) to the pcap-bpf.h
  1408. header?])
  1409. AC_MSG_RESULT(yes)
  1410. AC_SUBST(PCAP_BPF_H_FILE)
  1411. ],[AC_MSG_RESULT(no)
  1412. ])
  1413. foundbpfheader=no
  1414. AC_MSG_CHECKING(for libpcap bpf header)
  1415. for testfile in $LPCAPINCDIR/pcap/bpf.h $LPCAPINCDIR/pcap-bpf.h ; do
  1416. if test -f "${testfile}" -a $foundbpfheader = no ; then
  1417. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1418. #include <sys/types.h>
  1419. #include <sys/time.h>
  1420. #include <stdint.h>
  1421. #include "$testfile"]], [[
  1422. int foo;
  1423. foo = BPF_MAJOR_VERSION;
  1424. ]])],[
  1425. foundbpfheader=yes
  1426. PCAP_BPF_H_FILE=$testfile
  1427. AC_SUBST(PCAP_BPF_H_FILE)
  1428. AC_DEFINE([INCLUDE_PCAP_BPF_HEADER], [1],
  1429. [What is the path (if any) to the libpcap bpf header file?])
  1430. ],[])
  1431. fi
  1432. done
  1433. if test $foundbpfheader != no; then
  1434. AC_MSG_RESULT($testfile)
  1435. else
  1436. AC_MSG_RESULT(no)
  1437. fi
  1438. dnl ## Test for netmap-libpcap
  1439. have_pcap_netmap=no
  1440. if test $foundpcap != no ; then
  1441. AC_MSG_CHECKING(for netmap libpcap)
  1442. PCAP_NETMAP_C_FILE="$LPCAPINCDIR/pcap-netmap.c"
  1443. if test -f "${PCAP_NETMAP_C_FILE}" ; then
  1444. AC_DEFINE([HAVE_LIBPCAP_NETMAP], [1],
  1445. [Does this version of libpcap support netmap?])
  1446. have_pcap_netmap=yes
  1447. AC_MSG_RESULT(yes)
  1448. else
  1449. AC_MSG_RESULT(no)
  1450. fi
  1451. fi
  1452. dnl restore LIBS & CFLAGS
  1453. LIBS="$OLDLIBS"
  1454. CFLAGS="$OLDCFLAGS"
  1455. dnl ##################################################
  1456. dnl # Check for pcapnav
  1457. dnl ##################################################
  1458. pcapnav_ver=no
  1459. pcncfg=no
  1460. AC_ARG_WITH(pcapnav-config,
  1461. AS_HELP_STRING([--with-pcapnav-config=FILE],[Use given pcapnav-config]),
  1462. [ AC_MSG_CHECKING(for pcapnav-config)
  1463. if test -x $withval ; then
  1464. pcncfg=$withval
  1465. AC_MSG_RESULT($pcncfg)
  1466. elif test x$withval = xno ; then
  1467. AC_MSG_RESULT(no)
  1468. else
  1469. AC_MSG_RESULT([Can't find pcapnav-config: disabling offset jump feature])
  1470. fi ],
  1471. [ AC_PATH_PROG(pcncfg,[pcapnav-config], [no] ) ]
  1472. )
  1473. if test $pcncfg != no ; then
  1474. LNAVLIB=$($pcncfg --libs)
  1475. LNAV_CFLAGS=$($pcncfg --cflags)
  1476. PCAPNAV_VERSION=$($pcncfg --version)
  1477. AC_SUBST(LNAVLIB)
  1478. AC_SUBST(LNAV_CFLAGS)
  1479. AC_DEFINE_UNQUOTED(PCAPNAV_VERSION, "$PCAPNAV_VERSION",
  1480. [libpcapnav's version?])
  1481. dnl Check to see what version of libpcapnav
  1482. dnl this code has been reduced a lot, but probably still could be
  1483. dnl reduced quite a bit more if we chose too
  1484. AC_MSG_CHECKING(for libpcapnav version)
  1485. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  1486. #include <string.h>
  1487. #define PCAPNAV_TEST "0.4"
  1488. /*
  1489. * simple proggy to test the version of libpcapnav
  1490. * returns zero if version >= 0.4
  1491. * or one otherwise
  1492. */
  1493. int
  1494. main (int argc, char *argv[])
  1495. {
  1496. if (strncmp(PCAPNAV_VERSION, PCAPNAV_TEST, 3) >= 0)
  1497. exit(0);
  1498. exit(1);
  1499. } ]])],[libpcapnav_ver=yes
  1500. AC_MSG_RESULT(>= 0.4)],[libpcapnav_ver=no
  1501. AC_MSG_RESULT(< 0.4)],[libpcapnav_ver=no
  1502. ])
  1503. if test x$libpcapnav_ver = xno ; then
  1504. AC_MSG_WARN([Libpcapnav versions < 0.4 are not supported.
  1505. Please upgrade to version 0.4 or better.
  1506. Disabling offset jump feature.])
  1507. else
  1508. AC_DEFINE([HAVE_PCAPNAV], [1], [Do we have libpcapnav?])
  1509. fi
  1510. fi # checking pcapnav version
  1511. dnl (shamelessly ripped off from libpcap)
  1512. dnl Checks to see if unaligned memory accesses fail
  1513. dnl
  1514. dnl FORCE_ALIGN (DEFINED)
  1515. dnl
  1516. AC_MSG_CHECKING(for requires strict byte alignment)
  1517. AC_CACHE_VAL(unaligned_cv_fail,
  1518. [
  1519. case "$host_os" in
  1520. darwin*)
  1521. # macOS M1 test fails due to lack of fork() so just hard code it
  1522. unaligned_cv_fail=no
  1523. ;;
  1524. *)
  1525. case "$host_cpu" in
  1526. # XXX: should also check that they don't do weird things
  1527. alpha*|arm*|hp*|mips*|sparc*|ia64)
  1528. unaligned_cv_fail=yes
  1529. ;;
  1530. *)
  1531. cat >conftest.c <<EOF
  1532. #include <sys/types.h>
  1533. #include <sys/wait.h>
  1534. #include <stdio.h>
  1535. unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
  1536. main() {
  1537. unsigned int i;
  1538. pid_t pid;
  1539. int status;
  1540. /* avoid "core dumped" message */
  1541. pid = fork();
  1542. if (pid < 0)
  1543. exit(2);
  1544. if (pid > 0) {
  1545. /* parent */
  1546. pid = waitpid(pid, &status, 0);
  1547. if (pid < 0)
  1548. exit(3);
  1549. exit(!WIFEXITED(status));
  1550. }
  1551. /* child */
  1552. i = *(unsigned int *)&a[[1]];
  1553. printf("%d\n", i);
  1554. exit(0);
  1555. }
  1556. EOF
  1557. ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
  1558. conftest.c $LIBS >/dev/null 2>&1
  1559. if test ! -x conftest ; then
  1560. dnl failed to compile for some reason
  1561. unaligned_cv_fail=yes
  1562. else
  1563. ./conftest >conftest.out
  1564. if test ! -s conftest.out ; then
  1565. unaligned_cv_fail=yes
  1566. else
  1567. unaligned_cv_fail=no
  1568. fi
  1569. fi
  1570. rm -f conftest* core core.conftest
  1571. ;;
  1572. esac
  1573. ;;
  1574. esac
  1575. ])
  1576. AC_MSG_RESULT($unaligned_cv_fail)
  1577. if test $unaligned_cv_fail = yes ; then
  1578. AC_DEFINE([FORCE_ALIGN], [1], [Are we strictly aligned?])
  1579. fi
  1580. dnl ##################################################
  1581. dnl # Check for tcpdump.
  1582. dnl ##################################################
  1583. tcpdump_path=no
  1584. AC_ARG_WITH(tcpdump,
  1585. AS_HELP_STRING([--with-tcpdump=FILE],[Path to tcpdump binary]),
  1586. [ if test -x $withval ; then
  1587. tcpdump_path=$withval
  1588. AC_MSG_RESULT([Using tcpdump in $tcpdump_path])
  1589. else
  1590. AC_MSG_RESULT([Error: $withval does not exist or is not executable])
  1591. fi ],
  1592. [ AC_PATH_PROG(tcpdump_path, tcpdump, "no", [$PATH:/usr/sbin:/sbin:/usr/local/sbin]) ])
  1593. if test "$tcpdump_path" = "no"; then
  1594. AC_MSG_WARN([Unable to find tcpdump. Please specify --with-tcpdump.
  1595. Disabling --verbose])
  1596. else
  1597. AC_DEFINE([HAVE_TCPDUMP], [1], [Do we have tcpdump?])
  1598. AC_DEFINE_UNQUOTED(TCPDUMP_BINARY, "$tcpdump_path", [The tcpdump binary initially used])
  1599. fi
  1600. AM_CONDITIONAL([ENABLE_TCPDUMP], test "$tcpdump_path" != "no" -a x$have_pcap_dump_fopen = xyes)
  1601. if test x$tcpdump_path != xno -a x$have_pcap_dump_fopen = xyes ; then
  1602. AC_DEFINE([ENABLE_VERBOSE], [1], [Do we have tcpdump and pcap_dump_fopen()?])
  1603. else
  1604. AC_MSG_WARN([Your version of libpcap does not support --verbose])
  1605. fi
  1606. dnl No 'make test' when cross compile
  1607. AC_MSG_CHECKING(for 'make test' profile)
  1608. if test "$host" = "$build" ; then
  1609. AC_MSG_RESULT([yes])
  1610. else
  1611. AC_MSG_WARN(Unable to do tests when cross-compiling)
  1612. AC_MSG_RESULT([Unable to do tests when cross-compiling])
  1613. fi
  1614. dnl Allows user to choose which nic to use for testing purposes
  1615. AC_ARG_WITH(testnic,
  1616. AS_HELP_STRING([--with-testnic=NIC],[Select which network card to use for testing]),
  1617. [ nic1=$withval
  1618. nic2=$withval
  1619. AC_MSG_RESULT([Using --with-testnic=$withval])],
  1620. [
  1621. case $host in
  1622. *-*-linux*)
  1623. nic1=eth0
  1624. nic2=eth0
  1625. ;;
  1626. *-*-solaris*)
  1627. nic1=hme0
  1628. nic2=hme0
  1629. ;;
  1630. *-*-sunos*)
  1631. nic1=hme0
  1632. nic2=hme0
  1633. ;;
  1634. *-apple-darwin*)
  1635. nic1=en0
  1636. nic2=en0
  1637. ;;
  1638. *-*-openbsd*)
  1639. nic1=xl0
  1640. nic2=xl0
  1641. ;;
  1642. *-*-freebsd*)
  1643. nic1=em0
  1644. nic2=em0
  1645. ;;
  1646. *-*-cygwin)
  1647. nic1=%0
  1648. nic2=%0
  1649. ;;
  1650. *)
  1651. AC_MSG_RESULT([$host is unknown! Using first non-loopback interface])
  1652. nic1=%0
  1653. nic2=%0
  1654. ;;
  1655. esac])
  1656. dnl There's a bug in OS X which causes pcap_findalldevs() to make the wifi NIC to disassociate
  1657. dnl so under OSX we disable the interface list feature
  1658. disable_pcap_findalldevs=no
  1659. osx_frameworks=no
  1660. AC_MSG_CHECKING([for OS version])
  1661. dnl these need to be dynamic based on OS
  1662. case $host in
  1663. *-*-linux*)
  1664. AC_DEFINE([HAVE_LINUX], [1], [Building Linux])
  1665. AC_MSG_RESULT(Linux)
  1666. ;;
  1667. *-*-solaris*)
  1668. AC_DEFINE([HAVE_SOLARIS], [1], [Building Solaris])
  1669. AC_MSG_RESULT(Solaris)
  1670. ;;
  1671. *-*-sunos*)
  1672. AC_DEFINE([HAVE_SUNOS], [1], [Building SunOS])
  1673. AC_MSG_RESULT(SunOS)
  1674. ;;
  1675. *-apple-darwin*)
  1676. if test x$libpcap_version_096 = xno ; then
  1677. disable_pcap_findalldevs=yes
  1678. fi
  1679. osx_frameworks=yes
  1680. AC_DEFINE([HAVE_DARWIN], [1], [Building Apple/Darwin])
  1681. AC_MSG_RESULT(Apple macOS)
  1682. ;;
  1683. *-*-openbsd*)
  1684. AC_DEFINE([HAVE_OPENBSD], [1], [Building Open BSD])
  1685. AC_MSG_RESULT(OpenBSD)
  1686. ;;
  1687. *-*-freebsd*)
  1688. AC_DEFINE([HAVE_FREEBSD], [1], [Building Free BSD])
  1689. AC_MSG_RESULT(FreeBSD)
  1690. ;;
  1691. *-*-cygwin)
  1692. AC_MSG_RESULT(Win32/Cygwin)
  1693. AC_DEFINE([HAVE_CYGWIN], [1], [Building Cygwin])
  1694. ;;
  1695. *)
  1696. AC_MSG_RESULT([$host is unknown!])
  1697. ;;
  1698. esac
  1699. AM_CONDITIONAL([ENABLE_OSX_FRAMEWORKS], test "$osx_frameworks" = "yes")
  1700. AC_ARG_WITH(testnic2,
  1701. AS_HELP_STRING([--with-testnic2=NIC2],[Select an optional 2nd network card to use for testing]),
  1702. [ nic2=$withval ])
  1703. AC_MSG_NOTICE([Using $nic1 for 1st test network interface card])
  1704. AC_MSG_NOTICE([Using $nic2 for 2nd test network interface card])
  1705. AC_SUBST(nic1)
  1706. AC_SUBST(nic2)
  1707. AC_MSG_CHECKING([if it's ok to use pcap_findalldevs()])
  1708. if test x$disable_pcap_findalldevs = xno ; then
  1709. AC_DEFINE([ENABLE_PCAP_FINDALLDEVS], [1], [Enable use of pcap_findalldevs()])
  1710. AC_MSG_RESULT(yes)
  1711. else
  1712. AC_MSG_RESULT(no)
  1713. fi
  1714. LIBOPTS_CHECK(libopts)
  1715. AC_CONFIG_FILES([Makefile
  1716. doxygen.cfg
  1717. lib/Makefile
  1718. docs/Makefile
  1719. src/Makefile
  1720. src/tcpedit/Makefile
  1721. src/fragroute/Makefile
  1722. src/common/Makefile
  1723. src/defines.h
  1724. test/Makefile
  1725. test/config
  1726. scripts/Makefile])
  1727. AC_OUTPUT
  1728. # Configuration results
  1729. AC_MSG_RESULT([
  1730. ##########################################################################
  1731. TCPREPLAY Suite Configuration Results (${TCPREPLAY_VERSION})
  1732. ##########################################################################
  1733. libpcap: ${foundpcap} (${libpcap_version})
  1734. PF_RING libpcap ${pf_ring_found} ${pf_ring_lib}
  1735. libdnet: ${founddnet} ${libdnet_version}
  1736. autogen: ${AUTOGEN} (${AUTOGEN_VERSION})
  1737. Use libopts tearoff: ${enable_local_libopts}
  1738. 64bit counter support: ${use64bit_counters}
  1739. tcpdump binary path: ${tcpdump_path}
  1740. fragroute support: ${enable_fragroute}
  1741. tcpbridge support: ${enable_tcpbridge}
  1742. tcpliveplay support: ${enable_tcpliveplay}
  1743. Supported Packet Injection Methods (*):
  1744. Linux TX_RING: ${have_tx_ring}
  1745. Linux PF_PACKET: ${have_pf}
  1746. BSD BPF: ${have_bpf}
  1747. libdnet: ${have_libdnet}
  1748. pcap_inject: ${have_pcap_inject}
  1749. pcap_sendpacket: ${have_pcap_sendpacket} **
  1750. pcap_netmap ${have_pcap_netmap}
  1751. Linux/BSD netmap: ${have_netmap}
  1752. Tuntap device support: ${have_tuntap}
  1753. * In order of preference; see configure --help to override
  1754. ** Required for tcpbridge
  1755. ])
  1756. case $host in
  1757. *-*-cygwin)
  1758. AC_MSG_WARN([Windows/Cygwin support is still somewhat experimental.
  1759. Please report any bugs! https://github.com/appneta/tcpreplay/issues])
  1760. ;;
  1761. esac