configure.in 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. dnl $Id: configure.in 1857 2007-05-02 05:07:52Z aturner $
  2. AC_INIT(tcpreplay)
  3. AC_CONFIG_SRCDIR(src/tcpreplay.c)
  4. AM_CONFIG_HEADER(src/config.h)
  5. AC_CONFIG_AUX_DIR(config)
  6. AM_MAINTAINER_MODE
  7. AM_WITH_DMALLOC
  8. dnl Set version info here!
  9. MAJOR_VERSION=3
  10. MINOR_VERSION=0
  11. MICRO_VERSION=1
  12. TCPREPLAY_VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
  13. dnl Release is only used for the RPM spec file
  14. TCPREPLAY_RELEASE=1
  15. AC_DEFINE(PACKAGE, [tcpreplay], [This is our package name])
  16. AC_DEFINE_UNQUOTED(VERSION, "$TCPREPLAY_VERSION", [What is our version?])
  17. AC_SUBST(TCPREPLAY_VERSION)
  18. AC_SUBST(TCPREPLAY_RELEASE)
  19. USER_CFLAGS=$CFLAGS
  20. CFLAGS="${CFLAGS} -Wall -O3 -std=gnu99"
  21. dnl Determine OS
  22. AC_CANONICAL_BUILD
  23. AC_CANONICAL_HOST
  24. AC_CANONICAL_TARGET
  25. AC_SUBST(host)
  26. AC_SUBST(build)
  27. AC_SUBST(target)
  28. AC_MSG_CHECKING([for cygwin development environment])
  29. if test `echo $target | grep -c cygwin` -gt 0 ; then
  30. AC_DEFINE([HAVE_WIN32], [1], [Windows/Cygwin])
  31. AC_MSG_RESULT(yes)
  32. else
  33. AC_MSG_RESULT(no)
  34. fi
  35. AM_INIT_AUTOMAKE(tcpreplay, $TCPREPLAY_VERSION, nodefine)
  36. dnl Checks for programs.
  37. AC_PROG_INSTALL
  38. AC_PROG_LIBTOOL
  39. AC_PROG_CC
  40. AC_PROG_CC_STDC
  41. AC_PROG_CXX
  42. AC_PROG_CPP
  43. AC_PROG_LN_S
  44. AC_PROG_RANLIB
  45. AC_PROG_AWK
  46. AC_PROG_SED
  47. AC_PROG_MAKE_SET
  48. AC_EXEEXT
  49. AC_PATH_PROG(PRINTF, printf)
  50. AC_PATH_PROG(AUTOGEN, autogen)
  51. dnl check autogen version
  52. if test -n "${AUTOGEN}" ; then
  53. AC_MSG_CHECKING(for autogen version >= 5.9)
  54. AUTOGEN_VERSION=`${AUTOGEN} -v | ${SED} 's|.*\([[0-9\.]]\{3,\}\)$|\1|'`
  55. AUTOGEN_MAJOR=`echo ${AUTOGEN_VERSION} | ${SED} 's|^\([[0-9]]\)\.[[0-9]]|\1|'`
  56. AUTOGEN_MINOR=`echo ${AUTOGEN_VERSION} | ${SED} 's|^\([[0-9]]\)\.\([[0-9]]\)|\2|'`
  57. if test ${AUTOGEN_MAJOR} -le 5 && test ${AUTOGEN_MINOR} -lt 9 || test ${AUTOGEN_MAJOR} -lt 5 ; then
  58. AC_MSG_RESULT(no)
  59. AC_MSG_WARN([${AUTOGEN} is too old (${AUTOGEN_VERSION}) for building from SVN. Please upgrade to 5.9)])
  60. else
  61. AC_MSG_RESULT(yes)
  62. fi
  63. else
  64. AC_MSG_WARN([Please install autogen >= 5.9 if you are building from SVN])
  65. fi
  66. AC_HEADER_STDC
  67. AC_HEADER_MAJOR
  68. dnl Checks for typedefs, structures, and compiler characteristics.
  69. AC_TYPE_SIZE_T
  70. AC_HEADER_TIME
  71. AC_C_CONST
  72. AC_C_INLINE
  73. AC_SYS_LARGEFILE
  74. dnl Check for functions
  75. AC_FUNC_FSEEKO
  76. dnl Check for types.
  77. AC_CHECK_TYPE(u_int8_t, uint8_t)
  78. AC_CHECK_TYPE(u_int16_t, uint16_t)
  79. AC_CHECK_TYPE(u_int32_t, uint32_t)
  80. AC_CHECK_TYPE(u_int64_t, uint64_t)
  81. dnl Older versions of GCC don't support these options
  82. AC_MSG_CHECKING(for $CC -Wextra support)
  83. OLD_CFLAGS=$CFLAGS
  84. CFLAGS="$CFLAGS -Wextra"
  85. wextra=""
  86. AC_COMPILE_IFELSE([#include <stdlib.h>
  87. int main(int argc, char *argv[]) { return(0); }],
  88. [ AC_MSG_RESULT(yes)
  89. wextra="-Wextra" ],
  90. [ AC_MSG_RESULT(no) ])
  91. CFLAGS="$OLD_CFLAGS $wextra"
  92. AC_MSG_CHECKING(for $CC -Wno-variadic-macros support)
  93. OLD_CFLAGS=$CFLAGS
  94. CFLAGS="$CFLAGS -Wno-variadic-macros"
  95. wno_variadic_macros=""
  96. AC_COMPILE_IFELSE([#include <stdlib.h>
  97. int main(int argc, char *argv[]) { return(0); }],
  98. [ AC_MSG_RESULT(yes)
  99. wno_variadic_macros="-Wno-variadic-macros" ],
  100. [ AC_MSG_RESULT(no) ])
  101. CFLAGS="$OLD_CFLAGS $wno_variadic_macros"
  102. AC_MSG_CHECKING(for $CC -Wfatal-errors support)
  103. OLD_CFLAGS=$CFLAGS
  104. CFLAGS="$CFLAGS -Wfatal-errors"
  105. wfatal_errors=""
  106. AC_COMPILE_IFELSE([#include <stdlib.h>
  107. int main(int argc, char *argv[]) { return(0); }],
  108. [ AC_MSG_RESULT(yes)
  109. wfatal_errors="-Wfatal-errors" ],
  110. [ AC_MSG_RESULT(no) ])
  111. CFLAGS="$OLD_CFLAGS $wfatal_errors"
  112. dnl Check for other header files
  113. AC_CHECK_HEADERS([fcntl.h stddef.h sys/socket.h arpa/inet.h sys/time.h signal.h string.h strings.h sys/types.h sys/select.h netinet/in.h poll.h sys/poll.h unistd.h sys/param.h])
  114. dnl OpenBSD has special requirements
  115. AC_CHECK_HEADERS([sys/sysctl.h net/route.h], [], [], [
  116. [#if HAVE_SYS_PARAM_H
  117. #include <sys/param.h>
  118. #endif
  119. #if HAVE_SYS_TYPES_H
  120. #include <sys/types.h>
  121. #endif
  122. #if HAVE_SYS_SOCKET_H
  123. #include <sys/socket.h>
  124. #endif
  125. ]])
  126. dnl Checks for libraries.
  127. AC_CHECK_LIB(socket, socket)
  128. AC_CHECK_LIB(nsl, gethostbyname)
  129. AC_CHECK_LIB(rt, nanosleep)
  130. dnl Checks for library functions.
  131. AC_FUNC_MALLOC
  132. AC_FUNC_MEMCMP
  133. AC_TYPE_SIGNAL
  134. AC_FUNC_VPRINTF
  135. AC_CHECK_MEMBERS([struct timeval.tv_sec])
  136. AC_CHECK_FUNCS([gettimeofday ctime memset regcomp strdup strchr strerror strtol strncpy strtoull poll ntohll mmap snprintf vsnprintf])
  137. dnl Look for strlcpy since some BSD's have it
  138. AC_CHECK_FUNCS([strlcpy],have_strlcpy=true,have_strlcpy=false)
  139. AM_CONDITIONAL(SYSTEM_STRLCPY, [test x$have_strlcpy = xtrue])
  140. AC_C_BIGENDIAN
  141. AM_CONDITIONAL([WORDS_BIGENDIAN], [ test x$ac_cv_c_bigendian = xyes ])
  142. dnl Enable debugging in code/compiler options
  143. debug=no
  144. AC_ARG_ENABLE(debug,
  145. AC_HELP_STRING([--enable-debug], [Enable debugging code and support for the -d option]),
  146. [ if test x$enableval = xyes; then
  147. debug=yes
  148. CFLAGS="${USER_CFLAGS} -ggdb -std=gnu99 -Wall $wextra $wfatal_errors $wno_variadic_macros"
  149. # We may also want to add:
  150. # -Wformat-security -Wswitch-default -Wunused-paramter -Wpadded"
  151. AC_SUBST(debug_flag)
  152. AC_DEFINE([DEBUG], [1], [Enable debuging code and support for the -d option])
  153. fi])
  154. AC_ARG_ENABLE(pedantic,
  155. AC_HELP_STRING([--enable-pedantic], [Enable gcc's -pedantic option]),
  156. [ if test x$enableval = xyes; then
  157. CFLAGS="$CFLAGS -pedantic"
  158. fi ])
  159. dnl Enable Efense
  160. AC_ARG_ENABLE(efence,
  161. AC_HELP_STRING([--enable-efence], [Enable Electric Fence memory debugger]),
  162. [ if test x$enableval = xyes; then
  163. CFLAGS="$CFLAGS -lefence"
  164. AC_DEFINE([EFENCE], [1], [Enable Electric Fence memory debugger])
  165. fi])
  166. dnl Enable Gprof
  167. AC_ARG_ENABLE(gprof,
  168. AC_HELP_STRING([--enable-gprof], [Enable GNU Profiler]),
  169. [ if test x$enableval = xyes; then
  170. if test $debug = yes; then
  171. CFLAGS="$CFLAGS -pg"
  172. else
  173. # GPROF requires gdb
  174. CFLAGS="$CFLAGS -ggdb -pg -fprofile-arcs"
  175. fi
  176. AC_DEFINE([GPROF], [1], [Enable GNU Profiler])
  177. fi])
  178. dnl Use 64bits for packet counters
  179. AC_ARG_ENABLE(64bits,
  180. AC_HELP_STRING([--enable-64bits], [Use 64bit packet counters]),
  181. [ if test x$enableval = xyes; then
  182. AC_DEFINE([ENABLE_64BITS], [1], [Use 64bit packet counters])
  183. AC_MSG_NOTICE([Using u_int64_t for packet counters])
  184. else
  185. AC_MSG_NOTICE([Using u_int32_t for packet counters])
  186. fi
  187. ])
  188. AC_ARG_ENABLE(force-bpf,
  189. AC_HELP_STRING([--enable-force-bpf], [Force using BPF for sending packets]),
  190. [ AC_DEFINE([FORCE_INJECT_BPF], [1], [Force using BPF for sending packet])])
  191. AC_ARG_ENABLE(force-pf,
  192. AC_HELP_STRING([--enable-force-pf], [Force using Linux's PF_PACKET for sending packets]),
  193. [ AC_DEFINE([FORCE_INJECT_PF], [1], [Force using Linux's PF_PACKET for sending packets])])
  194. AC_ARG_ENABLE(force-libnet,
  195. AC_HELP_STRING([--enable-force-libnet], [Force using libnet for sending packets]),
  196. [ AC_DEFINE([FORCE_INJECT_LIBNET], [1], [Force using libnet for sending packets])])
  197. AC_ARG_ENABLE(force-inject,
  198. AC_HELP_STRING([--enable-force-inject], [Force using libpcap's pcap_inject() for sending packets]),
  199. [ AC_DEFINE([FORCE_INJECT_PCAP_INJECT],[1], [Force using libpcap's pcap_inject() for sending packets])])
  200. AC_ARG_ENABLE(force-sendpacket,
  201. AC_HELP_STRING([--enable-force-sendpacket], [Force using libpcap's pcap_sendpacket() for sending packets]),
  202. [ AC_DEFINE([FORCE_INJECT_PCAP_SENDPACKET], [1], [Force using libpcap's pcap_sendpacket() for sending packets])])
  203. tcpreplay_edit=no
  204. AC_ARG_ENABLE(tcpreplay-edit,
  205. AC_HELP_STRING([--enable-tcpreplay-edit], [Link packet editing code with tcpreplay]),
  206. [ AC_DEFINE([TCPREPLAY_EDIT], [1], [Link packet editing code with tcpreplay])
  207. tcpreplay_edit=yes
  208. ])
  209. AM_CONDITIONAL([ENABLE_TCPREPLAY_EDIT], [test x$tcpreplay_edit = xyes])
  210. dnl Dynamic link libraries
  211. dynamic_link=no
  212. AC_ARG_ENABLE(dynamic-link,
  213. AC_HELP_STRING([--enable-dynamic-link], [Dynamically link libraries]),
  214. [ if test x$enableval = xyes; then
  215. AC_DEFINE([ENABLE_DYNAMIC_LINK], [1], [Enable dynamically linking libs])
  216. dynamic_link=yes
  217. fi
  218. ])
  219. dnl Check for inet_aton and inet_pton
  220. AC_CHECK_FUNC(inet_aton,
  221. AC_DEFINE([HAVE_INET_ATON], [1], [Do we have inet_aton?])
  222. inet_aton=yes,
  223. inet_aton=no)
  224. AC_CHECK_FUNC(inet_pton,
  225. AC_DEFINE([HAVE_INET_PTON], [1], [Do we have inet_pton?])
  226. inet_pton=yes,
  227. inet_pton=no)
  228. AC_CHECK_FUNC(inet_ntop,
  229. AC_DEFINE([HAVE_INET_NTOP], [1], [Do we have inet_ntop?])
  230. inet_ntop=yes,
  231. inet_ntop=no)
  232. if test "$inet_ntop" = "no" -a "$inet_pton" = "no" ; then
  233. AC_MSG_ERROR([We need either inet_ntop or inet_pton])
  234. fi
  235. if test "$inet_aton" = "no" ; then
  236. AC_MSG_ERROR([We need inet_aton])
  237. fi
  238. AC_CHECK_FUNC(inet_addr,
  239. AC_DEFINE([HAVE_INET_ADDR], [1], [Do we have inet_addr?])
  240. inet_addr=yes,
  241. inet_addr=no)
  242. if test x$inet_addr = no ; then
  243. AC_MSG_ERROR([We need inet_addr. See bug 26])
  244. fi
  245. dnl Enable flowreplay
  246. flowreplay=no
  247. AC_ARG_ENABLE(flowreplay,
  248. AC_HELP_STRING([--enable-flowreplay], [Enable building flowreplay (alpha)]),
  249. [ if test x$enableval = xyes; then
  250. flowreplay=yes
  251. AC_DEFINE([ENABLE_FLOWREPLAY], [1], [Enable building flowreplay (alpha)])
  252. fi])
  253. AM_CONDITIONAL([ENABLE_FLOWREPLAY], [test x$flowreplay = xyes])
  254. dnl ##################################################
  255. dnl Checks for libnet IFF you specify --enable-libnet.
  256. dnl We no longer by default use libnet unless you tell me to.
  257. dnl ##################################################
  258. foundnet=no
  259. trynetdir=no
  260. have_libnet=no
  261. use_libnet=no
  262. AC_ARG_ENABLE(libnet,
  263. AC_HELP_STRING([--enable-libnet], [Enable using the libnet 1.1.x library (deprecated)]),
  264. [ if test x$enableval = xyes; then
  265. use_libnet=yes
  266. AC_MSG_WARN([Due to bugs in libnet, it is no longer officially supported])
  267. fi]
  268. )
  269. AC_ARG_WITH(libnet,
  270. AC_HELP_STRING([--with-libnet=DIR], [Use libnet in DIR]),
  271. [trynetdir=$withval])
  272. if test x$use_libnet = xyes ; then
  273. AC_MSG_CHECKING(for libnet)
  274. for testdir in $trynetdir /usr/local /opt/local /usr ; do
  275. if test -f "${testdir}/include/libnet.h" -a $foundnet = no ; then
  276. LNETINC="${testdir}/include/libnet.h"
  277. LNETINCDIR="${testdir}/include"
  278. if test $dynamic_link = yes; then
  279. if test -f "${testdir}/lib64/libnet.a" ; then
  280. LNETLIB="-L${testdir}/lib64 -lnet"
  281. elif test -f "${testdir}/lib/libnet.a" ; then
  282. LNETLIB="-L${testdir}/lib -lnet"
  283. else
  284. AC_ERROR([Unable to find libnet in ${testdir}])
  285. fi
  286. elif test -f "${testdir}/lib64/libnet.a" ; then
  287. LNETLIB="${testdir}/lib64/libnet.a"
  288. elif test -f "${testdir}/lib/libnet.a" ; then
  289. LNETLIB="${testdir}/lib/libnet.a"
  290. else
  291. AC_ERROR([Unable to find matching library for header file in ${testdir}])
  292. fi
  293. foundnet=$testdir
  294. fi
  295. done
  296. if test x$foundnet = xno ; then
  297. AC_MSG_RESULT(no)
  298. else
  299. AC_MSG_RESULT($foundnet)
  300. have_libnet=yes
  301. AC_DEFINE([HAVE_LIBNET], [1], [Enable libnet support])
  302. fi
  303. fi
  304. AC_SUBST(LNETINC)
  305. AC_SUBST(LNETLIB)
  306. if test $foundnet != no ; then
  307. OLDLIBS="$LIBS"
  308. OLDCFLAGS="$CFLAGS"
  309. LIBS="$LNETLIB"
  310. CFLAGS="$CFLAGS -I$LNETINCDIR"
  311. dnl Check to see what version of libnet
  312. dnl this code has been reduced a lot, but probably still could be
  313. dnl reduced quite a bit more if we chose too
  314. AC_MSG_CHECKING(for libnet version)
  315. AC_TRY_RUN([
  316. #include <string.h>
  317. #define LIBNET_LIL_ENDIAN 1
  318. #include "$LNETINC"
  319. #define LIB_TEST "1.0"
  320. /*
  321. * simple proggy to test the version of libnet
  322. * returns zero if it's 1.0.x
  323. * or one otherwise
  324. */
  325. int
  326. main (int argc, char *argv[])
  327. {
  328. if (strncmp(LIB_TEST, LIBNET_VERSION, 3) == 0)
  329. exit(0);
  330. exit(1);
  331. }],
  332. libnet_ver_10=yes
  333. AC_MSG_RESULT(1.0.x),
  334. libnet_ver_10=no,
  335. libnet_ver_10=no
  336. )
  337. AC_TRY_RUN([
  338. #include <string.h>
  339. #include "$LNETINC"
  340. #define LIB_TEST "1.1"
  341. /*
  342. * simple proggy to test the version of libnet
  343. * returns zero if it's 1.0.x
  344. * or one otherwise
  345. */
  346. int
  347. main (int argc, char *argv[])
  348. {
  349. if (strncmp(LIB_TEST, LIBNET_VERSION, 3) == 0)
  350. exit(0);
  351. exit(1);
  352. }],
  353. libnet_ver_11=yes
  354. AC_MSG_RESULT(1.1.x),
  355. libnet_ver_11=no,
  356. libnet_ver_11=no
  357. )
  358. if test $libnet_ver_10 = no -a $libnet_ver_11 = no ; then
  359. AC_MSG_RESULT(unknown)
  360. AC_MSG_ERROR(Unable to determine version of libnet)
  361. fi
  362. if test $libnet_ver_10 = yes ; then
  363. AC_MSG_ERROR(Libnet version 1.0.x is no longer supported.
  364. Please upgrade to 1.1.0 or better)
  365. fi
  366. dnl restore LIBS & CFLAGS
  367. LIBS="$OLDLIBS"
  368. CFLAGS="$OLDCFLAGS"
  369. fi
  370. dnl END OF if test $foundnet = yes
  371. dnl #####################################################
  372. dnl Checks for libpcap
  373. dnl #####################################################
  374. foundpcap=no
  375. trypcapdir=/usr/local
  376. AC_MSG_CHECKING(for libpcap)
  377. AC_ARG_WITH(libpcap,
  378. AC_HELP_STRING([--with-libpcap=DIR], [Use libpcap in DIR]),
  379. [trypcapdir=$withval])
  380. for testdir in $trypcapdir /usr/local /opt/local /usr ; do
  381. if test -f "${testdir}/include/pcap.h" -a $foundpcap = no ; then
  382. LPCAPINC="${testdir}/include/pcap.h"
  383. LPCAPINCDIR="${testdir}/include"
  384. if test $dynamic_link = yes; then
  385. if test -f "${testdir}/lib64/libpcap.a" ; then
  386. LPCAPLIB="-L${testdir}/lib64 -lpcap"
  387. elif test -f "${testdir}/lib/libpcap.a" ; then
  388. LPCAPLIB="-L${testdir}/lib -lpcap"
  389. else
  390. AC_ERROR([Unable to find libpcap in ${testdir}])
  391. fi
  392. elif test -f "${testdir}/lib64/libpcap.a" ; then
  393. LPCAPLIB="${testdir}/lib64/libpcap.a"
  394. elif test -f "${testdir}/lib/libpcap.a" ; then
  395. LPCAPLIB="${testdir}/lib/libpcap.a"
  396. elif test -f "${testdir}/lib/libwpcap.a" ; then
  397. LPCAPLIB="${testdir}/lib/libwpcap.a"
  398. AC_DEFINE([HAVE_WINPCAP], [1], [Do we have WinPcap?])
  399. else
  400. AC_ERROR([Unable to find matching library for header file in ${testdir}])
  401. fi
  402. foundpcap=$testdir
  403. fi
  404. done
  405. if test $foundpcap = no ; then
  406. AC_MSG_RESULT(no)
  407. AC_ERROR(libpcap not found)
  408. else
  409. AC_MSG_RESULT($foundpcap)
  410. fi
  411. AC_SUBST(LPCAPINC)
  412. AC_SUBST(LPCAPLIB)
  413. dnl Checks to see what version of libpcap we've got
  414. OLDLIBS="$LIBS"
  415. OLDCFLAGS="$CFLAGS -I$LPCAPINCDIR"
  416. LIBS="$LPCAPLIB"
  417. CFLAGS="$CFLAGS -I$LPCAPINCDIR"
  418. dnl Check to see what version of libpcap
  419. dnl this code has been reduced a lot, but probably still could be
  420. dnl reduced quite a bit more if we chose too
  421. AC_MSG_CHECKING(for libpcap version)
  422. AC_RUN_IFELSE(AC_LANG_PROGRAM([[
  423. #include <string.h>
  424. #include <stdlib.h>
  425. #include <stdio.h>
  426. #include "$LPCAPINC"
  427. #define PCAP_TEST "0.8"
  428. ]], [[
  429. /*
  430. * simple proggy to test the version of libpcap
  431. * returns zero if version >= 0.8.0
  432. * or one otherwise
  433. */
  434. if (strncmp(pcap_lib_version(), PCAP_TEST, 3) >= 0)
  435. exit(0);
  436. /* winpcap? */
  437. if (strncmp(pcap_lib_version(), "WinPcap", 7) == 0)
  438. exit(0);
  439. exit(1);
  440. ]]), [
  441. libpcap_ver8=yes
  442. ], [
  443. libpcap_ver8=no
  444. ])
  445. AC_RUN_IFELSE(AC_LANG_PROGRAM([[
  446. #include <string.h>
  447. #include <stdlib.h>
  448. #include <stdio.h>
  449. #include "$LPCAPINC"
  450. #define PCAP_TEST "0.7.2"
  451. extern const char pcap_version[[]]; /* double up since autoconf escapes things */
  452. ]], [[
  453. /*
  454. * simple proggy to test the version of libpcap
  455. * returns zero if version >= 0.7.2
  456. * or one otherwise
  457. */
  458. if (strncmp(pcap_version, PCAP_TEST, 5) >= 0)
  459. exit(0);
  460. exit(1);
  461. ]]), [
  462. libpcap_ver7=yes
  463. ], [
  464. libpcap_ver7=no
  465. ])
  466. if test $libpcap_ver8 = yes ; then
  467. AC_MSG_RESULT(>= 0.8.0)
  468. elif test $libpcap_ver7 = yes ; then
  469. AC_MSG_RESULT(>= 0.7.2)
  470. else
  471. AC_MSG_ERROR([Libpcap versions < 0.7.2 are not supported
  472. Please upgrade to version 0.7.2 or better])
  473. fi
  474. dnl Check to see if we've got pcap_datalink_val_to_name()
  475. AC_MSG_CHECKING(for pcap_datalink_val_to_description)
  476. AC_LINK_IFELSE(AC_LANG_PROGRAM([[
  477. #include <stdio.h>
  478. #include <stdlib.h>
  479. #include <string.h>
  480. #include "$LPCAPINC"
  481. ]],[[
  482. if (strcmp(pcap_datalink_val_to_description(1), "Ethernet (10Mb)") == 0)
  483. exit(0);
  484. exit(1);
  485. ]]),[
  486. have_dlt_to_desc=yes
  487. AC_MSG_RESULT(yes)
  488. ], [
  489. have_dlt_to_desc=no
  490. AC_MSG_RESULT(no)
  491. ])
  492. if test $have_dlt_to_desc = yes ; then
  493. AC_DEFINE([HAVE_DLT_VAL_TO_DESC], [1],
  494. [Does libpcap have dlt_val_to_desc?])
  495. fi
  496. dnl Check to see if we've got pcap_dump_fopen()
  497. AC_MSG_CHECKING(for pcap_dump_fopen)
  498. AC_LINK_IFELSE(AC_LANG_PROGRAM([[
  499. #include <stdio.h>
  500. #include <stdlib.h>
  501. #include <string.h>
  502. #include "$LPCAPINC"
  503. ]],[[
  504. pcap_dumper_t *dump;
  505. pcap_t *pcap;
  506. FILE *foo;
  507. dump = pcap_dump_fopen(pcap, foo);
  508. ]]),[
  509. have_pcap_dump_fopen=yes
  510. AC_MSG_RESULT(yes)
  511. ], [
  512. have_pcap_dump_fopen=no
  513. AC_MSG_RESULT(no)
  514. ])
  515. if test $have_pcap_dump_fopen = yes ; then
  516. AC_DEFINE([HAVE_PCAP_DUMP_FOPEN], [1],
  517. [Does libpcap have pcap_dump_fopen?])
  518. else
  519. AC_MSG_NOTICE([--verbose mode requires libpcap >= 0.9.0])
  520. fi
  521. have_pcap_inject=no
  522. dnl Check to see if we've got pcap_inject()
  523. AC_MSG_CHECKING(for pcap_inject sending support)
  524. AC_TRY_COMPILE([
  525. #include <stdio.h>
  526. #include <stdlib.h>
  527. #include <string.h>
  528. #include "$LPCAPINC"
  529. ],[
  530. pcap_t *pcap;
  531. char *buf;
  532. pcap_inject(pcap, (void *)buf, 0);
  533. ],[
  534. AC_DEFINE([HAVE_PCAP_INJECT], [1],
  535. [Does libpcap have pcap_inject?])
  536. AC_MSG_RESULT(yes)
  537. have_pcap_inject=yes
  538. ],[
  539. AC_MSG_RESULT(no)
  540. ])
  541. have_pcap_version=no
  542. dnl Check to see if we have pcap_version[]
  543. AC_MSG_CHECKING(for pcap_version[])
  544. AC_TRY_COMPILE([
  545. #include <stdio.h>
  546. #include <stdlib.h>
  547. #include <string.h>
  548. #include "$LPCAPINC"
  549. extern char pcap_version[];
  550. ],[
  551. printf("%s", pcap_version);
  552. ],[
  553. AC_DEFINE([HAVE_PCAP_VERSION],[1], [Does libpcap have pcap_version[]])
  554. AC_MSG_RESULT(yes)
  555. ],[
  556. AC_MSG_RESULT(no)
  557. ])
  558. have_pcap_sendpacket=no
  559. dnl Check to see if we've got pcap_sendpacket()
  560. AC_MSG_CHECKING(for pcap_sendpacket sending support)
  561. AC_TRY_COMPILE([
  562. #include <stdio.h>
  563. #include <stdlib.h>
  564. #include <string.h>
  565. #include "$LPCAPINC"
  566. ],[
  567. pcap_t *pcap;
  568. u_char *buf;
  569. pcap_sendpacket(pcap, buf, 0);
  570. ],[
  571. AC_DEFINE([HAVE_PCAP_SENDPACKET], [1],
  572. [Does libpcap have pcap_sendpacket?])
  573. AC_MSG_RESULT(yes)
  574. have_pcap_sendpacket=yes
  575. ],[
  576. AC_MSG_RESULT(no)
  577. ])
  578. have_pf=no
  579. dnl Check for linux PF_PACKET support
  580. AC_MSG_CHECKING(for PF_PACKET socket sending support)
  581. AC_TRY_COMPILE([
  582. #include <sys/socket.h>
  583. #include <netpacket/packet.h>
  584. #include <net/ethernet.h> /* the L2 protocols */
  585. #include <netinet/in.h> /* htons */
  586. ],[
  587. int pf_socket;
  588. pf_socket = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  589. ],[
  590. AC_DEFINE([HAVE_PF_PACKET], [1],
  591. [Do we have Linux PF_PACKET socket support?])
  592. AC_MSG_RESULT(yes)
  593. have_pf=yes
  594. ],[
  595. AC_MSG_RESULT(no)
  596. ])
  597. have_bpf=no
  598. dnl Check for BSD's BPF
  599. AC_MSG_CHECKING(for BPF device sending support)
  600. AC_TRY_RUN([
  601. #include <stdio.h>
  602. #include <stdlib.h>
  603. #include <net/bpf.h>
  604. #include <sys/types.h>
  605. #include <sys/socket.h>
  606. #include <fcntl.h>
  607. #include <sys/time.h>
  608. #include <sys/ioctl.h>
  609. #include <net/bpf.h>
  610. #include <errno.h>
  611. int
  612. main(int argc, char *argv[]) {
  613. int fd;
  614. fd = open("/dev/bpf0", O_RDONLY, 0);
  615. /* if we opened it, we're good */
  616. if (fd > 1)
  617. exit(0);
  618. /* if we got EBUSY or permission denied it exists, so we're good */
  619. if (fd < 0 && (errno == EBUSY || errno == 13))
  620. exit(0);
  621. /* else suck, no good */
  622. exit(-1);
  623. }],
  624. [
  625. AC_DEFINE([HAVE_BPF], [1],
  626. [Do we have BPF device support?])
  627. AC_MSG_RESULT(yes)
  628. have_bpf=yes
  629. ],[
  630. AC_MSG_RESULT(no)
  631. ])
  632. dnl Make sure we have a valid packet injection mechanisim
  633. if test $have_bpf = no -a $have_pcap_inject = no -a $have_pcap_sendpacket = no \
  634. -a $have_libnet = no -a $have_pf = no ; then
  635. AC_MSG_ERROR([Unable to find a supported method to send packets. Please upgrade your libpcap or enable libnet])
  636. fi
  637. dnl Libpcap support doesn't give us a method to get the hardware address of the
  638. dnl interfaces which prevents us from doing proper filtering to prevent bridging loops
  639. enable_tcpbridge=yes
  640. if test $have_bpf = no -a $have_libnet = no -a $have_pf = no ; then
  641. AC_MSG_NOTICE([tcpbridge support disabled without BPF, Libnet or Linux PF_PACKET])
  642. enable_tcpbridge=no
  643. fi
  644. # ADT: Commented for now
  645. # AM_CONDITIONAL(ENABLE_TCPBRIDGE, [test $enable_tcpbridge = yes])
  646. dnl Older versions of libpcap are missing some DLT types
  647. dnl If doesn't exist, we'll define them in src/common/fakepcap.h
  648. AC_MSG_CHECKING(for DLT_LINUX_SLL in libpcap)
  649. AC_TRY_COMPILE([#include "$LPCAPINC"],
  650. [ int foo;
  651. foo = DLT_LINUX_SLL ],
  652. [ AC_DEFINE([HAVE_DLT_LINUX_SLL], [1],
  653. [Does pcap.h include a header with DLT_LINUX_SLL?])
  654. AC_MSG_RESULT(yes)
  655. ],
  656. AC_MSG_RESULT(no)
  657. )
  658. AC_MSG_CHECKING(for DLT_C_HDLC in libpcap)
  659. AC_TRY_COMPILE([#include "$LPCAPINC"],
  660. [ int foo;
  661. foo = DLT_C_HDLC ],
  662. [ AC_DEFINE([HAVE_DLT_C_HDLC], [1],
  663. [Does pcap.h include a header with DLT_C_HDLC?])
  664. AC_MSG_RESULT(yes)
  665. ],
  666. AC_MSG_RESULT(no)
  667. )
  668. PCAP_BPF_H_FILE="$LPCAPINCDIR/pcap-bpf.h"
  669. AC_MSG_CHECKING(for $PCAP_BPF_H_FILE)
  670. AC_TRY_COMPILE([#include <sys/types.h>
  671. #include <sys/time.h>
  672. #include "$PCAP_BPF_H_FILE"],
  673. [ int foo;
  674. foo = BPF_MAJOR_VERSION; ],
  675. [ AC_DEFINE([INCLUDE_PCAP_BPF_HEADER], [1],
  676. [What is the path (if any) to the pcap-bpf.h
  677. header?])
  678. AC_MSG_RESULT(yes)
  679. AC_SUBST(PCAP_BPF_H_FILE)
  680. ],
  681. AC_MSG_RESULT(no)
  682. )
  683. foundbpfheader=no
  684. AC_MSG_CHECKING(for libpcap bpf header)
  685. for testfile in $LPCAPINCDIR/pcap/bpf.h $LPCAPINCDIR/pcap-bpf.h ; do
  686. if test -f "${testfile}" -a $foundbpfheader = no ; then
  687. AC_TRY_COMPILE([
  688. #include <sys/types.h>
  689. #include <sys/time.h>
  690. #include "$testfile"],
  691. [
  692. int foo;
  693. foo = BPF_MAJOR_VERSION;
  694. ],
  695. [
  696. foundbpfheader=yes
  697. PCAP_BPF_H_FILE=$testfile
  698. AC_SUBST(PCAP_BPF_H_FILE)
  699. AC_DEFINE([INCLUDE_PCAP_BPF_HEADER], [1],
  700. [What is the path (if any) to the libpcap bpf header file?])
  701. AC_MSG_RESULT($testfile)
  702. ],
  703. AC_MSG_RESULT(no)
  704. )
  705. fi
  706. done
  707. dnl restore LIBS & CFLAGS
  708. LIBS="$OLDLIBS"
  709. CFLAGS="$OLDCFLAGS"
  710. dnl ##################################################
  711. dnl # Check for pcapnav
  712. dnl ##################################################
  713. pcapnav_ver=no
  714. pcncfg=no
  715. AC_ARG_WITH(pcapnav-config,
  716. AC_HELP_STRING([--with-pcapnav-config=FILE], [Use given pcapnav-config]),
  717. [ AC_MSG_CHECKING(for pcapnav-config)
  718. if test -x $withval ; then
  719. pcncfg=$withval
  720. AC_MSG_RESULT($pcncfg)
  721. elif test x$withval = xno ; then
  722. AC_MSG_RESULT(no)
  723. else
  724. AC_MSG_RESULT([Can't find pcapnav-config: disabling offset jump feature])
  725. fi ],
  726. [ AC_PATH_PROG(pcncfg,[pcapnav-config], [no] ) ]
  727. )
  728. if test $pcncfg != no ; then
  729. LNAVLIB=`$pcncfg --libs`
  730. LNAV_CFLAGS=`$pcncfg --cflags`
  731. PCAPNAV_VERSION=`$pcncfg --version`
  732. AC_SUBST(LNAVLIB)
  733. AC_SUBST(LNAV_CFLAGS)
  734. AC_DEFINE_UNQUOTED(PCAPNAV_VERSION, "$PCAPNAV_VERSION",
  735. [libpcapnav's version?])
  736. dnl Check to see what version of libpcapnav
  737. dnl this code has been reduced a lot, but probably still could be
  738. dnl reduced quite a bit more if we chose too
  739. AC_MSG_CHECKING(for libpcapnav version)
  740. AC_TRY_RUN([
  741. #include <string.h>
  742. #define PCAPNAV_TEST "0.4"
  743. /*
  744. * simple proggy to test the version of libpcapnav
  745. * returns zero if version >= 0.4
  746. * or one otherwise
  747. */
  748. int
  749. main (int argc, char *argv[])
  750. {
  751. if (strncmp(PCAPNAV_VERSION, PCAPNAV_TEST, 3) >= 0)
  752. exit(0);
  753. exit(1);
  754. }],
  755. libpcapnav_ver=yes
  756. AC_MSG_RESULT(>= 0.4),
  757. libpcapnav_ver=no
  758. AC_MSG_RESULT(< 0.4),
  759. libpcapnav_ver=no
  760. )
  761. if test x$libpcapnav_ver = xno ; then
  762. AC_MSG_WARN([Libpcapnav versions < 0.4 are not supported.
  763. Please upgrade to version 0.4 or better.
  764. Disabling offset jump feature.])
  765. else
  766. AC_DEFINE([HAVE_PCAPNAV], [1], [Do we have libpcapnav?])
  767. fi
  768. fi # checking pcapnav version
  769. dnl (shamelessly ripped off from libpcap)
  770. dnl Checks to see if unaligned memory accesses fail
  771. dnl
  772. dnl FORCE_ALIGN (DEFINED)
  773. dnl
  774. AC_MSG_CHECKING(for requires strict byte alignment)
  775. AC_CACHE_VAL(unaligned_fail,
  776. [case "$host_cpu" in
  777. # XXX: should also check that they don't do weird things (like on arm)
  778. alpha*|arm*|hp*|mips*|sparc*|ia64)
  779. unaligned_fail=yes
  780. ;;
  781. *)
  782. cat >conftest.c <<EOF
  783. #include <sys/types.h>
  784. #include <sys/wait.h>
  785. #include <stdio.h>
  786. unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
  787. main() {
  788. unsigned int i;
  789. pid_t pid;
  790. int status;
  791. /* avoid "core dumped" message */
  792. pid = fork();
  793. if (pid < 0)
  794. exit(2);
  795. if (pid > 0) {
  796. /* parent */
  797. pid = waitpid(pid, &status, 0);
  798. if (pid < 0)
  799. exit(3);
  800. exit(!WIFEXITED(status));
  801. }
  802. /* child */
  803. i = *(unsigned int *)&a[[1]];
  804. printf("%d\n", i);
  805. exit(0);
  806. }
  807. EOF
  808. ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
  809. conftest.c $LIBS >/dev/null 2>&1
  810. if test ! -x conftest ; then
  811. dnl failed to compile for some reason
  812. unaligned_fail=yes
  813. else
  814. ./conftest >conftest.out
  815. if test ! -s conftest.out ; then
  816. unaligned_fail=yes
  817. else
  818. unaligned_fail=no
  819. fi
  820. fi
  821. rm -f conftest* core core.conftest
  822. ;;
  823. esac])
  824. AC_MSG_RESULT($unaligned_fail)
  825. if test $unaligned_fail = yes ; then
  826. AC_DEFINE([FORCE_ALIGN],[1],[Are we strictly aligned?])
  827. fi
  828. dnl ##################################################
  829. dnl # Check for tcpdump.
  830. dnl ##################################################
  831. td=no
  832. AC_ARG_WITH(tcpdump,
  833. AC_HELP_STRING([--with-tcpdump=FILE], [Path to tcpdump binary]),
  834. [ if test -x $withval ; then
  835. td=$withval
  836. AC_MSG_RESULT([Using tcpdump in $td])
  837. else
  838. AC_MSG_RESULT([Error: $withval does not exist or is not executable])
  839. fi ],
  840. [ AC_PATH_PROG(td, tcpdump, "no", [$PATH:/usr/sbin:/sbin:/usr/local/sbin]) ])
  841. if test "$td" = "no"; then
  842. AC_MSG_WARN([Unable to find tcpdump. Please specify --with-tcpdump.
  843. Disabling --verbose])
  844. else
  845. AC_DEFINE([HAVE_TCPDUMP], [1], [Do we have tcpdump?])
  846. AC_DEFINE_UNQUOTED(TCPDUMP_BINARY, "$td", [The tcpdump binary initially used])
  847. fi
  848. AM_CONDITIONAL([ENABLE_TCPDUMP], test "$td" != "no" -a x$have_pcap_dump_fopen = xyes)
  849. if test x$td != xno -a x$have_pcap_dump_fopen = xyes ; then
  850. AC_DEFINE([ENABLE_VERBOSE], [1], [Do we have tcpdump and pcap_dump_fopen()?])
  851. else
  852. AC_MSG_WARN([Your version of libpcap is too old for --verbose support])
  853. fi
  854. dnl No 'make test' when cross compile
  855. AC_MSG_CHECKING(for 'make test' profile)
  856. if test "$host" != "$build" ; then
  857. AC_MSG_WARN(Unable to do tests when cross-compiling)
  858. fi
  859. dnl Allows user to choose which nic to use for testing purposes
  860. AC_ARG_WITH(testnic,
  861. AC_HELP_STRING([--with-testnic=NIC], [Select which network card to use for testing]),
  862. [ nic1=$withval
  863. nic2=$withval
  864. AC_MSG_RESULT([Using --with-testnic=$withval])],
  865. [
  866. dnl There's a bug in OS X which causes pcap_findalldevs() to make the wifi NIC to disassociate
  867. dnl so under OSX we disable the interface list feature
  868. disable_pcap_findalldevs=no
  869. dnl these need to be dynamic based on OS
  870. case $host in
  871. *-*-linux*)
  872. nic1=eth0
  873. nic2=eth0
  874. AC_MSG_RESULT(Linux)
  875. ;;
  876. *-*-solaris*)
  877. nic1=hme0
  878. nic2=hme0
  879. AC_MSG_RESULT(Solaris)
  880. ;;
  881. *-*-sunos*)
  882. nic1=hme0
  883. nic2=hme0
  884. AC_MSG_RESULT(SunOS)
  885. ;;
  886. *-apple-darwin*)
  887. nic1=en0
  888. nic2=en0
  889. disable_pcap_findalldevs=yes
  890. AC_MSG_RESULT(Apple OS X)
  891. ;;
  892. *-*-openbsd*)
  893. nic1=xl0
  894. nic2=xl0
  895. AC_MSG_RESULT(OpenBSD)
  896. ;;
  897. *-*-cygwin)
  898. AC_MSG_RESULT(Win32/Cygwin)
  899. nic1=%0
  900. nic2=%0
  901. ;;
  902. *)
  903. AC_MSG_RESULT([$host is unknown! Using first non-loopback interface])
  904. nic1=%0
  905. nic2=%0
  906. ;;
  907. esac])
  908. AC_ARG_WITH(testnic2,
  909. AC_HELP_STRING([--with-testnic2=NIC2], [Select an optional 2nd network card to use for testing]),
  910. [ nic2=$withval ])
  911. AC_MSG_NOTICE([Using $nic1 for 1st test network interface card])
  912. AC_MSG_NOTICE([Using $nic2 for 2nd test network interface card])
  913. AC_SUBST(nic1)
  914. AC_SUBST(nic2)
  915. AC_MSG_CHECKING([if it's ok to use pcap_findalldevs()])
  916. if test x$disable_pcap_findalldevs = xno ; then
  917. AC_DEFINE([ENABLE_PCAP_FINDALLDEVS], [1], [Enable use of pcap_findalldevs()])
  918. AC_MSG_RESULT(yes)
  919. else
  920. AC_MSG_RESULT(no)
  921. fi
  922. LIBOPTS_CHECK
  923. AC_OUTPUT([Makefile
  924. doxygen.cfg
  925. lib/Makefile
  926. docs/Makefile
  927. src/Makefile
  928. src/common/Makefile
  929. src/tcpedit/Makefile
  930. src/flow/Makefile
  931. src/defines.h
  932. test/Makefile
  933. test/config
  934. scripts/Makefile
  935. tcpreplay.spec])
  936. case $host in
  937. *-apple-darwin*)
  938. AC_MSG_WARN([OS X <= 10.4.9 has a serious problem. Please see: http://tcpreplay.synfin.net/trac/ticket/142])
  939. ;;
  940. *-*-cygwin)
  941. AC_MSG_WARN([Windows/Cygwin support is still somewhat experimental. Please report any bugs!])
  942. ;;
  943. esac