3 dnl Autoconf input for iftop.
5 dnl I hate autoconf with a passion. It's an utter pain to write these bloody
6 dnl things and even once you have you find yourself testing for more and more
7 dnl special cases. But that's OK. Paul is going to maintain it :)
10 dnl $Id: configure.in,v 1.29 2010/11/27 11:39:32 pdw Exp $
12 dnl To regenerate everything from source, do:
17 dnl Now you should have good sources to make into a tarball and distribute.
18 dnl ./configure (perhaps with some arguments)
20 dnl Tested with Automake 1.4 and autoconf 2.59.
22 dnl Boilerplate configuration
27 AC_CONFIG_AUX_DIR(config)
31 AM_CONFIG_HEADER(config.h)
32 AM_INIT_AUTOMAKE(iftop, "1.0pre1")
34 AC_DEFINE_UNQUOTED(IFTOP_VERSION, "$VERSION", [The iftop version number])
36 dnl Make sure we have a C compiler....
41 dnl Options to configure.
45 [ --with-resolver=TYPE Technique iftop should use for name resolution.
47 netdb use gethostbyaddr_r in multiple
49 netdb_1thread use gethostbyaddr_r and
50 assume it is not reentrant.
51 ares use the MIT ARES asynchronous
53 forking use the REALLY SUCKY forking resolver.
54 guess run experiments to guess a
55 reasonable value. Only works if you
56 aren't cross-compiling. This
57 is the default. guess will
58 either select netdb or netdb_1thread.
59 none don't do name resolution.],
64 [ --with-libpcap=WHERE Where the libpcap packet-capture library is found.
65 The pcap library should be installed in WHERE/lib,
66 and the header file in either WHERE/include or
68 [default=look in standard locations]],
69 [libpcap_prefix=$withval],
73 dnl Fairly generic checks.
76 dnl Checks for system headers.
77 AC_CHECK_HEADERS(sys/ioctl.h sys/time.h sys/sockio.h unistd.h)
79 dnl Checks for typedefs, structures, and compiler characteristics.
85 dnl Are we on a system that uses the STREAMS low-level DLPI interface?
88 AC_CHECK_HEADER([sys/dlpi.h],[AC_DEFINE([HAVE_DLPI],1,[Are we running on a STREAMS system with DLPI?])])
90 dnl Checks for library functions.
91 AC_CHECK_FUNCS(regcomp select strdup strerror strspn)
93 AC_SEARCH_LIBS(socket, socket)
94 AC_SEARCH_LIBS(log, m)
95 AC_CHECK_FUNC(gethostbyname, ,
96 [AC_CHECK_LIB(nsl, gethostbyname)] )
98 AC_SEARCH_LIBS(inet_aton, [socket nsl])
99 AC_SEARCH_LIBS(inet_pton, [socket nsl])
100 AC_CHECK_FUNCS(inet_aton inet_pton)
103 dnl Find integers of known physical size. This is a pain in the arse because
104 dnl we can't use AC_CHECK_SIZEOF to find the original variables, since that
105 dnl function doesn't permit us to include a header file. Sigh.
108 for type in u_int8_t u_int16_t u_int32_t ; do
109 AC_MSG_CHECKING([size of $type])
111 #include <sys/types.h>
115 FILE *f=fopen("conftestval", "w");
117 fprintf(f, "%d\n", sizeof($1));
126 AC_MSG_RESULT([unknown type])
129 AC_MSG_RESULT([can't determine when cross-compiling])
133 dnl Groan. Have to do things this way so that autoheader can do its thing....
134 AC_DEFINE_UNQUOTED(SIZEOF_U_INT8_T, [$size_u_int8_t], [size of u_int8_t])
135 AC_DEFINE_UNQUOTED(SIZEOF_U_INT16_T, [$size_u_int16_t], [size of u_int16_t])
136 AC_DEFINE_UNQUOTED(SIZEOF_U_INT32_T, [$size_u_int32_t], [size of u_int32_t])
138 dnl If we already have these types, don't piss about any more....
140 if test $size_u_int8_t != 1 || test $size_u_int16_t != 2 || test $size_u_int32_t != 4 ; then
141 dnl XXXif test $size_u_int8_t != 1 -o $size_u_int16_t != 2 -o $size_u_int32_t != 4 ; then
145 sys/inttypes.h, dnl Solaris
146 [do_int_types=0; break])
148 if test $do_int_types = 1 ; then
149 dnl No C99 int types, so figure them out from basic types.
150 AC_CHECK_SIZEOF(unsigned short int)
151 AC_CHECK_SIZEOF(unsigned int)
152 AC_CHECK_SIZEOF(unsigned long int)
154 dnl Just use the C99 ones.
155 AC_DEFINE(HAVE_C99_INTS, 1, [C99 fixed-width int types available])
162 dnl This is complicated because we need some sort of reentrant mechanism for
163 dnl name resolution. Naturally, UNIX vendors have come up with a variety of
164 dnl incompatible schemes for this, many of which don't work at all.
167 dnl First, the default resolver, which uses getnameinfo or gethostbyaddr_r. If
168 dnl not available, we fall back to gethostbyaddr. We could fall back to ARES,
169 dnl but that's probably not available on typical machines.
171 dnl If we've been asked to guess, remember that fact in specified_resolver.
172 dnl From this point on, resolver is our preferred resolver given the
173 dnl experiments we've done so far, or "guess" if we have no idea.
174 specified_resolver=$resolver
175 if test x$specified_resolver = xguess ; then
176 dnl Best possibility is getnameinfo.
178 AC_SEARCH_LIBS(getnameinfo, [nsl], [use_getnameinfo=1])
180 dnl XXX For the moment, don't use getnameinfo, since it isn't actually
181 dnl thread safe on, e.g., NetBSD.
184 if test $use_getnameinfo = 1 ; then
186 AC_DEFINE(USE_GETNAMEINFO, 1, [use getnameinfo for name resolution])
188 dnl Best hope is netdb, which presently means gethostbyaddr_r.
193 if test x$resolver = xnetdb ; then
194 dnl Can use gethostbyaddr_r?
195 AC_SEARCH_LIBS(gethostbyaddr_r, [nsl], , [resolver=guess])
196 if test x$resolver = xguess && test x$specified_resolver != xguess ; then
197 dnl They wanted gethostbyaddr_r, but they can't have it, so stop.
198 AC_MSG_ERROR([no library defines gethostbyaddr_r])
202 dnl We still might do gethostbyaddr_r. Figure out whether we have
203 dnl glibc-style or Solaris-style gethostbyaddr_r (or neither...).
204 dnl Separate determining how to call gethostbyaddr_r from testing
205 dnl whether it works so we can support cross-compilation.
206 if test x$resolver = xnetdb ; then
207 AC_MSG_CHECKING([how to call gethostbyaddr_r])
208 dnl Try 7 arguments returning a struct hostent*.
209 AC_LINK_IFELSE(AC_LANG_SOURCE([`cat config/hostentp_ghba_r.c`]),
210 [AC_MSG_RESULT([7 args])
212 AC_DEFINE(GETHOSTBYADDR_R_RETURNS_HOSTENT_P, 1,
213 [7-argument gethostbyaddr_r returns struct hostent*])], [
214 dnl Try 8 arguments returning an int.
215 AC_LINK_IFELSE(AC_LANG_SOURCE([`cat config/int_ghba_r.c`]),
216 [AC_MSG_RESULT([8 args, int return])
218 AC_DEFINE(GETHOSTBYADDR_R_RETURNS_INT, 1,
219 [8-argument gethostbyaddr_r returns int])], [
221 AC_MSG_RESULT([don't know how])
223 if test x$resolver = xguess && test x$specified_resolver != xguess ; then
224 dnl They wanted gethostbyaddr_r, but they can't have it, so stop.
225 AC_MSG_ERROR([gethostbyaddr_r has no known calling convention])
229 dnl If we still want to do gethostbyaddr_r, and we aren't
230 dnl cross-compiling, test it.
231 if test x$resolver = xnetdb ; then
232 if test x$ghba_args = x8 ; then
235 testfile=hostentp_ghba_r
237 AC_MSG_CHECKING(gethostbyaddr_r usability)
238 AC_RUN_IFELSE([`cat config/$testfile.c`],
239 [AC_MSG_RESULT([yes])],
242 [AC_MSG_RESULT([can't test because we are cross-compiling])])
243 if test x$resolver = xguess ; then
244 if test x$specified_resolver = xguess ; then
245 AC_MSG_RESULT([gethostbyaddr_r doesn't work, so we'll try something else])
247 dnl They wanted gethostbyaddr_r, but it doesn't work, so stop.
248 AC_MSG_ERROR([gethostbyaddr_r doesn't work])
253 dnl We found a gethostbyaddr_r we know how to use and which seems to
255 if test x$resolver = xnetdb ; then
256 AC_DEFINE(USE_GETHOSTBYADDR_R, 1, [use gethostbyaddr_r for name resolution])
259 dnl They may have asked for ares.
260 if test x$resolver = xares ; then
261 dnl See if ares is to hand....
262 AC_SEARCH_LIBS(ares_init, [ares], [
263 AC_DEFINE(USE_ARES, 1, [use ARES for name resolution])
265 dnl They asked for ares, but we can't give it to them, so stop.
266 AC_MSG_ERROR([can't find ARES. Re-run configure and ask for a different resolver.])])
269 dnl Last thing to try if we haven't decided yet is netdb_1thread.
270 if test x$resolver = xguess ; then
271 resolver=netdb_1thread
274 dnl Ugh. Both the single-threaded and the forking resolvers use gethostbyaddr.
275 if test x$resolver = xnetdb_1thread || test x$resolver = xforking ; then
276 AC_SEARCH_LIBS(gethostbyaddr, [nsl], , [
277 AC_MSG_ERROR([gethostbyaddr is not available. You will have to
278 recompile with no name resolution at all.])])
280 if test x$resolver = xnetdb_1thread ; then
281 AC_MSG_WARN([using single-threaded resolver with gethostbyaddr
282 Consider obtaining ARES or a machine with a working gethostbyaddr_r.])
283 AC_DEFINE(USE_GETHOSTBYADDR, 1, [use gethostbyaddr for name resolution])
285 AC_DEFINE(USE_FORKING_RESOLVER, 1, [use a REALLY SUCKY forking resolver for name resolution])
289 dnl Otherwise, no resolver at all. Boo hoo.
295 if test x$libpcap_prefix = x ; then
296 libpcap_prefix="/usr /usr/local /opt /software"
299 AC_MSG_CHECKING([where to find pcap.h])
301 oldCPPFLAGS=$CPPFLAGS
302 for test_prefix in "" $libpcap_prefix ; do
303 for x in "" /pcap ; do
304 if test x$test_prefix != x ; then
305 CPPFLAGS="$oldCPPFLAGS -I$test_prefix/include$x"
310 AC_MSG_RESULT([$test_prefix/include$x])
315 if test $foundpcaph = 1 ; then
320 if test $foundpcaph = 0 ; then
321 AC_MSG_RESULT([no idea])
322 AC_MSG_ERROR([can't find pcap.h
323 You're not going to get very far without libpcap.])
325 dnl assume that -lpcap is under $test_prefix/lib
326 if test x$test_prefix != x ; then
327 LDFLAGS="$LDFLAGS -L$test_prefix/lib"
329 AC_CHECK_LIB(pcap, pcap_open_live, , [
330 AC_MSG_ERROR([can't find libpcap
331 You're not going to get very far without libpcap.])
336 AC_CHECK_HEADERS([pcap.h pcap/pcap.h], [
341 if test $foundpcap = 0 ; then
342 AC_MSG_ERROR([can't find pcap.h
343 You're not going to get very far without libpcap.])
347 dnl Curses. Really, we need ncurses or something similarly advanced, since
348 dnl we use the (apparently obscure) mvchgat function. Unfortunately, there's
349 dnl a solid chance that mvchgat is a macro, so we can't just use
350 dnl AC_SEARCH_LIBS....
353 AC_MSG_CHECKING([for a curses library containing mvchgat])
355 for curseslib in curses ncurses ; do
356 LIBS="$oldLIBS -l$curseslib"
360 mvchgat(0, 0, 1, A_REVERSE, 0, NULL)
362 foundcurseslib=$curseslib
367 if test x$foundcurseslib = x ; then
368 AC_MSG_RESULT([none found])
369 AC_MSG_ERROR([Curses! Foiled again!
370 (Can't find a curses library supporting mvchgat.)
371 Consider installing ncurses.])
373 AC_MSG_RESULT([-l$foundcurseslib])
378 dnl POSIX threads. Different systems like different combinations of flags,
379 dnl libraries, etc. We use a test program to figure this stuff out.
382 AC_MSG_CHECKING([POSIX threads compilation])
386 for flag in "" -mt -pthread -thread ; do
387 CFLAGS="$oldCFLAGS $flag"
388 for lib in "" -lpthread "-lpthread -lposix4" ; do
390 AC_LINK_IFELSE(AC_LANG_SOURCE([`cat config/pthread.c`]), [
397 if test $thrfail = 0 ; then
402 if test $thrfail = 1 ; then
403 AC_MSG_RESULT([no idea])
404 AC_MSG_ERROR([can't figure out how to compile with POSIX threads
405 If your system actually supports POSIX threads, this means we've messed up.])
408 AC_MSG_RESULT([CFLAGS=$foundthrflag and LIBS=$foundthrlib])
409 AC_MSG_CHECKING([POSIX threads usability])
410 AC_RUN_IFELSE([`cat config/pthread.c`],
411 [AC_MSG_RESULT([yes])],
413 [it fails. We probably guessed the wrong CFLAGS.])],
414 [AC_MSG_RESULT([can't test because we are cross-compiling])])
417 dnl Are we on a system (like Solaris) that requires promiscuous mode in order to
418 dnl see any outgoing packets?
421 AC_MSG_CHECKING([if we need to enable promiscuous mode by default])
423 enable_default_promiscuous="no"
426 solaris*) enable_default_promiscuous="yes" ;;
429 AC_ARG_ENABLE(default-promiscuous,
430 [ --enable-default-promiscuous If enabled, iftop will operate in promiscuous mode
431 to capture outgoing packets])
433 AC_MSG_RESULT([$enable_default_promiscuous])
435 if test x"$enable_default_promiscuous" = x"yes"; then
436 AC_DEFINE([NEED_PROMISCUOUS_FOR_OUTGOING],1,[Enable default promiscuous mode to capture outgoing packets])
440 dnl Wahey! This might even work.
445 AC_OUTPUT(Makefile config/Makefile)
447 if echo $VERSION | grep 'pre' ; then
449 ******************************************************************************
451 This is a pre-release version. Pre-releases are subject to limited
452 announcements, and therefore limited circulation, as a means of testing
453 the more widely circulated final releases.
455 Please do not be surprised if this release is broken, and if it is broken, do
456 not assume that someone else has spotted it. Instead, please drop a note on
457 the mailing list, or a brief email to me on pdw@ex-parrot.com
459 Thank you for taking the time to be the testing phase of this development
464 ******************************************************************************