xref: /freebsd/contrib/tcpdump/configure.ac (revision 55141f2c8991b2a6adbf30bb0fe3e6cbc303f06d)
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#	https://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.69)
17AC_INIT(tcpdump, m4_esyscmd_s([cat VERSION]))
18AC_CONFIG_SRCDIR(tcpdump.c)
19
20AC_CANONICAL_HOST
21
22AC_LBL_C_INIT_BEFORE_CC(V_INCLS)
23#
24# Try to enable as many C99 features as we can.
25# At minimum, we want C++/C99-style // comments.
26#
27AC_PROG_CC_C99
28if test "$ac_cv_prog_cc_c99" = "no"; then
29	AC_MSG_WARN([The C compiler does not support C99; there may be compiler errors])
30fi
31AC_LBL_C_INIT(V_CCOPT, V_INCLS)
32AC_LBL_C_INLINE
33
34AC_CHECK_HEADERS(fcntl.h rpc/rpc.h rpc/rpcent.h net/if.h)
35
36case "$host_os" in
37
38darwin*)
39	AC_ARG_ENABLE(universal,
40	AS_HELP_STRING([--disable-universal],[don't build universal on macOS]))
41	if test "$enable_universal" != "no"; then
42		case "$host_os" in
43
44		darwin9.*)
45			#
46			# Leopard.  Build for x86 and 32-bit PowerPC, with
47			# x86 first.  (That's what Apple does.)
48			#
49			V_CCOPT="$V_CCOPT -arch i386 -arch ppc"
50			LDFLAGS="$LDFLAGS -arch i386 -arch ppc"
51			;;
52
53		darwin10.*)
54			#
55			# Snow Leopard.  Build for x86-64 and x86, with
56			# x86-64 first.  (That's what Apple does.)
57			#
58			V_CCOPT="$V_CCOPT -arch x86_64 -arch i386"
59			LDFLAGS="$LDFLAGS -arch x86_64 -arch i386"
60			;;
61		esac
62	fi
63	;;
64esac
65
66
67AC_ARG_WITH([smi],
68   [AS_HELP_STRING([--with-smi],
69     [link with libsmi (allows to load MIBs on the fly to decode SNMP packets) [default=yes, if available]])],
70   [],
71   [with_smi=yes])
72
73if test "x$with_smi" != "xno" ; then
74	AC_CHECK_HEADER(smi.h,
75	[
76		#
77		# OK, we found smi.h.  Do we have libsmi with smiInit?
78		#
79		AC_CHECK_LIB(smi, smiInit,
80		[
81			#
82			# OK, we have libsmi with smiInit.  Can we use it?
83			#
84			AC_MSG_CHECKING([whether to enable libsmi])
85			savedlibs="$LIBS"
86			LIBS="-lsmi $LIBS"
87			AC_TRY_RUN(
88				[
89/* libsmi available check */
90#include <stdio.h>
91#include <stdlib.h>
92#include <string.h>
93#include <smi.h>
94int main()
95{
96  int current, revision, age, n;
97  const int required = 2;
98  if (smiInit(""))
99    exit(1);
100  if (strcmp(SMI_LIBRARY_VERSION, smi_library_version))
101    exit(2);
102  n = sscanf(smi_library_version, "%d:%d:%d", &current, &revision, &age);
103  if (n != 3)
104    exit(3);
105  if (required < current - age || required > current)
106    exit(4);
107  exit(0);
108}
109				],
110				[
111					AC_MSG_RESULT(yes)
112					AC_DEFINE(USE_LIBSMI, 1,
113					    [Define if you enable support for libsmi])
114				],
115				[
116					dnl autoconf documentation says that
117					dnl $? contains the exit value.
118					dnl reality is that it does not.
119					dnl We leave this in just in case
120					dnl autoconf ever comes back to
121					dnl match the documentation.
122					case $? in
123					  1) AC_MSG_RESULT(no - smiInit failed) ;;
124					  2) AC_MSG_RESULT(no - header/library version mismatch) ;;
125					  3) AC_MSG_RESULT(no - can't determine library version) ;;
126					  4) AC_MSG_RESULT(no - too old) ;;
127					  *) AC_MSG_RESULT(no) ;;
128					esac
129					LIBS="$savedlibs"
130				],
131				[
132					AC_MSG_RESULT(not when cross-compiling)
133					LIBS="$savedlibs"
134				]
135			)
136		])
137	])
138fi
139
140AC_MSG_CHECKING([whether to enable the possibly-buggy SMB printer])
141AC_ARG_ENABLE([smb],
142   [AS_HELP_STRING([--enable-smb],
143     [enable possibly-buggy SMB printer [default=no]])],
144   [],
145   [enableval=no])
146case "$enableval" in
147yes)	AC_MSG_RESULT(yes)
148	AC_DEFINE(ENABLE_SMB, 1,
149	    [define if you want to build the possibly-buggy SMB printer])
150	LOCALSRC="print-smb.c smbutil.c $LOCALSRC"
151	;;
152*)	AC_MSG_RESULT(no)
153	;;
154esac
155
156AC_ARG_WITH(user, [  --with-user=USERNAME    drop privileges by default to USERNAME])
157AC_MSG_CHECKING([whether to drop root privileges by default])
158if test ! -z "$with_user" ; then
159       AC_DEFINE_UNQUOTED(WITH_USER, "$withval",
160           [define if should drop privileges by default])
161       AC_MSG_RESULT(to \"$withval\")
162else
163       AC_MSG_RESULT(no)
164fi
165
166AC_ARG_WITH(chroot, [  --with-chroot=DIRECTORY when dropping privileges, chroot to DIRECTORY])
167AC_MSG_CHECKING([whether to chroot])
168if test ! -z "$with_chroot" && test "$with_chroot" != "no" ; then
169       AC_DEFINE_UNQUOTED(WITH_CHROOT, "$withval",
170           [define if should chroot when dropping privileges])
171       AC_MSG_RESULT(to \"$withval\")
172else
173       AC_MSG_RESULT(no)
174fi
175
176AC_ARG_WITH(sandbox-capsicum,
177	AS_HELP_STRING([--with-sandbox-capsicum],
178		       [use Capsicum security functions @<:@default=yes, if available@:>@]))
179#
180# Check whether various functions are available.  If any are, set
181# ac_lbl_capsicum_function_seen to yes; if any are not, set
182# ac_lbl_capsicum_function_not_seen to yes.
183#
184# We don't check cap_rights_init(), as it's a macro, wrapping another
185# function, in at least some versions of FreeBSD, and AC_CHECK_FUNCS()
186# doesn't handle that.
187#
188# All of the ones we check for must be available in order to enable
189# capsicum sandboxing.
190#
191# XXX - do we need to check for all of them, or are there some that, if
192# present, imply others are present?
193#
194if test -z "$with_sandbox_capsicum" || test "$with_sandbox_capsicum" != "no" ; then
195	#
196	# First, make sure we have the required header.
197	#
198	AC_CHECK_HEADER(sys/capsicum.h,
199	[
200		#
201		# We do; now make sure we have the required functions.
202		#
203		AC_CHECK_FUNCS(cap_enter cap_rights_limit cap_ioctls_limit openat,
204		    ac_lbl_capsicum_function_seen=yes,
205		    ac_lbl_capsicum_function_not_seen=yes)
206	])
207	AC_CHECK_LIB(casper, cap_init, LIBS="$LIBS -lcasper")
208	AC_CHECK_LIB(cap_dns, cap_gethostbyaddr, LIBS="$LIBS -lcap_dns")
209fi
210AC_MSG_CHECKING([whether to sandbox using capsicum])
211if test "x$ac_lbl_capsicum_function_seen" = "xyes" -a "x$ac_lbl_capsicum_function_not_seen" != "xyes"; then
212	AC_DEFINE(HAVE_CAPSICUM, 1, [capsicum support available])
213	AC_MSG_RESULT(yes)
214else
215	AC_MSG_RESULT(no)
216fi
217AC_MSG_CHECKING([whether to sandbox using Casper library])
218if test "x$ac_cv_lib_casper_cap_init" = "xyes" -a "x$ac_cv_lib_cap_dns_cap_gethostbyaddr" = "xyes"; then
219	AC_DEFINE(HAVE_CASPER, 1, [Casper support available])
220	AC_MSG_RESULT(yes)
221else
222	AC_MSG_RESULT(no)
223fi
224
225#
226# We must check this before checking whether to check the OS's IPv6,
227# support because, on some platforms (such as SunOS 5.x), the test
228# program requires the extra networking libraries.
229#
230AC_LBL_LIBRARY_NET
231
232#
233# Check whether AF_INET6 and struct in6_addr are defined.
234# If they aren't both defined, we don't have sufficient OS
235# support for IPv6, so we don't look for IPv6 support libraries,
236# and we define AF_INET6 and struct in6_addr ourselves.
237#
238AC_MSG_CHECKING([whether the operating system supports IPv6])
239AC_COMPILE_IFELSE(
240    [
241      AC_LANG_SOURCE(
242	[[
243#include <string.h>
244/* AF_INET6 available check */
245#include <sys/types.h>
246#ifdef _WIN32
247#include <ws2tcpip.h>
248#else
249#include <sys/socket.h>
250#include <netinet/in.h>
251#endif
252#ifdef AF_INET6
253void
254foo(struct in6_addr *addr)
255{
256 memset(addr, 0, sizeof (struct in6_addr));
257}
258#else
259#error "AF_INET6 not defined"
260#endif
261	]])
262    ],
263    [
264	AC_MSG_RESULT(yes)
265	AC_DEFINE(HAVE_OS_IPV6_SUPPORT, 1,
266	    [define if the OS provides AF_INET6 and struct in6_addr])
267	ipv6=yes
268    ],
269    [
270	AC_MSG_RESULT(no)
271	ipv6=no
272    ]
273)
274
275ipv6type=unknown
276ipv6lib=none
277ipv6trylibc=no
278
279if test "$ipv6" = "yes"; then
280	AC_MSG_CHECKING([ipv6 stack type])
281	for i in inria kame linux-glibc linux-libinet6 toshiba v6d zeta; do
282		case $i in
283		inria)
284			dnl http://www.kame.net/
285			AC_EGREP_CPP(yes,
286[#include <netinet/in.h>
287#ifdef IPV6_INRIA_VERSION
288yes
289#endif],
290				[ipv6type=$i])
291			;;
292		kame)
293			dnl http://www.kame.net/
294			AC_EGREP_CPP(yes,
295[#include <netinet/in.h>
296#ifdef __KAME__
297yes
298#endif],
299				[ipv6type=$i;
300				ipv6lib=inet6;
301				ipv6libdir=/usr/local/v6/lib;
302				ipv6trylibc=yes])
303			;;
304		linux-glibc)
305			dnl http://www.v6.linux.or.jp/
306			AC_EGREP_CPP(yes,
307[#include <features.h>
308#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1
309yes
310#endif],
311				[ipv6type=$i])
312			;;
313		linux-libinet6)
314			dnl http://www.v6.linux.or.jp/
315			dnl
316			dnl This also matches Solaris 8 and Tru64 UNIX 5.1,
317			dnl and possibly other versions of those OSes
318			dnl
319			if test -d /usr/inet6 -o -f /usr/include/netinet/ip6.h; then
320				ipv6type=$i
321				ipv6lib=inet6
322				ipv6libdir=/usr/inet6/lib
323				ipv6trylibc=yes;
324				CFLAGS="-I/usr/inet6/include $CFLAGS"
325			fi
326			;;
327		toshiba)
328			AC_EGREP_CPP(yes,
329[#include <sys/param.h>
330#ifdef _TOSHIBA_INET6
331yes
332#endif],
333				[ipv6type=$i;
334				ipv6lib=inet6;
335				ipv6libdir=/usr/local/v6/lib])
336			;;
337		v6d)
338			AC_EGREP_CPP(yes,
339[#include </usr/local/v6/include/sys/v6config.h>
340#ifdef __V6D__
341yes
342#endif],
343				[ipv6type=$i;
344				ipv6lib=v6;
345				ipv6libdir=/usr/local/v6/lib;
346				CFLAGS="-I/usr/local/v6/include $CFLAGS"])
347			;;
348		zeta)
349			AC_EGREP_CPP(yes,
350[#include <sys/param.h>
351#ifdef _ZETA_MINAMI_INET6
352yes
353#endif],
354				[ipv6type=$i;
355				ipv6lib=inet6;
356				ipv6libdir=/usr/local/v6/lib])
357			;;
358		esac
359		if test "$ipv6type" != "unknown"; then
360			break
361		fi
362	done
363	AC_MSG_RESULT($ipv6type)
364fi
365
366if test "$ipv6" = "yes" -a "$ipv6lib" != "none"; then
367	if test -d $ipv6libdir -a -f $ipv6libdir/lib$ipv6lib.a; then
368		LIBS="-L$ipv6libdir -l$ipv6lib $LIBS"
369		echo "You have $ipv6lib library, using it"
370	else
371		if test "$ipv6trylibc" = "yes"; then
372			echo "You do not have $ipv6lib library, using libc"
373		else
374			echo 'Fatal: no $ipv6lib library found.  cannot continue.'
375			echo "You need to fetch lib$ipv6lib.a from appropriate"
376			echo 'ipv6 kit and compile beforehand.'
377			exit 1
378		fi
379	fi
380fi
381
382AC_REPLACE_FUNCS(strlcat strlcpy strdup strsep getservent getopt_long)
383AC_CHECK_FUNCS(fork vfork)
384AC_CHECK_FUNCS(setlinebuf)
385
386#
387# Make sure we have vsnprintf() and snprintf(); we require them.
388#
389AC_CHECK_FUNC(vsnprintf,,
390    AC_MSG_ERROR([vsnprintf() is required but wasn't found]))
391AC_CHECK_FUNC(snprintf,,
392    AC_MSG_ERROR([snprintf() is required but wasn't found]))
393
394#
395# Define HAVE_NO_PRINTF_Z to make it possible to disable test cases that
396# depend on %zu.
397#
398AC_MSG_CHECKING([whether printf(3) supports the z length modifier])
399AC_RUN_IFELSE(
400    [
401        AC_LANG_SOURCE([[
402#include <stdio.h>
403#include <string.h>
404
405int main()
406{
407  char buf[100];
408  snprintf(buf, sizeof(buf), "%zu", sizeof(buf));
409  return strncmp(buf, "100", sizeof(buf)) ? 1 : 0;
410}
411        ]])
412    ],
413    [
414        AC_MSG_RESULT(yes)
415    ],
416    [
417        AC_MSG_RESULT(no)
418        AC_DEFINE(HAVE_NO_PRINTF_Z, 1,
419            [Define to 1 if printf(3) does not support the z length modifier.])
420    ],
421    [
422        AC_MSG_RESULT(not while cross-compiling)
423    ]
424)
425
426AC_CHECK_LIB(rpc, main)		dnl It's unclear why we might need -lrpc
427
428dnl Some platforms may need -lnsl for getrpcbynumber.
429AC_SEARCH_LIBS(getrpcbynumber, nsl,
430    AC_DEFINE(HAVE_GETRPCBYNUMBER, 1, [define if you have getrpcbynumber()]))
431
432AC_LBL_LIBPCAP(V_PCAPDEP, V_INCLS)
433
434#
435# Check for these after AC_LBL_LIBPCAP, so we link with the appropriate
436# libraries (e.g., "-lsocket -lnsl" on Solaris).
437#
438# You are in a twisty little maze of UN*Xes, all different.
439# Some might not have ether_ntohost().
440# Some might have it and declare it in <net/ethernet.h>.
441# Some might have it and declare it in <netinet/ether.h>
442# Some might have it and declare it in <sys/ethernet.h>.
443# Some might have it and declare it in <arpa/inet.h>.
444# Some might have it and declare it in <netinet/if_ether.h>.
445# Some might have it and not declare it in any header file.
446#
447# Before you is a C compiler.
448#
449AC_CHECK_FUNCS(ether_ntohost, [
450    AC_CACHE_CHECK(for buggy ether_ntohost, ac_cv_buggy_ether_ntohost, [
451	AC_TRY_RUN([
452		#include <netdb.h>
453		#include <netinet/ether.h>
454		#include <stdlib.h>
455		#include <sys/types.h>
456		#include <sys/param.h>
457		#include <sys/socket.h>
458
459		int
460		main(int argc, char **argv)
461		{
462			u_char ea[6] = { 0xff, 0xff, 0xff, 0xff, 0xff };
463			char name[MAXHOSTNAMELEN];
464
465			ether_ntohost(name, (struct ether_addr *)ea);
466			exit(0);
467		}
468	], [ac_cv_buggy_ether_ntohost=no],
469	   [ac_cv_buggy_ether_ntohost=yes],
470	   [ac_cv_buggy_ether_ntohost="not while cross-compiling"])])
471    if test "$ac_cv_buggy_ether_ntohost" = "no"; then
472	AC_DEFINE(USE_ETHER_NTOHOST, 1,
473	    [define if you have ether_ntohost() and it works])
474    fi
475])
476if test "$ac_cv_func_ether_ntohost" = yes -a \
477    "$ac_cv_buggy_ether_ntohost" = "no"; then
478	#
479	# OK, we have ether_ntohost().  Is it declared in <net/ethernet.h>?
480	#
481	# This test fails if we don't have <net/ethernet.h> or if we do
482	# but it doesn't declare ether_ntohost().
483	#
484	AC_CHECK_DECL(ether_ntohost,
485	    [
486		AC_DEFINE(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST,,
487		    [Define to 1 if net/ethernet.h declares `ether_ntohost'])
488	    ],,
489	    [
490#include <net/ethernet.h>
491	    ])
492	#
493	# Did that succeed?
494	#
495	if test "$ac_cv_have_decl_ether_ntohost" != yes; then
496		#
497		# No, how about <netinet/ether.h>, as on Linux?
498		#
499		# This test fails if we don't have <netinet/ether.h>
500		# or if we do but it doesn't declare ether_ntohost().
501		#
502		# Unset ac_cv_have_decl_ether_ntohost so we don't
503		# treat the previous failure as a cached value and
504		# suppress the next test.
505		#
506		unset ac_cv_have_decl_ether_ntohost
507		AC_CHECK_DECL(ether_ntohost,
508		    [
509			AC_DEFINE(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST,,
510			    [Define to 1 if netinet/ether.h declares `ether_ntohost'])
511		    ],,
512		    [
513#include <netinet/ether.h>
514		    ])
515	fi
516	#
517	# Did that succeed?
518	#
519	if test "$ac_cv_have_decl_ether_ntohost" != yes; then
520		#
521		# No, how about <sys/ethernet.h>, as on Solaris 10
522		# and later?
523		#
524		# This test fails if we don't have <sys/ethernet.h>
525		# or if we do but it doesn't declare ether_ntohost().
526		#
527		# Unset ac_cv_have_decl_ether_ntohost so we don't
528		# treat the previous failure as a cached value and
529		# suppress the next test.
530		#
531		unset ac_cv_have_decl_ether_ntohost
532		AC_CHECK_DECL(ether_ntohost,
533		    [
534			AC_DEFINE(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST,,
535			    [Define to 1 if sys/ethernet.h declares `ether_ntohost'])
536		    ],,
537		    [
538#include <sys/ethernet.h>
539		    ])
540	fi
541	#
542	# Did that succeed?
543	#
544	if test "$ac_cv_have_decl_ether_ntohost" != yes; then
545		#
546		# No, how about <arpa/inet.h>, as in AIX?
547		#
548		# This test fails if we don't have <arpa/inet.h>
549		# (if we have ether_ntohost(), we should have
550		# networking, and if we have networking, we should
551		# have <arpa/inet.h>) or if we do but it doesn't
552		# declare ether_ntohost().
553		#
554		# Unset ac_cv_have_decl_ether_ntohost so we don't
555		# treat the previous failure as a cached value and
556		# suppress the next test.
557		#
558		unset ac_cv_have_decl_ether_ntohost
559		AC_CHECK_DECL(ether_ntohost,
560		    [
561			AC_DEFINE(ARPA_INET_H_DECLARES_ETHER_NTOHOST,,
562			    [Define to 1 if arpa/inet.h declares `ether_ntohost'])
563		    ],,
564		    [
565#include <arpa/inet.h>
566		    ])
567	fi
568	#
569	# Did that succeed?
570	#
571	if test "$ac_cv_have_decl_ether_ntohost" != yes; then
572		#
573		# No, how about <netinet/if_ether.h>?
574		# On some platforms, it requires <net/if.h> and
575		# <netinet/in.h>, and we always include it with
576		# both of them, so test it with both of them.
577		#
578		# This test fails if we don't have <netinet/if_ether.h>
579		# and the headers we include before it, or if we do but
580		# <netinet/if_ether.h> doesn't declare ether_hostton().
581		#
582		# Unset ac_cv_have_decl_ether_ntohost so we don't
583		# treat the previous failure as a cached value and
584		# suppress the next test.
585		#
586		unset ac_cv_have_decl_ether_ntohost
587		AC_CHECK_DECL(ether_ntohost,
588		    [
589			AC_DEFINE(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST,,
590			    [Define to 1 if netinet/if_ether.h declares `ether_ntohost'])
591		    ],,
592		    [
593#include <sys/types.h>
594#include <sys/socket.h>
595#include <net/if.h>
596#include <netinet/in.h>
597#include <netinet/if_ether.h>
598		    ])
599	fi
600	#
601	# After all that, is ether_ntohost() declared?
602	#
603	if test "$ac_cv_have_decl_ether_ntohost" = yes; then
604		#
605		# Yes.
606		#
607		AC_DEFINE(HAVE_DECL_ETHER_NTOHOST, 1,
608		    [Define to 1 if you have the declaration of `ether_ntohost'])
609	else
610		#
611		# No, we'll have to declare it ourselves.
612		# Do we have "struct ether_addr" if we include
613		# <netinet/if_ether.h>?
614		#
615		AC_CHECK_TYPES(struct ether_addr,,,
616		    [
617			#include <sys/types.h>
618			#include <sys/socket.h>
619			#include <net/if.h>
620			#include <netinet/in.h>
621			#include <netinet/if_ether.h>
622		    ])
623	fi
624fi
625
626dnl
627dnl Check for "pcap_list_datalinks()" and use a substitute version if
628dnl it's not present.  If it is present, check for "pcap_free_datalinks()";
629dnl if it's not present, we don't replace it for now.  (We could do so
630dnl on UN*X, but not on Windows, where hilarity ensues if a program
631dnl built with one version of the MSVC support library tries to free
632dnl something allocated by a library built with another version of
633dnl the MSVC support library.)
634dnl
635AC_CHECK_FUNC(pcap_list_datalinks,
636	[
637	    AC_DEFINE(HAVE_PCAP_LIST_DATALINKS, 1,
638		[define if libpcap has pcap_list_datalinks()])
639	    AC_CHECK_FUNCS(pcap_free_datalinks)
640	],
641	[
642	    AC_LIBOBJ(datalinks)
643	])
644
645dnl
646dnl Check for "pcap_datalink_name_to_val()", and use a substitute
647dnl version if it's not present.  If it is present, check for
648dnl "pcap_datalink_val_to_description()", and if we don't have it,
649dnl use a substitute version.
650dnl
651AC_CHECK_FUNC(pcap_datalink_name_to_val,
652	[
653	    AC_DEFINE(HAVE_PCAP_DATALINK_NAME_TO_VAL, 1,
654		[define if libpcap has pcap_datalink_name_to_val()])
655	    AC_CHECK_FUNC(pcap_datalink_val_to_description,
656		AC_DEFINE(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION, 1,
657		    [define if libpcap has pcap_datalink_val_to_description()]),
658		[
659		    AC_LIBOBJ(dlnames)
660		])
661	],
662	[
663	    AC_LIBOBJ(dlnames)
664	])
665
666dnl
667dnl Check for "pcap_set_datalink()"; you can't substitute for it if
668dnl it's absent (it has hooks into libpcap), so just define the
669dnl HAVE_ value if it's there.
670dnl
671AC_CHECK_FUNCS(pcap_set_datalink)
672
673dnl
674dnl Check for "pcap_breakloop()"; you can't substitute for it if
675dnl it's absent (it has hooks into the live capture routines),
676dnl so just define the HAVE_ value if it's there.
677dnl
678AC_CHECK_FUNCS(pcap_breakloop)
679
680#
681# Do we have the new open API?  Check for pcap_create, and assume that,
682# if we do, we also have pcap_activate() and the other new routines
683# introduced in libpcap 1.0.0.
684#
685AC_CHECK_FUNCS(pcap_create)
686if test $ac_cv_func_pcap_create = "yes" ; then
687	#
688	# OK, do we have pcap_set_tstamp_type?  If so, assume we have
689	# pcap_list_tstamp_types and pcap_free_tstamp_types as well.
690	#
691	AC_CHECK_FUNCS(pcap_set_tstamp_type)
692	#
693	# And do we have pcap_set_tstamp_precision?  If so, we assume
694	# we also have pcap_open_offline_with_tstamp_precision.
695	#
696	AC_CHECK_FUNCS(pcap_set_tstamp_precision)
697fi
698
699#
700# Check for a miscellaneous collection of functions which we use
701# if we have them.
702#
703AC_CHECK_FUNCS(pcap_findalldevs)
704if test $ac_cv_func_pcap_findalldevs = "yes" ; then
705dnl Check for libpcap having pcap_findalldevs() but the pcap.h header
706dnl not having pcap_if_t; some versions of Mac OS X shipped with pcap.h
707dnl from 0.6 and libpcap 0.8, so that libpcap had pcap_findalldevs but
708dnl pcap.h didn't have pcap_if_t.
709    savedcppflags="$CPPFLAGS"
710    CPPFLAGS="$CPPFLAGS $V_INCLS"
711    AC_CHECK_TYPES(pcap_if_t, , , [#include <pcap.h>])
712    CPPFLAGS="$savedcppflags"
713fi
714AC_CHECK_FUNCS(pcap_dump_flush pcap_lib_version)
715if test $ac_cv_func_pcap_lib_version = "no" ; then
716    AC_MSG_CHECKING(whether pcap_version is defined by libpcap)
717    AC_TRY_LINK([],
718       [
719	extern char pcap_version[];
720
721	return (int)pcap_version;
722       ],
723       ac_lbl_cv_pcap_version_defined=yes,
724       ac_lbl_cv_pcap_version_defined=no)
725    if test "$ac_lbl_cv_pcap_version_defined" = yes ; then
726	AC_MSG_RESULT(yes)
727	AC_DEFINE(HAVE_PCAP_VERSION, 1, [define if libpcap has pcap_version])
728    else
729	AC_MSG_RESULT(no)
730    fi
731fi
732AC_CHECK_FUNCS(pcap_setdirection pcap_set_immediate_mode pcap_dump_ftell64)
733AC_CHECK_FUNCS(pcap_open pcap_findalldevs_ex)
734AC_REPLACE_FUNCS(pcap_dump_ftell)
735
736#
737# Check for special debugging functions
738#
739AC_CHECK_FUNCS(pcap_set_parser_debug)
740if test "$ac_cv_func_pcap_set_parser_debug" = "no" ; then
741	#
742	# OK, we don't have pcap_set_parser_debug() to set the libpcap
743	# filter expression parser debug flag; can we directly set the
744	# flag?
745	AC_MSG_CHECKING(whether pcap_debug is defined by libpcap)
746	AC_TRY_LINK([],
747	   [
748		extern int pcap_debug;
749
750		return pcap_debug;
751	   ],
752	   ac_lbl_cv_pcap_debug_defined=yes,
753	   ac_lbl_cv_pcap_debug_defined=no)
754	if test "$ac_lbl_cv_pcap_debug_defined" = yes ; then
755		AC_MSG_RESULT(yes)
756		AC_DEFINE(HAVE_PCAP_DEBUG, 1, [define if libpcap has pcap_debug])
757	else
758		AC_MSG_RESULT(no)
759		#
760		# OK, what about "yydebug"?
761		#
762		AC_MSG_CHECKING(whether yydebug is defined by libpcap)
763		AC_TRY_LINK([],
764		   [
765			extern int yydebug;
766
767			return yydebug;
768		   ],
769		   ac_lbl_cv_yydebug_defined=yes,
770		   ac_lbl_cv_yydebug_defined=no)
771		if test "$ac_lbl_cv_yydebug_defined" = yes ; then
772			AC_MSG_RESULT(yes)
773			AC_DEFINE(HAVE_YYDEBUG, 1, [define if libpcap has yydebug])
774		else
775			AC_MSG_RESULT(no)
776		fi
777	fi
778fi
779AC_CHECK_FUNCS(pcap_set_optimizer_debug)
780AC_REPLACE_FUNCS(bpf_dump)	dnl moved to libpcap in 0.6
781
782V_GROUP=0
783if test -f /etc/group -a ! -z "`grep '^wheel:' /etc/group`" ; then
784	V_GROUP=wheel
785fi
786#
787# Assume V7/BSD convention for man pages (file formats in section 5,
788# miscellaneous info in section 7).
789#
790MAN_FILE_FORMATS=5
791MAN_MISC_INFO=7
792case "$host_os" in
793
794aix*)
795	dnl Workaround to enable certain features
796	AC_DEFINE(_SUN,1,[define on AIX to get certain functions])
797	;;
798
799hpux*)
800	#
801	# Use System V conventions for man pages.
802	#
803	MAN_FILE_FORMATS=4
804	MAN_MISC_INFO=5
805	;;
806
807irix*)
808	V_GROUP=sys
809
810	#
811	# Use System V conventions for man pages.
812	#
813	MAN_FILE_FORMATS=4
814	MAN_MISC_INFO=5
815	;;
816
817osf*)
818	V_GROUP=system
819
820	#
821	# Use System V conventions for man pages.
822	#
823	MAN_FILE_FORMATS=4
824	MAN_MISC_INFO=5
825	;;
826
827solaris*)
828	V_GROUP=sys
829
830	#
831	# Use System V conventions for man pages.
832	#
833	MAN_FILE_FORMATS=4
834	MAN_MISC_INFO=5
835	;;
836esac
837
838if test -f /dev/bpf0 ; then
839	V_GROUP=bpf
840fi
841
842#
843# Make sure we have a definition for C99's uintptr_t (regardless of
844# whether the environment is a C99 environment or not).
845#
846AC_TYPE_UINTPTR_T
847
848#
849# Check whether we have pcap/pcap-inttypes.h.
850# If we do, we use that to get the C99 types defined.
851#
852savedcppflags="$CPPFLAGS"
853CPPFLAGS="$CPPFLAGS $V_INCLS"
854AC_CHECK_HEADERS(pcap/pcap-inttypes.h)
855CPPFLAGS="$savedcppflags"
856
857#
858# Define the old BSD specified-width types in terms of the C99 types;
859# we may need them with libpcap include files.
860#
861AC_CHECK_TYPE([u_int8_t], ,
862	[AC_DEFINE([u_int8_t], [uint8_t],
863	[Define to `uint8_t' if u_int8_t not defined.])],
864	[AC_INCLUDES_DEFAULT
865#include <sys/types.h>
866])
867AC_CHECK_TYPE([u_int16_t], ,
868	[AC_DEFINE([u_int16_t], [uint16_t],
869	[Define to `uint16_t' if u_int16_t not defined.])],
870	[AC_INCLUDES_DEFAULT
871#include <sys/types.h>
872])
873AC_CHECK_TYPE([u_int32_t], ,
874	[AC_DEFINE([u_int32_t], [uint32_t],
875	[Define to `uint32_t' if u_int32_t not defined.])],
876	[AC_INCLUDES_DEFAULT
877#include <sys/types.h>
878])
879AC_CHECK_TYPE([u_int64_t], ,
880	[AC_DEFINE([u_int64_t], [uint64_t],
881	[Define to `uint64_t' if u_int64_t not defined.])],
882	[AC_INCLUDES_DEFAULT
883#include <sys/types.h>
884])
885
886AC_PROG_RANLIB
887AC_CHECK_TOOL([AR], [ar])
888
889AC_LBL_DEVEL(V_CCOPT)
890
891# Check for OpenSSL/libressl libcrypto
892AC_MSG_CHECKING(whether to use OpenSSL/libressl libcrypto)
893# Specify location for both includes and libraries.
894want_libcrypto=ifavailable
895AC_ARG_WITH(crypto,
896    AS_HELP_STRING([--with-crypto]@<:@=DIR@:>@,
897		   [use OpenSSL/libressl libcrypto (located in directory DIR, if specified) @<:@default=yes, if available@:>@]),
898[
899	if test $withval = no
900	then
901		# User doesn't want to link with libcrypto.
902		want_libcrypto=no
903		AC_MSG_RESULT(no)
904	elif test $withval = yes
905	then
906		# User wants to link with libcrypto but hasn't specified
907		# a directory.
908		want_libcrypto=yes
909		AC_MSG_RESULT(yes)
910	else
911		# User wants to link with libcrypto and has specified
912		# a directory, so use the provided value.
913		want_libcrypto=yes
914		libcrypto_root=$withval
915		AC_MSG_RESULT([yes, using the version installed in $withval])
916
917		#
918		# Put the subdirectories of the libcrypto root directory
919		# at the front of the header and library search path.
920		#
921		CFLAGS="-I$withval/include $CFLAGS"
922		LIBS="-L$withval/lib $LIBS"
923	fi
924],[
925	#
926	# Use libcrypto if it's present, otherwise don't; no directory
927	# was specified.
928	#
929	want_libcrypto=ifavailable
930	AC_MSG_RESULT([yes, if available])
931])
932if test "$want_libcrypto" != "no"; then
933	#
934	# Don't check for libcrypto unless we have its headers;
935	# Apple, bless their pointy little heads, apparently ship
936	# libcrypto as a library, but not the header files, in
937	# El Capitan, probably because they don't want you writing
938	# nasty portable code that could run on other UN*Xes, they
939	# want you writing code that uses their Shiny New Crypto
940	# Library and that only runs on macOS.
941	#
942	AC_CHECK_HEADER(openssl/crypto.h,
943	[
944		AC_CHECK_LIB(crypto, DES_cbc_encrypt)
945		if test "$ac_cv_lib_crypto_DES_cbc_encrypt" = "yes"; then
946			AC_CHECK_HEADERS(openssl/evp.h)
947			#
948			# OK, then:
949			#
950			# 1) do we have EVP_CIPHER_CTX_new?
951			# If so, we use it to allocate an
952			# EVP_CIPHER_CTX, as EVP_CIPHER_CTX may be
953			# opaque; otherwise, we allocate it ourselves.
954			#
955			# 2) do we have EVP_DecryptInit_ex()?
956			# If so, we use it, because we need to be
957			# able to make two "initialize the cipher"
958			# calls, one with the cipher and key, and
959			# one with the IV, and, as of OpenSSL 1.1,
960			# You Can't Do That with EVP_DecryptInit(),
961			# because a call to EVP_DecryptInit() will
962			# unconditionally clear the context, and
963			# if you don't supply a cipher, it'll
964			# clear the cipher, rendering the context
965			# unusable and causing a crash.
966			#
967			AC_CHECK_FUNCS(EVP_CIPHER_CTX_new EVP_DecryptInit_ex)
968		fi
969	])
970fi
971
972# Check for libcap-ng
973AC_MSG_CHECKING(whether to use libcap-ng)
974# Specify location for both includes and libraries.
975want_libcap_ng=ifavailable
976AC_ARG_WITH(cap_ng,
977    AS_HELP_STRING([--with-cap-ng],
978		   [use libcap-ng @<:@default=yes, if available@:>@]),
979[
980	if test $withval = no
981	then
982		want_libcap_ng=no
983		AC_MSG_RESULT(no)
984	elif test $withval = yes
985	then
986		want_libcap_ng=yes
987		AC_MSG_RESULT(yes)
988	fi
989],[
990	#
991	# Use libcap-ng if it's present, otherwise don't.
992	#
993	want_libcap_ng=ifavailable
994	AC_MSG_RESULT([yes, if available])
995])
996if test "$want_libcap_ng" != "no"; then
997	AC_CHECK_LIB(cap-ng, capng_change_id)
998	AC_CHECK_HEADERS(cap-ng.h)
999fi
1000
1001dnl
1002dnl set additional include path if necessary
1003if test "$missing_includes" = "yes"; then
1004	CPPFLAGS="$CPPFLAGS -I$srcdir/missing"
1005	V_INCLS="$V_INCLS -I$srcdir/missing"
1006fi
1007
1008AC_SUBST(V_CCOPT)
1009AC_SUBST(V_DEFS)
1010AC_SUBST(V_GROUP)
1011AC_SUBST(V_INCLS)
1012AC_SUBST(V_PCAPDEP)
1013AC_SUBST(LOCALSRC)
1014AC_SUBST(MAN_FILE_FORMATS)
1015AC_SUBST(MAN_MISC_INFO)
1016
1017AC_PROG_INSTALL
1018
1019AC_CONFIG_HEADER(config.h)
1020
1021AC_OUTPUT_COMMANDS([if test -f .devel; then
1022	echo timestamp > stamp-h
1023	cat $srcdir/Makefile-devel-adds >> Makefile
1024	make depend || exit 1
1025fi])
1026AC_OUTPUT(Makefile tcpdump.1)
1027exit 0
1028