xref: /freebsd/contrib/tcpdump/configure.ac (revision 7937bfbc0ca53fe7cdd0d54414f9296e273a518e)
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(rpc/rpc.h rpc/rpcent.h net/if.h)
35#
36# Get the size of a void *, to know whether this is a 32-bit or 64-bit build.
37#
38AC_CHECK_SIZEOF([void *])
39
40#
41# Get the size of a time_t, to know whether it's 32-bit or 64-bit.
42#
43AC_CHECK_SIZEOF([time_t],,[#include <time.h>])
44
45case "$host_os" in
46
47darwin*)
48	AC_ARG_ENABLE(universal,
49	AS_HELP_STRING([--disable-universal],[don't build universal on macOS]))
50	if test "$enable_universal" != "no"; then
51		case "$host_os" in
52
53		darwin9.*)
54			#
55			# Leopard.  Build for x86 and 32-bit PowerPC, with
56			# x86 first.  (That's what Apple does.)
57			#
58			V_CCOPT="$V_CCOPT -arch i386 -arch ppc"
59			LDFLAGS="$LDFLAGS -arch i386 -arch ppc"
60			;;
61
62		darwin10.*)
63			#
64			# Snow Leopard.  Build for x86-64 and x86, with
65			# x86-64 first.  (That's what Apple does.)
66			#
67			V_CCOPT="$V_CCOPT -arch x86_64 -arch i386"
68			LDFLAGS="$LDFLAGS -arch x86_64 -arch i386"
69			;;
70		esac
71	fi
72	;;
73esac
74
75#
76# Do we have pkg-config?
77#
78PKG_PROG_PKG_CONFIG
79
80#
81# Do we have the brew command from Homebrew?
82#
83AC_PATH_PROG([BREW], [brew])
84
85AC_ARG_WITH([smi],
86   [AS_HELP_STRING([--with-smi],
87     [link with libsmi (allows to load MIBs on the fly to decode SNMP packets) [default=yes, if available]])],
88   [],
89   [with_smi=yes])
90
91if test "x$with_smi" != "xno" ; then
92	AC_CHECK_HEADER(smi.h,
93	[
94		#
95		# OK, we found smi.h.  Do we have libsmi with smiInit?
96		#
97		AC_CHECK_LIB(smi, smiInit,
98		[
99			#
100			# OK, we have libsmi with smiInit.  Can we use it?
101			#
102			AC_MSG_CHECKING([whether to enable libsmi])
103			savedlibs="$LIBS"
104			LIBS="-lsmi $LIBS"
105			AC_RUN_IFELSE([AC_LANG_SOURCE([[
106/* libsmi available check */
107#include <stdio.h>
108#include <stdlib.h>
109#include <string.h>
110#include <smi.h>
111int main()
112{
113  int current, revision, age, n;
114  const int required = 2;
115  if (smiInit(""))
116    exit(1);
117  if (strcmp(SMI_LIBRARY_VERSION, smi_library_version))
118    exit(2);
119  n = sscanf(smi_library_version, "%d:%d:%d", &current, &revision, &age);
120  if (n != 3)
121    exit(3);
122  if (required < current - age || required > current)
123    exit(4);
124  exit(0);
125}
126				]])
127				],
128				[
129					AC_MSG_RESULT(yes)
130					AC_DEFINE(USE_LIBSMI, 1,
131					    [Define if you enable support for libsmi])
132				],
133				[
134					dnl autoconf documentation says that
135					dnl $? contains the exit value.
136					dnl reality is that it does not.
137					dnl We leave this in just in case
138					dnl autoconf ever comes back to
139					dnl match the documentation.
140					case $? in
141					  1) AC_MSG_RESULT(no - smiInit failed) ;;
142					  2) AC_MSG_RESULT(no - header/library version mismatch) ;;
143					  3) AC_MSG_RESULT(no - can't determine library version) ;;
144					  4) AC_MSG_RESULT(no - too old) ;;
145					  *) AC_MSG_RESULT(no) ;;
146					esac
147					LIBS="$savedlibs"
148				],
149				[
150					AC_MSG_RESULT(not when cross-compiling)
151					LIBS="$savedlibs"
152				]
153			)
154		])
155	])
156fi
157
158AC_MSG_CHECKING([whether to enable the instrument functions code])
159AC_ARG_ENABLE([instrument-functions],
160   [AS_HELP_STRING([--enable-instrument-functions],
161     [enable instrument functions code [default=no]])],
162   [],
163   [enableval=no])
164case "$enableval" in
165yes)	AC_MSG_RESULT(yes)
166	AC_CHECK_LIB([bfd], [bfd_init],
167	    [true],
168	    [AC_MSG_ERROR(
169	       [--enable-instrument-functions was given, but test for library libbfd failed. Please install the 'binutils-dev' package.])],
170	    [])
171	AC_DEFINE(ENABLE_INSTRUMENT_FUNCTIONS, 1,
172	    [define if you want to build the instrument functions code])
173	LOCALSRC="$LOCALSRC instrument-functions.c"
174	# Add '-finstrument-functions' instrumentation option to generate
175	# instrumentation calls for entry and exit to functions.
176	# Try to avoid Address Space Layout Randomization (ALSR).
177	CFLAGS="$CFLAGS -O0 -ggdb -finstrument-functions -fno-stack-protector -fno-pic"
178	LDFLAGS="$LDFLAGS -O0 -ggdb -fno-stack-protector -no-pie"
179	LIBS="$LIBS -lbfd"
180	;;
181*)	AC_MSG_RESULT(no)
182	;;
183esac
184
185AC_MSG_CHECKING([whether to enable the possibly-buggy SMB printer])
186AC_ARG_ENABLE([smb],
187   [AS_HELP_STRING([--enable-smb],
188     [enable possibly-buggy SMB printer [default=no]])],
189   [],
190   [enableval=no])
191case "$enableval" in
192yes)	AC_MSG_RESULT(yes)
193	AC_DEFINE(ENABLE_SMB, 1,
194	    [define if you want to build the possibly-buggy SMB printer])
195	LOCALSRC="print-smb.c smbutil.c $LOCALSRC"
196	;;
197*)	AC_MSG_RESULT(no)
198	;;
199esac
200
201AC_MSG_CHECKING([whether to drop root privileges by default])
202AC_ARG_WITH(
203	[user],
204	[AS_HELP_STRING([--with-user=USERNAME],
205		[drop privileges by default to USERNAME]
206	)],
207	[],
208	[withval=no])
209AS_CASE(["$withval"],
210	[no], [AC_MSG_RESULT(no)],
211	[''|yes], [AC_MSG_ERROR([--with-user requires a username])],
212	[
213		AC_DEFINE_UNQUOTED(WITH_USER, "$withval",
214		    [define if should drop privileges by default])
215		AC_MSG_RESULT([yes, to user "$withval"])
216	]
217)
218
219AC_MSG_CHECKING([whether to chroot])
220AC_ARG_WITH(
221	[chroot],
222	[AS_HELP_STRING([--with-chroot=DIRECTORY],
223		[when dropping privileges, chroot to DIRECTORY]
224	)],
225	[],
226	[withval=no]
227)
228AS_CASE(["$withval"],
229	[no], [AC_MSG_RESULT(no)],
230	[''|yes], [AC_MSG_ERROR([--with-chroot requires a directory])],
231	[
232		AC_DEFINE_UNQUOTED(WITH_CHROOT, "$withval",
233		    [define if should chroot when dropping privileges])
234		AC_MSG_RESULT([yes, to directory "$withval"])
235	]
236)
237
238AC_ARG_WITH(sandbox-capsicum,
239	AS_HELP_STRING([--with-sandbox-capsicum],
240		       [use Capsicum security functions @<:@default=yes, if available@:>@]))
241#
242# Check whether various functions are available.  If any are, set
243# ac_lbl_capsicum_function_seen to yes; if any are not, set
244# ac_lbl_capsicum_function_not_seen to yes.
245#
246# We don't check cap_rights_init(), as it's a macro, wrapping another
247# function, in at least some versions of FreeBSD, and AC_CHECK_FUNCS()
248# doesn't handle that.
249#
250# All of the ones we check for must be available in order to enable
251# capsicum sandboxing.
252#
253# XXX - do we need to check for all of them, or are there some that, if
254# present, imply others are present?
255#
256if test -z "$with_sandbox_capsicum" || test "$with_sandbox_capsicum" != "no" ; then
257	#
258	# First, make sure we have the required header.
259	#
260	AC_CHECK_HEADER(sys/capsicum.h,
261	[
262		#
263		# We do; now make sure we have the required functions.
264		#
265		AC_CHECK_FUNCS(cap_enter cap_rights_limit cap_ioctls_limit openat,
266		    ac_lbl_capsicum_function_seen=yes,
267		    ac_lbl_capsicum_function_not_seen=yes)
268	])
269	AC_CHECK_LIB(casper, cap_init, LIBS="$LIBS -lcasper")
270	AC_CHECK_LIB(cap_dns, cap_gethostbyaddr, LIBS="$LIBS -lcap_dns")
271fi
272AC_MSG_CHECKING([whether to sandbox using capsicum])
273if test "x$ac_lbl_capsicum_function_seen" = "xyes" -a "x$ac_lbl_capsicum_function_not_seen" != "xyes"; then
274	AC_DEFINE(HAVE_CAPSICUM, 1, [capsicum support available])
275	AC_MSG_RESULT(yes)
276else
277	AC_MSG_RESULT(no)
278fi
279AC_MSG_CHECKING([whether to sandbox using Casper library])
280if test "x$ac_cv_lib_casper_cap_init" = "xyes" -a "x$ac_cv_lib_cap_dns_cap_gethostbyaddr" = "xyes"; then
281	AC_DEFINE(HAVE_CASPER, 1, [Casper support available])
282	AC_MSG_RESULT(yes)
283else
284	AC_MSG_RESULT(no)
285fi
286
287#
288# We must check this before checking whether to check the OS's IPv6,
289# support because, on some platforms (such as SunOS 5.x), the test
290# program requires the extra networking libraries.
291#
292AC_LBL_LIBRARY_NET
293
294#
295# Check whether AF_INET6 and struct in6_addr are defined.
296# If they aren't both defined, we don't have sufficient OS
297# support for IPv6, so we don't look for IPv6 support libraries,
298# and we define AF_INET6 and struct in6_addr ourselves.
299#
300AC_MSG_CHECKING([whether the operating system supports IPv6])
301AC_COMPILE_IFELSE(
302    [
303      AC_LANG_SOURCE(
304	[[
305#include <string.h>
306/* AF_INET6 available check */
307#include <sys/types.h>
308#ifdef _WIN32
309#include <ws2tcpip.h>
310#else
311#include <sys/socket.h>
312#include <netinet/in.h>
313#endif
314#ifdef AF_INET6
315void
316foo(struct in6_addr *addr)
317{
318 memset(addr, 0, sizeof (struct in6_addr));
319}
320#else
321#error "AF_INET6 not defined"
322#endif
323	]])
324    ],
325    [
326	AC_MSG_RESULT(yes)
327	AC_DEFINE(HAVE_OS_IPV6_SUPPORT, 1,
328	    [define if the OS provides AF_INET6 and struct in6_addr])
329	ipv6=yes
330    ],
331    [
332	AC_MSG_RESULT(no)
333	ipv6=no
334    ]
335)
336
337ipv6type=unknown
338ipv6lib=none
339ipv6trylibc=no
340
341if test "$ipv6" = "yes"; then
342	AC_MSG_CHECKING([ipv6 stack type])
343	for i in inria kame linux-glibc linux-libinet6 toshiba v6d zeta; do
344		case $i in
345		inria)
346			dnl http://www.kame.net/
347			AC_EGREP_CPP(yes,
348[#include <netinet/in.h>
349#ifdef IPV6_INRIA_VERSION
350yes
351#endif],
352				[ipv6type=$i])
353			;;
354		kame)
355			dnl http://www.kame.net/
356			AC_EGREP_CPP(yes,
357[#include <netinet/in.h>
358#ifdef __KAME__
359yes
360#endif],
361				[ipv6type=$i;
362				ipv6lib=inet6;
363				ipv6libdir=/usr/local/v6/lib;
364				ipv6trylibc=yes])
365			;;
366		linux-glibc)
367			dnl http://www.v6.linux.or.jp/
368			AC_EGREP_CPP(yes,
369[#include <features.h>
370#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1
371yes
372#endif],
373				[ipv6type=$i])
374			;;
375		linux-libinet6)
376			dnl http://www.v6.linux.or.jp/
377			dnl
378			dnl This also matches Solaris 8 and Tru64 UNIX 5.1,
379			dnl and possibly other versions of those OSes
380			dnl
381			if test -d /usr/inet6 -o -f /usr/include/netinet/ip6.h; then
382				ipv6type=$i
383				ipv6lib=inet6
384				ipv6libdir=/usr/inet6/lib
385				ipv6trylibc=yes;
386				CFLAGS="-I/usr/inet6/include $CFLAGS"
387			fi
388			;;
389		toshiba)
390			AC_EGREP_CPP(yes,
391[#include <sys/param.h>
392#ifdef _TOSHIBA_INET6
393yes
394#endif],
395				[ipv6type=$i;
396				ipv6lib=inet6;
397				ipv6libdir=/usr/local/v6/lib])
398			;;
399		v6d)
400			AC_EGREP_CPP(yes,
401[#include </usr/local/v6/include/sys/v6config.h>
402#ifdef __V6D__
403yes
404#endif],
405				[ipv6type=$i;
406				ipv6lib=v6;
407				ipv6libdir=/usr/local/v6/lib;
408				CFLAGS="-I/usr/local/v6/include $CFLAGS"])
409			;;
410		zeta)
411			AC_EGREP_CPP(yes,
412[#include <sys/param.h>
413#ifdef _ZETA_MINAMI_INET6
414yes
415#endif],
416				[ipv6type=$i;
417				ipv6lib=inet6;
418				ipv6libdir=/usr/local/v6/lib])
419			;;
420		esac
421		if test "$ipv6type" != "unknown"; then
422			break
423		fi
424	done
425	AC_MSG_RESULT($ipv6type)
426fi
427
428if test "$ipv6" = "yes" -a "$ipv6lib" != "none"; then
429	if test -d $ipv6libdir -a -f $ipv6libdir/lib$ipv6lib.a; then
430		LIBS="-L$ipv6libdir -l$ipv6lib $LIBS"
431		echo "You have $ipv6lib library, using it"
432	else
433		if test "$ipv6trylibc" = "yes"; then
434			echo "You do not have $ipv6lib library, using libc"
435		else
436			echo 'Fatal: no $ipv6lib library found.  cannot continue.'
437			echo "You need to fetch lib$ipv6lib.a from appropriate"
438			echo 'ipv6 kit and compile beforehand.'
439			exit 1
440		fi
441	fi
442fi
443
444AC_REPLACE_FUNCS(strlcat strlcpy strdup strsep getservent getopt_long)
445AC_CHECK_FUNCS(fork vfork)
446AC_CHECK_FUNCS(setlinebuf)
447
448#
449# Make sure we have snprintf(); we require it.
450#
451AC_CHECK_FUNC(snprintf,,
452    AC_MSG_ERROR([snprintf() is required but wasn't found]))
453
454#
455# It became apparent at some point that using a suitable C99 compiler does not
456# automatically mean snprintf(3) implementation in the libc supports all the
457# modifiers and specifiers used in the project, so let's test that before the
458# build, not after.
459#
460# Testing the sizeof_t length modifier takes making an snprintf() call and
461# comparing the actual result with the expected result.  If this fails, it will
462# most likely happen at run time, not compile time.
463#
464# Testing the 64-bit conversion specifiers in addition to that requires the
465# <inttypes.h> header to be present and the macros to be defined, so if this
466# fails, it will more likely happen at compile time.
467#
468AC_MSG_CHECKING([whether snprintf is suitable])
469AC_RUN_IFELSE(
470    [
471        AC_LANG_SOURCE([[
472#include <stdio.h>
473#include <string.h>
474#include <inttypes.h>
475#include <sys/types.h>
476
477int main()
478{
479  char buf[100];
480  uint64_t t = (uint64_t)1 << 32;
481
482  snprintf(buf, sizeof(buf), "%zu", sizeof(buf));
483  if (strncmp(buf, "100", sizeof(buf)))
484    return 1;
485
486  snprintf(buf, sizeof(buf), "%zd", -sizeof(buf));
487  if (strncmp(buf, "-100", sizeof(buf)))
488    return 2;
489
490  snprintf(buf, sizeof(buf), "%" PRId64, -t);
491  if (strncmp(buf, "-4294967296", sizeof(buf)))
492    return 3;
493
494  snprintf(buf, sizeof(buf), "0o%" PRIo64, t);
495  if (strncmp(buf, "0o40000000000", sizeof(buf)))
496    return 4;
497
498  snprintf(buf, sizeof(buf), "0x%" PRIx64, t);
499  if (strncmp(buf, "0x100000000", sizeof(buf)))
500    return 5;
501
502  snprintf(buf, sizeof(buf), "%" PRIu64, t);
503  if (strncmp(buf, "4294967296", sizeof(buf)))
504    return 6;
505
506  return 0;
507}
508        ]])
509    ],
510    [
511        AC_MSG_RESULT(yes)
512    ],
513    [
514        AC_MSG_RESULT(no)
515        AC_MSG_ERROR(
516[The snprintf(3) implementation in this libc is not suitable,
517tcpdump would not work correctly even if it managed to compile.])
518    ],
519    [
520        AC_MSG_RESULT(not while cross-compiling)
521    ]
522)
523
524AC_CHECK_LIB(rpc, main)		dnl It's unclear why we might need -lrpc
525
526dnl Some platforms may need -lnsl for getrpcbynumber.
527AC_SEARCH_LIBS(getrpcbynumber, nsl,
528    AC_DEFINE(HAVE_GETRPCBYNUMBER, 1, [define if you have getrpcbynumber()]))
529
530AC_LBL_LIBPCAP(V_PCAPDEP, V_INCLS)
531
532#
533# Check for these after AC_LBL_LIBPCAP, so we link with the appropriate
534# libraries (e.g., "-lsocket -lnsl" on Solaris).
535#
536# You are in a twisty little maze of UN*Xes, all different.
537# Some might not have ether_ntohost().
538# Some might have it and declare it in <net/ethernet.h>.
539# Some might have it and declare it in <netinet/ether.h>
540# Some might have it and declare it in <sys/ethernet.h>.
541# Some might have it and declare it in <arpa/inet.h>.
542# Some might have it and declare it in <netinet/if_ether.h>.
543# Some might have it and not declare it in any header file.
544#
545# Before you is a C compiler.
546#
547AC_CHECK_FUNCS(ether_ntohost, [
548    AC_CACHE_CHECK(for buggy ether_ntohost, ac_cv_buggy_ether_ntohost, [
549	AC_RUN_IFELSE([AC_LANG_SOURCE([[
550		#include <netdb.h>
551		#include <netinet/ether.h>
552		#include <stdlib.h>
553		#include <sys/types.h>
554		#include <sys/param.h>
555		#include <sys/socket.h>
556
557		int
558		main(int argc, char **argv)
559		{
560			u_char ea[6] = { 0xff, 0xff, 0xff, 0xff, 0xff };
561			char name[MAXHOSTNAMELEN];
562
563			ether_ntohost(name, (struct ether_addr *)ea);
564			exit(0);
565		}
566	]])
567	], [ac_cv_buggy_ether_ntohost=no],
568	   [ac_cv_buggy_ether_ntohost=yes],
569	   [ac_cv_buggy_ether_ntohost="not while cross-compiling"])])
570    if test "$ac_cv_buggy_ether_ntohost" = "no"; then
571	AC_DEFINE(USE_ETHER_NTOHOST, 1,
572	    [define if you have ether_ntohost() and it works])
573    fi
574])
575if test "$ac_cv_func_ether_ntohost" = yes -a \
576    "$ac_cv_buggy_ether_ntohost" = "no"; then
577	#
578	# OK, we have ether_ntohost().  Is it declared in <net/ethernet.h>?
579	#
580	# This test fails if we don't have <net/ethernet.h> or if we do
581	# but it doesn't declare ether_ntohost().
582	#
583	AC_CHECK_DECL(ether_ntohost,
584	    [
585		AC_DEFINE(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST,,
586		    [Define to 1 if net/ethernet.h declares `ether_ntohost'])
587	    ],,
588	    [
589#include <net/ethernet.h>
590	    ])
591	#
592	# Did that succeed?
593	#
594	if test "$ac_cv_have_decl_ether_ntohost" != yes; then
595		#
596		# No, how about <netinet/ether.h>, as on Linux?
597		#
598		# This test fails if we don't have <netinet/ether.h>
599		# or if we do but it doesn't declare ether_ntohost().
600		#
601		# Unset ac_cv_have_decl_ether_ntohost so we don't
602		# treat the previous failure as a cached value and
603		# suppress the next test.
604		#
605		unset ac_cv_have_decl_ether_ntohost
606		AC_CHECK_DECL(ether_ntohost,
607		    [
608			AC_DEFINE(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST,1,
609			    [Define to 1 if netinet/ether.h declares `ether_ntohost'])
610		    ],,
611		    [
612#include <netinet/ether.h>
613		    ])
614	fi
615	#
616	# Did that succeed?
617	#
618	if test "$ac_cv_have_decl_ether_ntohost" != yes; then
619		#
620		# No, how about <sys/ethernet.h>, as on Solaris 10
621		# and later?
622		#
623		# This test fails if we don't have <sys/ethernet.h>
624		# or if we do but it doesn't declare ether_ntohost().
625		#
626		# Unset ac_cv_have_decl_ether_ntohost so we don't
627		# treat the previous failure as a cached value and
628		# suppress the next test.
629		#
630		unset ac_cv_have_decl_ether_ntohost
631		AC_CHECK_DECL(ether_ntohost,
632		    [
633			AC_DEFINE(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST,,
634			    [Define to 1 if sys/ethernet.h declares `ether_ntohost'])
635		    ],,
636		    [
637#include <sys/ethernet.h>
638		    ])
639	fi
640	#
641	# Did that succeed?
642	#
643	if test "$ac_cv_have_decl_ether_ntohost" != yes; then
644		#
645		# No, how about <arpa/inet.h>, as in AIX?
646		#
647		# This test fails if we don't have <arpa/inet.h>
648		# (if we have ether_ntohost(), we should have
649		# networking, and if we have networking, we should
650		# have <arpa/inet.h>) or if we do but it doesn't
651		# declare ether_ntohost().
652		#
653		# Unset ac_cv_have_decl_ether_ntohost so we don't
654		# treat the previous failure as a cached value and
655		# suppress the next test.
656		#
657		unset ac_cv_have_decl_ether_ntohost
658		AC_CHECK_DECL(ether_ntohost,
659		    [
660			AC_DEFINE(ARPA_INET_H_DECLARES_ETHER_NTOHOST,,
661			    [Define to 1 if arpa/inet.h declares `ether_ntohost'])
662		    ],,
663		    [
664#include <arpa/inet.h>
665		    ])
666	fi
667	#
668	# Did that succeed?
669	#
670	if test "$ac_cv_have_decl_ether_ntohost" != yes; then
671		#
672		# No, how about <netinet/if_ether.h>?
673		# On some platforms, it requires <net/if.h> and
674		# <netinet/in.h>, and we always include it with
675		# both of them, so test it with both of them.
676		#
677		# This test fails if we don't have <netinet/if_ether.h>
678		# and the headers we include before it, or if we do but
679		# <netinet/if_ether.h> doesn't declare ether_hostton().
680		#
681		# Unset ac_cv_have_decl_ether_ntohost so we don't
682		# treat the previous failure as a cached value and
683		# suppress the next test.
684		#
685		unset ac_cv_have_decl_ether_ntohost
686		AC_CHECK_DECL(ether_ntohost,
687		    [
688			AC_DEFINE(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST,,
689			    [Define to 1 if netinet/if_ether.h declares `ether_ntohost'])
690		    ],,
691		    [
692#include <sys/types.h>
693#include <sys/socket.h>
694#include <net/if.h>
695#include <netinet/in.h>
696#include <netinet/if_ether.h>
697		    ])
698	fi
699	#
700	# After all that, is ether_ntohost() declared?
701	#
702	if test "$ac_cv_have_decl_ether_ntohost" = yes; then
703		#
704		# Yes.
705		#
706		AC_DEFINE(HAVE_DECL_ETHER_NTOHOST, 1,
707		    [Define to 1 if you have the declaration of `ether_ntohost'])
708	else
709		#
710		# No, we'll have to declare it ourselves.
711		# Do we have "struct ether_addr" if we include
712		# <netinet/if_ether.h>?
713		#
714		AC_CHECK_TYPES(struct ether_addr,,,
715		    [
716			#include <sys/types.h>
717			#include <sys/socket.h>
718			#include <net/if.h>
719			#include <netinet/in.h>
720			#include <netinet/if_ether.h>
721		    ])
722	fi
723fi
724
725dnl
726dnl Check for "pcap_list_datalinks()" and use a substitute version if
727dnl it's not present.  If it is present, check for "pcap_free_datalinks()";
728dnl if it's not present, we don't replace it for now.  (We could do so
729dnl on UN*X, but not on Windows, where hilarity ensues if a program
730dnl built with one version of the MSVC support library tries to free
731dnl something allocated by a library built with another version of
732dnl the MSVC support library.)
733dnl
734AC_CHECK_FUNC(pcap_list_datalinks,
735	[
736	    AC_DEFINE(HAVE_PCAP_LIST_DATALINKS, 1,
737		[define if libpcap has pcap_list_datalinks()])
738	    AC_CHECK_FUNCS(pcap_free_datalinks)
739	],
740	[
741	    AC_LIBOBJ(datalinks)
742	])
743
744dnl
745dnl Check for "pcap_datalink_name_to_val()", and use a substitute
746dnl version if it's not present.  If it is present, check for
747dnl "pcap_datalink_val_to_description()", and if we don't have it,
748dnl use a substitute version.
749dnl
750AC_CHECK_FUNC(pcap_datalink_name_to_val,
751	[
752	    AC_DEFINE(HAVE_PCAP_DATALINK_NAME_TO_VAL, 1,
753		[define if libpcap has pcap_datalink_name_to_val()])
754	    AC_CHECK_FUNC(pcap_datalink_val_to_description,
755		AC_DEFINE(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION, 1,
756		    [define if libpcap has pcap_datalink_val_to_description()]),
757		[
758		    AC_LIBOBJ(dlnames)
759		])
760	],
761	[
762	    AC_LIBOBJ(dlnames)
763	])
764
765dnl
766dnl Check for "pcap_set_datalink()"; you can't substitute for it if
767dnl it's absent (it has hooks into libpcap), so just define the
768dnl HAVE_ value if it's there.
769dnl
770AC_CHECK_FUNCS(pcap_set_datalink)
771
772dnl
773dnl Check for "pcap_breakloop()"; you can't substitute for it if
774dnl it's absent (it has hooks into the live capture routines),
775dnl so just define the HAVE_ value if it's there.
776dnl
777AC_CHECK_FUNCS(pcap_breakloop)
778
779#
780# Do we have the new open API?  Check for pcap_create, and assume that,
781# if we do, we also have pcap_activate() and the other new routines
782# introduced in libpcap 1.0.0.
783#
784AC_CHECK_FUNCS(pcap_create)
785if test $ac_cv_func_pcap_create = "yes" ; then
786	#
787	# OK, do we have pcap_set_tstamp_type?  If so, assume we have
788	# pcap_list_tstamp_types and pcap_free_tstamp_types as well.
789	#
790	AC_CHECK_FUNCS(pcap_set_tstamp_type)
791	#
792	# And do we have pcap_set_tstamp_precision?  If so, we assume
793	# we also have pcap_open_offline_with_tstamp_precision.
794	#
795	AC_CHECK_FUNCS(pcap_set_tstamp_precision)
796fi
797
798#
799# Check for a miscellaneous collection of functions which we use
800# if we have them.
801#
802AC_CHECK_FUNCS(pcap_findalldevs)
803AC_CHECK_FUNCS(pcap_dump_flush pcap_lib_version)
804if test $ac_cv_func_pcap_lib_version = "no" ; then
805    AC_MSG_CHECKING(whether pcap_version is defined by libpcap)
806    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
807	extern char pcap_version[];
808
809	return (int)pcap_version;
810       ]])
811       ],
812       [ac_lbl_cv_pcap_version_defined=yes],
813       [ac_lbl_cv_pcap_version_defined=no])
814    if test "$ac_lbl_cv_pcap_version_defined" = yes ; then
815	AC_MSG_RESULT(yes)
816	AC_DEFINE(HAVE_PCAP_VERSION, 1, [define if libpcap has pcap_version])
817    else
818	AC_MSG_RESULT(no)
819    fi
820fi
821AC_CHECK_FUNCS(pcap_setdirection pcap_set_immediate_mode pcap_dump_ftell64)
822#
823# See the comment in AC_LBL_LIBPCAP in aclocal.m4 for the reason
824# why we don't check for remote-capture APIs if we're building
825# with the system libpcap on macOS.
826#
827if test "$_dont_check_for_remote_apis" != "yes"; then
828	AC_CHECK_FUNCS(pcap_open pcap_findalldevs_ex)
829fi
830AC_REPLACE_FUNCS(pcap_dump_ftell)
831
832#
833# Check for special debugging functions
834#
835AC_CHECK_FUNCS(pcap_set_parser_debug)
836if test "$ac_cv_func_pcap_set_parser_debug" = "no" ; then
837	#
838	# OK, we don't have pcap_set_parser_debug() to set the libpcap
839	# filter expression parser debug flag; can we directly set the
840	# flag?
841	AC_MSG_CHECKING(whether pcap_debug is defined by libpcap)
842	AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
843		extern int pcap_debug;
844
845		return pcap_debug;
846	   ]])
847	   ],
848	   [ac_lbl_cv_pcap_debug_defined=yes],
849	   [ac_lbl_cv_pcap_debug_defined=no])
850	if test "$ac_lbl_cv_pcap_debug_defined" = yes ; then
851		AC_MSG_RESULT(yes)
852		AC_DEFINE(HAVE_PCAP_DEBUG, 1, [define if libpcap has pcap_debug])
853	else
854		AC_MSG_RESULT(no)
855		#
856		# OK, what about "yydebug"?
857		#
858		AC_MSG_CHECKING(whether yydebug is defined by libpcap)
859		AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
860			extern int yydebug;
861
862			return yydebug;
863		   ]])
864		   ],
865		   [ac_lbl_cv_yydebug_defined=yes],
866		   [ac_lbl_cv_yydebug_defined=no])
867		if test "$ac_lbl_cv_yydebug_defined" = yes ; then
868			AC_MSG_RESULT(yes)
869			AC_DEFINE(HAVE_YYDEBUG, 1, [define if libpcap has yydebug])
870		else
871			AC_MSG_RESULT(no)
872		fi
873	fi
874fi
875AC_CHECK_FUNCS(pcap_set_optimizer_debug)
876AC_REPLACE_FUNCS(bpf_dump)	dnl moved to libpcap in 0.6
877
878#
879# Assume V7/BSD convention for man pages (file formats in section 5,
880# miscellaneous info in section 7).
881#
882MAN_FILE_FORMATS=5
883MAN_MISC_INFO=7
884case "$host_os" in
885
886aix*)
887	dnl Workaround to enable certain features
888	AC_DEFINE(_SUN,1,[define on AIX to get certain functions])
889	;;
890
891hpux*)
892	#
893	# Use System V conventions for man pages.
894	#
895	MAN_FILE_FORMATS=4
896	MAN_MISC_INFO=5
897	;;
898
899irix*)
900	V_GROUP=sys
901
902	#
903	# Use System V conventions for man pages.
904	#
905	MAN_FILE_FORMATS=4
906	MAN_MISC_INFO=5
907	;;
908
909osf*)
910	V_GROUP=system
911
912	#
913	# Use System V conventions for man pages.
914	#
915	MAN_FILE_FORMATS=4
916	MAN_MISC_INFO=5
917	;;
918
919solaris*)
920	#
921	# Use System V conventions for man pages.
922	#
923	MAN_FILE_FORMATS=4
924	MAN_MISC_INFO=5
925	;;
926esac
927
928#
929# Make sure we have a definition for C99's uintptr_t (regardless of
930# whether the environment is a C99 environment or not).
931#
932AC_TYPE_UINTPTR_T
933
934savedcppflags="$CPPFLAGS"
935CPPFLAGS="$CPPFLAGS $V_INCLS"
936
937#
938# Check whether we have pcap/pcap-inttypes.h.
939# If we do, we use that to get the C99 types defined.
940#
941AC_CHECK_HEADERS(pcap/pcap-inttypes.h)
942
943#
944# At compile time HAVE_PCAP_FINDALLDEVS depends on HAVE_PCAP_IF_T.
945#
946AC_CHECK_TYPES(pcap_if_t, , , [#include <pcap.h>])
947
948CPPFLAGS="$savedcppflags"
949
950#
951# Define the old BSD specified-width types in terms of the C99 types;
952# we may need them with libpcap include files.
953#
954AC_CHECK_TYPE([u_int8_t], ,
955	[AC_DEFINE([u_int8_t], [uint8_t],
956	[Define to `uint8_t' if u_int8_t not defined.])],
957	[AC_INCLUDES_DEFAULT
958#include <sys/types.h>
959])
960AC_CHECK_TYPE([u_int16_t], ,
961	[AC_DEFINE([u_int16_t], [uint16_t],
962	[Define to `uint16_t' if u_int16_t not defined.])],
963	[AC_INCLUDES_DEFAULT
964#include <sys/types.h>
965])
966AC_CHECK_TYPE([u_int32_t], ,
967	[AC_DEFINE([u_int32_t], [uint32_t],
968	[Define to `uint32_t' if u_int32_t not defined.])],
969	[AC_INCLUDES_DEFAULT
970#include <sys/types.h>
971])
972AC_CHECK_TYPE([u_int64_t], ,
973	[AC_DEFINE([u_int64_t], [uint64_t],
974	[Define to `uint64_t' if u_int64_t not defined.])],
975	[AC_INCLUDES_DEFAULT
976#include <sys/types.h>
977])
978
979AC_PROG_RANLIB
980AC_CHECK_TOOL([AR], [ar])
981
982AC_LBL_DEVEL(V_CCOPT)
983
984# Check for OpenSSL/libressl libcrypto
985AC_MSG_CHECKING(whether to use OpenSSL/libressl libcrypto)
986# Specify location for both includes and libraries.
987want_libcrypto=ifavailable
988AC_ARG_WITH(crypto,
989    AS_HELP_STRING([--with-crypto]@<:@=DIR@:>@,
990		   [use OpenSSL/libressl libcrypto (located in directory DIR, if specified) @<:@default=yes, if available@:>@]),
991[
992	if test $withval = no
993	then
994		# User doesn't want to link with libcrypto.
995		want_libcrypto=no
996		AC_MSG_RESULT(no)
997	elif test $withval = yes
998	then
999		# User wants to link with libcrypto but hasn't specified
1000		# a directory.
1001		want_libcrypto=yes
1002		AC_MSG_RESULT(yes)
1003	else
1004		# User wants to link with libcrypto and has specified
1005		# a directory, so use the provided value.
1006		want_libcrypto=yes
1007		libcrypto_root=$withval
1008		AC_MSG_RESULT([yes, using the version installed in $withval])
1009	fi
1010],[
1011	#
1012	# Use libcrypto if it's present, otherwise don't; no directory
1013	# was specified.
1014	#
1015	want_libcrypto=ifavailable
1016	AC_MSG_RESULT([yes, if available])
1017])
1018if test "$want_libcrypto" != "no"; then
1019	#
1020	# Were we told where to look for libcrypto?
1021	#
1022	if test -z "$libcrypto_root"; then
1023		#
1024		# No.
1025		#
1026		# First, try looking for it with pkg-config, if we have it.
1027		#
1028		# Homebrew's pkg-config does not, by default, look for
1029		# pkg-config files for packages it has installed.
1030		# Furthermore, at least for OpenSSL, they appear to be
1031		# dumped in package-specific directories whose paths are
1032		# not only package-specific but package-version-specific.
1033		#
1034		# So the only way to find openssl is to get the value of
1035		# PKG_CONFIG_PATH from "brew --env openssl" and add that
1036		# to PKG_CONFIG_PATH.  (No, we can't just assume it's under
1037		# /usr/local; Homebrew have conveniently chosen to put it
1038		# under /opt/homebrew on ARM.)
1039		#
1040		# That's the nice thing about Homebrew - it makes things easier!
1041		# Thanks!
1042		#
1043		save_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
1044		if test -n "$BREW"; then
1045			openssl_pkgconfig_dir=`$BREW --env --plain openssl | sed -n 's/PKG_CONFIG_PATH: //p'`
1046			PKG_CONFIG_PATH="$openssl_pkgconfig_dir:$PKG_CONFIG_PATH"
1047		fi
1048		PKG_CHECK_MODULE(LIBCRYPTO, libcrypto,
1049		    [
1050			#
1051			# We found OpenSSL/libressl libcrypto.
1052			#
1053			HAVE_LIBCRYPTO=yes
1054		    ])
1055		PKG_CONFIG_PATH="$save_PKG_CONFIG_PATH"
1056
1057		#
1058		# If it wasn't found, and we have Homebrew installed, see
1059		# if it's in Homebrew.
1060		#
1061		if test "x$HAVE_LIBCRYPTO" != "xyes" -a -n "$BREW"; then
1062			AC_MSG_CHECKING(for openssl in Homebrew)
1063			#
1064			# The brew man page lies when it speaks of
1065			# $BREW --prefix --installed <formula>
1066			# outputting nothing.  In Homebrew 3.3.16,
1067			# it produces output regardless of whether
1068			# the formula is installed or not, so we
1069			# send the standard output and error to
1070			# the bit bucket.
1071			#
1072			# libcrypto isn't a formula, openssl is a formula.
1073			#
1074			if $BREW --prefix --installed openssl >/dev/null 2>&1; then
1075				#
1076				# Yes.  Get the include directory and library
1077				# directory.  (No, we can't just assume it's
1078				# under /usr/local; Homebrew have conveniently
1079				# chosen to put it under /opt/homebrew on ARM.)
1080				#
1081				AC_MSG_RESULT(yes)
1082				HAVE_LIBCRYPTO=yes
1083				openssl_path=`$BREW --prefix openssl`
1084				LIBCRYPTO_CFLAGS="-I$openssl_path/include"
1085				LIBCRYPTO_LIBS="-L$openssl_path/lib -lcrypto"
1086			else
1087				AC_MSG_RESULT(no)
1088			fi
1089		fi
1090
1091		#
1092		# If it wasn't found, and /usr/local/include and /usr/local/lib
1093		# exist, check if it's in /usr/local.  (We check whether they
1094		# exist because, if they don't exist, the compiler will warn
1095		# about that and then ignore the argument, so they test
1096		# using just the system header files and libraries.)
1097		#
1098		# We include the standard include file to 1) make sure that
1099		# it's installed (if it's just a shared library for the
1100		# benefit of existing programs, that's not useful) and 2)
1101		# because SSL_library_init() is a library routine in some
1102		# versions and a #defined wrapper around OPENSSL_init_ssl()
1103		# in others.
1104		#
1105		if test "x$HAVE_LIBCRYPTO" != "xyes" -a -d "/usr/local/include" -a -d "/usr/local/lib"; then
1106			AC_LBL_SAVE_CHECK_STATE
1107			CFLAGS="$CFLAGS -I/usr/local/include"
1108			LIBS="$LIBS -L/usr/local/lib -lcrypto"
1109			AC_MSG_CHECKING(whether we have an OpenSSL/libressl libcrypto in /usr/local that we can use)
1110			AC_LINK_IFELSE([AC_LANG_PROGRAM(
1111			    [[
1112#include <openssl/evp.h>
1113			    ]],
1114			    [[
1115EVP_CIPHER_CTX_block_size((EVP_CIPHER_CTX *)0);
1116return 0;
1117			    ]])],
1118			    [
1119				AC_MSG_RESULT(yes)
1120				HAVE_LIBCRYPTO=yes
1121				LIBCRYPTO_CFLAGS="-I/usr/local/include"
1122				LIBCRYPTO_LIBS="-L/usr/local/lib -lcrypto"
1123			    ],
1124			    AC_MSG_RESULT(no))
1125			AC_LBL_RESTORE_CHECK_STATE
1126		fi
1127
1128		#
1129		# If it wasn't found, check if it's a system library.
1130		#
1131		# We include the standard include file to 1) make sure that
1132		# it's installed (if it's just a shared library for the
1133		# benefit of existing programs, that's not useful) and 2)
1134		# make sure this isn't a newer macOS that provides libcrypto
1135		# as a shared library but doesn't provide headers - Apple,
1136		# bless their pointy little heads, apparently ship libcrypto
1137		# as a library, but not the header files, in El Capitan and
1138		# later, probably because they don't want you writing nasty
1139		# portable code that could run on other UN*Xes, they want you
1140		# writing code that uses their Shiny New Crypto Library and
1141		# that thus only runs on macOS.
1142		#
1143		if test "x$HAVE_LIBCRYPTO" != "xyes"; then
1144			AC_LBL_SAVE_CHECK_STATE
1145			LIBS="$LIBS -lcrypto"
1146			AC_MSG_CHECKING(whether we have a system OpenSSL/libressl that we can use)
1147			AC_LINK_IFELSE([AC_LANG_PROGRAM(
1148			    [[
1149#include <openssl/evp.h>
1150			    ]],
1151			    [[
1152EVP_CIPHER_CTX_block_size((EVP_CIPHER_CTX *)0);
1153return 0;
1154			    ]])],
1155			    [
1156				AC_MSG_RESULT(yes)
1157				HAVE_LIBCRYPTO=yes
1158				LIBCRYPTO_LIBS="-lcrypto"
1159			    ],
1160			    AC_MSG_RESULT(no))
1161			AC_LBL_RESTORE_CHECK_STATE
1162		fi
1163	else
1164		#
1165		# Yes.
1166		#
1167		# Look for it there.
1168		#
1169		AC_LBL_SAVE_CHECK_STATE
1170		CFLAGS="$CFLAGS -I$libcrypto_root/include"
1171		LIBS="$LIBS -L$libcrypto_root/lib -lcrypto"
1172		AC_MSG_CHECKING(whether we have a system OpenSSL/libressl that we can use)
1173		AC_LINK_IFELSE([AC_LANG_PROGRAM(
1174		    [[
1175#include <openssl/evp.h>
1176		    ]],
1177		    [[
1178EVP_CIPHER_CTX_block_size((EVP_CIPHER_CTX *)0);
1179return 0;
1180		    ]])],
1181		    [
1182			AC_MSG_RESULT(yes)
1183			HAVE_LIBCRYPTO=yes
1184			LIBCRYPTO_CFLAGS="-I$libcrypto_root/include"
1185			LIBCRYPTO_LIBS="-L$libcrypto_root/lib -lcrypto"
1186		    ],
1187		    AC_MSG_RESULT(no))
1188		AC_LBL_RESTORE_CHECK_STATE
1189	fi
1190
1191	#
1192	# OK, did we find it?
1193	#
1194	if test "x$HAVE_LIBCRYPTO" = "xyes"; then
1195		AC_DEFINE([HAVE_LIBCRYPTO], [1], [Define to 1 if you have a usable `crypto' library (-lcrypto).])
1196
1197		#
1198		# Put the subdirectories of the libcrypto root directory
1199		# at the end of the header and library search path, to
1200		# make sure they come after any -I or -L flags for
1201		# a local libpcap - those must take precedence of any
1202		# directory that might contain an installed version of
1203		# libpcap.
1204		#
1205		V_INCLS="$V_INCLS $LIBCRYPTO_CFLAGS"
1206		LIBS="$LIBS $LIBCRYPTO_LIBS"
1207
1208		#
1209		# OK, then:
1210		#
1211		# 1) do we have EVP_CIPHER_CTX_new?
1212		# If so, we use it to allocate an EVP_CIPHER_CTX, as
1213		# EVP_CIPHER_CTX may be opaque; otherwise, we allocate it
1214		# ourselves.
1215		#
1216		# 2) do we have EVP_DecryptInit_ex()?
1217		# If so, we use it, because we need to be able to make
1218		# two "initialize the cipher" calls, one with the cipher
1219		# and key, and one with the IV, and, as of OpenSSL 1.1,
1220		# You Can't Do That with EVP_DecryptInit(), because a
1221		# call to EVP_DecryptInit() will unconditionally clear
1222		# the context, and if you don't supply a cipher, it'll
1223		# clear the cipher, rendering the context unusable and
1224		# causing a crash.
1225		#
1226		AC_CHECK_FUNCS(EVP_CIPHER_CTX_new EVP_DecryptInit_ex)
1227	else
1228		AC_MSG_NOTICE(OpenSSL/libressl libcrypto not found)
1229	fi
1230fi
1231
1232# Check for libcap-ng
1233AC_MSG_CHECKING(whether to use libcap-ng)
1234# Specify location for both includes and libraries.
1235want_libcap_ng=ifavailable
1236AC_ARG_WITH(cap_ng,
1237    AS_HELP_STRING([--with-cap-ng],
1238		   [use libcap-ng @<:@default=yes, if available@:>@]),
1239[
1240	if test $withval = no
1241	then
1242		want_libcap_ng=no
1243		AC_MSG_RESULT(no)
1244	elif test $withval = yes
1245	then
1246		want_libcap_ng=yes
1247		AC_MSG_RESULT(yes)
1248	fi
1249],[
1250	#
1251	# Use libcap-ng if it's present, otherwise don't.
1252	#
1253	want_libcap_ng=ifavailable
1254	AC_MSG_RESULT([yes, if available])
1255])
1256if test "$want_libcap_ng" != "no"; then
1257	AC_CHECK_LIB(cap-ng, capng_change_id)
1258	AC_CHECK_HEADERS(cap-ng.h)
1259fi
1260
1261dnl
1262dnl set additional include path if necessary
1263if test "$missing_includes" = "yes"; then
1264	CPPFLAGS="$CPPFLAGS -I$srcdir/missing"
1265	V_INCLS="$V_INCLS -I$srcdir/missing"
1266fi
1267
1268AC_SUBST(V_CCOPT)
1269AC_SUBST(V_DEFS)
1270AC_SUBST(V_INCLS)
1271AC_SUBST(V_PCAPDEP)
1272AC_SUBST(LOCALSRC)
1273AC_SUBST(MAN_FILE_FORMATS)
1274AC_SUBST(MAN_MISC_INFO)
1275
1276AC_PROG_INSTALL
1277
1278AC_CONFIG_HEADER(config.h)
1279
1280AC_CONFIG_COMMANDS([.devel],[[if test -f .devel; then
1281	echo timestamp > stamp-h
1282	cat $srcdir/Makefile-devel-adds >> Makefile
1283	make depend || exit 1
1284fi]],[[]])
1285AC_CONFIG_FILES([Makefile tcpdump.1])
1286AC_OUTPUT
1287exit 0
1288