configure.ac 61 KB

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