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.ac,v 1.2 2014/01/19 20:28:31 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.9.6-1.14 and autoconf 2.59-2.69.
22 dnl Boilerplate configuration
25 AC_INIT([iftop], [1.0pre4], [pdw@ex-parrot.com], [iftop], [http://www.ex-parrot.com/pdw/iftop/])
27 AC_CONFIG_AUX_DIR(config)
31 AC_CONFIG_HEADERS([config.h])
34 dnl Make sure we have a C compiler....
39 dnl Options to configure.
43 [ --with-resolver=TYPE Technique iftop should use for name resolution.
45 netdb use gethostbyaddr_r in multiple
47 netdb_1thread use gethostbyaddr_r and
48 assume it is not reentrant.
49 ares use the MIT ARES asynchronous
51 forking use the REALLY SUCKY forking resolver.
52 guess run experiments to guess a
53 reasonable value. Only works if you
54 aren't cross-compiling. This
55 is the default. guess will
56 either select netdb or netdb_1thread.
57 none don't do name resolution.],
62 [ --with-libpcap=WHERE Where the libpcap packet-capture library is found.
63 The pcap library should be installed in WHERE/lib,
64 and the header file in either WHERE/include or
66 [default=look in standard locations]],
67 [libpcap_prefix=$withval],
71 dnl Fairly generic checks.
74 dnl Checks for system headers.
75 AC_CHECK_HEADERS([sgtty.h sys/ioctl.h sys/time.h sys/sockio.h termio.h termios.h unistd.h])
77 dnl Checks for typedefs, structures, and compiler characteristics.
83 dnl Are we on a system that uses the STREAMS low-level DLPI interface?
86 AC_CHECK_HEADER([sys/dlpi.h],[AC_DEFINE([HAVE_DLPI],1,[Are we running on a STREAMS system with DLPI?])])
88 dnl Checks for library functions.
89 AC_CHECK_FUNCS(regcomp select strdup strerror strspn)
91 AC_SEARCH_LIBS(socket, socket)
92 AC_SEARCH_LIBS(log, m)
93 AC_CHECK_FUNC(gethostbyname, ,
94 [AC_CHECK_LIB(nsl, gethostbyname)] )
96 AC_SEARCH_LIBS(inet_aton, [socket nsl])
97 AC_SEARCH_LIBS(inet_pton, [socket nsl])
98 AC_CHECK_FUNCS(inet_aton inet_pton)
101 dnl Find integers of known physical size. This is a pain in the arse because
102 dnl we can't use AC_CHECK_SIZEOF to find the original variables, since that
103 dnl function doesn't permit us to include a header file. Sigh.
106 for type in u_int8_t u_int16_t u_int32_t ; do
107 AC_MSG_CHECKING([size of $type])
108 AC_RUN_IFELSE([AC_LANG_SOURCE([
109 #include <sys/types.h>
113 FILE *f=fopen("conftestval", "w");
115 fprintf(f, "%d\n", sizeof($1));
124 AC_MSG_RESULT([unknown type])
127 AC_MSG_RESULT([can't determine when cross-compiling])
131 dnl Groan. Have to do things this way so that autoheader can do its thing....
132 AC_DEFINE_UNQUOTED(SIZEOF_U_INT8_T, [$size_u_int8_t], [size of u_int8_t])
133 AC_DEFINE_UNQUOTED(SIZEOF_U_INT16_T, [$size_u_int16_t], [size of u_int16_t])
134 AC_DEFINE_UNQUOTED(SIZEOF_U_INT32_T, [$size_u_int32_t], [size of u_int32_t])
136 dnl If we already have these types, don't piss about any more....
138 if test $size_u_int8_t != 1 || test $size_u_int16_t != 2 || test $size_u_int32_t != 4 ; then
139 dnl XXXif test $size_u_int8_t != 1 -o $size_u_int16_t != 2 -o $size_u_int32_t != 4 ; then
143 sys/inttypes.h, dnl Solaris
144 [do_int_types=0; break])
146 if test $do_int_types = 1 ; then
147 dnl No C99 int types, so figure them out from basic types.
148 AC_CHECK_SIZEOF(unsigned short int)
149 AC_CHECK_SIZEOF(unsigned int)
150 AC_CHECK_SIZEOF(unsigned long int)
152 dnl Just use the C99 ones.
153 AC_DEFINE(HAVE_C99_INTS, 1, [C99 fixed-width int types available])
160 dnl This is complicated because we need some sort of reentrant mechanism for
161 dnl name resolution. Naturally, UNIX vendors have come up with a variety of
162 dnl incompatible schemes for this, many of which don't work at all.
165 dnl First, the default resolver, which uses getnameinfo or gethostbyaddr_r. If
166 dnl not available, we fall back to gethostbyaddr. We could fall back to ARES,
167 dnl but that's probably not available on typical machines.
169 dnl If we've been asked to guess, remember that fact in specified_resolver.
170 dnl From this point on, resolver is our preferred resolver given the
171 dnl experiments we've done so far, or "guess" if we have no idea.
172 specified_resolver=$resolver
173 if test x$specified_resolver = xguess ; then
174 dnl Best possibility is getnameinfo.
176 AC_SEARCH_LIBS(getnameinfo, [nsl], [use_getnameinfo=1])
178 dnl XXX For the moment, don't use getnameinfo, since it isn't actually
179 dnl thread safe on, e.g., NetBSD.
182 if test $use_getnameinfo = 1 ; then
184 AC_DEFINE(USE_GETNAMEINFO, 1, [use getnameinfo for name resolution])
186 dnl Best hope is netdb, which presently means gethostbyaddr_r.
191 if test x$resolver = xnetdb ; then
192 dnl Can use gethostbyaddr_r?
193 AC_SEARCH_LIBS(gethostbyaddr_r, [nsl], , [resolver=guess])
194 if test x$resolver = xguess && test x$specified_resolver != xguess ; then
195 dnl They wanted gethostbyaddr_r, but they can't have it, so stop.
196 AC_MSG_ERROR([no library defines gethostbyaddr_r])
200 dnl We still might do gethostbyaddr_r. Figure out whether we have
201 dnl glibc-style or Solaris-style gethostbyaddr_r (or neither...).
202 dnl Separate determining how to call gethostbyaddr_r from testing
203 dnl whether it works so we can support cross-compilation.
204 if test x$resolver = xnetdb ; then
205 AC_MSG_CHECKING([how to call gethostbyaddr_r])
206 dnl Try 7 arguments returning a struct hostent*.
207 AC_LINK_IFELSE([AC_LANG_SOURCE([`cat config/hostentp_ghba_r.c`])],
208 [AC_MSG_RESULT([7 args])
210 AC_DEFINE(GETHOSTBYADDR_R_RETURNS_HOSTENT_P, 1,
211 [7-argument gethostbyaddr_r returns struct hostent*])], [
212 dnl Try 8 arguments returning an int.
213 AC_LINK_IFELSE([AC_LANG_SOURCE([`cat config/int_ghba_r.c`])],
214 [AC_MSG_RESULT([8 args, int return])
216 AC_DEFINE(GETHOSTBYADDR_R_RETURNS_INT, 1,
217 [8-argument gethostbyaddr_r returns int])], [
219 AC_MSG_RESULT([don't know how])
221 if test x$resolver = xguess && test x$specified_resolver != xguess ; then
222 dnl They wanted gethostbyaddr_r, but they can't have it, so stop.
223 AC_MSG_ERROR([gethostbyaddr_r has no known calling convention])
227 dnl If we still want to do gethostbyaddr_r, and we aren't
228 dnl cross-compiling, test it.
229 if test x$resolver = xnetdb ; then
230 if test x$ghba_args = x8 ; then
233 testfile=hostentp_ghba_r
235 AC_MSG_CHECKING(gethostbyaddr_r usability)
236 AC_RUN_IFELSE([AC_LANG_SOURCE([`cat config/$testfile.c`])],
237 [AC_MSG_RESULT([yes])],
240 [AC_MSG_RESULT([can't test because we are cross-compiling])])
241 if test x$resolver = xguess ; then
242 if test x$specified_resolver = xguess ; then
243 AC_MSG_RESULT([gethostbyaddr_r doesn't work, so we'll try something else])
245 dnl They wanted gethostbyaddr_r, but it doesn't work, so stop.
246 AC_MSG_ERROR([gethostbyaddr_r doesn't work])
251 dnl We found a gethostbyaddr_r we know how to use and which seems to
253 if test x$resolver = xnetdb ; then
254 AC_DEFINE(USE_GETHOSTBYADDR_R, 1, [use gethostbyaddr_r for name resolution])
257 dnl They may have asked for ares.
258 if test x$resolver = xares ; then
259 dnl See if ares is to hand....
260 AC_SEARCH_LIBS(ares_init, [ares], [
261 AC_DEFINE(USE_ARES, 1, [use ARES for name resolution])
263 dnl They asked for ares, but we can't give it to them, so stop.
264 AC_MSG_ERROR([can't find ARES. Re-run configure and ask for a different resolver.])])
267 dnl Last thing to try if we haven't decided yet is netdb_1thread.
268 if test x$resolver = xguess ; then
269 resolver=netdb_1thread
272 dnl Ugh. Both the single-threaded and the forking resolvers use gethostbyaddr.
273 if test x$resolver = xnetdb_1thread || test x$resolver = xforking ; then
274 AC_SEARCH_LIBS(gethostbyaddr, [nsl], , [
275 AC_MSG_ERROR([gethostbyaddr is not available. You will have to
276 recompile with no name resolution at all.])])
278 if test x$resolver = xnetdb_1thread ; then
279 AC_MSG_WARN([using single-threaded resolver with gethostbyaddr
280 Consider obtaining ARES or a machine with a working gethostbyaddr_r.])
281 AC_DEFINE(USE_GETHOSTBYADDR, 1, [use gethostbyaddr for name resolution])
283 AC_DEFINE(USE_FORKING_RESOLVER, 1, [use a REALLY SUCKY forking resolver for name resolution])
287 dnl Otherwise, no resolver at all. Boo hoo.
293 if test x$libpcap_prefix = x ; then
294 libpcap_prefix="/usr /usr/local /opt /software"
297 AC_MSG_CHECKING([where to find pcap.h])
299 oldCPPFLAGS=$CPPFLAGS
300 for test_prefix in "" $libpcap_prefix ; do
301 for x in "" /pcap ; do
302 if test x$test_prefix != x ; then
303 CPPFLAGS="$oldCPPFLAGS -I$test_prefix/include$x"
308 AC_MSG_RESULT([$test_prefix/include$x])
313 if test $foundpcaph = 1 ; then
318 if test $foundpcaph = 0 ; then
319 AC_MSG_RESULT([no idea])
320 AC_MSG_ERROR([can't find pcap.h
321 You're not going to get very far without libpcap.])
323 dnl assume that -lpcap is under $test_prefix/lib
324 if test x$test_prefix != x ; then
325 LDFLAGS="$LDFLAGS -L$test_prefix/lib"
327 AC_CHECK_LIB(pcap, pcap_open_live, , [
328 AC_MSG_ERROR([can't find libpcap
329 You're not going to get very far without libpcap.])
334 AC_CHECK_HEADERS([pcap.h pcap/pcap.h], [
339 if test $foundpcap = 0 ; then
340 AC_MSG_ERROR([can't find pcap.h
341 You're not going to get very far without libpcap.])
345 dnl Curses. Really, we need ncurses or something similarly advanced, since
346 dnl we use the (apparently obscure) mvchgat function. Unfortunately, there's
347 dnl a solid chance that mvchgat is a macro, so we can't just use
348 dnl AC_SEARCH_LIBS....
351 AC_MSG_CHECKING([for a curses library containing mvchgat])
353 for curseslib in ncursesw curses ncurses ; do
354 LIBS="$oldLIBS -l$curseslib"
356 #include <$curseslib.h>
358 mvchgat(0, 0, 1, A_REVERSE, 0, NULL)
360 foundcurseslib=$curseslib
365 if test x$foundcurseslib = x ; then
366 AC_MSG_RESULT([none found])
367 AC_MSG_ERROR([Curses! Foiled again!
368 (Can't find a curses library supporting mvchgat.)
369 Consider installing ncurses.])
371 AC_MSG_RESULT([-l$foundcurseslib])
376 dnl POSIX threads. Different systems like different combinations of flags,
377 dnl libraries, etc. We use a test program to figure this stuff out.
380 AC_MSG_CHECKING([POSIX threads compilation])
384 for flag in "" -mt -pthread -thread ; do
385 CFLAGS="$oldCFLAGS $flag"
386 for lib in "" -lpthread "-lpthread -lposix4" ; do
388 AC_LINK_IFELSE([AC_LANG_SOURCE([`cat config/pthread.c`])], [
395 if test $thrfail = 0 ; then
400 if test $thrfail = 1 ; then
401 AC_MSG_RESULT([no idea])
402 AC_MSG_ERROR([can't figure out how to compile with POSIX threads
403 If your system actually supports POSIX threads, this means we've messed up.])
406 AC_MSG_RESULT([CFLAGS=$foundthrflag and LIBS=$foundthrlib])
407 AC_MSG_CHECKING([POSIX threads usability])
408 AC_RUN_IFELSE([AC_LANG_SOURCE([`cat config/pthread.c`])],
409 [AC_MSG_RESULT([yes])],
411 [it fails. We probably guessed the wrong CFLAGS.])],
412 [AC_MSG_RESULT([can't test because we are cross-compiling])])
415 dnl Are we on a system (like Solaris) that requires promiscuous mode in order to
416 dnl see any outgoing packets?
419 AC_MSG_CHECKING([if we need to enable promiscuous mode by default])
421 enable_default_promiscuous="no"
424 solaris*) enable_default_promiscuous="yes" ;;
427 AC_ARG_ENABLE(default-promiscuous,
428 [ --enable-default-promiscuous If enabled, iftop will operate in promiscuous mode
429 to capture outgoing packets])
431 AC_MSG_RESULT([$enable_default_promiscuous])
433 if test x"$enable_default_promiscuous" = x"yes"; then
434 AC_DEFINE([NEED_PROMISCUOUS_FOR_OUTGOING],1,[Enable default promiscuous mode to capture outgoing packets])
438 dnl Wahey! This might even work.
443 AC_OUTPUT(Makefile config/Makefile)
445 if echo $PACKAGE_VERSION | grep 'pre' > /dev/null ; then
447 ******************************************************************************
449 This is a pre-release version. Pre-releases are subject to limited
450 announcements, and therefore limited circulation, as a means of testing
451 the more widely circulated final releases.
453 Please do not be surprised if this release is broken, and if it is broken, do
454 not assume that someone else has spotted it. Instead, please drop a note on
455 the mailing list, or a brief email to me on pdw@ex-parrot.com
457 Thank you for taking the time to be the testing phase of this development
462 ******************************************************************************