configure.ac 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  1. dnl $Id$
  2. AC_PREREQ([2.69])
  3. dnl Set version info here!
  4. AC_INIT([tcpreplay],[4.5.1],[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="-fsanitize=address ${LDFLAGS}"
  356. else
  357. build_asan=no
  358. fi
  359. AC_SUBST(build_asan)
  360. AC_ARG_ENABLE([tsan],
  361. AS_HELP_STRING([--enable-tsan],[Enable Thread Sanitizer support]))
  362. if test "x$enable_tsan" = "xyes"; then
  363. build_tsan=yes
  364. CFLAGS="${CFLAGS} -O1 -g -fsanitize=thread -fno-omit-frame-pointer"
  365. dnl -ltsan always need to be the first library
  366. LDFLAGS="-fsanitize=thread ${LDFLAGS}"
  367. else
  368. build_tsan=no
  369. fi
  370. AC_SUBST(build_tsan)
  371. if test "$build_asan" = "yes" -a "$build_tsan" = "yes" ; then
  372. AC_MSG_ERROR([--enable-asan and --eanble-tsan are mutually exclusive])
  373. fi
  374. dnl Enable debugging in code/compiler options
  375. debug=no
  376. debug_flag=NDEBUG
  377. debug_run_time_flag=
  378. AC_ARG_ENABLE(debug,
  379. AS_HELP_STRING([--enable-debug],[Enable debugging code and support for the -d option]),
  380. [ if test x$enableval = xyes; then
  381. debug=yes
  382. dnl replace '-0X' and add '-g' flags
  383. changequote({,})
  384. CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9s]*//g'`
  385. changequote([,])
  386. CFLAGS="${CFLAGS} -g -O0 -Wall $wextra $wfatal_errors $wno_variadic_macros $wno_format_contains_nul $wno_format"
  387. # We may also want to add:
  388. # -Wformat-security -Wswitch-default -Wunused-paramter -Wpadded"
  389. debug_flag=DEBUG
  390. debug_run_time_flag=--dbug=1
  391. AC_DEFINE([DEBUG], [1], [Enable debugging code and support for the -d option])
  392. fi])
  393. AC_SUBST(debug_flag)
  394. AC_SUBST(debug_run_time_flag)
  395. dnl Enable extra debugging in code/compiler options - may slow down performance
  396. extra_debug=no
  397. extra_debug_flag=NEXTRA_DBUG
  398. AC_ARG_ENABLE(extra-debug,
  399. AS_HELP_STRING([--enable-extra-debug],[Enable additional debugging code (may affect performance)]),
  400. [ if test x$enableval = xyes; then
  401. extra_debug=yes
  402. extra_debug_flag=EXTRA_DEBUG
  403. AC_DEFINE([EXTRA_DEBUG], [1], [Enable additional debugging code (may affect performance)])
  404. fi])
  405. AC_SUBST(extra_debug_flag)
  406. dnl Enable timestamp_trace in code/compiler options
  407. timestamp_trace=no
  408. AC_ARG_ENABLE(timestamp-trace,
  409. AS_HELP_STRING([--timestamp-trace],[Enable dumping of trace timestamps at the end of a test]),
  410. [ if test x$enableval = xyes; then
  411. timestamp_trace=yes
  412. CFLAGS="${CFLAGS} -DTIMESTAMP_TRACE"
  413. AC_DEFINE([TIMESTAMP_TRACE], [1], [Enable dumping of trace timestamps at the end of a test])
  414. fi])
  415. AC_SUBST(timestamp_trace_flag)
  416. AC_ARG_ENABLE(dmalloc,
  417. AS_HELP_STRING([--enable-dmalloc],[Enable linking to dmalloc for better memory debugging]),
  418. [ if test x$enableval = xyes ; then
  419. dmalloc=yes
  420. AC_DEFINE([ENABLE_DMALLOC], [1], [Enable dmalloc])
  421. AC_DEFINE([DMALLOC_FUNC_CHECK], [1], [Enable dmalloc function arg checking])
  422. CFLAGS="${CFLAGS} -I/opt/local/include"
  423. DMALLOC_LIB="/opt/local/lib/libdmalloc.a"
  424. AC_SUBST(DMALLOC_LIB)
  425. fi])
  426. AC_ARG_ENABLE(pedantic,
  427. AS_HELP_STRING([--enable-pedantic],[Enable gcc's -pedantic option]),
  428. [ if test x$enableval = xyes; then
  429. CFLAGS="$CFLAGS -pedantic"
  430. fi ])
  431. dnl Enable Efense
  432. AC_ARG_ENABLE(efence,
  433. AS_HELP_STRING([--enable-efence],[Enable Electric Fence memory debugger]),
  434. [ if test x$enableval = xyes; then
  435. CFLAGS="$CFLAGS -lefence"
  436. AC_DEFINE([EFENCE], [1], [Enable Electric Fence memory debugger])
  437. fi])
  438. dnl Enable Gprof
  439. AC_ARG_ENABLE(gprof,
  440. AS_HELP_STRING([--enable-gprof],[Enable GNU Profiler]),
  441. [ if test x$enableval = xyes; then
  442. if test $debug = yes; then
  443. CFLAGS="$CFLAGS -pg"
  444. else
  445. # GPROF requires gdb
  446. CFLAGS="$CFLAGS -ggdb -pg -fprofile-arcs"
  447. fi
  448. AC_DEFINE([GPROF], [1], [Enable GNU Profiler])
  449. fi])
  450. dnl Enable libpcap auto discovery via pcap-config
  451. enable_pcap_config=no
  452. AC_ARG_ENABLE(pcapconfig,
  453. AS_HELP_STRING([--enable-pcapconfig],[Enable automatic libpcap config, reverting to system scanning]),
  454. [
  455. if test $enableval = yes; then
  456. enable_pcap_config=yes
  457. AC_MSG_NOTICE([Enabling libpcap discovery via pcap_config])
  458. else
  459. enable_pcap_config=no
  460. AC_MSG_NOTICE([Disabling libpcap discovery via pcap_config])
  461. fi
  462. ],
  463. [
  464. AC_MSG_NOTICE([Bypassing libpcap discovery via pcap_config])
  465. ])
  466. dnl Use 64bits for packet counters
  467. use64bit_counters=yes
  468. AC_ARG_ENABLE(64bits,
  469. AS_HELP_STRING([--disable-64bits],[Do not use 64bit packet counters]),
  470. [
  471. AC_MSG_NOTICE([Using u_int32_t for packet counters])
  472. ],
  473. [
  474. AC_DEFINE([ENABLE_64BITS], [1], [Use 64bit packet counters])
  475. AC_MSG_NOTICE([Using u_int64_t for packet counters])
  476. ])
  477. # If we're running gcc add '-D_U_="__attribute__((unused))"' to CFLAGS as well,
  478. # so we can use _U_ to flag unused function arguments and not get warnings
  479. # about them. Otherwise, add '-D_U_=""', so that _U_ used to flag an unused
  480. # function argument will compile with non-GCC compilers.
  481. #
  482. if test "x$GCC" = "xyes" ; then
  483. CFLAGS="-D_U_=\"__attribute__((unused))\" $CFLAGS"
  484. else
  485. CFLAGS="-D_U_=\"\" $CFLAGS"
  486. fi
  487. AC_ARG_ENABLE(force-bpf,
  488. AS_HELP_STRING([--enable-force-bpf],[Force using BPF for sending packets]),
  489. [ AC_DEFINE([FORCE_INJECT_BPF], [1], [Force using BPF for sending packet])])
  490. AC_ARG_ENABLE(force-pf,
  491. AS_HELP_STRING([--enable-force-pf],[Force using Linux's PF_PACKET for sending packets]),
  492. [ AC_DEFINE([FORCE_INJECT_PF], [1], [Force using Linux's PF_PACKET for sending packets])])
  493. AC_ARG_ENABLE(force-libdnet,
  494. AS_HELP_STRING([--enable-force-libdnet],[Force using libdnet for sending packets]),
  495. [ AC_DEFINE([FORCE_INJECT_LIBDNET], [1], [Force using libdnet for sending packets])])
  496. AC_ARG_ENABLE(force-libxdp,
  497. AS_HELP_STRING([--enable-force-libxdp],[Force using libxdp for sending packets]),
  498. [ AC_DEFINE([FORCE_INJECT_LIBXDP], [1], [Force using libxdp for sending packets])])
  499. AC_ARG_ENABLE(force-inject,
  500. AS_HELP_STRING([--enable-force-inject],[Force using libpcap's pcap_inject() for sending packets]),
  501. [ AC_DEFINE([FORCE_INJECT_PCAP_INJECT],[1], [Force using libpcap's pcap_inject() for sending packets])])
  502. AC_ARG_ENABLE(force-sendpacket,
  503. AS_HELP_STRING([--enable-force-sendpacket],[Force using libpcap's pcap_sendpacket() for sending packets]),
  504. [ AC_DEFINE([FORCE_INJECT_PCAP_SENDPACKET], [1], [Force using libpcap's pcap_sendpacket() for sending packets])])
  505. dnl Static link libraries
  506. static_link=no
  507. dynamic_link=yes
  508. AC_ARG_ENABLE(static-link,
  509. AS_HELP_STRING([--enable-static-link],[Use static libraries ( .a or .A.tbd ) - default no]),
  510. [
  511. if test $enableval = yes; then
  512. static_link=yes
  513. dynamic_link=no
  514. fi
  515. ])
  516. dnl Dynamic link libraries
  517. AC_ARG_ENABLE(dynamic-link,
  518. AS_HELP_STRING([--enable-dynamic-link],[Use shared libraries ( .so .dylib or .tbd ) - default yes]),
  519. [
  520. if test $enableval = no; then
  521. dynamic_link=no
  522. static_link=yes
  523. elif test $static_link = yes; then
  524. AC_MSG_ERROR([Cannot specify both --enable-dynamic-link and --enable-static-link])
  525. fi
  526. ])
  527. if test $static_link = yes; then
  528. AC_DEFINE([ENABLE_STATIC_LINK], [1], [Use static libraries ( .a or .A.tbd )])
  529. else
  530. AC_DEFINE([ENABLE_DYNAMIC_LINK], [1], [Use shared libraries ( .so .dylib or .tbd )])
  531. fi
  532. dnl Check for inet_aton and inet_pton
  533. dnl On Haiku these functions are in libnetwork.
  534. AC_CHECK_FUNC(inet_aton,
  535. AC_DEFINE([HAVE_INET_ATON], [1], [Do we have inet_aton?])
  536. inet_aton=yes,
  537. [
  538. AC_CHECK_LIB(network, inet_aton,
  539. AC_DEFINE([HAVE_INET_ATON], [1], [Do we have inet_aton?])
  540. use_libnetwork=yes,
  541. [inet_aton=no]
  542. )
  543. ]
  544. )
  545. AC_CHECK_FUNC(inet_pton,
  546. AC_DEFINE([HAVE_INET_PTON], [1], [Do we have inet_pton?])
  547. inet_pton=yes,
  548. [
  549. AC_CHECK_LIB(network, inet_pton,
  550. AC_DEFINE([HAVE_INET_PTON], [1], [Do we have inet_pton?])
  551. use_libnetwork=yes,
  552. [inet_pton=no]
  553. )
  554. ]
  555. )
  556. AC_CHECK_FUNC(inet_ntop,
  557. AC_DEFINE([HAVE_INET_NTOP], [1], [Do we have inet_ntop?])
  558. inet_ntop=yes,
  559. [
  560. AC_CHECK_LIB(network, inet_ntop,
  561. AC_DEFINE([HAVE_INET_NTOP], [1], [Do we have inet_ntop?])
  562. use_libnetwork=yes,
  563. [inet_ntop=no]
  564. )
  565. ]
  566. )
  567. if test "$inet_ntop" = "no" -a "$inet_pton" = "no" ; then
  568. AC_MSG_ERROR([We need either inet_ntop or inet_pton])
  569. fi
  570. if test "$use_libnetwork" = "yes" ; then
  571. LIBS="-lnetwork $LIBS"
  572. fi
  573. AC_CHECK_FUNC(inet_addr,
  574. AC_DEFINE([HAVE_INET_ADDR], [1], [Do we have inet_addr?])
  575. inet_addr=yes,
  576. inet_addr=no)
  577. if test x$inet_addr = xno ; then
  578. AC_MSG_ERROR([We need inet_addr. See bug 26])
  579. fi
  580. dnl On Haiku fts_*() functions are in libbsd.
  581. AC_CHECK_FUNC(fts_read,,[AC_CHECK_LIB(bsd, fts_read)])
  582. dnl #####################################################
  583. dnl Checks for tuntap device support
  584. dnl #####################################################
  585. have_tuntap=no
  586. AC_ARG_ENABLE([tuntap],
  587. AS_HELP_STRING([--disable-tuntap], [Disable tuntap support]), [:],
  588. [case "$build_os" in
  589. linux*)
  590. AC_CHECK_HEADER([linux/if_tun.h], [have_tuntap=yes])
  591. ;;
  592. *)
  593. AC_CHECK_HEADER([net/if_tun.h], [have_tuntap=yes])
  594. ;;
  595. esac])
  596. if test $have_tuntap = yes ; then
  597. AC_DEFINE([HAVE_TUNTAP], [1],
  598. [Do we have TUNTAP device support?])
  599. fi
  600. dnl #####################################################
  601. dnl Checks for libpcap
  602. dnl #####################################################
  603. foundpcap=no
  604. pf_ring_found=no
  605. pf_ring_lib=${with_pfring_lib}
  606. using_pcap_config=no
  607. AC_MSG_CHECKING(for libpcap)
  608. AC_ARG_WITH(libpcap,
  609. AS_HELP_STRING([--with-libpcap=DIR],[Use libpcap in DIR]),
  610. [
  611. testdir=$withval
  612. for incl in ${testdir}/include/pcap.h ${testdir}/pcap.h ${testdir}/pcap/pcap.h; do
  613. if ! test -f "${incl}"; then
  614. continue
  615. fi
  616. LPCAPINC=${incl}
  617. LPCAPINCDIR=${testdir}
  618. if test $dynamic_link = yes; then
  619. for ext in .dylib .so .tbd ; do
  620. for dir in . lib lib64 lib32 lib/${host_cpu}-${host_os} ${host_cpu}-${host_os} lib/${MULTIARCH} ${MULTIARCH}; do
  621. sharefile=$(ls ${testdir}/$dir/libpcap${ext}* 2> /dev/null | sort | head -n1)
  622. if test -n "${sharefile}"; then
  623. LPCAP_LD_LIBRARY_PATH="$(dirname ${sharefile})"
  624. LPCAPLIB="-L$LPCAP_LD_LIBRARY_PATH -lpcap"
  625. foundpcap=$testdir
  626. break
  627. fi
  628. done
  629. if ! test $foundpcap = no; then
  630. break
  631. fi
  632. done
  633. else
  634. dnl
  635. dnl If dynamic library not found, try static
  636. dnl
  637. for ext in ${libext} .a .A.tbd ; do
  638. for dir in . lib lib64 lib32 lib/${host_cpu}-${host_os} ${host_cpu}-${host_os} lib/${MULTIARCH} ${MULTIARCH}; do
  639. staticfile=$(ls ${testdir}/$dir/libpcap${ext} 2> /dev/null | sort | head -n1)
  640. if test -n "${staticfile}"; then
  641. LPCAPLIB="${staticfile}"
  642. foundpcap=${testdir}
  643. break
  644. fi
  645. done
  646. done
  647. fi
  648. if test $foundpcap = no; then
  649. AC_MSG_ERROR("Unable to find matching library for header file in ${testdir}")
  650. fi
  651. break
  652. done
  653. ],[
  654. #
  655. # Look for pcap-config.
  656. #
  657. # I wish this option could be the default, but it is only enabled with --enable-pcapconfig
  658. #
  659. # The issue is that libpcap is one of those libraries that is nearly impossible to set up
  660. # properly across all platforms. The 'pcap-config' script is shipped with new versions of libpcap,
  661. # and was created to address portability issues. Unfortunately, the script is not updated properly
  662. # outside of the base distribution. Examples: PF_RING requires 'pthreads', 'numa' and 'rt', but
  663. # this is not reflect that in the script. OS X Xcode 10.11 SDK creates its own very broken
  664. # 'pcap-config' script that only occasionally works for dynamic definitions, and definitely
  665. # does not work for static.
  666. #
  667. # The ability to enable this script exists for corner cases where libpcap distributions starts
  668. # using even more libraries than I am currently not aware of. Originally, you only had to worry
  669. # about 'nl', but now we have to be prepared to add 'nl-3', 'nl-genl-3' and 'dbus-1' to make
  670. # libpcap functional. In the future, there may be more.
  671. #
  672. # (sigh)
  673. #
  674. # So, in the future if libpcap changes and stops working, try setting --enable-pcapconfig. It
  675. # it may work for you.
  676. if test $enable_pcap_config = yes; then
  677. AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
  678. if test -n "$PCAP_CONFIG"; then
  679. #
  680. # Found - use it to get the include flags for
  681. # libpcap and the flags to link with libpcap.
  682. #
  683. # Please read section 11.6 "Shell Substitutions"
  684. # in the autoconf manual before doing anything
  685. # to this that involves quoting. Especially note
  686. # the statement "There is just no portable way to use
  687. # double-quoted strings inside double-quoted back-quoted
  688. # expressions (pfew!)."
  689. #
  690. if test $dynamic_link = yes; then
  691. LPCAPLIB=$($PCAP_CONFIG --libs)
  692. else
  693. LPCAPLIB=$($PCAP_CONFIG --libs --static)
  694. fi
  695. CFLAGS="$CFLAGS $($PCAP_CONFIG --cflags)"
  696. if test -n "$LPCAPLIB"; then
  697. foundpcap=yes
  698. using_pcap_config=yes
  699. else
  700. AC_MSG_WARN(Unable to find libpcap using pcap-config)
  701. fi
  702. fi
  703. fi
  704. if test ! $foundpcap = yes; then
  705. #
  706. # Not found; look for pcap.
  707. #
  708. for testdir in /usr/local /opt/local /usr /wpdpack $MACOSX_SDK_PATH/usr /usr/local/opt/libpcap ; do
  709. if test -f "${testdir}/include/pcap.h"; then
  710. LPCAPINC="${testdir}/include/pcap.h"
  711. LPCAPINCDIR="${testdir}/include"
  712. if test $dynamic_link = yes; then
  713. for ext in .dylib .so .tbd; do
  714. for dir in . lib lib64 lib32 lib/${host_cpu}-${host_os} ${host_cpu}-${host_os} lib/${MULTIARCH} ${MULTIARCH}; do
  715. sharefile=$(ls "${testdir}/$dir/libpcap${ext}" 2> /dev/null | sort | head -n1)
  716. if test -n "${sharefile}"; then
  717. LPCAPLIB="-L$(dirname ${sharefile}) -lpcap"
  718. foundpcap=$testdir
  719. break
  720. fi
  721. done
  722. if ! test $foundpcap = no; then
  723. break
  724. fi
  725. done
  726. fi
  727. if test $foundpcap = no ; then
  728. dnl
  729. dnl If dynamic library not found, try static
  730. dnl
  731. for ext in ${libext} .a .A.tbd ; do
  732. for dir in . lib lib64 lib32 lib/${host_cpu}-${host_os} ${host_cpu}-${host_os} lib/${MULTIARCH} ${MULTIARCH}; do
  733. staticfile=$(ls "${testdir}/$dir/libpcap${ext}" 2> /dev/null | sort | head -n1)
  734. if test -n "${staticfile}"; then
  735. LPCAPLIB="${staticfile}"
  736. foundpcap=$testdir
  737. break
  738. fi
  739. done
  740. if ! test $foundpcap = no; then
  741. break
  742. fi
  743. done
  744. fi
  745. if test $foundpcap = no -a -f "${testdir}/lib/libwpcap.${libext}" ; then
  746. LPCAPLIB="${testdir}/lib/libwpcap.${libext}"
  747. AC_DEFINE([HAVE_WINPCAP], [1], [Do we have WinPcap?])
  748. foundpcap=$testdir
  749. fi
  750. fi
  751. if ! test $foundpcap = no; then
  752. break
  753. fi
  754. done
  755. fi
  756. ])
  757. if test $foundpcap = no ; then
  758. AC_MSG_RESULT(no)
  759. AC_MSG_ERROR(libpcap not found)
  760. else
  761. AC_MSG_RESULT($foundpcap)
  762. fi
  763. ## could be PF_RING
  764. #
  765. # library is static and in PF_RING build tree
  766. #
  767. # Need access to libpfring library
  768. # and must find an associated libpfring.a
  769. if test -n "${with_pfring_lib}"; then
  770. if test -f ${with_pfring_lib}; then
  771. pf_ring_lib=${with_pfring_lib}
  772. pf_ring_found=yes
  773. else
  774. AC_MSG_ERROR(["Unable to find PF_RING library ${with_pfring_lib}"])
  775. fi
  776. fi
  777. # libpcap can require libnl
  778. AC_SEARCH_LIBS([nl_handle_alloc], [nl],
  779. [AC_MSG_NOTICE([Unable to find nl library - may be needed by libpcap])])
  780. AC_CHECK_LIB(bpf, bpf_object__open_file,,
  781. [AC_MSG_NOTICE([Unable to find libbpf library ])])
  782. AC_CHECK_LIB(xdp, xsk_umem__delete,,
  783. [AC_MSG_NOTICE([Unable to find libxdp library ])])
  784. ##
  785. ## If not automatically configured,
  786. ## check for newer and full-featured libpcap's
  787. ##
  788. if ! test $using_pcap_config = yes; then
  789. ## newer libpcap requires dbus and latest nl (e.g. -lnl-genl-3 -lnl-3 -ldbus-1)
  790. AC_CHECK_LIB(nl, nl_cache_alloc, [nl_found=yes])
  791. AC_CHECK_LIB(nl-genl-3, genl_connect, [nl_genl_3_found=yes])
  792. AC_CHECK_LIB(nl-3, nl_cache_alloc, [nl_3_found=yes])
  793. AC_CHECK_LIB(dbus-1, dbus_malloc, [dbus_1_found=yes])
  794. if test "$nl_found" = "yes"; then
  795. LPCAPLIB="$LPCAPLIB -lnl"
  796. fi
  797. if test "$nl_genl_3_found" = "yes"; then
  798. LPCAPLIB="$LPCAPLIB -lnl-genl-3"
  799. fi
  800. if test "$nl_3_found" = "yes"; then
  801. LPCAPLIB="$LPCAPLIB -lnl-3"
  802. fi
  803. if test "$dbus_1_found" = "yes"; then
  804. LPCAPLIB="$LPCAPLIB -ldbus-1"
  805. fi
  806. ## See if prereqs for PF_RING exist
  807. AC_CHECK_LIB(numa, numa_available, [numa_found=yes])
  808. AC_CHECK_LIB(pthread, pthread_create, [pthread_found=yes])
  809. if test $pf_ring_found = yes; then
  810. if ! test "${numa_found}" = "yes"; then
  811. AC_MSG_ERROR([PF_RING requires libnuma and/or libnuma-dev])
  812. fi
  813. if ! test "${pthread_found}" = "yes"; then
  814. AC_MSG_ERROR([PF_RING requires libpthread])
  815. fi
  816. LPCAPLIB="$LPCAPLIB ${pf_ring_lib} -lnuma -lpthread -lrt"
  817. fi
  818. fi
  819. OLDLIBS="$LIBS"
  820. if test -n "$LPCAPINCDIR"; then
  821. OLDCFLAGS="$CFLAGS -I$LPCAPINCDIR"
  822. CFLAGS="$CFLAGS -I$LPCAPINCDIR"
  823. else
  824. OLDCFLAGS="$CFLAGS"
  825. LPCAPINCDIR=$(echo $CFLAGS | sed -e 's/^\-I//')
  826. if test -d "$LPCAPINCDIR/pcap"; then
  827. LPCAPINC="$LPCAPINCDIR/pcap/pcap.h"
  828. else
  829. LPCAPINC="$LPCAPINCDIR/pcap.h"
  830. fi
  831. fi
  832. LIBS="$LPCAPLIB"
  833. AC_SEARCH_LIBS([pcap_get_pfring_id],
  834. [pcap],
  835. AC_DEFINE([HAVE_PF_RING_PCAP],
  836. ,
  837. [${with_pfring_lib} numa pthread rt]))
  838. ## Does libpcap work with selected libraries?
  839. AC_SEARCH_LIBS([pcap_close], [pcap],
  840. , AC_MSG_ERROR(Unable to link libpcap in ${foundpcap}),)
  841. AC_SUBST(LPCAPINC)
  842. AC_SUBST(LPCAPLIB)
  843. dnl Check to see what version of libpcap
  844. AC_MSG_CHECKING(libpcap version)
  845. libpcap_version=unknown
  846. libpcap_version_096=no
  847. cat >conftest.c <<EOF
  848. #include <string.h>
  849. #include <stdio.h>
  850. #include "$LPCAPINC"
  851. /*
  852. * simple proggy to get the version of libpcap
  853. */
  854. int main() {
  855. printf("%s\n", pcap_lib_version());
  856. return 0;
  857. }
  858. EOF
  859. ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LPCAPLIB \
  860. conftest.c $LIBS >/dev/null 2>&1
  861. if test -x conftest -a "$cross_compiling" != "yes"; then
  862. full_libpcap_version=$(LD_LIBRARY_PATH="$LPCAP_LD_LIBRARY_PATH" ./conftest)
  863. libpcap_version=$(echo "$full_libpcap_version" | ${CUT} -d' ' -f3)
  864. pcap_version_ok=yes
  865. fi
  866. AC_MSG_RESULT([$libpcap_version])
  867. rm -rf conftest.* core core.conftest 2>&1 > /dev/null
  868. AC_MSG_CHECKING(for valid libpcap version)
  869. if test x$libpcap_version != xunknown; then
  870. libpcap_major=$(echo ${libpcap_version} | ${CUT} -d '.' -f1)
  871. libpcap_minor=$(echo ${libpcap_version} | ${CUT} -d '.' -f2)
  872. libpcap_build=$(echo ${libpcap_version} | ${CUT} -d '.' -f3)
  873. if test $libpcap_major -eq 0 && \
  874. (test $libpcap_minor -lt 7 || \
  875. (test $libpcap_minor -eq 7 && test $libpcap_build -lt 2))
  876. then
  877. AC_MSG_ERROR([Libpcap versions < 0.7.2 are not supported
  878. Please upgrade to version 0.7.2 or better. Your version is $libpcap_version])
  879. fi
  880. dnl 0.9.6 (which is still thinks it is 0.9.5 due to a bug) introduces an important
  881. dnl fix for OSX. See: http://tcpreplay.synfin.net/trac/ticket/167
  882. if test $libpcap_major -gt 0 || \
  883. (test $libpcap_minor -eq 9 && test $libpcap_build -ge 6)
  884. then
  885. libpcap_version_096=yes
  886. fi
  887. AC_MSG_RESULT([yes])
  888. else
  889. AC_MSG_RESULT([unknown])
  890. fi
  891. dnl Check for pcap_setnonblock()
  892. AC_MSG_CHECKING(for pcap_setnonblock)
  893. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  894. #include <stdio.h>
  895. #include <stdlib.h>
  896. #include <string.h>
  897. #include "$LPCAPINC"
  898. ]],[[
  899. pcap_t *p;
  900. char *errbuf;
  901. pcap_setnonblock(p, 1, errbuf);
  902. exit(0);
  903. ]])], [
  904. have_pcap_setnonblock=yes
  905. AC_MSG_RESULT(yes)
  906. ], [
  907. have_pcap_setnonblock=no
  908. AC_MSG_RESULT(no)
  909. ])
  910. if test $have_pcap_setnonblock = yes ; then
  911. AC_DEFINE([HAVE_PCAP_SETNONBLOCK], [1],
  912. [Does libpcap have pcap_setnonblock?])
  913. fi
  914. dnl Check to see if we've got pcap_datalink_val_to_name()
  915. AC_MSG_CHECKING(for pcap_datalink_val_to_description)
  916. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  917. #include <stdio.h>
  918. #include <stdlib.h>
  919. #include <string.h>
  920. #include "$LPCAPINC"
  921. ]],[[
  922. if (strcmp(pcap_datalink_val_to_description(1), "Ethernet (10Mb)") == 0)
  923. exit(0);
  924. exit(1);
  925. ]])],[
  926. have_dlt_to_desc=yes
  927. AC_MSG_RESULT(yes)
  928. ], [
  929. have_dlt_to_desc=no
  930. AC_MSG_RESULT(no)
  931. ])
  932. if test $have_dlt_to_desc = yes ; then
  933. AC_DEFINE([HAVE_DLT_VAL_TO_DESC], [1],
  934. [Does libpcap have pcap_datalink_val_to_description?])
  935. fi
  936. dnl Check for pcap_get_selectable_fd()
  937. AC_MSG_CHECKING(for pcap_get_selectable_fd)
  938. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  939. #include <stdio.h>
  940. #include <stdlib.h>
  941. #include <string.h>
  942. #include "$LPCAPINC"
  943. ]], [[
  944. int f;
  945. pcap_t *p;
  946. f = pcap_get_selectable_fd(p);
  947. exit(0);
  948. ]])], [
  949. have_pcap_get_selectable_fd=yes
  950. AC_MSG_RESULT(yes)
  951. ], [
  952. have_pcap_get_selectable_fd=no
  953. AC_MSG_RESULT(no)
  954. ])
  955. if test x$have_pcap_get_selectable_fd = xyes ; then
  956. AC_DEFINE([HAVE_PCAP_GET_SELECTABLE_FD], [1],
  957. [Does libpcap have pcap_get_selectable_fd?])
  958. fi
  959. dnl Important: winpcap apparently defines functions in it's header files
  960. dnl which aren't actually in the library. Totally fucked up. Hence, we
  961. dnl must actually LINK the code, not just compile it.
  962. dnl Check to see if we've got pcap_dump_fopen()
  963. AC_MSG_CHECKING(for pcap_dump_fopen)
  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_dumper_t *dump;
  971. pcap_t *pcap;
  972. FILE *foo;
  973. dump = pcap_dump_fopen(pcap, foo);
  974. ]])],[
  975. have_pcap_dump_fopen=yes
  976. AC_MSG_RESULT(yes)
  977. ], [
  978. have_pcap_dump_fopen=no
  979. AC_MSG_RESULT(no)
  980. ])
  981. if test $have_pcap_dump_fopen = yes ; then
  982. AC_DEFINE([HAVE_PCAP_DUMP_FOPEN], [1],
  983. [Does libpcap have pcap_dump_fopen?])
  984. else
  985. AC_MSG_NOTICE([--verbose mode requires libpcap >= 0.9.0])
  986. fi
  987. have_pcap_inject=no
  988. dnl Check to see if we've got pcap_inject()
  989. AC_MSG_CHECKING(for pcap_inject sending support)
  990. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  991. #include <stdio.h>
  992. #include <stdlib.h>
  993. #include <string.h>
  994. #include "$LPCAPINC"
  995. ]],[[
  996. pcap_t *pcap;
  997. char *buf;
  998. pcap_inject(pcap, (void *)buf, 0);
  999. ]])],[
  1000. have_pcap_inject=yes
  1001. AC_MSG_RESULT(yes)
  1002. ], [
  1003. have_pcap_inject=no
  1004. AC_MSG_RESULT(no)
  1005. ])
  1006. if test $have_pcap_inject = yes ; then
  1007. AC_DEFINE([HAVE_PCAP_INJECT], [1], [Does libpcap have pcap_inject?])
  1008. fi
  1009. have_pcap_sendpacket=no
  1010. dnl Check to see if we've got pcap_sendpacket()
  1011. AC_MSG_CHECKING(for pcap_sendpacket sending support)
  1012. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  1013. #include <stdio.h>
  1014. #include <stdlib.h>
  1015. #include <string.h>
  1016. #include "$LPCAPINC"
  1017. ]],[[
  1018. pcap_t *pcap;
  1019. u_char *buf;
  1020. pcap_sendpacket(pcap, buf, 0);
  1021. ]])],[
  1022. have_pcap_sendpacket=yes
  1023. AC_MSG_RESULT(yes)
  1024. ], [
  1025. have_pcap_sendpacket=no
  1026. AC_MSG_RESULT(no)
  1027. ])
  1028. if test $have_pcap_sendpacket = yes ; then
  1029. AC_DEFINE([HAVE_PCAP_SENDPACKET], [1], [Does libpcap have pcap_sendpacket?])
  1030. fi
  1031. have_pcap_breakloop=no
  1032. AC_MSG_CHECKING(for pcap_breakloop)
  1033. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  1034. #include <stdio.h>
  1035. #include <stdlib.h>
  1036. #include <string.h>
  1037. #include "$LPCAPINC"
  1038. ]],[[
  1039. pcap_t *pcap;
  1040. pcap_sendpacket(pcap);
  1041. ]])],[
  1042. have_pcap_breakloop=yes
  1043. AC_MSG_RESULT(yes)
  1044. ], [
  1045. have_pcap_breakloop=no
  1046. AC_MSG_RESULT(no)
  1047. ])
  1048. if test $have_pcap_breakloop = yes ; then
  1049. AC_DEFINE([HAVE_PCAP_BREAKLOOP], [1], [Does libpcap have pcap_breakloop?])
  1050. fi
  1051. have_pcap_version=no
  1052. dnl Check to see if we have pcap_version[]
  1053. AC_MSG_CHECKING(for pcap_version[])
  1054. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  1055. #include <stdio.h>
  1056. #include <stdlib.h>
  1057. #include <string.h>
  1058. #include "$LPCAPINC"
  1059. extern char pcap_version[];
  1060. ]], [[
  1061. printf("%s", pcap_version);
  1062. ]])],[
  1063. AC_DEFINE([HAVE_PCAP_VERSION],[1], [Does libpcap have pcap_version[]])
  1064. AC_MSG_RESULT(yes)
  1065. ],[
  1066. AC_MSG_RESULT(no)
  1067. ])
  1068. have_pcap_snapshot=no
  1069. dnl Check for pcap_snapshot()
  1070. AC_MSG_CHECKING(for pcap_snapshot)
  1071. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  1072. #include <stdio.h>
  1073. #include <stdlib.h>
  1074. #include <string.h>
  1075. #include "$LPCAPINC"
  1076. ]],[[
  1077. pcap_t *p;
  1078. int len;
  1079. len = pcap_snapshot(p);
  1080. exit(0);
  1081. ]])], [
  1082. have_pcap_snapshot=yes
  1083. AC_MSG_RESULT(yes)
  1084. ], [
  1085. have_pcap_snapshot=no
  1086. AC_MSG_RESULT(no)
  1087. ])
  1088. if test $have_pcap_snapshot = yes ; then
  1089. AC_DEFINE([HAVE_PCAP_SNAPSHOT], [1],
  1090. [Does libpcap have pcap_snapshot?])
  1091. fi
  1092. have_pcap_open_offline_with_tstamp_precision=no
  1093. dnl Check to see if we've got pcap_open_offline_with_tstamp_precision()
  1094. AC_MSG_CHECKING(for pcap_open_offline_with_tstamp_precision support)
  1095. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  1096. #include <stdio.h>
  1097. #include <stdlib.h>
  1098. #include <string.h>
  1099. #include "$LPCAPINC"
  1100. ]],[[
  1101. pcap_t *pcap;
  1102. char ebuf[PCAP_ERRBUF_SIZE];
  1103. pcap = pcap_open_offline_with_tstamp_precision("fake.pcap", PCAP_TSTAMP_PRECISION_NANO, &ebuf[0]);
  1104. ]])],[
  1105. have_pcap_open_offline_with_tstamp_precision=yes
  1106. AC_MSG_RESULT(yes)
  1107. ], [
  1108. have_pcap_open_offline_with_tstamp_precision=no
  1109. AC_MSG_RESULT(no)
  1110. ])
  1111. if test $have_pcap_open_offline_with_tstamp_precision = yes ; then
  1112. AC_DEFINE([HAVE_PCAP_OPEN_OFFLINE_WITH_TSTAMP_PRECISION], [1], [Does libpcap have pcap_open_offline_with_tstamp_precision?])
  1113. AC_DEFINE([PCAP_TSTAMP_US_TO_NS_MULTIPLIER], [1], [Multiplier for conversion from PCAP usec to nsec])
  1114. AC_DEFINE([PCAP_TSTAMP_US_TO_US_DIVISOR], [1000], [Divisor for conversion from PCAP usec to usec])
  1115. else
  1116. AC_DEFINE([PCAP_TSTAMP_US_TO_NS_MULTIPLIER], [1000], [Multiplier for conversion from PCAP usec to nsec])
  1117. AC_DEFINE([PCAP_TSTAMP_US_TO_US_DIVISOR], [1], [Divisor for conversion from PCAP usec to usec])
  1118. fi
  1119. # Tcpbridge requires libpcap and pcap_sendpacket()
  1120. enable_tcpbridge=no
  1121. if test x$foundpcap != xno -a x$have_pcap_sendpacket = xyes ; then
  1122. # if we have pcap_sendpacket() then we can build tcpbridge on non-BPF systems
  1123. if test x$have_bpf = xno; then
  1124. AC_DEFINE(ENABLE_TCPBRIDGE, [1], [Compile tcpbridge])
  1125. enable_tcpbridge=yes
  1126. AC_MSG_NOTICE([Building tcpbridge])
  1127. # BPF systems need to also have pcap_setnonblock()
  1128. elif test x$have_pcap_setnonblock = xyes ; then
  1129. AC_DEFINE(ENABLE_TCPBRIDGE, [1], [Compile tcpbridge])
  1130. enable_tcpbridge=yes
  1131. AC_MSG_NOTICE([Building tcpbridge])
  1132. else
  1133. AC_MSG_WARN([Unable to build tcpbridge. Try installing latest libpcap!])
  1134. fi
  1135. fi
  1136. AM_CONDITIONAL(COMPILE_TCPBRIDGE, [test x$enable_tcpbridge = xyes ])
  1137. # tcpliveplay requires linux OS to function properly
  1138. enable_tcpliveplay=no
  1139. case $host in
  1140. *-*-linux*)
  1141. AC_DEFINE(ENABLE_TCPLIVEPLAY, [1], [Compile tcpliveplay])
  1142. enable_tcpliveplay=yes
  1143. AC_MSG_NOTICE([Building tcpliveplay])
  1144. ;;
  1145. *)
  1146. AC_MSG_WARN([Unable to build tcpliveplay. This tool is only enabled on linux environments.])
  1147. ;;
  1148. esac
  1149. AM_CONDITIONAL(COMPILE_TCPLIVEPLAY, [test x$enable_tcpliveplay = xyes ])
  1150. dnl #####################################################
  1151. dnl Check for netmap support
  1152. dnl #####################################################
  1153. have_netmap=no
  1154. enable_netmap=no
  1155. trynetmapdir=
  1156. AC_MSG_CHECKING(for netmap socket sending support)
  1157. AC_ARG_WITH(netmap,
  1158. AS_HELP_STRING([--with-netmap=DIR],[Use netmap in DIR]),
  1159. [trynetmapdir=$withval])
  1160. NETMAP_SEARCH_DIRS=
  1161. if test "$cross_compiling" = yes; then
  1162. if test "x$trynetmapdir" != "x"; then
  1163. NETMAP_SEARCH_DIRS=$trynetmapdir
  1164. fi
  1165. else
  1166. 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"
  1167. fi
  1168. for testdir in $NETMAP_SEARCH_DIRS; do
  1169. if test -f "${testdir}/sys/net/netmap.h" ; then
  1170. NETMAPINC="${testdir}/sys/net/netmap.h"
  1171. NETMAPUSERINC="${testdir}/sys/net/netmap_user.h"
  1172. NETMAPINCDIR="${testdir}/sys"
  1173. have_netmap="yes $testdir"
  1174. enable_netmap=yes
  1175. else
  1176. if test -f "${testdir}/net/netmap.h" ; then
  1177. NETMAPINC="${testdir}/net/netmap.h"
  1178. NETMAPUSERINC="${testdir}/net/netmap_user.h"
  1179. NETMAPINCDIR="${testdir}"
  1180. have_netmap="yes $testdir"
  1181. enable_netmap=yes
  1182. fi
  1183. fi
  1184. if test "$have_netmap" != no ; then
  1185. NETMAPFLAGS="-DHAVE_NETMAP"
  1186. OLDCFLAGS="$CFLAGS -I$NETMAPINCDIR"
  1187. CFLAGS="$CFLAGS -DNETMAP_WITH_LIBS -DND -I$NETMAPINCDIR"
  1188. AC_SUBST(NETMAPINC)
  1189. AC_SUBST(NETMAPUSERINC)
  1190. AC_SUBST(NETMAPINCDIR)
  1191. AC_SUBST(NETMAPFLAGS)
  1192. AC_DEFINE([HAVE_NETMAP], [1],
  1193. [Do we have netmap support?])
  1194. have_netmap="yes $testdir"
  1195. enable_netmap=yes
  1196. break;
  1197. fi
  1198. done
  1199. AC_MSG_RESULT($have_netmap)
  1200. AM_CONDITIONAL(COMPILE_NETMAP, [test x$enable_netmap = xyes ])
  1201. dnl ###########################################################
  1202. dnl Check for nm_open() function available in netmap version 5
  1203. dnl Also check for other version-specific netmap definitions and structures
  1204. dnl ###########################################################
  1205. if test "x$NETMAPINCDIR" != "x"; then
  1206. OLDCPPFLAGS="$CPPFLAGS"
  1207. CPPFLAGS="$CPPFLAGS -DNETMAP_WITH_LIBS -DND -I$NETMAPINCDIR"
  1208. have_nm_open=no
  1209. have_nm_nr_reg_mask=no
  1210. have_nm_nr_flags=no
  1211. have_nmring_head_tail=no
  1212. if test "$have_netmap" != no ; then
  1213. dnl check for nm_open()
  1214. AC_CHECK_DECL([nm_open],[have_nm_open=yes], , [[
  1215. #include <stdio.h>
  1216. #include "${NETMAPUSERINC}"
  1217. ]])
  1218. dnl check for #define NR_REG_MASK
  1219. AC_MSG_CHECKING(for netmap NR_REG_MASK definition)
  1220. AC_COMPILE_IFELSE(
  1221. [AC_LANG_PROGRAM([[
  1222. #include <stdint.h>
  1223. #include <sys/socket.h>
  1224. #include <net/if.h>
  1225. #include <net/netmap.h>
  1226. ]],
  1227. [[
  1228. #ifdef NR_REG_MASK
  1229. /* OK */
  1230. #else
  1231. # error NR_REG_MASK not found
  1232. #endif
  1233. ]])
  1234. ],
  1235. [have_nm_nr_reg_mask=yes],
  1236. [])
  1237. AC_MSG_RESULT($have_nm_nr_reg_mask)
  1238. dnl check for nr_flags in struct nmreq
  1239. AC_MSG_CHECKING(for netmap nr_flags definition)
  1240. AC_COMPILE_IFELSE(
  1241. [AC_LANG_PROGRAM([[
  1242. #include <stdint.h>
  1243. #include <sys/socket.h>
  1244. #include <net/if.h>
  1245. #include <net/netmap.h>
  1246. ]],
  1247. [[
  1248. struct nmreq nmr;
  1249. nmr.nr_flags = 0;
  1250. ]])
  1251. ],
  1252. [have_nm_nr_flags=yes],
  1253. [])
  1254. AC_MSG_RESULT($have_nm_nr_flags)
  1255. dnl check for head/tail in struct netmap_ring
  1256. AC_MSG_CHECKING(for netmap ring head/tail definitions)
  1257. AC_COMPILE_IFELSE(
  1258. [AC_LANG_PROGRAM([[
  1259. #include <stdint.h>
  1260. #include <sys/socket.h>
  1261. #include <net/if.h>
  1262. #include <net/netmap.h>
  1263. ]],
  1264. [[
  1265. struct netmap_ring r;
  1266. r.head = r.tail = 0;
  1267. ]])
  1268. ],
  1269. [have_nmring_head_tail=yes],
  1270. [])
  1271. AC_MSG_RESULT($have_nmring_head_tail)
  1272. fi
  1273. if test "$have_nm_open" = yes ; then
  1274. AC_DEFINE([HAVE_NETMAP_NM_OPEN], [1], [Does netmap have nm_open function?])
  1275. fi
  1276. if test "$have_nm_nr_reg_mask" = yes ; then
  1277. AC_DEFINE([HAVE_NETMAP_NR_REG], [1], [Does netmap have NR_REG_MASK defined?])
  1278. fi
  1279. if test "$have_nm_nr_flags" = yes ; then
  1280. AC_DEFINE([HAVE_NETMAP_NR_FLAGS], [1], [Does netmap struct nmreq have nr_flags defined?])
  1281. fi
  1282. if test "$have_nmring_head_tail" = yes ; then
  1283. AC_DEFINE([HAVE_NETMAP_RING_HEAD_TAIL], [1], [Does structure netmap_ring have head/tail defined?])
  1284. fi
  1285. CPPFLAGS="$OLDCPPFLAGS"
  1286. fi
  1287. have_pf=no
  1288. dnl Check for linux PF_PACKET support
  1289. AC_MSG_CHECKING(for PF_PACKET socket sending support)
  1290. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1291. #include <sys/socket.h>
  1292. #include <netpacket/packet.h>
  1293. #include <net/ethernet.h> /* the L2 protocols */
  1294. #include <netinet/in.h> /* htons */
  1295. ]], [[
  1296. int pf_socket;
  1297. pf_socket = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  1298. ]])],[
  1299. AC_DEFINE([HAVE_PF_PACKET], [1],
  1300. [Do we have Linux PF_PACKET socket support?])
  1301. AC_MSG_RESULT(yes)
  1302. have_pf=yes
  1303. ],[
  1304. AC_MSG_RESULT(no)
  1305. ])
  1306. have_libxdp=no
  1307. dnl Check for LIBXDP AF_XDP socket support
  1308. AC_MSG_CHECKING(for LIBXDP XDP packet sending support)
  1309. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1310. #include <stdlib.h>
  1311. #include <xdp/xsk.h>
  1312. #include <sys/socket.h>
  1313. ]], [[
  1314. struct xsk_socket {
  1315. struct xsk_ring_cons *rx;
  1316. struct xsk_ring_prod *tx;
  1317. struct xsk_ctx *ctx;
  1318. struct xsk_socket_config config;
  1319. int fd;
  1320. };
  1321. struct xsk_socket xsk;
  1322. struct xsk_ring_cons *rxr = NULL;
  1323. struct xsk_ring_prod *txr = NULL;
  1324. int queue_id = 0;
  1325. xsk_socket__create(&xsk, "lo", queue_id, NULL, rxr, txr, NULL);
  1326. socket(AF_XDP, SOCK_RAW, 0);
  1327. ]])],[
  1328. AC_DEFINE([HAVE_LIBXDP], [1],
  1329. [Do we have LIBXDP AF_XDP socket support?])
  1330. AC_MSG_RESULT(yes)
  1331. have_libxdp=yes
  1332. ],[
  1333. AC_MSG_RESULT(no)
  1334. ])
  1335. have_tx_ring=no
  1336. dnl Check for older Linux TX_RING support
  1337. AC_MSG_CHECKING(for TX_RING socket sending support)
  1338. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1339. #include <sys/socket.h>
  1340. #include <netpacket/packet.h>
  1341. #include <net/ethernet.h> /* the L2 protocols */
  1342. #include <netinet/in.h> /* htons */
  1343. #include <linux/if_packet.h>
  1344. ]], [[
  1345. int test;
  1346. test = TP_STATUS_WRONG_FORMAT
  1347. ]])],[
  1348. AC_DEFINE([HAVE_TX_RING], [1],
  1349. [Do we have Linux TX_RING socket support?])
  1350. AC_MSG_RESULT(yes)
  1351. have_tx_ring=yes
  1352. ],[
  1353. AC_MSG_RESULT(no)
  1354. ])
  1355. AC_CHECK_HEADERS([bpf/libbpf.h])
  1356. AC_CHECK_HEADERS([bpf/bpf.h])
  1357. AC_CHECK_HEADERS([xdp/libxdp.h])
  1358. AC_CHECK_HEADERS([net/bpf.h], [have_bpf=yes], [have_bpf=no])
  1359. if test $have_bpf = yes ; then
  1360. AC_DEFINE([HAVE_BPF], [1],
  1361. [Do we have BPF device support?])
  1362. fi
  1363. dnl ##################################################
  1364. dnl # Check for libdnet, but only if not Cygwin!
  1365. dnl #
  1366. dnl # if your version of libdnet doesn't compile, try
  1367. dnl # getting it from ...
  1368. dnl # http://libdnet.sourceforge.net/
  1369. dnl # ... or ...
  1370. dnl # https://github.com/jncornett/libdnet
  1371. dnl # ... or ...
  1372. dnl # on Linux try 'apt-get install libdumbnet-dev'
  1373. dnl ##################################################
  1374. founddnet=no
  1375. have_libdnet=no
  1376. libdnet_version=
  1377. enable_fragroute=no
  1378. trydnetdir=/usr/local
  1379. if test $have_cygwin = no ; then
  1380. AC_MSG_CHECKING(for libdnet)
  1381. AC_ARG_WITH(libdnet,
  1382. AS_HELP_STRING([--with-libdnet=DIR],[Use libdnet in DIR]),
  1383. [trydnetdir=$withval])
  1384. if test $trydnetdir != no; then
  1385. case "$build_os" in
  1386. linux*)
  1387. dnl # Debian/Ubuntu already have a package called libdnet
  1388. dnl # so you the package you want to install libdumbnet-dev
  1389. for testdir in $trydnetdir /usr/local /opt/local /usr ; do
  1390. if test -x ${testdir}/bin/dumbnet-config -a $founddnet = no ; then
  1391. LDNETINC="$($testdir/bin/dumbnet-config --cflags)"
  1392. LDNETLIB="$($testdir/bin/dumbnet-config --libs)"
  1393. libdnet_version="$($testdir/bin/dumbnet-config --version) (libdumbnet)"
  1394. founddnet=$testdir
  1395. fi
  1396. done
  1397. ;;
  1398. esac
  1399. if test $founddnet = no ; then
  1400. for testdir in $trydnetdir /usr/local /opt/local $MACOSX_SDK_PATH/usr /usr ; do
  1401. if test -x ${testdir}/bin/dnet-config -a $founddnet = no ; then
  1402. LDNETINC="$($testdir/bin/dnet-config --cflags)"
  1403. LDNETLIB="$($testdir/bin/dnet-config --libs)"
  1404. libdnet_version="$($testdir/bin/dnet-config --version)"
  1405. founddnet=$testdir
  1406. fi
  1407. done
  1408. fi
  1409. fi
  1410. if test $founddnet = no ; then
  1411. AC_MSG_RESULT(no)
  1412. AC_MSG_WARN([libdnet not found, disabling fragroute feature])
  1413. else
  1414. AC_MSG_RESULT($founddnet)
  1415. enable_fragroute=yes
  1416. have_libdnet=yes
  1417. AC_DEFINE([HAVE_LIBDNET], [1], [Do we have libdnet?])
  1418. dnl Debian uses dumbnet.h instead of dnet.h due to naming conflict
  1419. old_cflags=$CFLAGS
  1420. CFLAGS=$LDNETINC
  1421. AC_CHECK_HEADERS([dumbnet.h dnet.h])
  1422. CFLAGS=$old_cflags
  1423. fi
  1424. else
  1425. AC_MSG_NOTICE([Skipping libdnet check under Cygwin for compatibility reasons])
  1426. fi
  1427. AC_SUBST(LDNETINC)
  1428. AC_SUBST(LDNETLIB)
  1429. AC_DEFINE_UNQUOTED([LIBDNET_VERSION], "$libdnet_version", [Version of libdnet])
  1430. AM_CONDITIONAL(COMPILE_FRAGROUTE, [test x$founddnet != xno])
  1431. if test x$founddnet != xno ; then
  1432. AC_DEFINE(ENABLE_FRAGROUTE, [1], [Enable fragroute module])
  1433. fi
  1434. dnl Make sure we have a valid packet injection mechanisim
  1435. if test $have_bpf = no -a $have_pcap_inject = no -a $have_pcap_sendpacket = no \
  1436. -a $have_libdnet = no -a $have_pf = no ; then
  1437. AC_MSG_ERROR([Unable to find a supported method to send packets. Please upgrade your libpcap or enable libdnet])
  1438. fi
  1439. dnl Older versions of libpcap are missing some DLT types
  1440. dnl If doesn't exist, we'll define them in src/common/fakepcap.h
  1441. AC_MSG_CHECKING(for DLT_LINUX_SLL in libpcap)
  1442. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "$LPCAPINC"]], [[ int foo;
  1443. foo = DLT_LINUX_SLL
  1444. ]])],[ AC_DEFINE([HAVE_DLT_LINUX_SLL], [1],
  1445. [Does pcap.h include a header with DLT_LINUX_SLL?])
  1446. AC_MSG_RESULT(yes)
  1447. ],[AC_MSG_RESULT(no)
  1448. ])
  1449. AC_MSG_CHECKING(for DLT_LINUX_SLL2 in libpcap)
  1450. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "$LPCAPINC"]], [[ int foo;
  1451. foo = DLT_LINUX_SLL2
  1452. ]])],[ AC_DEFINE([HAVE_DLT_LINUX_SLL2], [1],
  1453. [Does pcap.h include a header with DLT_LINUX_SLL2?])
  1454. AC_MSG_RESULT(yes)
  1455. ],[AC_MSG_RESULT(no)
  1456. ])
  1457. AC_MSG_CHECKING(for DLT_C_HDLC in libpcap)
  1458. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "$LPCAPINC"]], [[ int foo;
  1459. foo = DLT_C_HDLC ]])],[ AC_DEFINE([HAVE_DLT_C_HDLC], [1],
  1460. [Does pcap.h include a header with DLT_C_HDLC?])
  1461. AC_MSG_RESULT(yes)
  1462. ],[AC_MSG_RESULT(no)
  1463. ])
  1464. PCAP_BPF_H_FILE="$LPCAPINCDIR/pcap-bpf.h"
  1465. AC_MSG_CHECKING(for $PCAP_BPF_H_FILE)
  1466. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
  1467. #include <sys/time.h>
  1468. #include <stdint.h>
  1469. #include "$PCAP_BPF_H_FILE"]], [[ int foo;
  1470. foo = BPF_MAJOR_VERSION; ]])],[ AC_DEFINE([INCLUDE_PCAP_BPF_HEADER], [1],
  1471. [What is the path (if any) to the pcap-bpf.h
  1472. header?])
  1473. AC_MSG_RESULT(yes)
  1474. AC_SUBST(PCAP_BPF_H_FILE)
  1475. ],[AC_MSG_RESULT(no)
  1476. ])
  1477. foundbpfheader=no
  1478. AC_MSG_CHECKING(for libpcap bpf header)
  1479. for testfile in $LPCAPINCDIR/pcap/bpf.h $LPCAPINCDIR/pcap-bpf.h ; do
  1480. if test -f "${testfile}" -a $foundbpfheader = no ; then
  1481. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1482. #include <sys/types.h>
  1483. #include <sys/time.h>
  1484. #include <stdint.h>
  1485. #include "$testfile"]], [[
  1486. int foo;
  1487. foo = BPF_MAJOR_VERSION;
  1488. ]])],[
  1489. foundbpfheader=yes
  1490. PCAP_BPF_H_FILE=$testfile
  1491. AC_SUBST(PCAP_BPF_H_FILE)
  1492. AC_DEFINE([INCLUDE_PCAP_BPF_HEADER], [1],
  1493. [What is the path (if any) to the libpcap bpf header file?])
  1494. ],[])
  1495. fi
  1496. done
  1497. if test $foundbpfheader != no; then
  1498. AC_MSG_RESULT($testfile)
  1499. else
  1500. AC_MSG_RESULT(no)
  1501. fi
  1502. dnl ## Test for netmap-libpcap
  1503. have_pcap_netmap=no
  1504. if test $foundpcap != no ; then
  1505. AC_MSG_CHECKING(for netmap libpcap)
  1506. PCAP_NETMAP_C_FILE="$LPCAPINCDIR/pcap-netmap.c"
  1507. if test -f "${PCAP_NETMAP_C_FILE}" ; then
  1508. AC_DEFINE([HAVE_LIBPCAP_NETMAP], [1],
  1509. [Does this version of libpcap support netmap?])
  1510. have_pcap_netmap=yes
  1511. AC_MSG_RESULT(yes)
  1512. else
  1513. AC_MSG_RESULT(no)
  1514. fi
  1515. fi
  1516. dnl restore LIBS & CFLAGS
  1517. LIBS="$OLDLIBS"
  1518. CFLAGS="$OLDCFLAGS"
  1519. dnl ##################################################
  1520. dnl # Check for pcapnav
  1521. dnl ##################################################
  1522. pcapnav_ver=no
  1523. pcncfg=no
  1524. AC_ARG_WITH(pcapnav-config,
  1525. AS_HELP_STRING([--with-pcapnav-config=FILE],[Use given pcapnav-config]),
  1526. [ AC_MSG_CHECKING(for pcapnav-config)
  1527. if test -x $withval ; then
  1528. pcncfg=$withval
  1529. AC_MSG_RESULT($pcncfg)
  1530. elif test x$withval = xno ; then
  1531. AC_MSG_RESULT(no)
  1532. else
  1533. AC_MSG_RESULT([Can't find pcapnav-config: disabling offset jump feature])
  1534. fi ],
  1535. [ AC_PATH_PROG(pcncfg,[pcapnav-config], [no] ) ]
  1536. )
  1537. if test $pcncfg != no ; then
  1538. LNAVLIB=$($pcncfg --libs)
  1539. LNAV_CFLAGS=$($pcncfg --cflags)
  1540. PCAPNAV_VERSION=$($pcncfg --version)
  1541. AC_SUBST(LNAVLIB)
  1542. AC_SUBST(LNAV_CFLAGS)
  1543. AC_DEFINE_UNQUOTED(PCAPNAV_VERSION, "$PCAPNAV_VERSION",
  1544. [libpcapnav's version?])
  1545. dnl Check to see what version of libpcapnav
  1546. dnl this code has been reduced a lot, but probably still could be
  1547. dnl reduced quite a bit more if we chose too
  1548. AC_MSG_CHECKING(for libpcapnav version)
  1549. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  1550. #include <string.h>
  1551. #define PCAPNAV_TEST "0.4"
  1552. /*
  1553. * simple proggy to test the version of libpcapnav
  1554. * returns zero if version >= 0.4
  1555. * or one otherwise
  1556. */
  1557. int
  1558. main (int argc, char *argv[])
  1559. {
  1560. if (strncmp(PCAPNAV_VERSION, PCAPNAV_TEST, 3) >= 0)
  1561. return 0;
  1562. return 1;
  1563. } ]])],[libpcapnav_ver=yes
  1564. AC_MSG_RESULT(>= 0.4)],[libpcapnav_ver=no
  1565. AC_MSG_RESULT(< 0.4)],[libpcapnav_ver=no
  1566. ])
  1567. if test x$libpcapnav_ver = xno ; then
  1568. AC_MSG_WARN([Libpcapnav versions < 0.4 are not supported.
  1569. Please upgrade to version 0.4 or better.
  1570. Disabling offset jump feature.])
  1571. else
  1572. AC_DEFINE([HAVE_PCAPNAV], [1], [Do we have libpcapnav?])
  1573. fi
  1574. fi # checking pcapnav version
  1575. dnl (shamelessly ripped off from libpcap)
  1576. dnl Checks to see if unaligned memory accesses fail
  1577. dnl
  1578. dnl FORCE_ALIGN (DEFINED)
  1579. dnl
  1580. AC_MSG_CHECKING(for requires strict byte alignment)
  1581. AC_CACHE_VAL(unaligned_cv_fail,
  1582. [
  1583. case "$host_os" in
  1584. darwin*)
  1585. # macOS M1 test fails due to lack of fork() so just hard code it
  1586. unaligned_cv_fail=no
  1587. ;;
  1588. *)
  1589. case "$host_cpu" in
  1590. # XXX: should also check that they don't do weird things
  1591. alpha*|arm*|hp*|mips*|sparc*|ia64)
  1592. unaligned_cv_fail=yes
  1593. ;;
  1594. *)
  1595. cat >conftest.c <<EOF
  1596. #include <sys/types.h>
  1597. #include <sys/wait.h>
  1598. #include <stdio.h>
  1599. #include <unistd.h>
  1600. unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
  1601. int main() {
  1602. unsigned int i;
  1603. pid_t pid;
  1604. int status;
  1605. /* avoid "core dumped" message */
  1606. pid = fork();
  1607. if (pid < 0)
  1608. return 2;
  1609. if (pid > 0) {
  1610. /* parent */
  1611. pid = waitpid(pid, &status, 0);
  1612. if (pid < 0)
  1613. return 3;
  1614. return !WIFEXITED(status);
  1615. }
  1616. /* child */
  1617. i = *(unsigned int *)&a[[1]];
  1618. printf("%d\n", i);
  1619. return 0;
  1620. }
  1621. EOF
  1622. ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
  1623. conftest.c $LIBS >/dev/null 2>&1
  1624. if test ! -x conftest -o "$cross_compiling" = "yes" ; then
  1625. dnl failed to compile for some reason
  1626. unaligned_cv_fail=yes
  1627. else
  1628. ./conftest >conftest.out
  1629. if test ! -s conftest.out ; then
  1630. unaligned_cv_fail=yes
  1631. else
  1632. unaligned_cv_fail=no
  1633. fi
  1634. fi
  1635. rm -f conftest* core core.conftest
  1636. ;;
  1637. esac
  1638. ;;
  1639. esac
  1640. ])
  1641. AC_MSG_RESULT($unaligned_cv_fail)
  1642. if test $unaligned_cv_fail = yes ; then
  1643. AC_DEFINE([FORCE_ALIGN], [1], [Are we strictly aligned?])
  1644. fi
  1645. dnl ##################################################
  1646. dnl # Check for tcpdump.
  1647. dnl ##################################################
  1648. tcpdump_path=no
  1649. AC_ARG_WITH(tcpdump,
  1650. AS_HELP_STRING([--with-tcpdump=FILE],[Path to tcpdump binary]),
  1651. [ if test -x $withval ; then
  1652. tcpdump_path=$withval
  1653. AC_MSG_RESULT([Using tcpdump in $tcpdump_path])
  1654. else
  1655. AC_MSG_RESULT([Error: $withval does not exist or is not executable])
  1656. fi ],
  1657. [ AC_PATH_PROG(tcpdump_path, tcpdump, "no", [$PATH:/usr/sbin:/sbin:/usr/local/sbin]) ])
  1658. if test "$tcpdump_path" = "no"; then
  1659. AC_MSG_WARN([Unable to find tcpdump. Please specify --with-tcpdump.
  1660. Disabling --verbose])
  1661. else
  1662. AC_DEFINE([HAVE_TCPDUMP], [1], [Do we have tcpdump?])
  1663. AC_DEFINE_UNQUOTED(TCPDUMP_BINARY, "$tcpdump_path", [The tcpdump binary initially used])
  1664. fi
  1665. AM_CONDITIONAL([ENABLE_TCPDUMP], test "$tcpdump_path" != "no" -a x$have_pcap_dump_fopen = xyes)
  1666. if test x$tcpdump_path != xno -a x$have_pcap_dump_fopen = xyes ; then
  1667. AC_DEFINE([ENABLE_VERBOSE], [1], [Do we have tcpdump and pcap_dump_fopen()?])
  1668. else
  1669. AC_MSG_WARN([Your version of libpcap does not support --verbose])
  1670. fi
  1671. dnl No 'make test' when cross compile
  1672. AC_MSG_CHECKING(for 'make test' profile)
  1673. if test "$host" = "$build" ; then
  1674. AC_MSG_RESULT([yes])
  1675. else
  1676. AC_MSG_WARN(Unable to do tests when cross-compiling)
  1677. AC_MSG_RESULT([Unable to do tests when cross-compiling])
  1678. fi
  1679. dnl Allows user to choose which nic to use for testing purposes
  1680. AC_ARG_WITH(testnic,
  1681. AS_HELP_STRING([--with-testnic=NIC],[Select which network card to use for testing]),
  1682. [ nic1=$withval
  1683. nic2=$withval
  1684. AC_MSG_RESULT([Using --with-testnic=$withval])],
  1685. [
  1686. case $host in
  1687. *-*-linux*)
  1688. nic1=eth0
  1689. nic2=eth0
  1690. ;;
  1691. *-*-solaris*)
  1692. nic1=hme0
  1693. nic2=hme0
  1694. ;;
  1695. *-*-sunos*)
  1696. nic1=hme0
  1697. nic2=hme0
  1698. ;;
  1699. *-apple-darwin*)
  1700. nic1=en0
  1701. nic2=en0
  1702. ;;
  1703. *-*-openbsd*)
  1704. nic1=xl0
  1705. nic2=xl0
  1706. ;;
  1707. *-*-freebsd*)
  1708. nic1=em0
  1709. nic2=em0
  1710. ;;
  1711. *-*-cygwin)
  1712. nic1=%0
  1713. nic2=%0
  1714. ;;
  1715. *)
  1716. AC_MSG_RESULT([$host is unknown! Using first non-loopback interface])
  1717. nic1=%0
  1718. nic2=%0
  1719. ;;
  1720. esac])
  1721. dnl There's a bug in OS X which causes pcap_findalldevs() to make the wifi NIC to disassociate
  1722. dnl so under OSX we disable the interface list feature
  1723. disable_pcap_findalldevs=no
  1724. osx_frameworks=no
  1725. AC_MSG_CHECKING([for OS version])
  1726. dnl these need to be dynamic based on OS
  1727. case $host in
  1728. *-*-linux*)
  1729. AC_DEFINE([HAVE_LINUX], [1], [Building Linux])
  1730. AC_MSG_RESULT(Linux)
  1731. ;;
  1732. *-*-solaris*)
  1733. AC_DEFINE([HAVE_SOLARIS], [1], [Building Solaris])
  1734. AC_MSG_RESULT(Solaris)
  1735. ;;
  1736. *-*-sunos*)
  1737. AC_DEFINE([HAVE_SUNOS], [1], [Building SunOS])
  1738. AC_MSG_RESULT(SunOS)
  1739. ;;
  1740. *-apple-darwin*)
  1741. if test x$libpcap_version_096 = xno ; then
  1742. disable_pcap_findalldevs=yes
  1743. fi
  1744. osx_frameworks=yes
  1745. AC_DEFINE([HAVE_DARWIN], [1], [Building Apple/Darwin])
  1746. AC_MSG_RESULT(Apple macOS)
  1747. ;;
  1748. *-*-openbsd*)
  1749. AC_DEFINE([HAVE_OPENBSD], [1], [Building Open BSD])
  1750. AC_MSG_RESULT(OpenBSD)
  1751. ;;
  1752. *-*-freebsd*)
  1753. AC_DEFINE([HAVE_FREEBSD], [1], [Building Free BSD])
  1754. AC_MSG_RESULT(FreeBSD)
  1755. ;;
  1756. *-*-cygwin)
  1757. AC_MSG_RESULT(Win32/Cygwin)
  1758. AC_DEFINE([HAVE_CYGWIN], [1], [Building Cygwin])
  1759. ;;
  1760. *)
  1761. AC_MSG_RESULT([$host is unknown!])
  1762. ;;
  1763. esac
  1764. AM_CONDITIONAL([ENABLE_OSX_FRAMEWORKS], test "$osx_frameworks" = "yes")
  1765. AC_ARG_WITH(testnic2,
  1766. AS_HELP_STRING([--with-testnic2=NIC2],[Select an optional 2nd network card to use for testing]),
  1767. [ nic2=$withval ])
  1768. AC_MSG_NOTICE([Using $nic1 for 1st test network interface card])
  1769. AC_MSG_NOTICE([Using $nic2 for 2nd test network interface card])
  1770. AC_SUBST(nic1)
  1771. AC_SUBST(nic2)
  1772. AC_MSG_CHECKING([if it's ok to use pcap_findalldevs()])
  1773. if test x$disable_pcap_findalldevs = xno ; then
  1774. AC_DEFINE([ENABLE_PCAP_FINDALLDEVS], [1], [Enable use of pcap_findalldevs()])
  1775. AC_MSG_RESULT(yes)
  1776. else
  1777. AC_MSG_RESULT(no)
  1778. fi
  1779. LIBOPTS_CHECK(libopts)
  1780. AC_CONFIG_FILES([Makefile
  1781. doxygen.cfg
  1782. lib/Makefile
  1783. docs/Makefile
  1784. src/Makefile
  1785. src/tcpedit/Makefile
  1786. src/fragroute/Makefile
  1787. src/common/Makefile
  1788. src/defines.h
  1789. test/Makefile
  1790. test/config
  1791. scripts/Makefile])
  1792. AC_OUTPUT
  1793. # Configuration results
  1794. AC_MSG_RESULT([
  1795. ##########################################################################
  1796. TCPREPLAY Suite Configuration Results (${TCPREPLAY_VERSION})
  1797. ##########################################################################
  1798. libpcap: ${foundpcap} (${libpcap_version})
  1799. PF_RING libpcap ${pf_ring_found} ${pf_ring_lib}
  1800. libdnet: ${founddnet} ${libdnet_version}
  1801. autogen: ${AUTOGEN} (${AUTOGEN_VERSION})
  1802. Use libopts tearoff: ${enable_local_libopts}
  1803. 64bit counter support: ${use64bit_counters}
  1804. tcpdump binary path: ${tcpdump_path}
  1805. fragroute support: ${enable_fragroute}
  1806. tcpbridge support: ${enable_tcpbridge}
  1807. tcpliveplay support: ${enable_tcpliveplay}
  1808. Supported Packet Injection Methods (*):
  1809. Linux TX_RING: ${have_tx_ring}
  1810. Linux PF_PACKET: ${have_pf}
  1811. BSD BPF: ${have_bpf}
  1812. libdnet: ${have_libdnet}
  1813. pcap_inject: ${have_pcap_inject}
  1814. pcap_sendpacket: ${have_pcap_sendpacket} **
  1815. pcap_netmap ${have_pcap_netmap}
  1816. Linux/BSD netmap: ${have_netmap}
  1817. Tuntap device support: ${have_tuntap}
  1818. LIBXDP for AF_XDP socket: ${have_libxdp}
  1819. * In order of preference; see configure --help to override
  1820. ** Required for tcpbridge
  1821. ])
  1822. case $host in
  1823. *-*-cygwin)
  1824. AC_MSG_WARN([Windows/Cygwin support is still somewhat experimental.
  1825. Please report any bugs! https://github.com/appneta/tcpreplay/issues])
  1826. ;;
  1827. esac