xref: /src/contrib/libpcap/configure.ac (revision 16cef5f7a65588def71db4fdfa961f959847e3b6)
1dnl
2dnl Copyright (c) 1994, 1995, 1996, 1997
3dnl	The Regents of the University of California.  All rights reserved.
4dnl
5dnl Process this file with autoconf to produce a configure script.
6dnl
7
8#
9# See
10#
11#	https://ftp.gnu.org/gnu/config/README
12#
13# for the URLs to use to fetch new versions of config.guess and
14# config.sub.
15#
16
17AC_PREREQ(2.69)
18
19AC_INIT(pcap, m4_esyscmd_s([cat VERSION]))
20AC_CONFIG_SRCDIR(pcap.c)
21AC_SUBST(PACKAGE_NAME)
22
23#
24# These are the variables that are used in Makefile, pcap-config, and
25# libpcap.pc.
26#
27# CFLAGS: inherited from the environment, not modified by us except
28# for flags required for the platform for which we're building (and
29# except temporarily during tests that involve compilation).  Used only
30# when compiling C source.
31#
32# LDFLAGS: inherited from the environment, not modified by us.
33#
34# LIBS: inherited from the environment; we add libraries required by
35# libpcap.  Libraries that the core libpcap code requires are added
36# first; libraries required by additional pcap modules are first
37# added to ADDITIONAL_LIBS, and only added to LIBS at the end, after
38# we're finished doing configuration tests for the modules.
39#
40# LIBS_STATIC: libraries with which a program using the libpcap *static*
41# library needs to be linked.  This is a superset of LIBS, used in
42# pcap-config, so that "pcap-config --libs --static" will report them.
43# Initialized to LIBS.
44#
45# REQUIRES_PRIVATE: pkg-config package names for additional libraries
46# with which a program using the libpcap *static* library needs to be
47# linked and for which a .pc file exists.  This is used in libpcap.pc,
48# so that "pkg-config --libs --static" will report them, and so that
49# those libraries will be determined using the library's .pc file, not
50# from our .pc file.  Initialized to an empty string.
51#
52# V_CCOPT: additional compiler flags other than -I and -D flags
53# needed when compiling libpcap.  Used in Makefile for both C and
54# C++ source.
55#
56# V_DEFS: additional -D compiler flags needed when compiling
57# libpcap.  Used in Makefile for both C and C++ source.
58#
59# V_INCLS: additional -I compiler flags needed when compiling
60# libpcap.  Used in Makefile for both C and C++ source.
61#
62# ADDITIONAL_LIBS: additional libraries with which the libpcap dynamic
63# library needs to be linked.  Used in Makefile; not used in pcap-config
64# or libpcap.pc, as, in all platforms on which we run, if a dynamic
65# library is linked with other dynamic libraries, a program using
66# that dynamic library doesn't have to link with those libraries -
67# they will be automatically loaded at run time.  Initialized to an
68# empty string.
69#
70# ADDITIONAL_LIBS_STATIC: additional libraries with which a program
71# using the libpcap *static* library needs to be linked.  This is used
72# in pcap-config, so that "pcap-config --libs --static" will report
73# them.  Initialized to an empty string.
74#
75# REQUIRES_PRIVATE: pkg-config package names for additional libraries
76# with which a program using the libpcap *static* library needs to be
77# linked and for which a .pc file exists.  This is used in libpcap.pc,
78# so that "pkg-config --libs --static" will report them, and so that
79# those libraries will be determined using the library's .pc file, not
80# from our .pc file.  Initialized to an empty string.
81#
82# LIBS_PRIVATE: pkg-config package names for additional libraries with
83# which a program using the libpcap *static* library needs to be linked
84# and for which a .pc file does not exist.  This is used in libpcap.pc,
85# so that "pkg-config --libs --static" will report them (those libraries
86# cannot be determined using the library's .pc file, as there is no such
87# file, so it has to come from our .pc file.  Initialized to an empty
88# string.
89#
90LIBS_STATIC=""
91REQUIRES_PRIVATE=""
92LIBS_PRIVATE=""
93
94AC_SUBST(V_CCOPT)
95AC_SUBST(V_DEFS)
96AC_SUBST(V_INCLS)
97AC_SUBST(LIBS_STATIC)
98AC_SUBST(REQUIRES_PRIVATE)
99AC_SUBST(LIBS_PRIVATE)
100
101AC_CANONICAL_SYSTEM
102
103AC_LBL_C_INIT_BEFORE_CC(V_CCOPT, V_INCLS)
104#
105# We require C99 or later.
106# Try to get it, which may involve adding compiler flags;
107# if that fails, give up.
108#
109AC_PROG_CC_C99
110if test "$ac_cv_prog_cc_c99" = "no"; then
111	AC_MSG_ERROR([The C compiler does not support C99])
112fi
113
114#
115# Try to arrange for large file support.
116#
117AC_SYS_LARGEFILE
118AC_FUNC_FSEEKO
119
120#
121# Get the size of a void *, to determine whether this is a 32-bit
122# or 64-bit build.
123#
124AC_CHECK_SIZEOF([void *])
125ac_lbl_c_sizeof_void_p="$ac_cv_sizeof_void_p"
126
127#
128# Get the size of a time_t, to know whether it's 32-bit or 64-bit.
129#
130AC_CHECK_SIZEOF([time_t],,[#include <time.h>])
131
132AC_LBL_C_INIT(V_CCOPT, V_INCLS)
133AC_LBL_SHLIBS_INIT
134AC_LBL_C_INLINE
135AC_PCAP_C___ATOMICS
136
137dnl
138dnl Even if <net/bpf.h> were, on all OSes that support BPF, fixed to
139dnl include <sys/ioccom.h>, and we were to drop support for older
140dnl releases without that fix, so that pcap-bpf.c doesn't need to
141dnl include <sys/ioccom.h>, the test program in "AC_LBL_FIXINCLUDES"
142dnl in "aclocal.m4" uses it, so we would still have to test for it
143dnl and set "HAVE_SYS_IOCCOM_H" if we have it, otherwise
144dnl "AC_LBL_FIXINCLUDES" wouldn't work on some platforms such as Solaris.
145dnl
146AC_CHECK_HEADERS(sys/ioccom.h sys/sockio.h)
147AC_CHECK_HEADERS(netpacket/packet.h)
148
149#
150# Check whether the platform for which we're compiling requires extra
151# defines and libraries.  If so, add them to CFLAGS and LIBS, as we want
152# all subsequent tests to be done with those defines and libraries.
153#
154case "$host_os" in
155haiku*)
156	#
157	# Haiku needs _BSD_SOURCE for the _IO* macros because it doesn't
158	# use them.
159	#
160	CFLAGS="$CFLAGS -D_BSD_SOURCE"
161	#
162	# Haiku has getpass in libbsd.
163	#
164	AC_CHECK_LIB(bsd, getpass)
165	;;
166esac
167
168AC_LBL_SAVE_CHECK_STATE
169AC_LBL_FIXINCLUDES
170AC_LBL_RESTORE_CHECK_STATE
171
172AC_CHECK_FUNC(strerror_r,
173    [
174	#
175	# We have strerror_r; if we define _GNU_SOURCE, is it a
176	# POSIX-compliant strerror_r() or a GNU strerror_r()?
177	#
178	AC_MSG_CHECKING(whether strerror_r is GNU-style)
179	AC_COMPILE_IFELSE(
180	    [
181		AC_LANG_SOURCE(
182#define _GNU_SOURCE
183#include <string.h>
184
185/* Define it GNU-style; that will cause an error if it's not GNU-style */
186extern char *strerror_r(int, char *, size_t);
187
188int
189main(void)
190{
191	return 0;
192}
193)
194	    ],
195	    [
196		# GNU-style
197		AC_MSG_RESULT(yes)
198		AC_DEFINE(HAVE_GNU_STRERROR_R,,
199		    [Define to 1 if you have a GNU-style `strerror_r' function.])
200	    ],
201	    [
202		AC_MSG_RESULT(no)
203		AC_DEFINE(HAVE_POSIX_STRERROR_R,,
204		    [Define to 1 if you have a POSIX-style `strerror_r' function.])
205	    ])
206    ],
207    [
208	#
209	# We don't have strerror_r; do we have _wcserror_s?
210	#
211	AC_CHECK_FUNCS(_wcserror_s)
212    ])
213
214#
215# Thanks, IBM, for not providing vsyslog() in AIX!
216#
217AC_CHECK_FUNCS(vsyslog)
218
219#
220# Make sure we have vsnprintf() and snprintf(); we require them.
221#
222AC_CHECK_FUNC(vsnprintf,,
223    AC_MSG_ERROR([vsnprintf() is required but wasn't found]))
224AC_CHECK_FUNC(snprintf,,
225    AC_MSG_ERROR([snprintf() is required but wasn't found]))
226
227needasprintf=no
228AC_CHECK_FUNCS(vasprintf asprintf,,
229	[needasprintf=yes])
230if test $needasprintf = yes; then
231	AC_LIBOBJ([asprintf])
232fi
233
234needstrlcat=no
235AC_CHECK_FUNCS(strlcat,,
236	[needstrlcat=yes])
237if test $needstrlcat = yes; then
238	AC_LIBOBJ([strlcat])
239fi
240
241needstrlcpy=no
242AC_CHECK_FUNCS(strlcpy,,
243	[needstrlcpy=yes])
244if test $needstrlcpy = yes; then
245	AC_LIBOBJ([strlcpy])
246fi
247
248needstrtok_r=no
249AC_CHECK_FUNCS(strtok_r,,
250	[needstrtok_r=yes])
251if test $needstrtok_r = yes; then
252	AC_LIBOBJ([strtok_r])
253fi
254
255#
256# Do we have ffs(), and is it declared in <strings.h>?
257#
258AC_CHECK_FUNCS(ffs)
259if test "$ac_cv_func_ffs" = yes; then
260	#
261	# We have ffs(); is it declared in <strings.h>?
262	#
263	# This test fails if we don't have <strings.h> or if we do
264	# but it doesn't declare ffs().
265	#
266	AC_CHECK_DECL(ffs,
267	    [
268		AC_DEFINE(STRINGS_H_DECLARES_FFS,,
269		    [Define to 1 if strings.h declares `ffs'])
270	    ],,
271	    [
272#include <strings.h>
273	    ])
274fi
275
276#
277# Do this before checking for ether_hostton(), as it's a
278# "getaddrinfo()-ish function".
279#
280AC_LBL_LIBRARY_NET
281
282#
283# Check for reentrant versions of getnetbyname_r(), as provided by
284# Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
285# If we don't find one, we just use getnetbyname(), which uses
286# thread-specific data on many platforms, but doesn't use it on
287# NetBSD or OpenBSD, and may not use it on older versions of other
288# platforms.
289#
290# Only do the check if we have a declaration of getnetbyname_r();
291# without it, we can't check which API it has.  (We assume that
292# if there's a declaration, it has a prototype, so that the API
293# can be checked.)
294#
295AC_CHECK_DECL(getnetbyname_r,
296    [
297	AC_MSG_CHECKING([for the Linux getnetbyname_r()])
298	AC_TRY_LINK(
299	    [#include <netdb.h>],
300	    [
301		struct netent netent_buf;
302		char buf[1024];
303		struct netent *resultp;
304		int h_errnoval;
305
306		return getnetbyname_r((const char *)0, &netent_buf, buf, sizeof buf, &resultp, &h_errnoval);
307	    ],
308	    [
309		AC_MSG_RESULT(yes)
310		AC_DEFINE(HAVE_LINUX_GETNETBYNAME_R, 1,
311		    [define if we have the Linux getnetbyname_r()])
312	    ],
313	    [
314		AC_MSG_RESULT(no)
315
316		AC_MSG_CHECKING([for Solaris/IRIX getnetbyname_r()])
317		AC_TRY_LINK(
318		    [#include <netdb.h>],
319		    [
320			struct netent netent_buf;
321			char buf[1024];
322
323			return getnetbyname_r((const char *)0, &netent_buf, buf, (int)sizeof buf) != NULL;
324		    ],
325		    [
326			AC_MSG_RESULT(yes)
327			AC_DEFINE(HAVE_SOLARIS_IRIX_GETNETBYNAME_R, 1,
328			    [define if we have the Solaris/IRIX getnetbyname_r()])
329		    ],
330		    [
331			AC_MSG_RESULT(no)
332
333			AC_MSG_CHECKING([for AIX getnetbyname_r()])
334			AC_TRY_LINK(
335			    [#include <netdb.h>],
336			    [
337				struct netent netent_buf;
338				struct netent_data net_data;
339
340				return getnetbyname_r((const char *)0, &netent_buf, &net_data);
341			    ],
342			    [
343				AC_MSG_RESULT(yes)
344				AC_DEFINE(HAVE_AIX_GETNETBYNAME_R, 1,
345				    [define if we have the AIX getnetbyname_r()])
346			    ],
347			    [
348				AC_MSG_RESULT(no)
349			    ])
350		    ])
351	    ])
352    ],,[#include <netdb.h>])
353
354#
355# Check for reentrant versions of getprotobyname_r(), as provided by
356# Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
357# If we don't find one, we just use getprotobyname(), which uses
358# thread-specific data on many platforms, but doesn't use it on
359# NetBSD or OpenBSD, and may not use it on older versions of other
360# platforms.
361#
362# Only do the check if we have a declaration of getprotobyname_r();
363# without it, we can't check which API it has.  (We assume that
364# if there's a declaration, it has a prototype, so that the API
365# can be checked.)
366#
367AC_CHECK_DECL(getprotobyname_r,
368    [
369	AC_MSG_CHECKING([for the Linux getprotobyname_r()])
370	AC_TRY_LINK(
371	    [#include <netdb.h>],
372	    [
373		struct protoent protoent_buf;
374		char buf[1024];
375		struct protoent *resultp;
376
377		return getprotobyname_r((const char *)0, &protoent_buf, buf, sizeof buf, &resultp);
378	    ],
379	    [
380		AC_MSG_RESULT(yes)
381		AC_DEFINE(HAVE_LINUX_GETPROTOBYNAME_R, 1,
382		    [define if we have the Linux getprotobyname_r()])
383	    ],
384	    [
385		AC_MSG_RESULT(no)
386
387		AC_MSG_CHECKING([for Solaris/IRIX getprotobyname_r()])
388		AC_TRY_LINK(
389		    [#include <netdb.h>],
390		    [
391			struct protoent protoent_buf;
392			char buf[1024];
393
394			return getprotobyname_r((const char *)0, &protoent_buf, buf, (int)sizeof buf) != NULL;
395		    ],
396		    [
397			AC_MSG_RESULT(yes)
398			AC_DEFINE(HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R, 1,
399			    [define if we have the Solaris/IRIX getprotobyname_r()])
400		    ],
401		    [
402			AC_MSG_RESULT(no)
403
404			AC_MSG_CHECKING([for AIX getprotobyname_r()])
405			AC_TRY_LINK(
406			    [#include <netdb.h>],
407			    [
408				struct protoent protoent_buf;
409				struct protoent_data proto_data;
410
411				return getprotobyname_r((const char *)0, &protoent_buf, &proto_data);
412			    ],
413			    [
414				AC_MSG_RESULT(yes)
415				AC_DEFINE(HAVE_AIX_GETPROTOBYNAME_R, 1,
416				    [define if we have the AIX getprotobyname_r()])
417			    ],
418			    [
419				AC_MSG_RESULT(no)
420			    ])
421		    ])
422	    ])
423    ],,[#include <netdb.h>])
424
425#
426# You are in a twisty little maze of UN*Xes, all different.
427# Some might not have ether_hostton().
428# Some might have it and declare it in <net/ethernet.h>.
429# Some might have it and declare it in <netinet/ether.h>
430# Some might have it and declare it in <sys/ethernet.h>.
431# Some might have it and declare it in <arpa/inet.h>.
432# Some might have it and declare it in <netinet/if_ether.h>.
433# Some might have it and not declare it in any header file.
434#
435# Before you is a C compiler.
436#
437AC_CHECK_FUNCS(ether_hostton)
438if test "$ac_cv_func_ether_hostton" = yes; then
439	#
440	# OK, we have ether_hostton().  Is it declared in <net/ethernet.h>?
441	#
442	# This test fails if we don't have <net/ethernet.h> or if we do
443	# but it doesn't declare ether_hostton().
444	#
445	AC_CHECK_DECL(ether_hostton,
446	    [
447		AC_DEFINE(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON,,
448		    [Define to 1 if net/ethernet.h declares `ether_hostton'])
449	    ],,
450	    [
451#include <net/ethernet.h>
452	    ])
453	#
454	# Did that succeed?
455	#
456	if test "$ac_cv_have_decl_ether_hostton" != yes; then
457		#
458		# No, how about <netinet/ether.h>, as on Linux?
459		#
460		# This test fails if we don't have <netinet/ether.h>
461		# or if we do but it doesn't declare ether_hostton().
462		#
463		# Unset ac_cv_have_decl_ether_hostton so we don't
464		# treat the previous failure as a cached value and
465		# suppress the next test.
466		#
467		unset ac_cv_have_decl_ether_hostton
468		AC_CHECK_DECL(ether_hostton,
469		    [
470			AC_DEFINE(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON,,
471			    [Define to 1 if netinet/ether.h declares `ether_hostton'])
472		    ],,
473		    [
474#include <netinet/ether.h>
475		    ])
476	fi
477	#
478	# Did that succeed?
479	#
480	if test "$ac_cv_have_decl_ether_hostton" != yes; then
481		#
482		# No, how about <sys/ethernet.h>, as on Solaris 10
483		# and later?
484		#
485		# This test fails if we don't have <sys/ethernet.h>
486		# or if we do but it doesn't declare ether_hostton().
487		#
488		# Unset ac_cv_have_decl_ether_hostton so we don't
489		# treat the previous failure as a cached value and
490		# suppress the next test.
491		#
492		unset ac_cv_have_decl_ether_hostton
493		AC_CHECK_DECL(ether_hostton,
494		    [
495			AC_DEFINE(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON,,
496			    [Define to 1 if sys/ethernet.h declares `ether_hostton'])
497		    ],,
498		    [
499#include <sys/ethernet.h>
500		    ])
501	fi
502	#
503	# Did that succeed?
504	#
505	if test "$ac_cv_have_decl_ether_hostton" != yes; then
506		#
507		# No, how about <arpa/inet.h>, as in AIX?
508		#
509		# This test fails if we don't have <arpa/inet.h>
510		# (if we have ether_hostton(), we should have
511		# networking, and if we have networking, we should
512		# have <arpa/inet.h>) or if we do but it doesn't
513		# declare ether_hostton().
514		#
515		# Unset ac_cv_have_decl_ether_hostton so we don't
516		# treat the previous failure as a cached value and
517		# suppress the next test.
518		#
519		unset ac_cv_have_decl_ether_hostton
520		AC_CHECK_DECL(ether_hostton,
521		    [
522			AC_DEFINE(ARPA_INET_H_DECLARES_ETHER_HOSTTON,,
523			    [Define to 1 if arpa/inet.h declares `ether_hostton'])
524		    ],,
525		    [
526#include <arpa/inet.h>
527		    ])
528	fi
529	#
530	# Did that succeed?
531	#
532	if test "$ac_cv_have_decl_ether_hostton" != yes; then
533		#
534		# No, how about <netinet/if_ether.h>?
535		# On some platforms, it requires <net/if.h> and
536		# <netinet/in.h>, and we always include it with
537		# both of them, so test it with both of them.
538		#
539		# This test fails if we don't have <netinet/if_ether.h>
540		# and the headers we include before it, or if we do but
541		# <netinet/if_ether.h> doesn't declare ether_hostton().
542		#
543		# Unset ac_cv_have_decl_ether_hostton so we don't
544		# treat the previous failure as a cached value and
545		# suppress the next test.
546		#
547		unset ac_cv_have_decl_ether_hostton
548		AC_CHECK_DECL(ether_hostton,
549		    [
550			AC_DEFINE(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON,,
551			    [Define to 1 if netinet/if_ether.h declares `ether_hostton'])
552		    ],,
553		    [
554#include <sys/types.h>
555#include <sys/socket.h>
556#include <net/if.h>
557#include <netinet/in.h>
558#include <netinet/if_ether.h>
559		    ])
560	fi
561	#
562	# After all that, is ether_hostton() declared?
563	#
564	if test "$ac_cv_have_decl_ether_hostton" = yes; then
565		#
566		# Yes.
567		#
568		AC_DEFINE(HAVE_DECL_ETHER_HOSTTON, 1,
569		    [Define to 1 if you have the declaration of `ether_hostton'])
570        else
571		#
572		# No, we'll have to declare it ourselves.
573		# Do we have "struct ether_addr" if we include
574		# <netinet/if_ether.h>?
575		#
576		AC_CHECK_TYPES(struct ether_addr,,,
577		    [
578			#include <sys/types.h>
579			#include <sys/socket.h>
580			#include <net/if.h>
581			#include <netinet/in.h>
582			#include <netinet/if_ether.h>
583		    ])
584	fi
585fi
586
587#
588# For various things that might use pthreads.
589#
590AC_CHECK_HEADER(pthread.h,
591    [
592	#
593	# OK, we have pthread.h.  Do we have pthread_create in the
594	# system libraries?
595	#
596	AC_CHECK_FUNC(pthread_create,
597	    [
598		#
599		# Yes.
600		#
601		ac_lbl_have_pthreads="found"
602	    ],
603	    [
604		#
605		# No - do we have it in -lpthreads?
606		#
607		AC_CHECK_LIB(pthreads, pthread_create,
608		    [
609			#
610			# Yes - add -lpthreads.
611			#
612			ac_lbl_have_pthreads="found"
613			PTHREAD_LIBS="$PTHREAD_LIBS -lpthreads"
614		    ],
615		    [
616			#
617			# No - do we have it in -lpthread?
618			#
619			AC_CHECK_LIB(pthread, pthread_create,
620			    [
621				#
622				# Yes - add -lpthread.
623				#
624                                ac_lbl_have_pthreads="found"
625				PTHREAD_LIBS="$PTHREAD_LIBS -lpthread"
626			    ],
627			    [
628				#
629				# No.
630				#
631				ac_lbl_have_pthreads="not found"
632			    ])
633		    ])
634	    ])
635    ],
636    [
637	#
638	# We didn't find pthread.h.
639	#
640	ac_lbl_have_pthreads="not found"
641    ]
642)
643
644AC_MSG_CHECKING([whether to enable the instrument functions code])
645AC_ARG_ENABLE([instrument-functions],
646   [AS_HELP_STRING([--enable-instrument-functions],
647     [enable instrument functions code [default=no]])],
648   [],
649   [enableval=no])
650case "$enableval" in
651yes)	AC_MSG_RESULT(yes)
652	AC_DEFINE(ENABLE_INSTRUMENT_FUNCTIONS, 1,
653	    [define if you want to build the instrument functions code])
654	# Add '-finstrument-functions' instrumentation option to generate
655	# instrumentation calls for entry and exit to functions.
656	# Use '--enable-instrument-functions' also with tcpdump (or tcpslice)
657	# to see the output. See also https://www.tcpdump.org/faq.html#q17.
658	CFLAGS="$CFLAGS -O0 -ggdb -finstrument-functions"
659	;;
660*)	AC_MSG_RESULT(no)
661	;;
662esac
663
664dnl to pacify those who hate protochain insn
665AC_MSG_CHECKING(if --disable-protochain option is specified)
666AC_ARG_ENABLE(protochain,
667AS_HELP_STRING([--disable-protochain],[disable \"protochain\" insn]))
668case "x$enable_protochain" in
669xyes)	enable_protochain=enabled	;;
670xno)	enable_protochain=disabled	;;
671x)	enable_protochain=enabled	;;
672esac
673
674if test "$enable_protochain" = "disabled"; then
675	AC_DEFINE(NO_PROTOCHAIN,1,[do not use protochain])
676fi
677AC_MSG_RESULT(${enable_protochain})
678
679#
680# valgrindtest directly uses the native capture mechanism, but
681# only tests with BPF and PF_PACKET sockets; only enable it if
682# we have BPF or PF_PACKET sockets.
683#
684VALGRINDTEST_SRC=
685
686AC_ARG_WITH(pcap,
687AS_HELP_STRING([--with-pcap=TYPE],[use packet capture TYPE]))
688if test ! -z "$with_pcap" ; then
689	V_PCAP="$withval"
690else
691	#
692	# Check for a bunch of headers for various packet
693	# capture mechanisms.
694	#
695	AC_CHECK_HEADERS(net/bpf.h)
696	if test "$ac_cv_header_net_bpf_h" = yes; then
697		#
698		# Does it define BIOCSETIF?
699		# I.e., is it a header for an LBL/BSD-style capture
700		# mechanism, or is it just a header for a BPF filter
701		# engine?  Some versions of Arch Linux, for example,
702		# have a net/bpf.h that doesn't define BIOCSETIF;
703		# as it's a Linux, it should use packet sockets,
704		# instead.
705		#
706		# We need:
707		#
708		#  sys/types.h, because FreeBSD 10's net/bpf.h
709		#  requires that various BSD-style integer types
710		#  be defined;
711		#
712		#  sys/time.h, because AIX 5.2 and 5.3's net/bpf.h
713		#  doesn't include it but does use struct timeval
714		#  in ioctl definitions;
715		#
716		#  sys/ioctl.h and, if we have it, sys/ioccom.h,
717		#  because net/bpf.h defines ioctls;
718		#
719		#  net/if.h, because it defines some structures
720		#  used in ioctls defined by net/bpf.h;
721		#
722		#  sys/socket.h, because OpenBSD 5.9's net/bpf.h
723		#  defines some structure fields as being
724		#  struct sockaddrs;
725		#
726		# and net/bpf.h doesn't necessarily include all
727		# of those headers itself.
728		#
729		AC_MSG_CHECKING(if net/bpf.h defines BIOCSETIF)
730		AC_CACHE_VAL(ac_cv_lbl_bpf_h_defines_biocsetif,
731			AC_TRY_COMPILE(
732[
733#include <sys/types.h>
734#include <sys/time.h>
735#include <sys/ioctl.h>
736#include <sys/socket.h>
737#ifdef HAVE_SYS_IOCCOM_H
738#include <sys/ioccom.h>
739#endif
740#include <net/bpf.h>
741#include <net/if.h>
742],
743			[u_int i = BIOCSETIF;],
744			ac_cv_lbl_bpf_h_defines_biocsetif=yes,
745			ac_cv_lbl_bpf_h_defines_biocsetif=no))
746		AC_MSG_RESULT($ac_cv_lbl_bpf_h_defines_biocsetif)
747	fi
748	AC_CHECK_HEADERS(net/pfilt.h net/enet.h)
749	AC_CHECK_HEADERS(net/nit.h sys/net/nit.h)
750	AC_CHECK_HEADERS(linux/socket.h net/raw.h sys/dlpi.h)
751	AC_CHECK_HEADERS(config/HaikuConfig.h)
752
753	if test "$ac_cv_lbl_bpf_h_defines_biocsetif" = yes; then
754		#
755		# BPF.
756		# Check this before DLPI, so that we pick BPF on
757		# Solaris 11 and later.
758		#
759		V_PCAP=bpf
760
761		#
762		# We have BPF, so build valgrindtest with "make test"
763		# on macOS and FreeBSD (add your OS once there's a
764		# valgrind for it).
765		#
766		case "$host_os" in
767
768		freebsd*|darwin*|linux*)
769			VALGRINDTEST_SRC=valgrindtest.c
770			;;
771		esac
772	elif test "$ac_cv_header_linux_socket_h" = yes; then
773		#
774		# No prizes for guessing this one.
775		#
776		V_PCAP=linux
777		VALGRINDTEST_SRC=valgrindtest.c
778	elif test "$ac_cv_header_net_pfilt_h" = yes; then
779		#
780		# DEC OSF/1, Digital UNIX, Tru64 UNIX
781		#
782		V_PCAP=pf
783	elif test "$ac_cv_header_net_enet_h" = yes; then
784		#
785		# Stanford Enetfilter.
786		#
787		V_PCAP=enet
788	elif test "$ac_cv_header_net_nit_h" = yes; then
789		#
790		# SunOS 4.x STREAMS NIT.
791		#
792		V_PCAP=snit
793	elif test "$ac_cv_header_sys_net_nit_h" = yes; then
794		#
795		# Pre-SunOS 4.x non-STREAMS NIT.
796		#
797		V_PCAP=nit
798	elif test "$ac_cv_header_net_raw_h" = yes; then
799		#
800		# IRIX snoop.
801		#
802		V_PCAP=snoop
803	elif test "$ac_cv_header_sys_dlpi_h" = yes; then
804		#
805		# DLPI on pre-Solaris 11 SunOS 5, HP-UX, possibly others.
806		#
807		V_PCAP=dlpi
808	elif test "$ac_cv_header_config_HaikuConfig_h" = yes; then
809		#
810		# Haiku.
811		#
812		V_PCAP=haiku
813	else
814		#
815		# We don't have any capture type we know about.
816		# Report an error, and tell the user to configure with
817		# --with-pcap=null if they want a libpcap that can't
818		# capture but that can read capture files.  That way,
819		# nobody gets surprised by getting a no-capture
820		# libpcap without asking for that.
821		#
822		AC_MSG_ERROR([No supported packet capture interface was found.
823 See the INSTALL.md file for information on packet capture support in
824 various operating systems.
825 If you want a libpcap that cannot capture packets but that can read
826 pcap and pcapng files, run configure with --with-pcap=null.])
827	fi
828fi
829AC_MSG_CHECKING(packet capture type)
830AC_MSG_RESULT($V_PCAP)
831AC_SUBST(VALGRINDTEST_SRC)
832
833#
834# Do we have pkg-config?
835#
836PKG_PROG_PKG_CONFIG
837
838#
839# Do we have the brew command from Homebrew?
840#
841AC_PATH_PROG([BREW], [brew])
842
843#
844# Solaris pkg-config is annoying.  For at least one package (D-Bus, I'm
845# looking at *you*!), there are separate include files for 32-bit and
846# 64-bit builds (I guess using "unsigned long long" as a 64-bit integer
847# type on a 64-bit build is like crossing the beams or something), and
848# there are two separate .pc files, so if we're doing a 32-bit build we
849# should make sure we look in /usr/lib/pkgconfig for .pc files and if
850# we're doing a 64-bit build we should make sure we look in
851# /usr/lib/amd64/pkgconfig for .pc files.
852#
853case "$host_os" in
854
855solaris*)
856	if test "$ac_cv_sizeof_void_p" -eq 8; then
857		#
858		# 64-bit build.  If the path is empty, set it to
859                # /usr/lib/amd64/pkgconfig; otherwise, if
860                # /usr/lib/pkgconfig appears in the path, prepend
861		# /usr/lib/amd64/pkgconfig to it; otherwise, put
862		# /usr/lib/amd64/pkgconfig at the end.
863		#
864		if test -z "$PKG_CONFIG_PATH"; then
865			#
866			# Not set, or empty.  Set it to
867			# /usr/lib/amd64/pkgconfig.
868			#
869			PKG_CONFIG_PATH=/usr/lib/amd64/pkgconfig
870		elif test ! -z `echo "$PKG_CONFIG_PATH" | grep "/usr/lib/pkgconfig"`; then
871			#
872			# It contains /usr/lib/pkgconfig.  Prepend
873			# /usr/lib/amd64/pkgconfig to /usr/lib/pkgconfig.
874			#
875			PKG_CONFIG_PATH=`echo "$PKG_CONFIG_PATH" | sed "s;/usr/lib/pkgconfig;/usr/lib/amd64/pkgconfig:/usr/lib/pkgconfig;"`
876		else
877			#
878			# Not empty, but doesn't contain /usr/lib/pkgconfig.
879			# Append /usr/lib/amd64/pkgconfig to it.
880			#
881			PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/lib/amd64/pkgconfig"
882		fi
883		export PKG_CONFIG_PATH
884	elif test "$ac_cv_sizeof_void_p" -eq 4; then
885		#
886		# 32-bit build.  If /usr/amd64/lib/pkgconfig appears
887		# in the path, prepend /usr/lib/pkgconfig to it.
888		#
889		if test ! -z `echo "$PKG_CONFIG_PATH" | grep "/usr/lib/amd64/pkgconfig"`; then
890			#
891			# It contains /usr/lib/amd64/pkgconfig.  Prepend
892			# /usr/lib/pkgconfig to /usr/lib/amd64/pkgconfig.
893			#
894			PKG_CONFIG_PATH=`echo "$PKG_CONFIG_PATH" | sed "s;/usr/lib/amd64/pkgconfig;/usr/lib/pkgconfig:/usr/lib/amd64/pkgconfig;"`
895			export PKG_CONFIG_PATH
896		fi
897	fi
898esac
899
900#
901# Handle each capture type.
902#
903case "$V_PCAP" in
904dlpi)
905	#
906	# Checks for some header files.
907	#
908	AC_CHECK_HEADERS(sys/bufmod.h sys/dlpi_ext.h zone.h)
909
910	#
911	# Checks to see if Solaris has the public libdlpi(3LIB) library.
912	# Note: The existence of /usr/include/libdlpi.h does not mean it is the
913	# public libdlpi(3LIB) version. Before libdlpi was made public, a
914	# private version also existed, which did not have the same APIs.
915	# Due to a gcc bug, the default search path for 32-bit libraries does
916	# not include /lib, we add it explicitly here.
917	# [http://bugs.opensolaris.org/view_bug.do?bug_id=6619485].
918	# Also, due to the bug above applications that link to libpcap with
919	# libdlpi will have to add "-L/lib" option to "configure".
920	#
921	save_LDFLAGS="$LDFLAGS"
922	LDFLAGS="$LIBS -L/lib"
923	AC_CHECK_LIB(dlpi, dlpi_walk,
924		[
925			LIBS="-ldlpi $LIBS"
926			LIBS_STATIC="-ldlpi $LIBS_STATIC"
927			LIBS_PRIVATE="-ldlpi $LIBS_PRIVATE"
928			V_PCAP=libdlpi
929
930			#
931			# Capture module plus common code needed for
932			# common functions used by pcap-[dlpi,libdlpi].c
933			#
934			PLATFORM_C_SRC="pcap-libdlpi.c dlpisubs.c"
935			AC_DEFINE(HAVE_LIBDLPI,1,[if libdlpi exists])
936		],
937		[
938			V_PCAP=dlpi
939
940			#
941			# Capture module plus common code needed for
942			# common functions used by pcap-[dlpi,libdlpi].c
943			#
944			PLATFORM_C_SRC="pcap-dlpi.c dlpisubs.c"
945		])
946	LDFLAGS="$save_LDFLAGS"
947
948	#
949	# Checks whether <sys/dlpi.h> is usable, to catch weird SCO
950	# versions of DLPI.
951	#
952	AC_MSG_CHECKING(whether <sys/dlpi.h> is usable)
953	AC_CACHE_VAL(ac_cv_sys_dlpi_usable,
954		AC_TRY_COMPILE(
955		    [
956			#include <sys/types.h>
957			#include <sys/time.h>
958			#include <sys/dlpi.h>
959		    ],
960		    [int i = DL_PROMISC_PHYS;],
961		    ac_cv_sys_dlpi_usable=yes,
962		    ac_cv_sys_dlpi_usable=no))
963	AC_MSG_RESULT($ac_cv_sys_dlpi_usable)
964	if test $ac_cv_sys_dlpi_usable = no ; then
965		AC_MSG_ERROR(<sys/dlpi.h> is not usable on this system; it probably has a non-standard DLPI)
966	fi
967
968	#
969	# Check to see if Solaris has the dl_passive_req_t struct defined
970	# in <sys/dlpi.h>.
971	# This check is for DLPI support for passive modes.
972	# See dlpi(7P) for more details.
973	#
974	AC_CHECK_TYPES(dl_passive_req_t,,,
975	    [
976		#include <sys/types.h>
977		#include <sys/dlpi.h>
978	    ])
979	;;
980
981enet)
982	#
983	# Capture module
984	#
985	PLATFORM_C_SRC="pcap-enet.c"
986	;;
987
988haiku)
989	#
990	# Capture module
991	#
992	PLATFORM_C_SRC="pcap-haiku.c"
993
994	#
995	# Just for the sake of it.
996	#
997	AC_CHECK_HEADERS(net/if.h net/if_dl.h net/if_types.h)
998	;;
999
1000linux)
1001	#
1002	# Capture module
1003	#
1004	PLATFORM_C_SRC="pcap-linux.c"
1005
1006	#
1007	# Do we have libnl?
1008	# We only want version 3.  Version 2 was, apparently,
1009	# short-lived, and version 1 is source and binary
1010	# incompatible with version 3, and it appears that,
1011	# these days, everybody's using version 3.  We're
1012	# not supporting older versions of the Linux kernel;
1013	# let's drop support for older versions of libnl, too.
1014	#
1015	AC_ARG_WITH(libnl,
1016	AS_HELP_STRING([--without-libnl],[disable libnl support @<:@default=yes, on Linux, if present@:>@]),
1017		with_libnl=$withval,with_libnl=if_available)
1018
1019	if test x$with_libnl != xno ; then
1020		#
1021		# Check for libnl-genl-3.0 with pkg-config.
1022		#
1023		PKG_CHECK_MODULE(LIBNL, libnl-genl-3.0,
1024		    [
1025			pkg_config_found_libnl=yes
1026			V_INCLS="$V_INCLS $LIBNL_CFLAGS"
1027			ADDITIONAL_LIBS="$LIBNL_LIBS $ADDITIONAL_LIBS"
1028			ADDITIONAL_LIBS_STATIC="$LIBNL_LIBS_STATIC $ADDITIONAL_LIBS_STATIC"
1029			REQUIRES_PRIVATE="libnl-genl-3.0 $REQUIRES_PRIVATE"
1030			AC_DEFINE(HAVE_LIBNL,1,[if libnl exists])
1031		    ])
1032
1033		if test x$pkg_config_found_libnl != xyes; then
1034			#
1035			# OK, either we don't have pkg-config or there
1036			# wasn't a .pc file for it; Check for it directly.
1037			#
1038			case "$with_libnl" in
1039
1040			yes|if_available)
1041				incdir=-I/usr/include/libnl3
1042				libnldir=
1043				;;
1044
1045			*)
1046				if test -d $withval; then
1047					libnldir=-L${withval}/lib
1048					incdir=-I${withval}/include
1049				fi
1050				;;
1051			esac
1052
1053			AC_CHECK_LIB(nl-3, nl_socket_alloc,
1054			[
1055				#
1056				# Yes, we have libnl 3.x.
1057				#
1058				ADDITIONAL_LIBS="${libnldir} -lnl-genl-3 -lnl-3 $ADDITIONAL_LIBS"
1059				ADDITIONAL_LIBS_STATIC="${libnldir} -lnl-genl-3 -lnl-3 $ADDITIONAL_LIBS_STATIC"
1060				LIBS_PRIVATE="${libnldir} -lnl-genl-3 -lnl-3 $LIBS_PRIVATE"
1061				AC_DEFINE(HAVE_LIBNL,1,[if libnl exists])
1062				V_INCLS="$V_INCLS ${incdir}"
1063			],[
1064				#
1065				# No, we don't have libnl at all.
1066				# Fail if the user explicitly requested
1067				# it.
1068				#
1069				if test x$with_libnl = xyes ; then
1070					AC_MSG_ERROR([libnl support requested but libnl not found])
1071				fi
1072			], ${incdir} ${libnldir} -lnl-genl-3 -lnl-3 )
1073		fi
1074	fi
1075
1076	#
1077	# Check to see if the tpacket_auxdata struct has a tp_vlan_tci member.
1078	#
1079	# NOTE: any failure means we conclude that it doesn't have that
1080	# member, so if we don't have tpacket_auxdata, we conclude it
1081	# doesn't have that member (which is OK, as either we won't be
1082	# using code that would use that member, or we wouldn't compile
1083	# in any case).
1084	AC_CHECK_MEMBERS([struct tpacket_auxdata.tp_vlan_tci],,,
1085	    [
1086		#include <sys/types.h>
1087		#include <linux/if_packet.h>
1088	    ])
1089	;;
1090
1091bpf)
1092	#
1093	# Capture module
1094	#
1095	PLATFORM_C_SRC="pcap-bpf.c"
1096
1097	#
1098	# Check whether we have the *BSD-style ioctls.
1099	#
1100	AC_CHECK_HEADERS(net/if_media.h)
1101
1102	#
1103	# Check whether we have struct BPF_TIMEVAL.
1104	#
1105	AC_CHECK_TYPES(struct BPF_TIMEVAL,,,
1106	    [
1107		#include <sys/types.h>
1108		#include <sys/ioctl.h>
1109		#ifdef HAVE_SYS_IOCCOM_H
1110		#include <sys/ioccom.h>
1111		#endif
1112		#include <net/bpf.h>
1113	    ])
1114
1115	#
1116	# Check whether there's a net/ipnet.h header and,
1117	# if so, whether it defines IPNET_ANY_LINK - if so,
1118	# we assume we have the "any" device (that's a
1119	# Solaris header, and later versions of Solaris
1120	# have an "any" device).
1121	#
1122	# Attempting to include it at compile time could
1123	# be a pain, as it's a kernel header.
1124	#
1125	AC_MSG_CHECKING(whether the Solaris "any" device is supported)
1126	if test -e /usr/include/inet/ipnet.h &&
1127	    grep -q IPNET_ANY_LINK /usr/include/inet/ipnet.h; then
1128		AC_MSG_RESULT(yes)
1129		AC_DEFINE(HAVE_SOLARIS_ANY_DEVICE, 1, [target host supports Solaris "any" device])
1130	else
1131		AC_MSG_RESULT(no)
1132	fi
1133	;;
1134
1135pf)
1136	#
1137	# Capture module
1138	#
1139	PLATFORM_C_SRC="pcap-pf.c"
1140	;;
1141
1142snit)
1143	#
1144	# Capture module
1145	#
1146	PLATFORM_C_SRC="pcap-snit.c"
1147	;;
1148
1149snoop)
1150	#
1151	# Capture module
1152	#
1153	PLATFORM_C_SRC="pcap-snoop.c"
1154	;;
1155
1156dag)
1157	#
1158	# --with-pcap=dag is the only way to get here, and it means
1159	# "DAG support but nothing else"
1160	#
1161	V_DEFS="$V_DEFS -DDAG_ONLY"
1162	PLATFORM_C_SRC="pcap-dag.c"
1163	xxx_only=yes
1164	;;
1165
1166dpdk)
1167	#
1168	# --with-pcap=dpdk is the only way to get here, and it means
1169	# "DPDK support but nothing else"
1170	#
1171	V_DEFS="$V_DEFS -DDPDK_ONLY"
1172	PLATFORM_C_SRC="pcap-dpdk.c"
1173	xxx_only=yes
1174	;;
1175
1176septel)
1177	#
1178	# --with-pcap=septel is the only way to get here, and it means
1179	# "Septel support but nothing else"
1180	#
1181	V_DEFS="$V_DEFS -DSEPTEL_ONLY"
1182	PLATFORM_C_SRC="pcap-septel.c"
1183	xxx_only=yes
1184	;;
1185
1186snf)
1187	#
1188	# --with-pcap=snf is the only way to get here, and it means
1189	# "SNF support but nothing else"
1190	#
1191	V_DEFS="$V_DEFS -DSNF_ONLY"
1192	PLATFORM_C_SRC="pcap-snf.c"
1193	xxx_only=yes
1194	;;
1195
1196null)
1197	#
1198	# Capture module
1199	#
1200	PLATFORM_C_SRC="pcap-null.c"
1201	;;
1202
1203*)
1204	AC_MSG_ERROR($V_PCAP is not a valid pcap type)
1205	;;
1206esac
1207
1208dnl
1209dnl Now figure out how we get a list of interfaces and addresses,
1210dnl if we support capturing.  Don't bother if we don't support
1211dnl capturing.
1212dnl
1213if test "$V_PCAP" != null
1214then
1215	AC_CHECK_FUNC(getifaddrs,[
1216		#
1217		# We have "getifaddrs()"; make sure we have <ifaddrs.h>
1218		# as well, just in case some platform is really weird.
1219		#
1220		AC_CHECK_HEADER(ifaddrs.h,[
1221		    #
1222		    # We have the header, so we use "getifaddrs()" to
1223		    # get the list of interfaces.
1224		    #
1225		    PLATFORM_C_SRC="$PLATFORM_C_SRC fad-getad.c"
1226		],[
1227		    #
1228		    # We don't have the header - give up.
1229		    # XXX - we could also fall back on some other
1230		    # mechanism, but, for now, this'll catch this
1231		    # problem so that we can at least try to figure
1232		    # out something to do on systems with "getifaddrs()"
1233		    # but without "ifaddrs.h", if there is something
1234		    # we can do on those systems.
1235		    #
1236		    AC_MSG_ERROR([Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.])
1237		])
1238	],[
1239		#
1240		# Well, we don't have "getifaddrs()", at least not with the
1241		# libraries with which we've decided we need to link
1242		# libpcap with, so we have to use some other mechanism.
1243		#
1244		# Note that this may happen on Solaris, which has
1245		# getifaddrs(), but in -lsocket, not in -lxnet, so we
1246		# won't find it if we link with -lxnet, which we want
1247		# to do for other reasons.
1248		#
1249		# For now, we use either the SIOCGIFCONF ioctl or the
1250		# SIOCGLIFCONF ioctl, preferring the latter if we have
1251		# it; the latter is a Solarisism that first appeared
1252		# in Solaris 8.  (Solaris's getifaddrs() appears to
1253		# be built atop SIOCGLIFCONF; using it directly
1254		# avoids a not-all-that-useful middleman.)
1255		#
1256		AC_MSG_CHECKING(whether we have SIOCGLIFCONF)
1257		AC_CACHE_VAL(ac_cv_lbl_have_siocglifconf,
1258		    AC_TRY_COMPILE(
1259			[#include <sys/param.h>
1260			#include <sys/file.h>
1261			#include <sys/ioctl.h>
1262			#include <sys/socket.h>
1263			#include <sys/sockio.h>],
1264			[ioctl(0, SIOCGLIFCONF, (char *)0);],
1265			ac_cv_lbl_have_siocglifconf=yes,
1266			ac_cv_lbl_have_siocglifconf=no))
1267		AC_MSG_RESULT($ac_cv_lbl_have_siocglifconf)
1268		if test $ac_cv_lbl_have_siocglifconf = yes ; then
1269			PLATFORM_C_SRC="$PLATFORM_C_SRC fad-glifc.c"
1270		else
1271			PLATFORM_C_SRC="$PLATFORM_C_SRC fad-gifc.c"
1272		fi
1273	])
1274fi
1275
1276dnl check for hardware timestamp support
1277case "$host_os" in
1278linux*)
1279	AC_CHECK_HEADERS([linux/net_tstamp.h])
1280	;;
1281*)
1282	AC_MSG_NOTICE(no hardware timestamp support implemented for $host_os)
1283	;;
1284esac
1285
1286#
1287# Check for socklen_t.
1288#
1289AC_CHECK_TYPES(socklen_t,,,
1290    [
1291	#include <sys/types.h>
1292	#include <sys/socket.h>
1293    ])
1294
1295AC_ARG_ENABLE(ipv6,
1296AS_HELP_STRING([--enable-ipv6],[build IPv6-capable version @<:@default=yes@:>@]),
1297    [],
1298    [enable_ipv6=yes])
1299if test "$enable_ipv6" != "no"; then
1300	#
1301	# We've already made sure we have getaddrinfo above in
1302	# AC_LBL_LIBRARY_NET.
1303	#
1304	AC_DEFINE(INET6,1,[IPv6])
1305fi
1306
1307# Check for Endace DAG card support.
1308AC_ARG_WITH([dag],
1309AS_HELP_STRING([--with-dag@<:@=DIR@:>@],[include Endace DAG support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1310[
1311	if test "$withval" = no
1312	then
1313		# User doesn't want DAG support.
1314		want_dag=no
1315	elif test "$withval" = yes
1316	then
1317		# User wants DAG support but hasn't specified a directory.
1318		want_dag=yes
1319	else
1320		# User wants DAG support and has specified a directory, so use the provided value.
1321		want_dag=yes
1322		dag_root=$withval
1323	fi
1324],[
1325	if test "$V_PCAP" = dag; then
1326		# User requested DAG-only libpcap, so we'd better have
1327		# the DAG API.
1328		want_dag=yes
1329	elif test "xxx_only" = yes; then
1330		# User requested something-else-only pcap, so they don't
1331		# want DAG support.
1332		want_dag=no
1333	else
1334		#
1335		# Use DAG API if present, otherwise don't
1336		#
1337		want_dag=ifpresent
1338	fi
1339])
1340
1341AC_ARG_WITH([dag-includes],
1342AS_HELP_STRING([--with-dag-includes=IDIR],[Endace DAG include directory, if not DIR/include]),
1343[
1344	# User wants DAG support and has specified a header directory, so use the provided value.
1345	want_dag=yes
1346	dag_include_dir=$withval
1347],[])
1348
1349AC_ARG_WITH([dag-libraries],
1350AS_HELP_STRING([--with-dag-libraries=LDIR],[Endace DAG library directory, if not DIR/lib]),
1351[
1352	# User wants DAG support and has specified a library directory, so use the provided value.
1353	want_dag=yes
1354	dag_lib_dir=$withval
1355],[])
1356
1357if test "$want_dag" != no; then
1358
1359	# If necessary, set default paths for DAG API headers and libraries.
1360	if test -z "$dag_root"; then
1361		dag_root=/usr/local
1362	fi
1363
1364	if test -z "$dag_include_dir"; then
1365		dag_include_dir="$dag_root/include"
1366	fi
1367
1368	if test -z "$dag_lib_dir"; then
1369		dag_lib_dir="$dag_root/lib"
1370		#
1371		# Handle multiarch systems.
1372		#
1373		if test -d "$dag_lib_dir/$host"
1374		then
1375			dag_lib_dir="$dag_lib_dir/$host"
1376		fi
1377	fi
1378
1379	AC_LBL_SAVE_CHECK_STATE
1380	CFLAGS="$CFLAGS -I$dag_include_dir"
1381	AC_CHECK_HEADERS([dagapi.h])
1382	AC_LBL_RESTORE_CHECK_STATE
1383
1384	if test "$ac_cv_header_dagapi_h" = yes; then
1385
1386		V_INCLS="$V_INCLS -I$dag_include_dir"
1387
1388		if test $V_PCAP != dag ; then
1389			 MODULE_C_SRC="$MODULE_C_SRC pcap-dag.c"
1390		fi
1391
1392		# Check for various DAG API functions.
1393		# Don't need to save and restore LIBS to prevent -ldag being
1394		# included if there's a found-action (arg 3).
1395		AC_LBL_SAVE_CHECK_STATE
1396		LDFLAGS="-L$dag_lib_dir"
1397		AC_CHECK_LIB([dag], [dag_attach_stream],
1398		    [
1399			#
1400			# We assume that if we have libdag we have
1401			# libdagconf, as they're installed at the
1402			# same time from the same package.
1403			#
1404			ADDITIONAL_LIBS="-L$dag_lib_dir $ADDITIONAL_LIBS -ldag -ldagconf"
1405			ADDITIONAL_LIBS_STATIC="-L$dag_lib_dir $ADDITIONAL_LIBS_STATIC -ldag -ldagconf"
1406			LIBS_PRIVATE="-L$dag_lib_dir $LIBS_PRIVATE -ldag -ldagconf"
1407		    ],
1408		    [AC_MSG_ERROR(DAG library lacks streams support)])
1409		AC_CHECK_LIB([dag], [dag_attach_stream64], [dag_large_streams="1"], [dag_large_streams="0"])
1410		AC_CHECK_LIB([dag],[dag_get_erf_types], [
1411			AC_DEFINE(HAVE_DAG_GET_ERF_TYPES, 1, [define if you have dag_get_erf_types()])])
1412		AC_CHECK_LIB([dag],[dag_get_stream_erf_types], [
1413			AC_DEFINE(HAVE_DAG_GET_STREAM_ERF_TYPES, 1, [define if you have dag_get_stream_erf_types()])])
1414		AC_LBL_RESTORE_CHECK_STATE
1415
1416		#
1417		# We assume that if we have libdag we have libdagconf,
1418		# as they're installed at the same time from the same
1419		# package.
1420		#
1421		if test "$dag_large_streams" = 1; then
1422			AC_DEFINE(HAVE_DAG_LARGE_STREAMS_API, 1, [define if you have large streams capable DAG API])
1423			AC_LBL_SAVE_CHECK_STATE
1424			LIBS="$LIBS -ldag -ldagconf"
1425			LDFLAGS="$LDFLAGS -L$dag_lib_dir"
1426			AC_CHECK_LIB([vdag],[vdag_set_device_info], [ac_dag_have_vdag="1"], [ac_dag_have_vdag="0"])
1427			AC_LBL_RESTORE_CHECK_STATE
1428			if test "$ac_dag_have_vdag" = 1; then
1429				AC_DEFINE(HAVE_DAG_VDAG, 1, [define if you have vdag_set_device_info()])
1430				if test "$ac_lbl_have_pthreads" != "found"; then
1431					AC_MSG_ERROR([DAG requires pthreads, but we didn't find them])
1432				fi
1433				ADDITIONAL_LIBS="$ADDITIONAL_LIBS $PTHREAD_LIBS"
1434				ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $PTHREAD_LIBS"
1435				LIBS_PRIVATE="$LIBS_PRIVATE $PTHREAD_LIBS"
1436			fi
1437		fi
1438
1439		AC_DEFINE(HAVE_DAG_API, 1, [define if you have the DAG API])
1440	else
1441		if test "$V_PCAP" = dag; then
1442			# User requested "dag" capture type but we couldn't
1443			# find the DAG API support.
1444			AC_MSG_ERROR([DAG support requested with --with-pcap=dag, but the DAG headers weren't found at $dag_include_dir: make sure the DAG support is installed, specify a different path or paths if necessary, or don't request DAG support])
1445		fi
1446
1447		if test "$want_dag" = yes; then
1448			# User wanted DAG support but we couldn't find it.
1449			AC_MSG_ERROR([DAG support requested with --with-dag, but the DAG headers weren't found at $dag_include_dir: make sure the DAG support is installed, specify a different path or paths if necessary, or don't request DAG support])
1450		fi
1451	fi
1452	CFLAGS="$save_CFLAGS"
1453fi
1454
1455AC_ARG_WITH(septel,
1456AS_HELP_STRING([--with-septel@<:@=DIR@:>@],[include Septel support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1457[
1458	if test "$withval" = no
1459	then
1460		want_septel=no
1461	elif test "$withval" = yes
1462	then
1463		want_septel=yes
1464		septel_root=
1465	else
1466		want_septel=yes
1467		septel_root=$withval
1468	fi
1469],[
1470	if test "$V_PCAP" = septel; then
1471		# User requested Septel-only libpcap, so we'd better have
1472		# the Septel API.
1473		want_septel=yes
1474	elif test "xxx_only" = yes; then
1475		# User requested something-else-only pcap, so they don't
1476		# want Septel support.
1477		want_septel=no
1478	else
1479		#
1480		# Use Septel API if present, otherwise don't
1481		#
1482		want_septel=ifpresent
1483	fi
1484])
1485
1486ac_cv_lbl_septel_api=no
1487if test "$with_septel" != no; then
1488
1489	AC_MSG_CHECKING([whether we have Septel API headers])
1490
1491	# If necessary, set default paths for Septel API headers and libraries.
1492	if test -z "$septel_root"; then
1493		septel_root=$srcdir/../septel
1494	fi
1495
1496	septel_tools_dir="$septel_root"
1497	septel_include_dir="$septel_root/INC"
1498
1499	if test -r "$septel_include_dir/msg.h"; then
1500		ac_cv_lbl_septel_api=yes
1501	fi
1502
1503	if test "$ac_cv_lbl_septel_api" = yes; then
1504		AC_MSG_RESULT([yes ($septel_include_dir)])
1505
1506		V_INCLS="$V_INCLS -I$septel_include_dir"
1507		ADDLOBJS="$ADDLOBJS $septel_tools_dir/asciibin.o $septel_tools_dir/bit2byte.o $septel_tools_dir/confirm.o $septel_tools_dir/fmtmsg.o $septel_tools_dir/gct_unix.o $septel_tools_dir/hqueue.o $septel_tools_dir/ident.o $septel_tools_dir/mem.o $septel_tools_dir/pack.o $septel_tools_dir/parse.o $septel_tools_dir/pool.o $septel_tools_dir/sdlsig.o $septel_tools_dir/strtonum.o $septel_tools_dir/timer.o $septel_tools_dir/trace.o"
1508		ADDLARCHIVEOBJS="$ADDLARCHIVEOBJS $septel_tools_dir/asciibin.o $septel_tools_dir/bit2byte.o $septel_tools_dir/confirm.o $septel_tools_dir/fmtmsg.o $septel_tools_dir/gct_unix.o $septel_tools_dir/hqueue.o $septel_tools_dir/ident.o $septel_tools_dir/mem.o $septel_tools_dir/pack.o $septel_tools_dir/parse.o $septel_tools_dir/pool.o $septel_tools_dir/sdlsig.o $septel_tools_dir/strtonum.o $septel_tools_dir/timer.o $septel_tools_dir/trace.o"
1509
1510		if test "$V_PCAP" != septel ; then
1511			 MODULE_C_SRC="$MODULE_C_SRC pcap-septel.c"
1512		fi
1513
1514		AC_DEFINE(HAVE_SEPTEL_API, 1, [define if you have the Septel API])
1515	else
1516		AC_MSG_RESULT(no)
1517
1518		if test "$V_PCAP" = septel; then
1519			# User requested "septel" capture type but
1520			# we couldn't find the Septel API support.
1521			AC_MSG_ERROR([Septel support requested with --with-pcap=septel, but the Septel headers weren't found at $septel_include_dir: make sure the Septel support is installed, specify a different path or paths if necessary, or don't request Septel support])
1522		fi
1523
1524		if test "$want_septel" = yes; then
1525			# User wanted Septel support but we couldn't find it.
1526			AC_MSG_ERROR([Septel support requested with --with-septel, but the Septel headers weren't found at $septel_include_dir: make sure the Septel support is installed, specify a different path or paths if necessary, or don't request Septel support])
1527		fi
1528	fi
1529fi
1530
1531# Check for Myricom SNF support.
1532AC_ARG_WITH([snf],
1533AS_HELP_STRING([--with-snf@<:@=DIR@:>@],[include Myricom SNF support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1534[
1535	if test "$withval" = no
1536	then
1537		# User explicitly doesn't want SNF
1538		want_snf=no
1539	elif test "$withval" = yes
1540	then
1541		# User wants SNF support but hasn't specified a directory.
1542		want_snf=yes
1543	else
1544		# User wants SNF support with a specified directory.
1545		want_snf=yes
1546		snf_root=$withval
1547	fi
1548],[
1549	if test "$V_PCAP" = snf; then
1550		# User requested Sniffer-only libpcap, so we'd better have
1551		# the Sniffer API.
1552		want_snf=yes
1553	elif test "xxx_only" = yes; then
1554		# User requested something-else-only pcap, so they don't
1555		# want SNF support.
1556		want_snf=no
1557	else
1558		#
1559		# Use Sniffer API if present, otherwise don't
1560		#
1561		want_snf=ifpresent
1562	fi
1563])
1564
1565AC_ARG_WITH([snf-includes],
1566AS_HELP_STRING([--with-snf-includes=IDIR],[Myricom SNF include directory, if not DIR/include]),
1567[
1568	# User wants SNF with specific header directory
1569	want_snf=yes
1570	snf_include_dir=$withval
1571],[])
1572
1573AC_ARG_WITH([snf-libraries],
1574AS_HELP_STRING([--with-snf-libraries=LDIR],[Myricom SNF library directory, if not DIR/lib]),
1575[
1576	# User wants SNF with specific lib directory
1577	want_snf=yes
1578	snf_lib_dir=$withval
1579],[])
1580
1581ac_cv_lbl_snf_api=no
1582if test "$with_snf" != no; then
1583
1584	AC_MSG_CHECKING(whether we have Myricom Sniffer API)
1585
1586	# If necessary, set default paths for Sniffer headers and libraries.
1587	if test -z "$snf_root"; then
1588		snf_root=/opt/snf
1589	fi
1590
1591	if test -z "$snf_include_dir"; then
1592		snf_include_dir="$snf_root/include"
1593	fi
1594
1595	if test -z "$snf_lib_dir"; then
1596		snf_lib_dir="$snf_root/lib"
1597		#
1598		# Handle multiarch systems.
1599		#
1600		if test -d "$snf_lib_dir/$host"
1601		then
1602			snf_lib_dir="$snf_lib_dir/$host"
1603		fi
1604	fi
1605
1606	if test -f "$snf_include_dir/snf.h"; then
1607		# We found a header; make sure we can link with the library
1608		AC_LBL_SAVE_CHECK_STATE
1609		LDFLAGS="$LDFLAGS -L$snf_lib_dir"
1610		AC_CHECK_LIB([snf], [snf_init], [ac_cv_lbl_snf_api="yes"])
1611		AC_LBL_RESTORE_CHECK_STATE
1612		if test "$ac_cv_lbl_snf_api" = no; then
1613			AC_MSG_ERROR(SNF API cannot correctly be linked; check config.log)
1614		fi
1615	fi
1616
1617	if test "$ac_cv_lbl_snf_api" = yes; then
1618		AC_MSG_RESULT([yes ($snf_root)])
1619
1620		V_INCLS="$V_INCLS -I$snf_include_dir"
1621		ADDITIONAL_LIBS="$ADDITIONAL_LIBS -L$snf_lib_dir -lsnf"
1622		ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC -L$snf_lib_dir -lsnf"
1623		LIBS_PRIVATE="$LIBS_PRIVATE -L$snf_lib_dir -lsnf"
1624
1625		if test "$V_PCAP" != snf ; then
1626			MODULE_C_SRC="$MODULE_C_SRC pcap-snf.c"
1627		fi
1628
1629		AC_DEFINE(HAVE_SNF_API, 1, [define if you have the Myricom SNF API])
1630	else
1631		AC_MSG_RESULT(no)
1632
1633		if test "$want_snf" = yes; then
1634			# User requested "snf" capture type but
1635			# we couldn't find the Sniffer API support.
1636			AC_MSG_ERROR([Myricom Sniffer support requested with --with-pcap=snf, but the Sniffer headers weren't found at $snf_include_dir: make sure the Sniffer support is installed, specify a different path or paths if necessary, or don't request Sniffer support])
1637		fi
1638
1639		if test "$want_snf" = yes; then
1640			AC_MSG_ERROR([Myricom Sniffer support requested with --with-snf, but the Sniffer headers weren't found at $snf_include_dir: make sure the Sniffer support is installed, specify a different path or paths if necessary, or don't request Sniffer support])
1641		fi
1642	fi
1643fi
1644
1645# Check for Riverbed TurboCap support.
1646AC_ARG_WITH([turbocap],
1647AS_HELP_STRING([--with-turbocap@<:@=DIR@:>@],[include Riverbed TurboCap support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1648[
1649	if test "$withval" = no
1650	then
1651		# User explicitly doesn't want TurboCap
1652		want_turbocap=no
1653	elif test "$withval" = yes
1654	then
1655		# User wants TurboCap support but hasn't specified a directory.
1656		want_turbocap=yes
1657	else
1658		# User wants TurboCap support with a specified directory.
1659		want_turbocap=yes
1660		turbocap_root=$withval
1661	fi
1662],[
1663	if test "xxx_only" = yes; then
1664		# User requested something-else-only pcap, so they don't
1665		# want TurboCap support.
1666		want_turbocap=no
1667	else
1668		#
1669		# Use TurboCap API if present, otherwise don't
1670		#
1671		want_turbocap=ifpresent
1672	fi
1673])
1674
1675ac_cv_lbl_turbocap_api=no
1676if test "$want_turbocap" != no; then
1677
1678	AC_MSG_CHECKING(whether TurboCap is supported)
1679
1680	AC_LBL_SAVE_CHECK_STATE
1681	if test ! -z "$turbocap_root"; then
1682		TURBOCAP_CFLAGS="-I$turbocap_root/include"
1683		TURBOCAP_LDFLAGS="-L$turbocap_root/lib"
1684		CFLAGS="$CFLAGS $TURBOCAP_CFLAGS"
1685		LDFLAGS="$LDFLAGS $TURBOCAP_LDFLAGS"
1686	fi
1687
1688	AC_TRY_COMPILE(
1689	[
1690	    #include <TcApi.h>
1691	],
1692	[
1693	    TC_INSTANCE a; TC_PORT b; TC_BOARD c;
1694	    TC_INSTANCE i;
1695	    (void)TcInstanceCreateByName("foo", &i);
1696	],
1697	ac_cv_lbl_turbocap_api=yes)
1698
1699	AC_LBL_RESTORE_CHECK_STATE
1700	if test $ac_cv_lbl_turbocap_api = yes; then
1701		AC_MSG_RESULT(yes)
1702
1703		MODULE_C_SRC="$MODULE_C_SRC pcap-tc.c"
1704		V_INCLS="$V_INCLS $TURBOCAP_CFLAGS"
1705		ADDITIONAL_LIBS="$ADDITIONAL_LIBS $TURBOCAP_LDFLAGS -lTcApi -lpthread -lstdc++"
1706		ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $TURBOCAP_LDFLAGS -lTcApi -lpthread -lstdc++"
1707		LIBS_PRIVATE="$LIBS_PRIVATE $TURBOCAP_LDFLAGS -lTcApi -lpthread -lstdc++"
1708
1709		AC_DEFINE(HAVE_TC_API, 1, [define if you have the TurboCap API])
1710	else
1711		AC_MSG_RESULT(no)
1712
1713		if test "$want_turbocap" = yes; then
1714			# User wanted Turbo support but we couldn't find it.
1715			AC_MSG_ERROR([TurboCap support requested with --with-turbocap, but the TurboCap headers weren't found: make sure the TurboCap support is installed or don't request TurboCap support])
1716		fi
1717	fi
1718fi
1719
1720dnl
1721dnl Allow the user to enable remote capture.
1722dnl It's off by default, as that increases the attack surface of
1723dnl libpcap, exposing it to malicious servers.
1724dnl
1725AC_MSG_CHECKING([whether to enable remote packet capture])
1726AC_ARG_ENABLE([remote],
1727   [AS_HELP_STRING([--enable-remote],
1728     [enable remote packet capture @<:@default=no@:>@])],
1729   [],
1730   [enableval=no])
1731case "$enableval" in
1732yes)	AC_MSG_RESULT(yes)
1733	AC_WARN([Remote packet capture may expose libpcap-based applications])
1734	AC_WARN([to attacks by malicious remote capture servers!])
1735	#
1736	# rpcapd requires pthreads on UN*X.
1737	#
1738	if test "$ac_lbl_have_pthreads" != "found"; then
1739		AC_MSG_ERROR([rpcapd requires pthreads, but we didn't find them])
1740	fi
1741	#
1742	# It also requires crypt().
1743	# Do we have it in the system libraries?
1744	#
1745	AC_CHECK_FUNC(crypt,,
1746	    [
1747		#
1748		# No.  Do we have it in -lcrypt?
1749		#
1750		AC_CHECK_LIB(crypt, crypt,
1751		    [
1752			#
1753			# Yes; add -lcrypt to the libraries for rpcapd.
1754			#
1755			RPCAPD_LIBS="$RPCAPD_LIBS -lcrypt"
1756		    ],
1757		    [
1758			AC_MSG_ERROR([rpcapd requires crypt(), but we didn't find it])
1759		    ])
1760	    ])
1761
1762	#
1763	# OK, we have crypt().  Do we have getspnam()?
1764	#
1765	AC_CHECK_FUNCS(getspnam)
1766
1767	#
1768	# Check for various members of struct msghdr.
1769	#
1770	AC_CHECK_MEMBERS([struct msghdr.msg_control],,,
1771	    [
1772		#include "ftmacros.h"
1773		#include <sys/socket.h>
1774	    ])
1775	AC_CHECK_MEMBERS([struct msghdr.msg_flags],,,
1776	    [
1777		#include "ftmacros.h"
1778		#include <sys/socket.h>
1779	    ])
1780
1781	#
1782	# Optionally, we may want to support SSL.
1783	# Check for OpenSSL/libressl.
1784	#
1785	# First, try looking for it with pkg-config, if we have it.
1786	#
1787	# Homebrew's pkg-config does not, by default, look for
1788	# pkg-config files for packages it has installed.
1789	# Furthermore, at least for OpenSSL, they appear to be
1790	# dumped in package-specific directories whose paths are
1791	# not only package-specific but package-version-specific.
1792	#
1793	# So the only way to find openssl is to get the value of
1794	# PKG_CONFIG_PATH from "brew --env openssl" and add that
1795	# to PKG_CONFIG_PATH.  (No, we can't just assume it's under
1796	# /usr/local; Homebrew have conveniently chosen to put it
1797	# under /opt/homebrew on ARM.)
1798	#
1799	# That's the nice thing about Homebrew - it makes things easier!
1800	# Thanks!
1801	#
1802	save_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
1803	if test -n "$BREW"; then
1804		openssl_pkgconfig_dir=`$BREW --env --plain openssl | sed -n 's/PKG_CONFIG_PATH: //p'`
1805		PKG_CONFIG_PATH="$openssl_pkgconfig_dir:$PKG_CONFIG_PATH"
1806	fi
1807	PKG_CHECK_MODULE(OPENSSL, openssl,
1808	    [
1809		#
1810		# We found OpenSSL/libressl.
1811		#
1812		HAVE_OPENSSL=yes
1813		REQUIRES_PRIVATE="$REQUIRES_PRIVATE openssl"
1814	    ])
1815	PKG_CONFIG_PATH="$save_PKG_CONFIG_PATH"
1816
1817	#
1818	# If it wasn't found, and we have Homebrew installed, see
1819	# if it's in Homebrew.
1820	#
1821	if test "x$HAVE_OPENSSL" != "xyes" -a -n "$BREW"; then
1822		AC_MSG_CHECKING(for openssl in Homebrew)
1823		#
1824		# The brew man page lies when it speaks of
1825		# $BREW --prefix --installed <formula>
1826		# outputting nothing.  In Homebrew 3.3.16,
1827		# it produces output regardless of whether
1828		# the formula is installed or not, so we
1829		# send the standard output and error to
1830		# the bit bucket.
1831		#
1832		if $BREW --prefix --installed openssl >/dev/null 2>&1; then
1833			#
1834			# Yes.  Get the include directory and library
1835			# directory.  (No, we can't just assume it's
1836			# under /usr/local; Homebrew have conveniently
1837			# chosen to put it under /opt/homebrew on ARM.)
1838			#
1839			AC_MSG_RESULT(yes)
1840			HAVE_OPENSSL=yes
1841			openssl_path=`$BREW --prefix openssl`
1842			OPENSSL_CFLAGS="-I$openssl_path/include"
1843			OPENSSL_LIBS="-L$openssl_path/lib -lssl -lcrypto"
1844			OPENSSL_LIBS_STATIC="-L$openssl_path/lib -lssl -lcrypto"
1845			OPENSSL_LIBS_PRIVATE="-L$openssl_path/lib -lssl -lcrypto"
1846		else
1847			AC_MSG_RESULT(no)
1848		fi
1849	fi
1850
1851	#
1852	# If it wasn't found, and /usr/local/include and /usr/local/lib
1853	# exist, check if it's in /usr/local.  (We check whether they
1854	# exist because, if they don't exist, the compiler will warn
1855	# about that and then ignore the argument, so they test
1856	# using just the system header files and libraries.)
1857	#
1858	# We include the standard include file to 1) make sure that
1859	# it's installed (if it's just a shared library for the
1860	# benefit of existing programs, that's not useful) and 2)
1861	# because SSL_library_init() is a library routine in some
1862	# versions and a #defined wrapper around OPENSSL_init_ssl()
1863	# in others.
1864	#
1865	if test "x$HAVE_OPENSSL" != "xyes" -a -d "/usr/local/include" -a -d "/usr/local/lib"; then
1866		AC_LBL_SAVE_CHECK_STATE
1867		CFLAGS="$CFLAGS -I/usr/local/include"
1868		LIBS="$LIBS -L/usr/local/lib -lssl -lcrypto"
1869		AC_MSG_CHECKING(whether we have OpenSSL/libressl in /usr/local that we can use)
1870		AC_TRY_LINK(
1871		    [
1872#include <openssl/ssl.h>
1873		    ],
1874		    [
1875SSL_library_init();
1876return 0;
1877		    ],
1878		    [
1879			AC_MSG_RESULT(yes)
1880			HAVE_OPENSSL=yes
1881			OPENSSL_CFLAGS="-I/usr/local/include"
1882			OPENSSL_LIBS="-L/usr/local/lib -lssl -lcrypto"
1883			OPENSSL_LIBS_STATIC="-L/usr/local/lib -lssl -lcrypto"
1884			OPENSSL_LIBS_PRIVATE="-L/usr/local/lib -lssl -lcrypto"
1885		    ],
1886		    AC_MSG_RESULT(no))
1887		AC_LBL_RESTORE_CHECK_STATE
1888	fi
1889
1890	#
1891	# If it wasn't found, check if it's a system library.
1892	#
1893	# We include the standard include file to 1) make sure that
1894	# it's installed (if it's just a shared library for the
1895	# benefit of existing programs, that's not useful) and 2)
1896	# because SSL_library_init() is a library routine in some
1897	# versions and a #defined wrapper around OPENSSL_init_ssl()
1898	# in others.
1899	#
1900	if test "x$HAVE_OPENSSL" != "xyes"; then
1901		AC_LBL_SAVE_CHECK_STATE
1902		LIBS="$LIBS -lssl -lcrypto"
1903		AC_MSG_CHECKING(whether we have a system OpenSSL/libressl that we can use)
1904		AC_TRY_LINK(
1905		    [
1906#include <openssl/ssl.h>
1907		    ],
1908		    [
1909SSL_library_init();
1910return 0;
1911		    ],
1912		    [
1913			AC_MSG_RESULT(yes)
1914			HAVE_OPENSSL=yes
1915			OPENSSL_LIBS="-lssl -lcrypto"
1916			OPENSSL_LIBS_STATIC="-lssl -lcrypto"
1917			OPENSSL_LIBS_PRIVATE="-lssl -lcrypto"
1918		    ],
1919		    AC_MSG_RESULT(no))
1920		AC_LBL_RESTORE_CHECK_STATE
1921	fi
1922
1923	#
1924	# OK, did we find it?
1925	#
1926	if test "x$HAVE_OPENSSL" = "xyes"; then
1927		AC_DEFINE([HAVE_OPENSSL], [1], [Use OpenSSL])
1928		V_INCLS="$V_INCLS $OPENSSL_CFLAGS"
1929		ADDITIONAL_LIBS="$ADDITIONAL_LIBS $OPENSSL_LIBS"
1930		ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $OPENSSL_LIBS_STATIC"
1931		LIBS_PRIVATE="$LIBS_PRIVATE $OPENSSL_LIBS_PRIVATE"
1932		REQUIRES_PRIVATE="$REQUIRES_PRIVATE $OPENSSL_REQUIRES_PRIVATE"
1933		REMOTE_C_SRC="$REMOTE_C_SRC sslutils.c"
1934	else
1935		AC_MSG_NOTICE(OpenSSL not found)
1936	fi
1937
1938	AC_DEFINE(ENABLE_REMOTE,,
1939	    [Define to 1 if remote packet capture is to be supported])
1940	REMOTE_C_SRC="$REMOTE_C_SRC pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c"
1941	BUILD_RPCAPD=build-rpcapd
1942	INSTALL_RPCAPD=install-rpcapd
1943	;;
1944*)	AC_MSG_RESULT(no)
1945	;;
1946esac
1947
1948AC_MSG_CHECKING(whether to build optimizer debugging code)
1949AC_ARG_ENABLE(optimizer-dbg,
1950AS_HELP_STRING([--enable-optimizer-dbg],[build optimizer debugging code]))
1951if test "$enable_optimizer_dbg" = "yes"; then
1952	AC_DEFINE(BDEBUG,1,[Enable optimizer debugging])
1953fi
1954AC_MSG_RESULT(${enable_optimizer_dbg-no})
1955
1956AC_MSG_CHECKING(whether to build parser debugging code)
1957AC_ARG_ENABLE(yydebug,
1958AS_HELP_STRING([--enable-yydebug],[build parser debugging code]))
1959if test "$enable_yydebug" = "yes"; then
1960	AC_DEFINE(YYDEBUG,1,[Enable parser debugging])
1961fi
1962AC_MSG_RESULT(${enable_yydebug-no})
1963
1964#
1965# Look for {f}lex.
1966#
1967AC_PROG_LEX
1968if test "$LEX" = ":"; then
1969	AC_MSG_ERROR([Neither flex nor lex was found.])
1970fi
1971
1972#
1973# Make sure {f}lex supports the -P, --header-file, and --nounput flags
1974# and supports processing our scanner.l.
1975#
1976AC_CACHE_CHECK([for capable lex], tcpdump_cv_capable_lex,
1977	if $LEX -P pcap_ --header-file=/dev/null --nounput -t $srcdir/scanner.l > /dev/null 2>&1; then
1978	    tcpdump_cv_capable_lex=yes
1979	else
1980	    tcpdump_cv_capable_lex=insufficient
1981	fi)
1982if test $tcpdump_cv_capable_lex = insufficient ; then
1983	AC_MSG_ERROR([$LEX is insufficient to compile libpcap.
1984 libpcap requires Flex 2.5.31 or later, or a compatible version of lex.
1985 If a suitable version of Lex/Flex is available as a non-standard command
1986 and/or not in the PATH, you can specify it using the LEX environment
1987 variable. That said, on some systems the error can mean that Flex/Lex is
1988 actually acceptable, but m4 is not. Likewise, if a suitable version of
1989 m4 (such as GNU M4) is available but has not been detected, you can
1990 specify it using the M4 environment variable.])
1991fi
1992
1993#
1994# Look for yacc/bison/byacc.
1995# If it's Bison, we do not want -y, as 1) we will be using -o to cause
1996# the output for XXX.y to be written to XXX.c and 2) we don't want
1997# it to issue warnings about stuff not supported by POSIX YACC - we
1998# want to use that stuff, and don't care whether plain YACC supports
1999# it or not, we require either Bison or Berkeley YACC.
2000#
2001BISON_BYACC=""
2002#
2003# Look for Bison.
2004#
2005AC_CHECK_PROGS(BISON_BYACC, bison)
2006if test x"$BISON_BYACC" != x; then
2007	#
2008	# We found Bison.
2009	#
2010	# Bison prior to 2.4(.1) doesn't support "%define api.pure", so use
2011	# "%pure-parser".
2012	#
2013	bison_major_version=`$BISON_BYACC -V | sed -n 's/.* \(@<:@1-9@:>@@<:@0-9@:>@*\)\.@<:@0-9@:>@@<:@0-9.@:>@*/\1/p'`
2014	bison_minor_version=`$BISON_BYACC -V | sed -n 's/.* @<:@1-9@:>@@<:@0-9@:>@*\.\(@<:@0-9@:>@+\).*/\1/p'`
2015	if test "$bison_major_version" -lt 2 -o \
2016	    \( "$bison_major_version" -eq 2 -a "$bison_major_version" -lt 4 \)
2017	then
2018		REENTRANT_PARSER="%pure-parser"
2019	else
2020		REENTRANT_PARSER="%define api.pure"
2021	fi
2022else
2023	#
2024	# We didn't find Bison; check for Berkeley YACC, under the
2025	# names byacc and yacc.
2026	#
2027	AC_CHECK_PROGS(BISON_BYACC, byacc yacc)
2028	if test x"$BISON_BYACC" != x; then
2029		#
2030		# Make sure this is Berkeley YACC, not AT&T YACC;
2031		# the latter doesn't support reentrant parsers.
2032		# Run it with "-V"; that succeeds and reports the
2033		# version number with Berkeley YACC, but will
2034		# (probably) fail with various vendor flavors
2035		# of AT&T YACC.
2036		#
2037		# Hopefully this also eliminates any versions
2038		# of Berkeley YACC that don't support reentrant
2039		# parsers, if there are any.
2040		#
2041		AC_CACHE_CHECK([for capable yacc], tcpdump_cv_capable_yacc,
2042		    if $BISON_BYACC -V >/dev/null 2>&1; then
2043			tcpdump_cv_capable_yacc=yes
2044		    else
2045			tcpdump_cv_capable_yacc=insufficient
2046		    fi)
2047		if test $tcpdump_cv_capable_yacc = insufficient ; then
2048		    AC_MSG_ERROR([$BISON_BYACC is insufficient to compile libpcap.
2049 libpcap requires Bison, a newer version of Berkeley YACC with support
2050 for reentrant parsers, or another YACC compatible with them.])
2051		fi
2052	else
2053		#
2054		# OK, we found neither byacc nor yacc.
2055		#
2056		AC_MSG_ERROR([Neither bison, byacc, nor yacc was found.
2057 libpcap requires Bison, a newer version of Berkeley YACC with support
2058 for reentrant parsers, or another YACC compatible with them.])
2059	fi
2060
2061	#
2062	# Berkeley YACC doesn't support "%define api.pure", so use
2063	# "%pure-parser".
2064	#
2065	REENTRANT_PARSER="%pure-parser"
2066fi
2067AC_SUBST(BISON_BYACC)
2068AC_SUBST(REENTRANT_PARSER)
2069
2070#
2071# Do various checks for various OSes and versions of those OSes.
2072#
2073# Assume, by default, no support for shared libraries and V7/BSD
2074# convention for man pages (devices in section 4, file formats in
2075# section 5, miscellaneous info in section 7, administrative commands
2076# and daemons in section 8).  Individual cases can override this.
2077#
2078DYEXT="none"
2079MAN_DEVICES=4
2080MAN_FILE_FORMATS=5
2081MAN_MISC_INFO=7
2082MAN_ADMIN_COMMANDS=8
2083case "$host_os" in
2084
2085aix*)
2086	dnl Workaround to enable certain features
2087	AC_DEFINE(_SUN,1,[define on AIX to get certain functions])
2088
2089	#
2090	# AIX makes it fun to build shared and static libraries,
2091	# because they're *both* ".a" archive libraries.  We
2092	# build the static library for the benefit of the traditional
2093	# scheme of building libpcap and tcpdump in subdirectories of
2094	# the same directory, with tcpdump statically linked with the
2095	# libpcap in question, but we also build a shared library as
2096	# "libpcap.shareda" and install *it*, rather than the static
2097	# library, as "libpcap.a".
2098	#
2099	DYEXT="shareda"
2100
2101	case "$V_PCAP" in
2102
2103	dlpi)
2104		#
2105		# If we're using DLPI, applications will need to
2106		# use /lib/pse.exp if present, as we use the
2107		# STREAMS routines.
2108		#
2109		pseexe="/lib/pse.exp"
2110		AC_MSG_CHECKING(for $pseexe)
2111		if test -f $pseexe ; then
2112			AC_MSG_RESULT(yes)
2113			LIBS="-I:$pseexe"
2114		fi
2115		;;
2116
2117	bpf)
2118		#
2119		# If we're using BPF, we need "-lodm" and "-lcfg", as
2120		# we use them to load the BPF module.
2121		#
2122		LIBS="-lodm -lcfg"
2123		;;
2124	esac
2125	;;
2126
2127darwin*)
2128	DYEXT="dylib"
2129	V_CCOPT="$V_CCOPT -fno-common"
2130	AC_ARG_ENABLE(universal,
2131	AS_HELP_STRING([--disable-universal],[don't build universal on macOS]))
2132	if test "$enable_universal" != "no"; then
2133		case "$host_os" in
2134
2135		darwin[[0-7]].*)
2136			#
2137			# Pre-Tiger.  Build only for 32-bit PowerPC; no
2138			# need for any special compiler or linker flags.
2139			#
2140			;;
2141
2142		darwin8.[[0123]]|darwin8.[[0123]].*)
2143			#
2144			# Tiger, prior to Intel support.  Build
2145			# libraries and executables for 32-bit PowerPC
2146			# and 64-bit PowerPC, with 32-bit PowerPC first.
2147			# (I'm guessing that's what Apple does.)
2148			#
2149			# (The double brackets are needed because
2150			# autotools/m4 use brackets as a quoting
2151			# character; the double brackets turn into
2152			# single brackets in the generated configure
2153			# file.)
2154			#
2155			V_LIB_CCOPT_FAT="-arch ppc -arch ppc64"
2156			V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64"
2157			V_PROG_CCOPT_FAT="-arch ppc -arch ppc64"
2158			V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64"
2159			;;
2160
2161		darwin8.[[456]]|darwin8.[[456]].*)
2162			#
2163			# Tiger, subsequent to Intel support but prior
2164			# to x86-64 support.  Build libraries and
2165			# executables for 32-bit PowerPC, 64-bit
2166			# PowerPC, and 32-bit x86, with 32-bit PowerPC
2167			# first.  (I'm guessing that's what Apple does.)
2168			#
2169			# (The double brackets are needed because
2170			# autotools/m4 use brackets as a quoting
2171			# character; the double brackets turn into
2172			# single brackets in the generated configure
2173			# file.)
2174			#
2175			V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386"
2176			V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386"
2177			V_PROG_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386"
2178			V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386"
2179			;;
2180
2181		darwin8.*)
2182			#
2183			# All other Tiger, so subsequent to x86-64
2184			# support.  Build libraries and executables for
2185			# 32-bit PowerPC, 64-bit PowerPC, 32-bit x86,
2186			# and x86-64, with 32-bit PowerPC first.  (I'm
2187			# guessing that's what Apple does.)
2188			#
2189			V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2190			V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2191			V_PROG_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2192			V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2193			;;
2194
2195		darwin9.*)
2196			#
2197			# Leopard.  Build libraries for 32-bit PowerPC,
2198			# 64-bit PowerPC, 32-bit x86, and x86-64, with
2199			# 32-bit PowerPC first, and build executables
2200			# for 32-bit x86 and 32-bit PowerPC, with 32-bit
2201			# x86 first.  (That's what Apple does.)
2202			#
2203			V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2204			V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2205			V_PROG_CCOPT_FAT="-arch i386 -arch ppc"
2206			V_PROG_LDFLAGS_FAT="-arch i386 -arch ppc"
2207			;;
2208
2209		darwin10.*)
2210			#
2211			# Snow Leopard.  Build libraries for x86-64,
2212			# 32-bit x86, and 32-bit PowerPC, with x86-64
2213			# first, and build executables for x86-64 and
2214			# 32-bit x86, with x86-64 first.  (That's what
2215			# Apple does, even though Snow Leopard doesn't
2216			# run on PPC, so PPC libpcap runs under Rosetta,
2217			# and Rosetta doesn't support BPF ioctls, so PPC
2218			# programs can't do live captures.)
2219			#
2220			V_LIB_CCOPT_FAT="-arch x86_64 -arch i386 -arch ppc"
2221			V_LIB_LDFLAGS_FAT="-arch x86_64 -arch i386 -arch ppc"
2222			V_PROG_CCOPT_FAT="-arch x86_64 -arch i386"
2223			V_PROG_LDFLAGS_FAT="-arch x86_64 -arch i386"
2224			;;
2225
2226		darwin1[[1-8]]*)
2227			#
2228			# Post-Snow Leopard, pre-Catalina.  Build
2229			# libraries for x86-64 and 32-bit x86, with
2230			# x86-64 first, and build executables only for
2231			# x86-64.  (That's what Apple does.)  This
2232			# requires no special flags for programs.
2233			#
2234			# We check whether we *can* build for i386 and,
2235			# if not, suggest that the user install the
2236			# /usr/include headers if they want to build
2237			# fat.
2238			#
2239			AC_MSG_CHECKING(whether building for 32-bit x86 is supported)
2240			AC_LBL_SAVE_CHECK_STATE
2241			CFLAGS="$CFLAGS -arch i386"
2242			AC_TRY_LINK(
2243			    [],
2244			    [return 0;],
2245			    [
2246				AC_MSG_RESULT(yes)
2247				V_LIB_CCOPT_FAT="-arch x86_64"
2248				V_LIB_LDFLAGS_FAT="-arch x86_64"
2249
2250				#
2251				# OpenSSL installation on macOS seems
2252				# to install only the libs for 64-bit
2253				# x86 - at least that's what Brew does:
2254				# only configure 32-bit builds if we
2255				# don't have OpenSSL.
2256				#
2257				if test "$HAVE_OPENSSL" != yes; then
2258					V_LIB_CCOPT_FAT="$V_LIB_CCOPT_FAT -arch i386"
2259					V_LIB_LDFLAGS_FAT="$V_LIB_LDFLAGS_FAT -arch i386"
2260				fi
2261			    ],
2262			    [
2263				AC_MSG_RESULT(no)
2264				V_LIB_CCOPT_FAT="-arch x86_64"
2265				V_LIB_LDFLAGS_FAT="-arch x86_64"
2266				case "$host_os" in
2267
2268				darwin18.*)
2269					#
2270					# Mojave; you need to install the
2271					# /usr/include headers to get
2272					# 32-bit x86 builds to work.
2273					#
2274					AC_MSG_WARN([Compiling for 32-bit x86 gives an error; try installing the command-line tools and, after that, installing the /usr/include headers from the /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg package])
2275					;;
2276
2277				*)
2278					#
2279					# Pre-Mojave; the command-line
2280					# tools should be sufficient to
2281					# enable 32-bit x86 builds.
2282					#
2283					AC_MSG_WARN([Compiling for 32-bit x86 gives an error; try installing the command-line tools])
2284					;;
2285				esac
2286			    ])
2287			AC_LBL_RESTORE_CHECK_STATE
2288			;;
2289
2290		darwin19*)
2291			#
2292			# Catalina.  Build libraries and executables
2293			# only for x86-64.  (That's what Apple does;
2294			# 32-bit x86 binaries are not supported on
2295			# Catalina.)
2296			#
2297			V_LIB_CCOPT_FAT="-arch x86_64"
2298			V_LIB_LDFLAGS_FAT="-arch x86_64"
2299			V_PROG_CCOPT_FAT="-arch x86_64"
2300			V_PROG_LDFLAGS_FAT="-arch x86_64"
2301			;;
2302
2303		darwin*)
2304			#
2305			# Post-Catalina.  Build libraries and
2306			# executables for x86-64 and ARM64.
2307			# (That's what Apple does, except they
2308			# build for arm64e, which may include
2309			# some of the pointer-checking extensions.)
2310			#
2311			# If we're building with libssl, make sure
2312			# we can build fat with it (i.e., that it
2313			# was built fat); if we can't, don't set
2314			# the target architectures, and just
2315			# build for the host we're on.
2316			#
2317			# Otherwise, just add both of them.
2318			#
2319			if test "$HAVE_OPENSSL" = yes; then
2320				AC_MSG_CHECKING(whether building fat with libssl is supported)
2321				AC_LBL_SAVE_CHECK_STATE
2322				CFLAGS="$CFLAGS -arch x86_64 -arch arm64"
2323				LDFLAGS="$LDFLAGS $OPENSSL_LIBS"
2324				AC_TRY_LINK(
2325				    [
2326					#include <openssl/ssl.h>
2327				    ],
2328				    [
2329					SSL_library_init();
2330					return 0;
2331				    ],
2332				    [
2333					AC_MSG_RESULT(yes)
2334					V_LIB_CCOPT_FAT="-arch x86_64 -arch arm64"
2335					V_LIB_LDFLAGS_FAT="-arch x86_64 -arch arm64"
2336					V_PROG_CCOPT_FAT="-arch x86_64 -arch arm64"
2337					V_PROG_LDFLAGS_FAT="-arch x86_64 -arch arm64"
2338				    ],
2339				    [AC_MSG_RESULT(no)]
2340				)
2341				AC_LBL_RESTORE_CHECK_STATE
2342			else
2343				V_LIB_CCOPT_FAT="-arch x86_64 -arch arm64"
2344				V_LIB_LDFLAGS_FAT="-arch x86_64 -arch arm64"
2345				V_PROG_CCOPT_FAT="-arch x86_64 -arch arm64"
2346				V_PROG_LDFLAGS_FAT="-arch x86_64 -arch arm64"
2347			fi
2348			;;
2349		esac
2350	fi
2351	;;
2352
2353hpux9*)
2354	AC_DEFINE(HAVE_HPUX9,1,[on HP-UX 9.x])
2355
2356	#
2357	# Use System V conventions for man pages.
2358	#
2359	MAN_ADMIN_COMMANDS=1m
2360	MAN_FILE_FORMATS=4
2361	MAN_MISC_INFO=5
2362	;;
2363
2364hpux10.0*)
2365
2366	#
2367	# Use System V conventions for man pages.
2368	#
2369	MAN_ADMIN_COMMANDS=1m
2370	MAN_FILE_FORMATS=4
2371	MAN_MISC_INFO=5
2372	;;
2373
2374hpux10.1*)
2375
2376	#
2377	# Use System V conventions for man pages.
2378	#
2379	MAN_ADMIN_COMMANDS=1m
2380	MAN_FILE_FORMATS=4
2381	MAN_MISC_INFO=5
2382	;;
2383
2384hpux*)
2385	dnl HPUX 10.20 and above is similar to HPUX 9, but
2386	dnl not the same....
2387	dnl
2388	dnl XXX - DYEXT should be set to "sl" if this is building
2389	dnl for 32-bit PA-RISC, but should be left as "so" for
2390	dnl 64-bit PA-RISC or, I suspect, IA-64.
2391	AC_DEFINE(HAVE_HPUX10_20_OR_LATER,1,[on HP-UX 10.20 or later])
2392	if test "`uname -m`" = "ia64"; then
2393		DYEXT="so"
2394	else
2395		DYEXT="sl"
2396	fi
2397
2398	#
2399	# "-b" builds a shared library; "+h" sets the soname.
2400	#
2401	SHLIB_OPT="-b"
2402	SONAME_OPT="+h"
2403
2404	#
2405	# Use System V conventions for man pages.
2406	#
2407	MAN_FILE_FORMATS=4
2408	MAN_MISC_INFO=5
2409	;;
2410
2411irix*)
2412	#
2413	# Use IRIX conventions for man pages; they're the same as the
2414	# System V conventions, except that they use section 8 for
2415	# administrative commands and daemons.
2416	#
2417	MAN_FILE_FORMATS=4
2418	MAN_MISC_INFO=5
2419	;;
2420
2421linux*|freebsd*|netbsd*|openbsd*|dragonfly*|kfreebsd*|gnu*|haiku*|midipix*)
2422	DYEXT="so"
2423	;;
2424
2425osf*)
2426	DYEXT="so"
2427
2428	#
2429	# DEC OSF/1, a/k/a Digital UNIX, a/k/a Tru64 UNIX.
2430	# Use Tru64 UNIX conventions for man pages; they're the same as
2431	# the System V conventions except that they use section 8 for
2432	# administrative commands and daemons.
2433	#
2434	MAN_FILE_FORMATS=4
2435	MAN_MISC_INFO=5
2436	MAN_DEVICES=7
2437	;;
2438
2439sinix*)
2440	AC_MSG_CHECKING(if SINIX compiler defines sinix)
2441	AC_CACHE_VAL(ac_cv_cc_sinix_defined,
2442		AC_TRY_COMPILE(
2443		    [],
2444		    [int i = sinix;],
2445		    ac_cv_cc_sinix_defined=yes,
2446		    ac_cv_cc_sinix_defined=no))
2447	    AC_MSG_RESULT($ac_cv_cc_sinix_defined)
2448	    if test $ac_cv_cc_sinix_defined = no ; then
2449		    AC_DEFINE(sinix,1,[on sinix])
2450	    fi
2451	;;
2452
2453solaris*)
2454	AC_DEFINE(HAVE_SOLARIS,1,[On solaris])
2455
2456	DYEXT="so"
2457
2458	#
2459	# Make sure errno is thread-safe, in case we're called in
2460	# a multithreaded program.  We don't guarantee that two
2461	# threads can use the *same* pcap_t safely, but the
2462	# current version does guarantee that you can use different
2463	# pcap_t's in different threads, and even that pcap_compile()
2464	# is thread-safe (it wasn't thread-safe in some older versions).
2465	#
2466	V_CCOPT="$V_CCOPT -D_TS_ERRNO"
2467
2468	case "`uname -r`" in
2469
2470	5.12)
2471		;;
2472
2473	*)
2474		#
2475		# Use System V conventions for man pages.
2476		#
2477		MAN_ADMIN_COMMANDS=1m
2478		MAN_FILE_FORMATS=4
2479		MAN_MISC_INFO=5
2480		MAN_DEVICES=7D
2481	esac
2482	;;
2483esac
2484AC_SUBST(V_LIB_CCOPT_FAT)
2485AC_SUBST(V_LIB_LDFLAGS_FAT)
2486AC_SUBST(V_PROG_CCOPT_FAT)
2487AC_SUBST(V_PROG_LDFLAGS_FAT)
2488AC_SUBST(DYEXT)
2489AC_SUBST(MAN_DEVICES)
2490AC_SUBST(MAN_FILE_FORMATS)
2491AC_SUBST(MAN_MISC_INFO)
2492AC_SUBST(MAN_ADMIN_COMMANDS)
2493
2494AC_ARG_ENABLE(shared,
2495AS_HELP_STRING([--enable-shared],[build shared libraries @<:@default=yes, if support available@:>@]))
2496test "x$enable_shared" = "xno" && DYEXT="none"
2497
2498AC_PROG_RANLIB
2499AC_CHECK_TOOL([AR], [ar])
2500
2501AC_PROG_LN_S
2502AC_SUBST(LN_S)
2503
2504AC_LBL_DEVEL(V_CCOPT)
2505
2506#
2507# Check to see if the sockaddr struct has the 4.4 BSD sa_len member.
2508#
2509AC_CHECK_MEMBERS([struct sockaddr.sa_len],,,
2510    [
2511	#include <sys/types.h>
2512	#include <sys/socket.h>
2513    ])
2514
2515#
2516# Check to see if there's a sockaddr_storage structure.
2517#
2518AC_CHECK_TYPES(struct sockaddr_storage,,,
2519    [
2520	#include <sys/types.h>
2521	#include <sys/socket.h>
2522    ])
2523
2524#
2525# Check to see if the dl_hp_ppa_info_t struct has the HP-UX 11.00
2526# dl_module_id_1 member.
2527#
2528# NOTE: any failure means we conclude that it doesn't have that member,
2529# so if we don't have DLPI, don't have a <sys/dlpi_ext.h> header, or
2530# have one that doesn't declare a dl_hp_ppa_info_t type, we conclude
2531# it doesn't have that member (which is OK, as either we won't be
2532# using code that would use that member, or we wouldn't compile in
2533# any case).
2534#
2535AC_CHECK_MEMBERS([dl_hp_ppa_info_t.dl_module_id_1],,,
2536    [
2537	#include <sys/types.h>
2538	#include <sys/dlpi.h>
2539	#include <sys/dlpi_ext.h>
2540    ])
2541
2542#
2543# Various Linux-specific mechanisms.
2544#
2545AC_ARG_ENABLE([usb],
2546[AS_HELP_STRING([--enable-usb],[enable Linux usbmon USB capture support @<:@default=yes, if support available@:>@])],
2547    [],
2548    [enable_usb=yes])
2549
2550#
2551# If somebody requested an XXX-only pcap, that doesn't include
2552# additional mechanisms.
2553#
2554if test "xxx_only" != yes; then
2555  case "$host_os" in
2556  linux*)
2557    dnl check for USB sniffing support
2558    AC_MSG_CHECKING(for Linux usbmon USB sniffing support)
2559    if test "x$enable_usb" != "xno" ; then
2560      AC_DEFINE(PCAP_SUPPORT_LINUX_USBMON, 1, [target host supports Linux usbmon for USB sniffing])
2561      MODULE_C_SRC="$MODULE_C_SRC pcap-usb-linux.c"
2562      AC_MSG_RESULT(yes)
2563      #
2564      # Note: if the directory for special files is *EVER* somewhere
2565      # other than the UN*X standard of /dev (which will break any
2566      # software that looks for /dev/null or /dev/tty, for example,
2567      # so doing that is *REALLY* not a good idea), please provide
2568      # some mechanism to determine that directory at *run time*,
2569      # rather than *configure time*, so that it works when doing
2570      # a cross-build, and that works with *multiple* distributions,
2571      # with our without udev, and with multiple versions of udev,
2572      # with udevinfo or udevadm or any other mechanism to get the
2573      # special files directory.
2574      #
2575      # Do we have a version of <linux/compiler.h> available?
2576      # If so, we might need it for <linux/usbdevice_fs.h>.
2577      #
2578      AC_CHECK_HEADERS(linux/compiler.h)
2579      if test "$ac_cv_header_linux_compiler_h" = yes; then
2580        #
2581        # Yes - include it when testing for <linux/usbdevice_fs.h>.
2582        #
2583        AC_CHECK_HEADERS(linux/usbdevice_fs.h,,,[#include <linux/compiler.h>])
2584      else
2585        AC_CHECK_HEADERS(linux/usbdevice_fs.h)
2586      fi
2587      if test "$ac_cv_header_linux_usbdevice_fs_h" = yes; then
2588        #
2589        # OK, does it define bRequestType?  Older versions of the kernel
2590        # define fields with names like "requesttype, "request", and
2591        # "value", rather than "bRequestType", "bRequest", and
2592        # "wValue".
2593        #
2594        AC_CHECK_MEMBERS([struct usbdevfs_ctrltransfer.bRequestType],,,
2595          [
2596            AC_INCLUDES_DEFAULT
2597            #ifdef HAVE_LINUX_COMPILER_H
2598            #include <linux/compiler.h>
2599            #endif
2600            #include <linux/usbdevice_fs.h>
2601          ])
2602      fi
2603    else
2604      AC_MSG_RESULT(no)
2605    fi
2606
2607    #
2608    # Life's too short to deal with trying to get this to compile
2609    # if you don't get the right types defined with
2610    # __KERNEL_STRICT_NAMES getting defined by some other include.
2611    #
2612    # Check whether the includes Just Work.  If not, don't turn on
2613    # netfilter support.
2614    #
2615    AC_MSG_CHECKING(whether we can compile the netfilter support)
2616    AC_CACHE_VAL(ac_cv_netfilter_can_compile,
2617      AC_TRY_COMPILE([
2618AC_INCLUDES_DEFAULT
2619#include <sys/socket.h>
2620#include <netinet/in.h>
2621#include <linux/types.h>
2622
2623#include <linux/netlink.h>
2624#include <linux/netfilter.h>
2625#include <linux/netfilter/nfnetlink.h>
2626#include <linux/netfilter/nfnetlink_log.h>
2627#include <linux/netfilter/nfnetlink_queue.h>],
2628        [],
2629        ac_cv_netfilter_can_compile=yes,
2630        ac_cv_netfilter_can_compile=no))
2631    AC_MSG_RESULT($ac_cv_netfilter_can_compile)
2632    if test $ac_cv_netfilter_can_compile = yes ; then
2633      AC_DEFINE(PCAP_SUPPORT_NETFILTER, 1,
2634        [target host supports netfilter sniffing])
2635      MODULE_C_SRC="$MODULE_C_SRC pcap-netfilter-linux.c"
2636    fi
2637    ;;
2638  esac
2639fi
2640AC_SUBST(PCAP_SUPPORT_LINUX_USBMON)
2641AC_SUBST(PCAP_SUPPORT_NETFILTER)
2642
2643AC_ARG_ENABLE([netmap],
2644[AS_HELP_STRING([--enable-netmap],[enable netmap support @<:@default=yes, if support available@:>@])],
2645    [],
2646    [enable_netmap=yes])
2647
2648if test "x$enable_netmap" != "xno" ; then
2649	#
2650	# Check whether net/netmap_user.h is usable if NETMAP_WITH_LIBS is
2651	# defined; it's not usable on DragonFly BSD 4.6 if NETMAP_WITH_LIBS
2652	# is defined, for example, as it includes a nonexistent malloc.h
2653	# header.
2654	#
2655	AC_MSG_CHECKING(whether we can compile the netmap support)
2656	AC_CACHE_VAL(ac_cv_net_netmap_user_can_compile,
2657	  AC_TRY_COMPILE([
2658AC_INCLUDES_DEFAULT
2659#define NETMAP_WITH_LIBS
2660#include <net/netmap_user.h>],
2661	    [],
2662	    ac_cv_net_netmap_user_can_compile=yes,
2663	    ac_cv_net_netmap_user_can_compile=no))
2664	AC_MSG_RESULT($ac_cv_net_netmap_user_can_compile)
2665	if test $ac_cv_net_netmap_user_can_compile = yes ; then
2666	  AC_DEFINE(PCAP_SUPPORT_NETMAP, 1,
2667	    [target host supports netmap])
2668	    MODULE_C_SRC="$MODULE_C_SRC pcap-netmap.c"
2669	fi
2670	AC_SUBST(PCAP_SUPPORT_NETMAP)
2671fi
2672
2673# Check for DPDK support.
2674AC_ARG_WITH([dpdk],
2675AS_HELP_STRING([--with-dpdk@<:@=DIR@:>@],[include DPDK support (located in directory DIR, if supplied).  @<:@default=no@:>@]),
2676[
2677	if test "$withval" = no
2678	then
2679		# User doesn't want DPDK support.
2680		want_dpdk=no
2681	elif test "$withval" = yes
2682	then
2683		# User wants DPDK support but hasn't specified a directory.
2684		want_dpdk=yes
2685	else
2686		# User wants DPDK support and has specified a directory,
2687		# so use the provided value.
2688		want_dpdk=yes
2689		dpdk_dir=$withval
2690	fi
2691],[
2692	if test "$V_PCAP" = dpdk; then
2693		# User requested DPDK-only libpcap, so we'd better have
2694		# the DPDK API.
2695		want_dpdk=yes
2696	elif test "xxx_only" = yes; then
2697		# User requested something-else-only pcap, so they don't
2698		# want DPDK support.
2699		want_dpdk=no
2700	else
2701		#
2702		# User didn't explicitly request DPDK; don't give it
2703		# to them without their consent, as the code is
2704		# immensely hard to keep compiling for every random
2705		# API change the DPDK folks make.
2706		#
2707		want_dpdk=no
2708	fi
2709])
2710
2711if test "$want_dpdk" != no; then
2712	#
2713	# The user didn't explicitly say they don't want DPDK,
2714	# so see if we have it.
2715	#
2716	# We only try to find it using pkg-config; DPDK is *SO*
2717	# complicated - DPDK 19.02, for example, has about 117(!)
2718	# libraries, and the precise set of libraries required has
2719	# changed over time - so attempting to guess which libraries
2720	# you need, and hardcoding that in an attempt to find the
2721	# libraries without DPDK, rather than relying on DPDK to
2722	# tell you, with a .pc file, what libraries are needed,
2723	# is *EXTREMELY* fragile and has caused some bug reports,
2724	# so we're just not going to do it.
2725	#
2726	# If that causes a problem, the only thing we will do is
2727	# accept an alternative way of finding the appropriate
2728	# library set for the installed version of DPDK that is
2729	# as robust as pkg-config (i.e., it had better work as well
2730	# as pkg-config with *ALL* versions of DPDK that provide a
2731	# libdpdk.pc file).
2732	#
2733	# If --with-dpdk={path} was specified, add {path}/pkgconfig
2734	# to PKG_CONFIG_PATH, so we look for the .pc file there,
2735	# first.
2736	#
2737	save_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
2738	if test -n "$dpdk_dir"; then
2739		PKG_CONFIG_PATH="$dpdk_dir:$PKG_CONFIG_PATH"
2740	fi
2741	PKG_CHECK_MODULE(DPDK, libdpdk,
2742	    [
2743		found_dpdk=yes
2744	    ])
2745	PKG_CONFIG_PATH="$save_PKG_CONFIG_PATH"
2746
2747	#
2748	# Did we find DPDK?
2749	#
2750	if test "$found_dpdk" = yes; then
2751		#
2752		# Found it.
2753		#
2754		# We call rte_eth_dev_count_avail(), and older versions
2755		# of DPDK didn't have it, so check for it.
2756		#
2757		AC_LBL_SAVE_CHECK_STATE
2758		CFLAGS="$CFLAGS $DPDK_CFLAGS"
2759		LIBS="$LIBS $DPDK_LIBS"
2760		AC_CHECK_FUNC(rte_eth_dev_count_avail)
2761		AC_LBL_RESTORE_CHECK_STATE
2762	fi
2763
2764	if test "$ac_cv_func_rte_eth_dev_count_avail" = yes; then
2765		#
2766		# We found a usable DPDK.
2767		#
2768		# Check whether the rte_ether.h file defines
2769		# struct ether_addr or struct rte_ether_addr.
2770		#
2771		# ("API compatibility?  That's for losers!")
2772		#
2773		AC_LBL_SAVE_CHECK_STATE
2774		CFLAGS="$CFLAGS $DPDK_CFLAGS"
2775		LIBS="$LIBS $DPDK_LIBS"
2776		AC_CHECK_TYPES(struct rte_ether_addr,,,
2777		    [
2778			#include <rte_ether.h>
2779		    ])
2780		AC_LBL_RESTORE_CHECK_STATE
2781
2782		#
2783		# We can build with DPDK.
2784		#
2785		V_INCLS="$V_INCLS $DPDK_CFLAGS"
2786		ADDITIONAL_LIBS="$ADDITIONAL_LIBS $DPDK_LIBS"
2787		ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $DPDK_LIBS_STATIC"
2788		REQUIRES_PRIVATE="$REQUIRES_PRIVATE libdpdk"
2789		AC_DEFINE(PCAP_SUPPORT_DPDK, 1, [target host supports DPDK])
2790		if test $V_PCAP != dpdk ; then
2791			MODULE_C_SRC="$MODULE_C_SRC pcap-dpdk.c"
2792		fi
2793	else
2794		#
2795		# We didn't find a usable DPDK.
2796		# If we required it (with --with-dpdk or --with-pcap=dpdk),
2797		# fail with an appropriate message telling the user what
2798		# the problem was, otherwise note the problem with a
2799		# warning.
2800		#
2801		if test "$found_dpdk" != yes; then
2802			#
2803			# Not found with pkg-config.  Note that we
2804			# require that DPDK must be findable with
2805			# pkg-config.
2806			#
2807			if test "$V_PCAP" = dpdk; then
2808				#
2809				# User requested DPDK-only capture support.
2810				#
2811				AC_MSG_ERROR(
2812[DPDK support requested with --with-pcap=dpdk, but
2813we couldn't find DPDK with pkg-config.  Make sure that pkg-config is
2814installed, that DPDK 18.02.2 or later is installed, and that DPDK
2815provides a .pc file.])
2816			fi
2817
2818			if test "$want_dpdk" = yes; then
2819				#
2820				# User requested that libpcap include
2821				# DPDK capture support.
2822				#
2823				AC_MSG_ERROR(
2824[DPDK support requested with --with-dpdk, but we
2825couldn't find DPDK with pkg-config.  Make sure that pkg-config
2826is installed, that DPDK 18.02.2 or later is installed, and that
2827DPDK provides .pc file.])
2828			fi
2829
2830			#
2831			# User didn't indicate whether they wanted DPDK
2832			# or not; just warn why we didn't find it.
2833			#
2834			AC_MSG_WARN(
2835[We couldn't find DPDK with pkg-config.  If
2836you want DPDK support, make sure that pkg-config is installed,
2837that DPDK 18.02.2 or later is installed, and that DPDK provides a
2838.pc file.])
2839		elif test "$ac_cv_func_rte_eth_dev_count_avail" != yes; then
2840			#
2841			# Found with pkg-config, but we couldn't compile
2842			# a program that calls rte_eth_dev_count(); we
2843			# probably have the developer package installed,
2844			# but don't have a sufficiently recent version
2845			# of DPDK.  Note that we need a sufficiently
2846			# recent version of DPDK.
2847			#
2848			if test "$V_PCAP" = dpdk; then
2849				#
2850				# User requested DPDK-only capture support.
2851				#
2852				AC_MSG_ERROR(
2853[DPDK support requested with --with-pcap=dpdk, but we
2854can't compile libpcap with DPDK.  Make sure that DPDK 18.02.2 or later
2855is installed.])
2856			fi
2857
2858			if test "$want_dpdk" = yes; then
2859				#
2860				# User requested that libpcap include
2861				# DPDK capture support.
2862				#
2863				AC_MSG_ERROR(
2864[DPDK support requested with --with-dpdk, but
2865we can't compile libpcap with DPDK.  Make sure that DPDK 18.02.2
2866or later is DPDK is installed.])
2867			fi
2868
2869			#
2870			# User didn't indicate whether they wanted DPDK
2871			# or not; just warn why we didn't find it.
2872			#
2873			AC_MSG_WARN(
2874[DPDK was found, but we can't compile libpcap with it.
2875Make sure that DPDK 18.02.2 or later is installed.])
2876		fi
2877	fi
2878fi
2879AC_SUBST(PCAP_SUPPORT_DPDK)
2880
2881AC_ARG_ENABLE([bluetooth],
2882[AS_HELP_STRING([--enable-bluetooth],[enable Bluetooth support @<:@default=yes, if support available@:>@])],
2883    [],
2884    [enable_bluetooth=ifsupportavailable])
2885
2886if test "xxx_only" = yes; then
2887	# User requested something-else-only pcap, so they don't
2888	# want Bluetooth support.
2889	enable_bluetooth=no
2890fi
2891
2892if test "x$enable_bluetooth" != "xno" ; then
2893	dnl check for Bluetooth sniffing support
2894	case "$host_os" in
2895	linux*)
2896		AC_CHECK_HEADER(bluetooth/bluetooth.h,
2897		    [
2898			#
2899			# We have bluetooth.h, so we support Bluetooth
2900			# sniffing.
2901			#
2902			AC_DEFINE(PCAP_SUPPORT_BT, 1, [target host supports Bluetooth sniffing])
2903			MODULE_C_SRC="$MODULE_C_SRC pcap-bt-linux.c"
2904			AC_MSG_NOTICE(Bluetooth sniffing is supported)
2905			ac_lbl_bluetooth_available=yes
2906
2907			#
2908			# OK, does struct sockaddr_hci have an hci_channel
2909			# member?
2910			#
2911			AC_CHECK_MEMBERS([struct sockaddr_hci.hci_channel],
2912			    [
2913				#
2914				# Yes; is HCI_CHANNEL_MONITOR defined?
2915				#
2916				AC_MSG_CHECKING(if HCI_CHANNEL_MONITOR is defined)
2917				AC_CACHE_VAL(ac_cv_lbl_hci_channel_monitor_is_defined,
2918				    AC_TRY_COMPILE(
2919					[
2920					    #include <bluetooth/bluetooth.h>
2921					    #include <bluetooth/hci.h>
2922					],
2923					[
2924					    int i = HCI_CHANNEL_MONITOR;
2925					],
2926					[
2927					    AC_MSG_RESULT(yes)
2928					    AC_DEFINE(PCAP_SUPPORT_BT_MONITOR, 1,
2929					      [target host supports Bluetooth Monitor])
2930					    MODULE_C_SRC="$MODULE_C_SRC pcap-bt-monitor-linux.c"
2931					],
2932					[
2933					    AC_MSG_RESULT(no)
2934					]))
2935			    ],,
2936			    [
2937				#include <bluetooth/bluetooth.h>
2938				#include <bluetooth/hci.h>
2939			    ])
2940		    ],
2941		    [
2942			#
2943			# We don't have bluetooth.h, so we don't support
2944			# Bluetooth sniffing.
2945			#
2946			if test "x$enable_bluetooth" = "xyes" ; then
2947				AC_MSG_ERROR(Bluetooth sniffing is not supported; install a Bluetooth devel library (libbluetooth-dev|bluez-libs-devel|bluez-dev|libbluetooth-devel|...) to enable it)
2948			else
2949				AC_MSG_NOTICE(Bluetooth sniffing is not supported; install a Bluetooth devel library (libbluetooth-dev|bluez-libs-devel|bluez-dev|libbluetooth-devel|...) to enable it)
2950			fi
2951		    ])
2952		;;
2953	*)
2954		if test "x$enable_bluetooth" = "xyes" ; then
2955			AC_MSG_ERROR(no Bluetooth sniffing support implemented for $host_os)
2956		else
2957			AC_MSG_NOTICE(no Bluetooth sniffing support implemented for $host_os)
2958		fi
2959		;;
2960	esac
2961	AC_SUBST(PCAP_SUPPORT_BT)
2962fi
2963
2964AC_ARG_ENABLE([dbus],
2965[AS_HELP_STRING([--enable-dbus],[enable D-Bus capture support @<:@default=yes, if support available@:>@])],
2966    [],
2967    [enable_dbus=ifavailable])
2968
2969if test "xxx_only" = yes; then
2970	# User requested something-else-only pcap, so they don't
2971	# want D-Bus support.
2972	enable_dbus=no
2973fi
2974
2975if test "x$enable_dbus" != "xno"; then
2976	if test "x$enable_dbus" = "xyes"; then
2977		case "$host_os" in
2978
2979		darwin*)
2980			#
2981			# We don't support D-Bus sniffing on macOS; see
2982			#
2983			# https://bugs.freedesktop.org/show_bug.cgi?id=74029
2984			#
2985			# The user requested it, so fail.
2986			#
2987			AC_MSG_ERROR([Due to freedesktop.org bug 74029, D-Bus capture support is not available on macOS])
2988		esac
2989	else
2990		case "$host_os" in
2991
2992		darwin*)
2993			#
2994			# We don't support D-Bus sniffing on macOS; see
2995			#
2996			# https://bugs.freedesktop.org/show_bug.cgi?id=74029
2997			#
2998			# The user didn't explicitly request it, so just
2999			# silently refuse to enable it.
3000			#
3001			enable_dbus="no"
3002			;;
3003		esac
3004	fi
3005fi
3006
3007if test "x$enable_dbus" != "xno"; then
3008	PKG_CHECK_MODULE(DBUS, dbus-1,
3009	    [
3010		AC_LBL_SAVE_CHECK_STATE
3011		CFLAGS="$CFLAGS $DBUS_CFLAGS"
3012		LIBS="$LIBS $DBUS_LIBS"
3013		AC_MSG_CHECKING(whether the D-Bus library defines dbus_connection_read_write)
3014		AC_TRY_LINK(
3015		    [#include <string.h>
3016
3017		     #include <time.h>
3018		     #include <sys/time.h>
3019
3020		     #include <dbus/dbus.h>],
3021		    [return dbus_connection_read_write(NULL, 0);],
3022		    [
3023			AC_MSG_RESULT([yes])
3024			AC_DEFINE(PCAP_SUPPORT_DBUS, 1, [support D-Bus sniffing])
3025			MODULE_C_SRC="$MODULE_C_SRC pcap-dbus.c"
3026			V_INCLS="$V_INCLS $DBUS_CFLAGS"
3027			ADDITIONAL_LIBS="$ADDITIONAL_LIBS $DBUS_LIBS"
3028			ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $DBUS_LIBS_STATIC"
3029			REQUIRES_PRIVATE="$REQUIRES_PRIVATE dbus-1"
3030		    ],
3031		    [
3032			AC_MSG_RESULT([no])
3033			if test "x$enable_dbus" = "xyes"; then
3034			    AC_MSG_ERROR([--enable-dbus was given, but the D-Bus library doesn't define dbus_connection_read_write()])
3035			fi
3036		     ])
3037		AC_LBL_RESTORE_CHECK_STATE
3038	    ],
3039	    [
3040		if test "x$enable_dbus" = "xyes"; then
3041			AC_MSG_ERROR([--enable-dbus was given, but the dbus-1 package is not installed])
3042		fi
3043	    ])
3044	AC_SUBST(PCAP_SUPPORT_DBUS)
3045fi
3046
3047AC_ARG_ENABLE([rdma],
3048[AS_HELP_STRING([--enable-rdma],[enable RDMA capture support @<:@default=yes, if support available@:>@])],
3049    [],
3050    [enable_rdma=ifavailable])
3051
3052if test "xxx_only" = yes; then
3053	# User requested something-else-only pcap, so they don't
3054	# want RDMA support.
3055	enable_rdma=no
3056fi
3057
3058if test "x$enable_rdma" != "xno"; then
3059	PKG_CHECK_MODULE(LIBIBVERBS, libibverbs,
3060	    [
3061		found_libibverbs=yes
3062		LIBIBVERBS_REQUIRES_PRIVATE="libibverbs"
3063	    ])
3064
3065	if test "x$found_libibverbs" != "xyes"; then
3066		AC_CHECK_LIB(ibverbs, ibv_get_device_list,
3067		    [
3068			found_libibverbs=yes
3069			LIBIBVERBS_CFLAGS=""
3070			LIBIBVERBS_LIBS="-libverbs"
3071			# XXX - at least on Ubuntu 20.04, there are many more
3072			# libraries needed; is there any platform where
3073			# libibverbs is available but where pkg-config isn't
3074			# available or libibverbs doesn't use it?  If not,
3075			# we should only use pkg-config for it.
3076			LIBIBVERBS_LIBS_STATIC="-libverbs"
3077			LIBIBVERBS_LIBS_PRIVATE="-libverbs"
3078		    ]
3079		)
3080	fi
3081
3082	if test "x$found_libibverbs" = "xyes"; then
3083		AC_LBL_SAVE_CHECK_STATE
3084		CFLAGS="$CFLAGS $LIBIBVERBS_CFLAGS"
3085		LIBS="$LIBS $LIBIBVERBS_LIBS"
3086		AC_CHECK_HEADER(infiniband/verbs.h, [
3087			#
3088			# ibv_create_flow may be defined as a static inline
3089			# function in infiniband/verbs.h, so we can't
3090			# use AC_CHECK_LIB.
3091			#
3092			# Too bad autoconf has no AC_SYMBOL_EXISTS()
3093			# macro that works like CMake's check_symbol_exists()
3094			# function, to check do a compile check like
3095			# this (they do a clever trick to avoid having
3096			# to know the function's signature).
3097			#
3098			AC_MSG_CHECKING(whether libibverbs defines ibv_create_flow)
3099			AC_TRY_LINK(
3100				[
3101					#include <infiniband/verbs.h>
3102				],
3103				[
3104					(void) ibv_create_flow((struct ibv_qp *) NULL,
3105							       (struct ibv_flow_attr *) NULL);
3106				],
3107				[
3108					AC_MSG_RESULT([yes])
3109					found_usable_libibverbs=yes
3110				],
3111				[
3112					AC_MSG_RESULT([no])
3113				]
3114			)
3115		])
3116		AC_LBL_RESTORE_CHECK_STATE
3117	fi
3118
3119	if test "x$found_usable_libibverbs" = "xyes"
3120	then
3121		AC_DEFINE(PCAP_SUPPORT_RDMASNIFF, 1, [target host supports RDMA sniffing])
3122		MODULE_C_SRC="$MODULE_C_SRC pcap-rdmasniff.c"
3123		CFLAGS="$LIBIBVERBS_CFLAGS $CFLAGS"
3124		ADDITIONAL_LIBS="$LIBIBVERBS_LIBS $ADDITIONAL_LIBS"
3125		ADDITIONAL_LIBS_STATIC="$LIBIBVERBS_LIBS_STATIC $ADDITIONAL_LIBS_STATIC"
3126		LIBS_PRIVATE="$LIBIBVERBS_LIBS_PRIVATE $LIBS_PRIVATE"
3127		REQUIRES_PRIVATE="$REQUIRES_PRIVATE $LIBIBVERBS_REQUIRES_PRIVATE"
3128	fi
3129	AC_SUBST(PCAP_SUPPORT_RDMASNIFF)
3130fi
3131
3132#
3133# If this is a platform where we need to have the .pc file and
3134# pcap-config script supply an rpath option to specify the directory
3135# in which the libpcap shared library is installed, and the install
3136# prefix /usr (meaning we're not installing a system library), provide
3137# the rpath option.
3138#
3139# (We must check $prefix, as $libdir isn't necessarily /usr/lib in this
3140# case - for example, Linux distributions for 64-bit platforms that
3141# also provide support for binaries for a 32-bit version of the
3142# platform may put the 64-bit libraries, the 32-bit libraries, or both
3143# in directories other than /usr/lib.)
3144#
3145# In AIX, do we have to do this?
3146#
3147# In Darwin-based OSes, the full paths of the shared libraries with
3148# which the program was linked are stored in the executable, so we don't
3149# need to provide an rpath option.
3150#
3151# With the HP-UX linker, directories specified with -L are, by default,
3152# added to the run-time search path, so we don't need to supply them.
3153#
3154# For Tru64 UNIX, "-rpath" works with DEC's^WCompaq's^WHP's C compiler
3155# for Alpha, but isn't documented as working with GCC, and no GCC-
3156# compatible option is documented as working with the DEC compiler.
3157# If anybody needs this on Tru64/Alpha, they're welcome to figure out a
3158# way to make it work.
3159#
3160# This must *not* depend on the compiler, as, on platforms where there's
3161# a GCC-compatible compiler and a vendor compiler, we need to work with
3162# both.
3163#
3164if test "$prefix" != "/usr"; then
3165	case "$host_os" in
3166
3167	freebsd*|netbsd*|openbsd*|dragonfly*|linux*|haiku*|midipix*|gnu*)
3168		#
3169		# Platforms where the "native" C compiler is GCC or
3170		# accepts compatible command-line arguments, and the
3171		# "native" linker is the GNU linker or accepts
3172		# compatible command-line arguments.
3173		#
3174		RPATH="-Wl,-rpath,\${libdir}"
3175		;;
3176
3177	solaris*)
3178		#
3179		# Sun/Oracle's linker, the GNU linker, and
3180		# GNU-compatible linkers all support -R.
3181		#
3182		RPATH="-Wl,-R,\${libdir}"
3183		;;
3184	esac
3185fi
3186
3187AC_PROG_INSTALL
3188
3189AC_CONFIG_HEADER(config.h)
3190
3191AC_SUBST(V_SHLIB_CCOPT)
3192AC_SUBST(V_SHLIB_CMD)
3193AC_SUBST(V_SHLIB_OPT)
3194AC_SUBST(V_SONAME_OPT)
3195AC_SUBST(RPATH)
3196AC_SUBST(ADDLOBJS)
3197AC_SUBST(ADDLARCHIVEOBJS)
3198AC_SUBST(PLATFORM_C_SRC)
3199AC_SUBST(MODULE_C_SRC)
3200AC_SUBST(REMOTE_C_SRC)
3201AC_SUBST(PTHREAD_LIBS)
3202AC_SUBST(BUILD_RPCAPD)
3203AC_SUBST(INSTALL_RPCAPD)
3204AC_SUBST(RPCAPD_LIBS)
3205
3206#
3207# We're done with configuration operations; add ADDITIONAL_LIBS and
3208# ADDITIONAL_LIBS_STATIC to LIBS and LIBS_STATIC, respectively.
3209#
3210LIBS="$ADDITIONAL_LIBS $LIBS"
3211LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $LIBS_STATIC"
3212
3213AC_OUTPUT_COMMANDS([if test -f .devel; then
3214	echo timestamp > stamp-h
3215	cat $srcdir/Makefile-devel-adds >> Makefile
3216	make depend || exit 1
3217fi])
3218AC_OUTPUT(Makefile grammar.y pcap-filter.manmisc pcap-linktype.manmisc
3219	pcap-tstamp.manmisc pcap-savefile.manfile pcap.3pcap
3220	pcap_compile.3pcap pcap_datalink.3pcap pcap_dump_open.3pcap
3221	pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap
3222	pcap_list_tstamp_types.3pcap pcap_open_dead.3pcap
3223	pcap_open_offline.3pcap pcap_set_immediate_mode.3pcap
3224	pcap_set_tstamp_precision.3pcap pcap_set_tstamp_type.3pcap
3225	rpcapd/Makefile rpcapd/rpcapd.manadmin rpcapd/rpcapd-config.manfile
3226	testprogs/Makefile)
3227exit 0
3228