xref: /minix/external/bsd/tcpdump/dist/configure.in (revision b636d99d)
1dnl Copyright (c) 1994, 1995, 1996, 1997
2dnl	The Regents of the University of California.  All rights reserved.
3dnl
4dnl Process this file with autoconf to produce a configure script.
5dnl
6
7#
8# See
9#
10#	http://ftp.gnu.org/gnu/config/README
11#
12# for the URLs to use to fetch new versions of config.guess and
13# config.sub.
14#
15
16AC_PREREQ(2.61)
17AC_INIT(tcpdump.c)
18
19AC_CANONICAL_HOST
20
21AC_LBL_C_INIT_BEFORE_CC(V_INCLS)
22AC_PROG_CC
23AC_LBL_C_INIT(V_CCOPT, V_INCLS)
24AC_LBL_C_INLINE
25AC_C___ATTRIBUTE__
26if test "$ac_cv___attribute__" = "yes"; then
27	AC_C___ATTRIBUTE___UNUSED
28	AC_C___ATTRIBUTE___NORETURN_FUNCTION_POINTER
29	AC_C___ATTRIBUTE___FORMAT
30	if test "$ac_cv___attribute___format" = "yes"; then
31		AC_C___ATTRIBUTE___FORMAT_FUNCTION_POINTER
32	fi
33fi
34
35AC_CHECK_HEADERS(fcntl.h rpc/rpc.h rpc/rpcent.h netdnet/dnetdb.h)
36AC_CHECK_HEADERS(net/pfvar.h, , , [#include <sys/types.h>
37#include <sys/socket.h>
38#include <net/if.h>])
39if test "$ac_cv_header_net_pfvar_h" = yes; then
40	LOCALSRC="print-pflog.c $LOCALSRC"
41fi
42AC_CHECK_HEADERS(netinet/if_ether.h, , , [#include <sys/types.h>
43#include <sys/socket.h>])
44if test "$ac_cv_header_netinet_if_ether_h" != yes; then
45	#
46	# The simple test didn't work.
47	# Do we need to include <net/if.h> first?
48	# Unset ac_cv_header_netinet_if_ether_h so we don't
49	# treat the previous failure as a cached value and
50	# suppress the next test.
51	#
52	AC_MSG_NOTICE([Rechecking with some additional includes])
53	unset ac_cv_header_netinet_if_ether_h
54	AC_CHECK_HEADERS(netinet/if_ether.h, , , [#include <sys/types.h>
55#include <sys/socket.h>
56#include <netinet/in.h>
57struct mbuf;
58struct rtentry;
59#include <net/if.h>])
60fi
61
62AC_HEADER_TIME
63
64case "$host_os" in
65
66darwin*)
67	AC_ARG_ENABLE(universal,
68	AC_HELP_STRING([--disable-universal],[don't build universal on OS X]))
69	if test "$enable_universal" != "no"; then
70		case "$host_os" in
71
72		darwin9.*)
73			#
74			# Leopard.  Build for x86 and 32-bit PowerPC, with
75			# x86 first.  (That's what Apple does.)
76			#
77			V_CCOPT="$V_CCOPT -arch i386 -arch ppc"
78			LDFLAGS="$LDFLAGS -arch i386 -arch ppc"
79			;;
80
81		darwin10.*)
82			#
83			# Snow Leopard.  Build for x86-64 and x86, with
84			# x86-64 first.  (That's what Apple does.)
85			#
86			V_CCOPT="$V_CCOPT -arch x86_64 -arch i386"
87			LDFLAGS="$LDFLAGS -arch x86_64 -arch i386"
88			;;
89		esac
90	fi
91	;;
92esac
93
94
95AC_ARG_WITH(smi,
96[  --with-smi              link with libsmi (allows to load MIBs on the fly to decode SNMP packets. [default=yes]
97  --without-smi           don't link with libsmi],,
98   with_smi=yes)
99
100if test "x$with_smi" != "xno" ; then
101	AC_CHECK_HEADER(smi.h,
102	[
103		#
104		# OK, we found smi.h.  Do we have libsmi with smiInit?
105		#
106		AC_CHECK_LIB(smi, smiInit,
107		[
108			#
109			# OK, we have libsmi with smiInit.  Can we use it?
110			#
111			AC_MSG_CHECKING([whether to enable libsmi])
112			savedlibs="$LIBS"
113			LIBS="-lsmi $LIBS"
114			AC_TRY_RUN(
115				[
116/* libsmi available check */
117#include <smi.h>
118main()
119{
120  int current, revision, age, n;
121  const int required = 2;
122  if (smiInit(""))
123    exit(1);
124  if (strcmp(SMI_LIBRARY_VERSION, smi_library_version))
125    exit(2);
126  n = sscanf(smi_library_version, "%d:%d:%d", &current, &revision, &age);
127  if (n != 3)
128    exit(3);
129  if (required < current - age || required > current)
130    exit(4);
131  exit(0);
132}
133				],
134				[
135					AC_MSG_RESULT(yes)
136					AC_DEFINE(USE_LIBSMI, 1,
137					    [Define if you enable support for libsmi])
138				],
139				[
140					dnl autoconf documentation says that
141					dnl $? contains the exit value.
142					dnl reality is that it does not.
143					dnl We leave this in just in case
144					dnl autoconf ever comes back to
145					dnl match the documentation.
146					case $? in
147					  1) AC_MSG_RESULT(no - smiInit failed) ;;
148					  2) AC_MSG_RESULT(no - header/library version mismatch) ;;
149					  3) AC_MSG_RESULT(no - can't determine library version) ;;
150					  4) AC_MSG_RESULT(no - too old) ;;
151					  *) AC_MSG_RESULT(no) ;;
152					esac
153					LIBS="$savedlibs"
154				],
155				[
156					AC_MSG_RESULT(not when cross-compiling)
157					LIBS="$savedlibs"
158				]
159			)
160		])
161	])
162fi
163
164AC_MSG_CHECKING([whether to enable the possibly-buggy SMB printer])
165AC_ARG_ENABLE(smb,
166[  --enable-smb            enable possibly-buggy SMB printer [default=yes]
167  --disable-smb           disable possibly-buggy SMB printer],,
168   enableval=yes)
169case "$enableval" in
170yes)	AC_MSG_RESULT(yes)
171	AC_WARN([The SMB printer may have exploitable buffer overflows!!!])
172	AC_DEFINE(TCPDUMP_DO_SMB, 1,
173	    [define if you want to build the possibly-buggy SMB printer])
174	LOCALSRC="print-smb.c smbutil.c $LOCALSRC"
175	;;
176*)	AC_MSG_RESULT(no)
177	;;
178esac
179
180AC_ARG_WITH(user, [  --with-user=USERNAME    drop privileges by default to USERNAME])
181AC_MSG_CHECKING([whether to drop root privileges by default])
182if test ! -z "$with_user" ; then
183       AC_DEFINE_UNQUOTED(WITH_USER, "$withval",
184           [define if should drop privileges by default])
185       AC_MSG_RESULT(to \"$withval\")
186else
187       AC_MSG_RESULT(no)
188fi
189
190AC_ARG_WITH(chroot, [  --with-chroot=DIRECTORY when dropping privileges, chroot to DIRECTORY])
191AC_MSG_CHECKING([whether to chroot])
192if test ! -z "$with_chroot" && test "$with_chroot" != "no" ; then
193       AC_DEFINE_UNQUOTED(WITH_CHROOT, "$withval",
194           [define if should chroot when dropping privileges])
195       AC_MSG_RESULT(to \"$withval\")
196else
197       AC_MSG_RESULT(no)
198fi
199
200AC_ARG_WITH(sandbox-capsicum,
201	AS_HELP_STRING([--with-sandbox-capsicum],
202		       [use Capsicum security functions @<:@default=yes, if available@:>@]))
203#
204# Check whether various functions are available.  If any are, set
205# ac_lbl_capsicum_function_seen to yes; if any are not, set
206# ac_lbl_capsicum_function_not_seen to yes.
207#
208# We don't check cap_rights_init(), as it's a macro, wrapping another
209# function, in at least some versions of FreeBSD, and AC_CHECK_FUNCS()
210# doesn't handle that.
211#
212# All of the ones we check for must be available in order to enable
213# capsicum sandboxing.
214#
215# XXX - do we need to check for all of them, or are there some that, if
216# present, imply others are present?
217#
218if test ! -z "$with_sandbox-capsicum" && test "$with_sandbox-capsicum" != "no" ; then
219	AC_CHECK_FUNCS(cap_enter cap_rights_limit cap_ioctls_limit openat,
220	    ac_lbl_capsicum_function_seen=yes,
221	    ac_lbl_capsicum_function_not_seen=yes)
222fi
223AC_MSG_CHECKING([whether to sandbox using capsicum])
224if test "x$ac_lbl_capsicum_function_seen" = "xyes" -a "x$ac_lbl_capsicum_function_not_seen" != "xyes"; then
225	AC_DEFINE(HAVE_CAPSICUM, 1, [capsicum support available])
226	AC_MSG_RESULT(yes)
227else
228	AC_MSG_RESULT(no)
229fi
230
231#
232# We must check this before checking whether to enable IPv6, because,
233# on some platforms (such as SunOS 5.x), the test program requires
234# the extra networking libraries.
235#
236AC_LBL_LIBRARY_NET
237
238AC_MSG_CHECKING([whether to enable ipv6])
239AC_ARG_ENABLE(ipv6,
240[  --enable-ipv6           enable ipv6 (with ipv4) support
241  --disable-ipv6          disable ipv6 support],
242[ case "$enableval" in
243yes)   AC_MSG_RESULT(yes)
244       LOCALSRC="print-ip6opts.c print-mobility.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c print-dhcp6.c print-babel.c $LOCALSRC"
245       AC_DEFINE(INET6, 1, [Define if you enable IPv6 support])
246       ipv6=yes
247       ;;
248*)
249       AC_MSG_RESULT(no)
250       ipv6=no
251       ;;
252  esac ],
253
254  AC_COMPILE_IFELSE(
255    [
256      AC_LANG_SOURCE(
257	[[/* AF_INET6 available check */
258#include <sys/types.h>
259#include <sys/socket.h>
260#include <netinet/in.h>
261#ifdef AF_INET6
262void
263foo(struct in6_addr *addr)
264{
265 memset(addr, 0, sizeof (struct in6_addr));
266}
267#else
268#error "AF_INET6 not defined"
269#endif
270        ]])
271    ],
272[ AC_MSG_RESULT(yes)
273  LOCALSRC="print-ip6opts.c print-mobility.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c print-dhcp6.c print-babel.c $LOCALSRC"
274  AC_DEFINE(INET6, 1, [Define if you enable IPv6 support])
275  ipv6=yes],
276[ AC_MSG_RESULT(no)
277  ipv6=no],
278[ AC_MSG_RESULT(no)
279  ipv6=no]
280))
281
282ipv6type=unknown
283ipv6lib=none
284ipv6trylibc=no
285
286if test "$ipv6" = "yes"; then
287	AC_MSG_CHECKING([ipv6 stack type])
288	for i in inria kame linux-glibc linux-libinet6 toshiba v6d zeta; do
289		case $i in
290		inria)
291			dnl http://www.kame.net/
292			AC_EGREP_CPP(yes,
293[#include <netinet/in.h>
294#ifdef IPV6_INRIA_VERSION
295yes
296#endif],
297				[ipv6type=$i;
298				CFLAGS="-DINET6 $CFLAGS"])
299			;;
300		kame)
301			dnl http://www.kame.net/
302			AC_EGREP_CPP(yes,
303[#include <netinet/in.h>
304#ifdef __KAME__
305yes
306#endif],
307				[ipv6type=$i;
308				ipv6lib=inet6;
309				ipv6libdir=/usr/local/v6/lib;
310				ipv6trylibc=yes;
311				CFLAGS="-DINET6 $CFLAGS"])
312			;;
313		linux-glibc)
314			dnl http://www.v6.linux.or.jp/
315			AC_EGREP_CPP(yes,
316[#include <features.h>
317#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1
318yes
319#endif],
320				[ipv6type=$i;
321				CFLAGS="-DINET6 $CFLAGS"])
322			;;
323		linux-libinet6)
324			dnl http://www.v6.linux.or.jp/
325			dnl
326			dnl This also matches Solaris 8 and Tru64 UNIX 5.1,
327			dnl and possibly other versions of those OSes
328			dnl
329			if test -d /usr/inet6 -o -f /usr/include/netinet/ip6.h; then
330				ipv6type=$i
331				ipv6lib=inet6
332				ipv6libdir=/usr/inet6/lib
333				ipv6trylibc=yes;
334				CFLAGS="-DINET6 -I/usr/inet6/include $CFLAGS"
335			fi
336			;;
337		toshiba)
338			AC_EGREP_CPP(yes,
339[#include <sys/param.h>
340#ifdef _TOSHIBA_INET6
341yes
342#endif],
343				[ipv6type=$i;
344				ipv6lib=inet6;
345				ipv6libdir=/usr/local/v6/lib;
346				CFLAGS="-DINET6 $CFLAGS"])
347			;;
348		v6d)
349			AC_EGREP_CPP(yes,
350[#include </usr/local/v6/include/sys/v6config.h>
351#ifdef __V6D__
352yes
353#endif],
354				[ipv6type=$i;
355				ipv6lib=v6;
356				ipv6libdir=/usr/local/v6/lib;
357				CFLAGS="-I/usr/local/v6/include $CFLAGS"])
358			;;
359		zeta)
360			AC_EGREP_CPP(yes,
361[#include <sys/param.h>
362#ifdef _ZETA_MINAMI_INET6
363yes
364#endif],
365				[ipv6type=$i;
366				ipv6lib=inet6;
367				ipv6libdir=/usr/local/v6/lib;
368				CFLAGS="-DINET6 $CFLAGS"])
369			;;
370		esac
371		if test "$ipv6type" != "unknown"; then
372			break
373		fi
374	done
375	AC_MSG_RESULT($ipv6type)
376fi
377
378if test "$ipv6" = "yes" -a "$ipv6lib" != "none"; then
379	if test -d $ipv6libdir -a -f $ipv6libdir/lib$ipv6lib.a; then
380		LIBS="-L$ipv6libdir -l$ipv6lib $LIBS"
381		echo "You have $ipv6lib library, using it"
382	else
383		if test "$ipv6trylibc" = "yes"; then
384			echo "You do not have $ipv6lib library, using libc"
385		else
386			echo 'Fatal: no $ipv6lib library found.  cannot continue.'
387			echo "You need to fetch lib$ipv6lib.a from appropriate"
388			echo 'ipv6 kit and compile beforehand.'
389			exit 1
390		fi
391	fi
392fi
393
394
395if test "$ipv6" = "yes"; then
396	#
397	# XXX - on Tru64 UNIX 5.1, there is no "getaddrinfo()"
398	# function in libc; there are "ngetaddrinfo()" and
399	# "ogetaddrinfo()" functions, and <netdb.h> #defines
400	# "getaddrinfo" to be either "ngetaddrinfo" or
401	# "ogetaddrinfo", depending on whether _SOCKADDR_LEN
402	# or _XOPEN_SOURCE_EXTENDED are defined or not.
403	#
404	# So this test doesn't work on Tru64 5.1, and possibly
405	# on other 5.x releases.  This causes the configure
406	# script to become confused, and results in libpcap
407	# being unbuildable.
408	#
409	AC_SEARCH_LIBS(getaddrinfo, socket, [dnl
410	AC_MSG_CHECKING(getaddrinfo bug)
411	AC_CACHE_VAL(td_cv_buggygetaddrinfo, [AC_TRY_RUN([
412#include <sys/types.h>
413#include <netdb.h>
414#include <string.h>
415#include <sys/socket.h>
416#include <netinet/in.h>
417
418main()
419{
420  int passive, gaierr, inet4 = 0, inet6 = 0;
421  struct addrinfo hints, *ai, *aitop;
422  char straddr[INET6_ADDRSTRLEN], strport[16];
423
424  for (passive = 0; passive <= 1; passive++) {
425    memset(&hints, 0, sizeof(hints));
426    hints.ai_family = AF_UNSPEC;
427    hints.ai_flags = passive ? AI_PASSIVE : 0;
428    hints.ai_socktype = SOCK_STREAM;
429    hints.ai_protocol = IPPROTO_TCP;
430    if ((gaierr = getaddrinfo(NULL, "54321", &hints, &aitop)) != 0) {
431      (void)gai_strerror(gaierr);
432      goto bad;
433    }
434    for (ai = aitop; ai; ai = ai->ai_next) {
435      if (ai->ai_addr == NULL ||
436          ai->ai_addrlen == 0 ||
437          getnameinfo(ai->ai_addr, ai->ai_addrlen,
438                      straddr, sizeof(straddr), strport, sizeof(strport),
439                      NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
440        goto bad;
441      }
442      switch (ai->ai_family) {
443      case AF_INET:
444        if (strcmp(strport, "54321") != 0) {
445          goto bad;
446        }
447        if (passive) {
448          if (strcmp(straddr, "0.0.0.0") != 0) {
449            goto bad;
450          }
451        } else {
452          if (strcmp(straddr, "127.0.0.1") != 0) {
453            goto bad;
454          }
455        }
456        inet4++;
457        break;
458      case AF_INET6:
459        if (strcmp(strport, "54321") != 0) {
460          goto bad;
461        }
462        if (passive) {
463          if (strcmp(straddr, "::") != 0) {
464            goto bad;
465          }
466        } else {
467          if (strcmp(straddr, "::1") != 0) {
468            goto bad;
469          }
470        }
471        inet6++;
472        break;
473      case AF_UNSPEC:
474        goto bad;
475        break;
476#ifdef AF_UNIX
477      case AF_UNIX:
478#else
479#ifdef AF_LOCAL
480      case AF_LOCAL:
481#endif
482#endif
483      default:
484        /* another family support? */
485        break;
486      }
487    }
488  }
489
490  /* supported family should be 2, unsupported family should be 0 */
491  if (!(inet4 == 0 || inet4 == 2))
492    goto bad;
493  if (!(inet6 == 0 || inet6 == 2))
494    goto bad;
495
496  if (aitop)
497    freeaddrinfo(aitop);
498  exit(0);
499
500 bad:
501  if (aitop)
502    freeaddrinfo(aitop);
503  exit(1);
504}
505],
506	td_cv_buggygetaddrinfo=no,
507	td_cv_buggygetaddrinfo=yes,
508	td_cv_buggygetaddrinfo=unknown)])
509	if test "$td_cv_buggygetaddrinfo" = no; then
510		AC_MSG_RESULT(good)
511	elif test "$td_cv_buggygetaddrinfo" = unknown; then
512		AC_MSG_RESULT([unknown (cross-compiling)])
513	else
514		AC_MSG_RESULT(buggy)
515	fi
516
517	if test "$td_cv_buggygetaddrinfo" = "yes"; then
518		#
519		# XXX - it doesn't appear that "ipv6type" can ever be
520		# set to "linux".  Should this be testing for
521		# "linux-glibc", or for that *or* "linux-libinet6"?
522		# If the latter, note that "linux-libinet6" is also
523		# the type given to some non-Linux OSes.
524		#
525		if test "$ipv6type" != "linux"; then
526			echo 'Fatal: You must get working getaddrinfo() function.'
527			echo '       or you can specify "--disable-ipv6"'.
528			exit 1
529		else
530			echo 'Warning: getaddrinfo() implementation on your system seems be buggy.'
531			echo '         Better upgrade your system library to newest version'
532			echo '         of GNU C library (aka glibc).'
533		fi
534	fi
535	])
536	AC_REPLACE_FUNCS(getnameinfo)
537fi
538
539AC_CACHE_CHECK([for dnet_htoa declaration in netdnet/dnetdb.h],
540[td_cv_decl_netdnet_dnetdb_h_dnet_htoa],
541[AC_EGREP_HEADER(dnet_htoa, netdnet/dnetdb.h,
542	td_cv_decl_netdnet_dnetdb_h_dnet_htoa=yes,
543	td_cv_decl_netdnet_dnetdb_h_dnet_htoa=no)])
544if test "$td_cv_decl_netdnet_dnetdb_h_dnet_htoa" = yes; then
545	AC_DEFINE(HAVE_NETDNET_DNETDB_H_DNET_HTOA, 1,
546	    [define if you have a dnet_htoa declaration in <netdnet/dnetdb.h>])
547fi
548
549dnl
550dnl Checks for addrinfo structure
551AC_STRUCT_ADDRINFO(ac_cv_addrinfo)
552if test "$ac_cv_addrinfo" = no; then
553	missing_includes=yes
554fi
555
556dnl
557dnl Checks for NI_MAXSERV
558AC_NI_MAXSERV(ac_cv_maxserv)
559if test "$ac_cv_maxserv" = no; then
560	missing_includes=yes
561fi
562
563dnl
564dnl Checks for NI_NAMEREQD
565AC_NI_NAMEREQD(ac_cv_namereqd)
566if test "$ac_cv_namereqd" = no; then
567	missing_includes=yes
568fi
569
570AC_REPLACE_FUNCS(vfprintf strcasecmp strlcat strlcpy strdup strsep getopt_long)
571AC_CHECK_FUNCS(fork vfork strftime)
572AC_CHECK_FUNCS(setlinebuf alarm)
573
574needsnprintf=no
575AC_CHECK_FUNCS(vsnprintf snprintf,,
576	[needsnprintf=yes])
577if test $needsnprintf = yes; then
578	AC_LIBOBJ(snprintf)
579fi
580
581AC_LBL_TYPE_SIGNAL
582
583AC_SEARCH_LIBS(dnet_htoa, dnet,
584    AC_DEFINE(HAVE_DNET_HTOA, 1, [define if you have the dnet_htoa function]))
585
586AC_CHECK_LIB(rpc, main)		dnl It's unclear why we might need -lrpc
587
588dnl Some platforms may need -lnsl for getrpcbynumber.
589AC_SEARCH_LIBS(getrpcbynumber, nsl,
590    AC_DEFINE(HAVE_GETRPCBYNUMBER, 1, [define if you have getrpcbynumber()]))
591
592dnl AC_CHECK_LIB(z, uncompress)
593dnl AC_CHECK_HEADERS(zlib.h)
594
595AC_LBL_LIBPCAP(V_PCAPDEP, V_INCLS)
596
597#
598# Check for these after AC_LBL_LIBPCAP, so we link with the appropriate
599# libraries (e.g., "-lsocket -lnsl" on Solaris).
600#
601# We don't use AC_REPLACE_FUNCS because that uses AC_CHECK_FUNCS which
602# use AC_CHECK_FUNC which doesn't let us specify the right #includes
603# to make this work on BSD/OS 4.x.  BSD/OS 4.x ships with the BIND8
604# resolver, and the way it defines inet_{ntop,pton} is rather strange;
605# it does not ship with a libc symbol "inet_ntop()", it ships with
606# "_inet_ntop()", and has a #define macro in one of the system headers
607# to rename it.
608#
609dnl AC_TRY_COMPILE(inet_ntop inet_pton inet_aton)
610AC_MSG_CHECKING(for inet_ntop)
611AC_TRY_LINK([#include <sys/types.h>
612#include <sys/socket.h>
613#include <netinet/in.h>
614#include <arpa/inet.h>], [char src[4], dst[128];
615inet_ntop(AF_INET, src, dst, sizeof(dst));],
616	[AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
617	AC_LIBOBJ(inet_ntop)])
618AC_MSG_CHECKING(for inet_pton)
619AC_TRY_LINK([#include <sys/types.h>
620#include <sys/socket.h>
621#include <netinet/in.h>
622#include <arpa/inet.h>], [char src[128], dst[4];
623inet_pton(AF_INET, src, dst);],
624	[AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
625	AC_LIBOBJ(inet_pton)])
626AC_MSG_CHECKING(for inet_aton)
627AC_TRY_LINK([#include <sys/types.h>
628#include <netinet/in.h>
629#include <arpa/inet.h>], [char src[128];
630struct in_addr dst;
631inet_aton(src, &dst);],
632	[AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
633	AC_LIBOBJ(inet_aton)])
634
635#
636# Check for these after AC_LBL_LIBPCAP, for the same reason.
637#
638# You are in a twisty little maze of UN*Xes, all different.
639# Some might not have ether_ntohost().
640# Some might have it, but not declare it in any header file.
641# Some might have it, but declare it in <netinet/if_ether.h>.
642# Some might have it, but declare it in <netinet/ether.h>
643# (And some might have it but document it as something declared in
644# <netinet/ethernet.h>, although <netinet/if_ether.h> appears to work.)
645#
646# Before you is a C compiler.
647#
648AC_CHECK_FUNCS(ether_ntohost, [
649    AC_CACHE_CHECK(for buggy ether_ntohost, ac_cv_buggy_ether_ntohost, [
650	AC_TRY_RUN([
651		#include <netdb.h>
652		#include <sys/types.h>
653		#include <sys/param.h>
654		#include <sys/socket.h>
655
656		int
657		main(int argc, char **argv)
658		{
659			u_char ea[6] = { 0xff, 0xff, 0xff, 0xff, 0xff };
660			char name[MAXHOSTNAMELEN];
661
662			ether_ntohost(name, (struct ether_addr *)ea);
663			exit(0);
664		}
665	], [ac_cv_buggy_ether_ntohost=no],
666	   [ac_cv_buggy_ether_ntohost=yes],
667	   [ac_cv_buggy_ether_ntohost="not while cross-compiling"])])
668    if test "$ac_cv_buggy_ether_ntohost" = "no"; then
669	AC_DEFINE(USE_ETHER_NTOHOST, 1,
670	    [define if you have ether_ntohost() and it works])
671    fi
672])
673if test "$ac_cv_func_ether_ntohost" = yes -a \
674    "$ac_cv_buggy_ether_ntohost" = "no"; then
675	#
676	# OK, we have ether_ntohost().  Do we have <netinet/if_ether.h>?
677	#
678	if test "$ac_cv_header_netinet_if_ether_h" = yes; then
679		#
680		# Yes.  Does it declare ether_ntohost()?
681		#
682		AC_CHECK_DECL(ether_ntohost,
683		    [
684			AC_DEFINE(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST,,
685			    [Define to 1 if netinet/if_ether.h declares `ether_ntohost'])
686		    ],,
687		    [
688#include <sys/types.h>
689#include <sys/socket.h>
690#include <netinet/in.h>
691#include <arpa/inet.h>
692struct mbuf;
693struct rtentry;
694#include <net/if.h>
695#include <netinet/if_ether.h>
696		    ])
697	fi
698	#
699	# Did that succeed?
700	#
701	if test "$ac_cv_have_decl_ether_ntohost" != yes; then
702		#
703		# No, how about <netinet/ether.h>, as on Linux?
704		#
705		AC_CHECK_HEADERS(netinet/ether.h)
706		if test "$ac_cv_header_netinet_ether_h" = yes; then
707			#
708			# We have it - does it declare ether_ntohost()?
709			# Unset ac_cv_have_decl_ether_ntohost so we don't
710			# treat the previous failure as a cached value and
711			# suppress the next test.
712			#
713			unset ac_cv_have_decl_ether_ntohost
714			AC_CHECK_DECL(ether_ntohost,
715			    [
716				AC_DEFINE(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST,,
717				    [Define to 1 if netinet/ether.h declares `ether_ntohost'])
718			    ],,
719			    [
720#include <netinet/ether.h>
721			    ])
722		fi
723	fi
724	#
725	# Is ether_ntohost() declared?
726	#
727	if test "$ac_cv_have_decl_ether_ntohost" != yes; then
728		#
729		# No, we'll have to declare it ourselves.
730		# Do we have "struct ether_addr"?
731		#
732		AC_CHECK_TYPES(struct ether_addr,,,
733		    [
734#include <sys/types.h>
735#include <sys/socket.h>
736#include <netinet/in.h>
737#include <arpa/inet.h>
738struct mbuf;
739struct rtentry;
740#include <net/if.h>
741#include <netinet/if_ether.h>
742		    ])
743		AC_DEFINE(HAVE_DECL_ETHER_NTOHOST, 0,
744		    [Define to 1 if you have the declaration of `ether_ntohost', and to 0 if you
745don't.])
746	else
747		AC_DEFINE(HAVE_DECL_ETHER_NTOHOST, 1,
748		    [Define to 1 if you have the declaration of `ether_ntohost', and to 0 if you
749don't.])
750	fi
751fi
752
753# libdlpi is needed for Solaris 11 and later.
754AC_CHECK_LIB(dlpi, dlpi_walk, LIBS="$LIBS -ldlpi" LDFLAGS="-L/lib $LDFLAGS", ,-L/lib)
755
756dnl portability macros for getaddrinfo/getnameinfo
757dnl
758dnl Check for sa_len
759AC_CHECK_SA_LEN(ac_cv_sockaddr_has_sa_len)
760if test "$ac_cv_sockaddr_has_sa_len" = no; then
761	missing_includes=yes
762fi
763
764dnl
765dnl Check for "pcap_list_datalinks()", "pcap_set_datalink()",
766dnl and "pcap_datalink_name_to_val()", and use substitute versions
767dnl if they're not present.
768dnl
769AC_CHECK_FUNC(pcap_list_datalinks,
770	[
771	    AC_DEFINE(HAVE_PCAP_LIST_DATALINKS, 1,
772		[define if libpcap has pcap_list_datalinks()])
773	    AC_CHECK_FUNCS(pcap_free_datalinks)
774	],
775	[
776	    AC_LIBOBJ(datalinks)
777	])
778AC_CHECK_FUNCS(pcap_set_datalink)
779AC_CHECK_FUNC(pcap_datalink_name_to_val,
780	[
781	    AC_DEFINE(HAVE_PCAP_DATALINK_NAME_TO_VAL, 1,
782		[define if libpcap has pcap_datalink_name_to_val()])
783	    AC_CHECK_FUNC(pcap_datalink_val_to_description,
784		AC_DEFINE(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION, 1,
785		    [define if libpcap has pcap_datalink_val_to_description()]),
786		[
787		    AC_LIBOBJ(dlnames)
788		])
789	],
790	[
791	    AC_LIBOBJ(dlnames)
792	])
793
794dnl
795dnl Check for "pcap_breakloop()"; you can't substitute for it if
796dnl it's absent (it has hooks into the live capture routines),
797dnl so just define the HAVE_ value if it's there.
798dnl
799AC_CHECK_FUNCS(pcap_breakloop)
800
801dnl
802dnl Check for "pcap_dump_ftell()" and use a substitute version
803dnl if it's not present.
804dnl
805AC_CHECK_FUNC(pcap_dump_ftell,
806	AC_DEFINE(HAVE_PCAP_DUMP_FTELL, 1,
807	    [define if libpcap has pcap_dump_ftell()]),
808	[
809	    AC_LIBOBJ(pcap_dump_ftell)
810	])
811
812#
813# Do we have the new open API?  Check for pcap_create, and assume that,
814# if we do, we also have pcap_activate() and the other new routines
815# introduced in libpcap 1.0.0.
816#
817AC_CHECK_FUNCS(pcap_create)
818if test $ac_cv_func_pcap_create = "yes" ; then
819	#
820	# OK, do we have pcap_set_tstamp_type?  If so, assume we have
821	# pcap_list_tstamp_types and pcap_free_tstamp_types as well.
822	#
823	AC_CHECK_FUNCS(pcap_set_tstamp_type)
824	#
825	# And do we have pcap_set_tstamp_precision?  If so, we assume
826	# we also have pcap_open_offline_with_tstamp_precision.
827	#
828	AC_CHECK_FUNCS(pcap_set_tstamp_precision)
829fi
830
831#
832# Check for a miscellaneous collection of functions which we use
833# if we have them.
834#
835AC_CHECK_FUNCS(pcap_findalldevs pcap_dump_flush pcap_lib_version pcap_setdirection pcap_set_immediate_mode)
836if test $ac_cv_func_pcap_findalldevs = "yes" ; then
837dnl Check for Mac OS X, which may ship pcap.h from 0.6 but libpcap may
838dnl be 0.8; this means that lib has pcap_findalldevs but header doesn't
839dnl have pcap_if_t.
840    savedcppflags="$CPPFLAGS"
841    CPPFLAGS="$CPPFLAGS $V_INCLS"
842    AC_CHECK_TYPES(pcap_if_t, , , [#include <pcap.h>])
843    CPPFLAGS="$savedcppflags"
844fi
845
846if test $ac_cv_func_pcap_lib_version = "no" ; then
847    AC_MSG_CHECKING(whether pcap_version is defined by libpcap)
848    AC_TRY_LINK([],
849       [
850	extern char pcap_version[];
851
852	return (int)pcap_version;
853       ],
854       ac_lbl_cv_pcap_version_defined=yes,
855       ac_lbl_cv_pcap_version_defined=no)
856    if test "$ac_lbl_cv_pcap_version_defined" = yes ; then
857	AC_MSG_RESULT(yes)
858	AC_DEFINE(HAVE_PCAP_VERSION, 1, [define if libpcap has pcap_version])
859    else
860	AC_MSG_RESULT(no)
861    fi
862fi
863AC_MSG_CHECKING(whether pcap_debug is defined by libpcap)
864AC_TRY_LINK([],
865   [
866	extern int pcap_debug;
867
868	return pcap_debug;
869   ],
870   ac_lbl_cv_pcap_debug_defined=yes,
871   ac_lbl_cv_pcap_debug_defined=no)
872if test "$ac_lbl_cv_pcap_debug_defined" = yes ; then
873	AC_MSG_RESULT(yes)
874	AC_DEFINE(HAVE_PCAP_DEBUG, 1, [define if libpcap has pcap_debug])
875else
876	AC_MSG_RESULT(no)
877	#
878	# OK, what about "yydebug"?
879	#
880	AC_MSG_CHECKING(whether yydebug is defined by libpcap)
881	AC_TRY_LINK([],
882	   [
883		extern int yydebug;
884
885		return yydebug;
886	   ],
887	   ac_lbl_cv_yydebug_defined=yes,
888	   ac_lbl_cv_yydebug_defined=no)
889	if test "$ac_lbl_cv_yydebug_defined" = yes ; then
890		AC_MSG_RESULT(yes)
891		AC_DEFINE(HAVE_YYDEBUG, 1, [define if libpcap has yydebug])
892	else
893		AC_MSG_RESULT(no)
894	fi
895fi
896AC_REPLACE_FUNCS(bpf_dump)	dnl moved to libpcap in 0.6
897
898V_GROUP=0
899if test -f /etc/group -a ! -z "`grep '^wheel:' /etc/group`" ; then
900	V_GROUP=wheel
901fi
902#
903# Assume V7/BSD convention for man pages (file formats in section 5,
904# miscellaneous info in section 7).
905#
906MAN_FILE_FORMATS=5
907MAN_MISC_INFO=7
908case "$host_os" in
909
910aix*)
911	dnl Workaround to enable certain features
912	AC_DEFINE(_SUN,1,[define on AIX to get certain functions])
913	;;
914
915hpux*)
916	#
917	# Use System V conventions for man pages.
918	#
919	MAN_FILE_FORMATS=4
920	MAN_MISC_INFO=5
921	;;
922
923irix*)
924	V_GROUP=sys
925
926	#
927	# Use System V conventions for man pages.
928	#
929	MAN_FILE_FORMATS=4
930	MAN_MISC_INFO=5
931	;;
932
933osf*)
934	V_GROUP=system
935
936	#
937	# Use System V conventions for man pages.
938	#
939	MAN_FILE_FORMATS=4
940	MAN_MISC_INFO=5
941	;;
942
943solaris*)
944	V_GROUP=sys
945
946	#
947	# Use System V conventions for man pages.
948	#
949	MAN_FILE_FORMATS=4
950	MAN_MISC_INFO=5
951	;;
952esac
953
954if test -f /dev/bpf -o -f /dev/bpf0; then
955	V_GROUP=bpf
956fi
957
958#
959# Make sure we have definitions for all the C99 specified-width types
960# (regardless of whether the environment is a C99 environment or not).
961#
962AC_TYPE_INT8_T
963AC_TYPE_INT16_T
964AC_TYPE_INT32_T
965AC_TYPE_INT64_T
966AC_TYPE_UINT8_T
967AC_TYPE_UINT16_T
968AC_TYPE_UINT32_T
969AC_TYPE_UINT64_T
970
971#
972# Make sure we have a definition for C99's uintptr_t (regardless of
973# whether the environment is a C99 environment or not).
974#
975AC_TYPE_UINTPTR_T
976
977#
978# Define the old BSD specified-width types in terms of the C99 types;
979# we may need them with libpcap include files.
980#
981AC_CHECK_TYPE([u_int8_t], ,
982	[AC_DEFINE([u_int8_t], [uint8_t],
983	[Define to `uint8_t' if u_int8_t not defined.])],
984	[AC_INCLUDES_DEFAULT
985#include <sys/types.h>
986])
987AC_CHECK_TYPE([u_int16_t], ,
988	[AC_DEFINE([u_int16_t], [uint16_t],
989	[Define to `uint16_t' if u_int16_t not defined.])],
990	[AC_INCLUDES_DEFAULT
991#include <sys/types.h>
992])
993AC_CHECK_TYPE([u_int32_t], ,
994	[AC_DEFINE([u_int32_t], [uint32_t],
995	[Define to `uint32_t' if u_int32_t not defined.])],
996	[AC_INCLUDES_DEFAULT
997#include <sys/types.h>
998])
999AC_CHECK_TYPE([u_int64_t], ,
1000	[AC_DEFINE([u_int64_t], [uint64_t],
1001	[Define to `uint64_t' if u_int64_t not defined.])],
1002	[AC_INCLUDES_DEFAULT
1003#include <sys/types.h>
1004])
1005
1006#
1007# Check for <inttypes.h>
1008#
1009AC_CHECK_HEADERS(inttypes.h,
1010  [
1011    #
1012    # OK, we have inttypes.h, but does it define all the PRI[doxu]64 macros?
1013    # Some systems have an inttypes.h that doesn't define all of them.
1014    #
1015    AC_MSG_CHECKING([[whether inttypes.h defines the PRI[doxu]64 macros]])
1016    AC_COMPILE_IFELSE(
1017      [
1018	AC_LANG_SOURCE(
1019	  [[
1020	    #include <inttypes.h>
1021	    #include <stdio.h>
1022	    #include <sys/types.h>
1023
1024	    main()
1025	    {
1026	      printf("%" PRId64 "\n", (uint64_t)1);
1027	      printf("%" PRIo64 "\n", (uint64_t)1);
1028	      printf("%" PRIx64 "\n", (uint64_t)1);
1029	      printf("%" PRIu64 "\n", (uint64_t)1);
1030	    }
1031	  ]])
1032      ],
1033      [
1034	AC_MSG_RESULT(yes)
1035	ac_lbl_inttypes_h_defines_formats=yes
1036      ],
1037      [
1038	AC_MSG_RESULT(no)
1039	ac_lbl_inttypes_h_defines_formats=no
1040      ])
1041  ],
1042  [
1043    #
1044    # We don't have inttypes.h, so it obviously can't define those
1045    # macros.
1046    #
1047    ac_lbl_inttypes_h_defines_formats=no
1048  ])
1049if test "$ac_lbl_inttypes_h_defines_formats" = no; then
1050  AC_LBL_CHECK_64BIT_FORMAT(l,
1051    [
1052      AC_LBL_CHECK_64BIT_FORMAT(ll,
1053        [
1054          AC_LBL_CHECK_64BIT_FORMAT(L,
1055	    [
1056	      AC_LBL_CHECK_64BIT_FORMAT(q,
1057	        [
1058	          AC_MSG_ERROR([neither %llx nor %Lx nor %qx worked on a 64-bit integer])
1059	        ])
1060	    ])
1061	])
1062    ])
1063fi
1064
1065#
1066# Check for some headers introduced in later versions of libpcap
1067# and used by some printers.
1068#
1069# Those headers use the {u_}intN_t types, so we must do this after
1070# we check for what's needed to get them defined.
1071#
1072savedcppflags="$CPPFLAGS"
1073CPPFLAGS="$CPPFLAGS $V_INCLS"
1074AC_CHECK_HEADERS(pcap/bluetooth.h,,,[#include "tcpdump-stdinc.h"])
1075AC_CHECK_HEADERS(pcap/nflog.h,,,[#include "tcpdump-stdinc.h"])
1076AC_CHECK_HEADERS(pcap/usb.h,,,[#include "tcpdump-stdinc.h"])
1077CPPFLAGS="$savedcppflags"
1078
1079AC_PROG_RANLIB
1080AC_CHECK_TOOL([AR], [ar])
1081
1082AC_LBL_DEVEL(V_CCOPT)
1083
1084AC_LBL_SOCKADDR_SA_LEN
1085
1086AC_LBL_UNALIGNED_ACCESS
1087
1088AC_VAR_H_ERRNO
1089
1090# Check for OpenSSL libcrypto
1091AC_MSG_CHECKING(whether to use OpenSSL libcrypto)
1092# Specify location for both includes and libraries.
1093want_libcrypto=ifavailable
1094AC_ARG_WITH(crypto,
1095    AS_HELP_STRING([--with-crypto],
1096		   [use OpenSSL libcrypto @<:@default=yes, if available@:>@]),
1097[
1098	if test $withval = no
1099	then
1100		want_libcrypto=no
1101		AC_MSG_RESULT(no)
1102	elif test $withval = yes
1103	then
1104		want_libcrypto=yes
1105		AC_MSG_RESULT(yes)
1106	fi
1107],[
1108	#
1109	# Use libcrypto if it's present, otherwise don't.
1110	#
1111	want_libcrypto=ifavailable
1112	AC_MSG_RESULT([yes, if available])
1113])
1114if test "$want_libcrypto" != "no"; then
1115	AC_CHECK_LIB(crypto, DES_cbc_encrypt)
1116	AC_CHECK_HEADERS(openssl/evp.h)
1117fi
1118
1119# Check for libcap-ng
1120AC_MSG_CHECKING(whether to use libcap-ng)
1121# Specify location for both includes and libraries.
1122want_libcap_ng=ifavailable
1123AC_ARG_WITH(cap_ng,
1124    AS_HELP_STRING([--with-cap-ng],
1125		   [use libcap-ng @<:@default=yes, if available@:>@]),
1126[
1127	if test $withval = no
1128	then
1129		want_libcap_ng=no
1130		AC_MSG_RESULT(no)
1131	elif test $withval = yes
1132	then
1133		want_libcap_ng=yes
1134		AC_MSG_RESULT(yes)
1135	fi
1136],[
1137	#
1138	# Use libcap-ng if it's present, otherwise don't.
1139	#
1140	want_libcap_ng=ifavailable
1141	AC_MSG_RESULT([yes, if available])
1142])
1143if test "$want_libcap_ng" != "no"; then
1144	AC_CHECK_LIB(cap-ng, capng_change_id)
1145	AC_CHECK_HEADERS(cap-ng.h)
1146fi
1147
1148dnl
1149dnl set additional include path if necessary
1150if test "$missing_includes" = "yes"; then
1151	CPPFLAGS="$CPPFLAGS -I$srcdir/missing"
1152	V_INCLS="$V_INCLS -I$srcdir/missing"
1153fi
1154
1155AC_SUBST(V_CCOPT)
1156AC_SUBST(V_DEFS)
1157AC_SUBST(V_GROUP)
1158AC_SUBST(V_INCLS)
1159AC_SUBST(V_PCAPDEP)
1160AC_SUBST(LOCALSRC)
1161AC_SUBST(MAN_FILE_FORMATS)
1162AC_SUBST(MAN_MISC_INFO)
1163
1164AC_PROG_INSTALL
1165
1166AC_CONFIG_HEADER(config.h)
1167
1168AC_OUTPUT_COMMANDS([if test -f .devel; then
1169	echo timestamp > stamp-h
1170	cat Makefile-devel-adds >> Makefile
1171	make depend
1172fi])
1173AC_OUTPUT(Makefile tcpdump.1)
1174exit 0
1175