xref: /freebsd/contrib/libpcap/configure.ac (revision afdbf109c6a661a729938f68211054a0a50d38ac)
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# Get the size of a void *, to determine whether this is a 32-bit
116# or 64-bit build.
117#
118AC_CHECK_SIZEOF([void *])
119ac_lbl_c_sizeof_void_p="$ac_cv_sizeof_void_p"
120
121#
122# Get the size of a time_t, to know whether it's 32-bit or 64-bit.
123#
124AC_CHECK_SIZEOF([time_t],,[#include <time.h>])
125
126AC_LBL_C_INIT(V_CCOPT, V_INCLS)
127AC_LBL_SHLIBS_INIT
128AC_LBL_C_INLINE
129AC_PCAP_C___ATOMICS
130
131#
132# Try to arrange for large file support.
133#
134AC_SYS_LARGEFILE
135AC_FUNC_FSEEKO
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)
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 the wireless extensions?
1008	#
1009	AC_CHECK_HEADERS(linux/wireless.h, [], [],
1010	[
1011#include <sys/socket.h>
1012#include <linux/if.h>
1013#include <linux/types.h>
1014	])
1015
1016	#
1017	# Do we have libnl?
1018	# We only want version 3.  Version 2 was, apparently,
1019	# short-lived, and version 1 is source and binary
1020	# incompatible with version 3, and it appears that,
1021	# these days, everybody's using version 3.  We're
1022	# not supporting older versions of the Linux kernel;
1023	# let's drop support for older versions of libnl, too.
1024	#
1025	AC_ARG_WITH(libnl,
1026	AS_HELP_STRING([--without-libnl],[disable libnl support @<:@default=yes, on Linux, if present@:>@]),
1027		with_libnl=$withval,with_libnl=if_available)
1028
1029	if test x$with_libnl != xno ; then
1030		#
1031		# Check for libnl-genl-3.0 with pkg-config.
1032		#
1033		PKG_CHECK_MODULE(LIBNL, libnl-genl-3.0,
1034		    [
1035			pkg_config_found_libnl=yes
1036			V_INCLS="$V_INCLS $LIBNL_CFLAGS"
1037			ADDITIONAL_LIBS="$LIBNL_LIBS $ADDITIONAL_LIBS"
1038			ADDITIONAL_LIBS_STATIC="$LIBNL_LIBS_STATIC $ADDITIONAL_LIBS_STATIC"
1039			REQUIRES_PRIVATE="libnl-genl-3.0 $REQUIRES_PRIVATE"
1040			AC_DEFINE(HAVE_LIBNL,1,[if libnl exists])
1041		    ])
1042
1043		if test x$pkg_config_found_libnl != xyes; then
1044			#
1045			# OK, either we don't have pkg-config or there
1046			# wasn't a .pc file for it; Check for it directly.
1047			#
1048			case "$with_libnl" in
1049
1050			yes|if_available)
1051				incdir=-I/usr/include/libnl3
1052				libnldir=
1053				;;
1054
1055			*)
1056				if test -d $withval; then
1057					libnldir=-L${withval}/lib
1058					incdir=-I${withval}/include
1059				fi
1060				;;
1061			esac
1062
1063			AC_CHECK_LIB(nl-3, nl_socket_alloc,
1064			[
1065				#
1066				# Yes, we have libnl 3.x.
1067				#
1068				ADDITIONAL_LIBS="${libnldir} -lnl-genl-3 -lnl-3 $ADDITIONAL_LIBS"
1069				ADDITIONAL_LIBS_STATIC="${libnldir} -lnl-genl-3 -lnl-3 $ADDITIONAL_LIBS_STATIC"
1070				LIBS_PRIVATE="${libnldir} -lnl-genl-3 -lnl-3 $LIBS_PRIVATE"
1071				AC_DEFINE(HAVE_LIBNL,1,[if libnl exists])
1072				V_INCLS="$V_INCLS ${incdir}"
1073			],[
1074				#
1075				# No, we don't have libnl at all.
1076				# Fail if the user explicitly requested
1077				# it.
1078				#
1079				if test x$with_libnl = xyes ; then
1080					AC_MSG_ERROR([libnl support requested but libnl not found])
1081				fi
1082			], ${incdir} ${libnldir} -lnl-genl-3 -lnl-3 )
1083		fi
1084	fi
1085
1086	#
1087	# Check to see if the tpacket_auxdata struct has a tp_vlan_tci member.
1088	#
1089	# NOTE: any failure means we conclude that it doesn't have that
1090	# member, so if we don't have tpacket_auxdata, we conclude it
1091	# doesn't have that member (which is OK, as either we won't be
1092	# using code that would use that member, or we wouldn't compile
1093	# in any case).
1094	AC_CHECK_MEMBERS([struct tpacket_auxdata.tp_vlan_tci],,,
1095	    [
1096		#include <sys/types.h>
1097		#include <linux/if_packet.h>
1098	    ])
1099	;;
1100
1101bpf)
1102	#
1103	# Capture module
1104	#
1105	PLATFORM_C_SRC="pcap-bpf.c"
1106
1107	#
1108	# Check whether we have the *BSD-style ioctls.
1109	#
1110	AC_CHECK_HEADERS(net/if_media.h)
1111
1112	#
1113	# Check whether we have struct BPF_TIMEVAL.
1114	#
1115	AC_CHECK_TYPES(struct BPF_TIMEVAL,,,
1116	    [
1117		#include <sys/types.h>
1118		#include <sys/ioctl.h>
1119		#ifdef HAVE_SYS_IOCCOM_H
1120		#include <sys/ioccom.h>
1121		#endif
1122		#include <net/bpf.h>
1123	    ])
1124
1125	#
1126	# Check whether there's a net/ipnet.h header and,
1127	# if so, whether it defines IPNET_ANY_LINK - if so,
1128	# we assume we have the "any" device (that's a
1129	# Solaris header, and later versions of Solaris
1130	# have an "any" device).
1131	#
1132	# Attempting to include it at compile time could
1133	# be a pain, as it's a kernel header.
1134	#
1135	AC_MSG_CHECKING(whether the Solaris "any" device is supported)
1136	if test -e /usr/include/inet/ipnet.h &&
1137	    grep -q IPNET_ANY_LINK /usr/include/inet/ipnet.h; then
1138		AC_MSG_RESULT(yes)
1139		AC_DEFINE(HAVE_SOLARIS_ANY_DEVICE, 1, [target host supports Solaris "any" device])
1140	else
1141		AC_MSG_RESULT(no)
1142	fi
1143	;;
1144
1145pf)
1146	#
1147	# Capture module
1148	#
1149	PLATFORM_C_SRC="pcap-pf.c"
1150	;;
1151
1152snit)
1153	#
1154	# Capture module
1155	#
1156	PLATFORM_C_SRC="pcap-snit.c"
1157	;;
1158
1159snoop)
1160	#
1161	# Capture module
1162	#
1163	PLATFORM_C_SRC="pcap-snoop.c"
1164	;;
1165
1166dag)
1167	#
1168	# --with-pcap=dag is the only way to get here, and it means
1169	# "DAG support but nothing else"
1170	#
1171	V_DEFS="$V_DEFS -DDAG_ONLY"
1172	PLATFORM_C_SRC="pcap-dag.c"
1173	xxx_only=yes
1174	;;
1175
1176dpdk)
1177	#
1178	# --with-pcap=dpdk is the only way to get here, and it means
1179	# "DPDK support but nothing else"
1180	#
1181	V_DEFS="$V_DEFS -DDPDK_ONLY"
1182	PLATFORM_C_SRC="pcap-dpdk.c"
1183	xxx_only=yes
1184	;;
1185
1186septel)
1187	#
1188	# --with-pcap=septel is the only way to get here, and it means
1189	# "Septel support but nothing else"
1190	#
1191	V_DEFS="$V_DEFS -DSEPTEL_ONLY"
1192	PLATFORM_C_SRC="pcap-septel.c"
1193	xxx_only=yes
1194	;;
1195
1196snf)
1197	#
1198	# --with-pcap=snf is the only way to get here, and it means
1199	# "SNF support but nothing else"
1200	#
1201	V_DEFS="$V_DEFS -DSNF_ONLY"
1202	PLATFORM_C_SRC="pcap-snf.c"
1203	xxx_only=yes
1204	;;
1205
1206null)
1207	#
1208	# Capture module
1209	#
1210	PLATFORM_C_SRC="pcap-null.c"
1211	;;
1212
1213*)
1214	AC_MSG_ERROR($V_PCAP is not a valid pcap type)
1215	;;
1216esac
1217
1218dnl
1219dnl Now figure out how we get a list of interfaces and addresses,
1220dnl if we support capturing.  Don't bother if we don't support
1221dnl capturing.
1222dnl
1223if test "$V_PCAP" != null
1224then
1225	AC_CHECK_FUNC(getifaddrs,[
1226		#
1227		# We have "getifaddrs()"; make sure we have <ifaddrs.h>
1228		# as well, just in case some platform is really weird.
1229		#
1230		AC_CHECK_HEADER(ifaddrs.h,[
1231		    #
1232		    # We have the header, so we use "getifaddrs()" to
1233		    # get the list of interfaces.
1234		    #
1235		    PLATFORM_C_SRC="$PLATFORM_C_SRC fad-getad.c"
1236		],[
1237		    #
1238		    # We don't have the header - give up.
1239		    # XXX - we could also fall back on some other
1240		    # mechanism, but, for now, this'll catch this
1241		    # problem so that we can at least try to figure
1242		    # out something to do on systems with "getifaddrs()"
1243		    # but without "ifaddrs.h", if there is something
1244		    # we can do on those systems.
1245		    #
1246		    AC_MSG_ERROR([Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.])
1247		])
1248	],[
1249		#
1250		# Well, we don't have "getifaddrs()", at least not with the
1251		# libraries with which we've decided we need to link
1252		# libpcap with, so we have to use some other mechanism.
1253		#
1254		# Note that this may happen on Solaris, which has
1255		# getifaddrs(), but in -lsocket, not in -lxnet, so we
1256		# won't find it if we link with -lxnet, which we want
1257		# to do for other reasons.
1258		#
1259		# For now, we use either the SIOCGIFCONF ioctl or the
1260		# SIOCGLIFCONF ioctl, preferring the latter if we have
1261		# it; the latter is a Solarisism that first appeared
1262		# in Solaris 8.  (Solaris's getifaddrs() appears to
1263		# be built atop SIOCGLIFCONF; using it directly
1264		# avoids a not-all-that-useful middleman.)
1265		#
1266		AC_MSG_CHECKING(whether we have SIOCGLIFCONF)
1267		AC_CACHE_VAL(ac_cv_lbl_have_siocglifconf,
1268		    AC_TRY_COMPILE(
1269			[#include <sys/param.h>
1270			#include <sys/file.h>
1271			#include <sys/ioctl.h>
1272			#include <sys/socket.h>
1273			#include <sys/sockio.h>],
1274			[ioctl(0, SIOCGLIFCONF, (char *)0);],
1275			ac_cv_lbl_have_siocglifconf=yes,
1276			ac_cv_lbl_have_siocglifconf=no))
1277		AC_MSG_RESULT($ac_cv_lbl_have_siocglifconf)
1278		if test $ac_cv_lbl_have_siocglifconf = yes ; then
1279			PLATFORM_C_SRC="$PLATFORM_C_SRC fad-glifc.c"
1280		else
1281			PLATFORM_C_SRC="$PLATFORM_C_SRC fad-gifc.c"
1282		fi
1283	])
1284fi
1285
1286dnl check for hardware timestamp support
1287case "$host_os" in
1288linux*)
1289	AC_CHECK_HEADERS([linux/net_tstamp.h])
1290	;;
1291*)
1292	AC_MSG_NOTICE(no hardware timestamp support implemented for $host_os)
1293	;;
1294esac
1295
1296#
1297# Check for socklen_t.
1298#
1299AC_CHECK_TYPES(socklen_t,,,
1300    [
1301	#include <sys/types.h>
1302	#include <sys/socket.h>
1303    ])
1304
1305AC_ARG_ENABLE(ipv6,
1306AS_HELP_STRING([--enable-ipv6],[build IPv6-capable version @<:@default=yes@:>@]),
1307    [],
1308    [enable_ipv6=yes])
1309if test "$enable_ipv6" != "no"; then
1310	#
1311	# We've already made sure we have getaddrinfo above in
1312	# AC_LBL_LIBRARY_NET.
1313	#
1314	AC_DEFINE(INET6,1,[IPv6])
1315fi
1316
1317# Check for Endace DAG card support.
1318AC_ARG_WITH([dag],
1319AS_HELP_STRING([--with-dag@<:@=DIR@:>@],[include Endace DAG support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1320[
1321	if test "$withval" = no
1322	then
1323		# User doesn't want DAG support.
1324		want_dag=no
1325	elif test "$withval" = yes
1326	then
1327		# User wants DAG support but hasn't specified a directory.
1328		want_dag=yes
1329	else
1330		# User wants DAG support and has specified a directory, so use the provided value.
1331		want_dag=yes
1332		dag_root=$withval
1333	fi
1334],[
1335	if test "$V_PCAP" = dag; then
1336		# User requested DAG-only libpcap, so we'd better have
1337		# the DAG API.
1338		want_dag=yes
1339	elif test "xxx_only" = yes; then
1340		# User requested something-else-only pcap, so they don't
1341		# want DAG support.
1342		want_dag=no
1343	else
1344		#
1345		# Use DAG API if present, otherwise don't
1346		#
1347		want_dag=ifpresent
1348	fi
1349])
1350
1351AC_ARG_WITH([dag-includes],
1352AS_HELP_STRING([--with-dag-includes=IDIR],[Endace DAG include directory, if not DIR/include]),
1353[
1354	# User wants DAG support and has specified a header directory, so use the provided value.
1355	want_dag=yes
1356	dag_include_dir=$withval
1357],[])
1358
1359AC_ARG_WITH([dag-libraries],
1360AS_HELP_STRING([--with-dag-libraries=LDIR],[Endace DAG library directory, if not DIR/lib]),
1361[
1362	# User wants DAG support and has specified a library directory, so use the provided value.
1363	want_dag=yes
1364	dag_lib_dir=$withval
1365],[])
1366
1367if test "$want_dag" != no; then
1368
1369	# If necessary, set default paths for DAG API headers and libraries.
1370	if test -z "$dag_root"; then
1371		dag_root=/usr/local
1372	fi
1373
1374	if test -z "$dag_include_dir"; then
1375		dag_include_dir="$dag_root/include"
1376	fi
1377
1378	if test -z "$dag_lib_dir"; then
1379		dag_lib_dir="$dag_root/lib"
1380		#
1381		# Handle multiarch systems.
1382		#
1383		if test -d "$dag_lib_dir/$host"
1384		then
1385			dag_lib_dir="$dag_lib_dir/$host"
1386		fi
1387	fi
1388
1389	AC_LBL_SAVE_CHECK_STATE
1390	CFLAGS="$CFLAGS -I$dag_include_dir"
1391	AC_CHECK_HEADERS([dagapi.h])
1392	AC_LBL_RESTORE_CHECK_STATE
1393
1394	if test "$ac_cv_header_dagapi_h" = yes; then
1395
1396		V_INCLS="$V_INCLS -I$dag_include_dir"
1397
1398		if test $V_PCAP != dag ; then
1399			 MODULE_C_SRC="$MODULE_C_SRC pcap-dag.c"
1400		fi
1401
1402		# Check for various DAG API functions.
1403		# Don't need to save and restore LIBS to prevent -ldag being
1404		# included if there's a found-action (arg 3).
1405		AC_LBL_SAVE_CHECK_STATE
1406		LDFLAGS="-L$dag_lib_dir"
1407		AC_CHECK_LIB([dag], [dag_attach_stream],
1408		    [
1409			#
1410			# We assume that if we have libdag we have
1411			# libdagconf, as they're installed at the
1412			# same time from the same package.
1413			#
1414			ADDITIONAL_LIBS="-L$dag_lib_dir $ADDITIONAL_LIBS -ldag -ldagconf"
1415			ADDITIONAL_LIBS_STATIC="-L$dag_lib_dir $ADDITIONAL_LIBS_STATIC -ldag -ldagconf"
1416			LIBS_PRIVATE="-L$dag_lib_dir $LIBS_PRIVATE -ldag -ldagconf"
1417		    ],
1418		    [AC_MSG_ERROR(DAG library lacks streams support)])
1419		AC_CHECK_LIB([dag], [dag_attach_stream64], [dag_large_streams="1"], [dag_large_streams="0"])
1420		AC_CHECK_LIB([dag],[dag_get_erf_types], [
1421			AC_DEFINE(HAVE_DAG_GET_ERF_TYPES, 1, [define if you have dag_get_erf_types()])])
1422		AC_CHECK_LIB([dag],[dag_get_stream_erf_types], [
1423			AC_DEFINE(HAVE_DAG_GET_STREAM_ERF_TYPES, 1, [define if you have dag_get_stream_erf_types()])])
1424		AC_LBL_RESTORE_CHECK_STATE
1425
1426		#
1427		# We assume that if we have libdag we have libdagconf,
1428		# as they're installed at the same time from the same
1429		# package.
1430		#
1431		if test "$dag_large_streams" = 1; then
1432			AC_DEFINE(HAVE_DAG_LARGE_STREAMS_API, 1, [define if you have large streams capable DAG API])
1433			AC_LBL_SAVE_CHECK_STATE
1434			LIBS="$LIBS -ldag -ldagconf"
1435			LDFLAGS="$LDFLAGS -L$dag_lib_dir"
1436			AC_CHECK_LIB([vdag],[vdag_set_device_info], [ac_dag_have_vdag="1"], [ac_dag_have_vdag="0"])
1437			AC_LBL_RESTORE_CHECK_STATE
1438			if test "$ac_dag_have_vdag" = 1; then
1439				AC_DEFINE(HAVE_DAG_VDAG, 1, [define if you have vdag_set_device_info()])
1440				if test "$ac_lbl_have_pthreads" != "found"; then
1441					AC_MSG_ERROR([DAG requires pthreads, but we didn't find them])
1442				fi
1443				ADDITIONAL_LIBS="$ADDITIONAL_LIBS $PTHREAD_LIBS"
1444				ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $PTHREAD_LIBS"
1445				LIBS_PRIVATE="$LIBS_PRIVATE $PTHREAD_LIBS"
1446			fi
1447		fi
1448
1449		AC_DEFINE(HAVE_DAG_API, 1, [define if you have the DAG API])
1450	else
1451		if test "$V_PCAP" = dag; then
1452			# User requested "dag" capture type but we couldn't
1453			# find the DAG API support.
1454			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])
1455		fi
1456
1457		if test "$want_dag" = yes; then
1458			# User wanted DAG support but we couldn't find it.
1459			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])
1460		fi
1461	fi
1462	CFLAGS="$save_CFLAGS"
1463fi
1464
1465AC_ARG_WITH(septel,
1466AS_HELP_STRING([--with-septel@<:@=DIR@:>@],[include Septel support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1467[
1468	if test "$withval" = no
1469	then
1470		want_septel=no
1471	elif test "$withval" = yes
1472	then
1473		want_septel=yes
1474		septel_root=
1475	else
1476		want_septel=yes
1477		septel_root=$withval
1478	fi
1479],[
1480	if test "$V_PCAP" = septel; then
1481		# User requested Septel-only libpcap, so we'd better have
1482		# the Septel API.
1483		want_septel=yes
1484	elif test "xxx_only" = yes; then
1485		# User requested something-else-only pcap, so they don't
1486		# want Septel support.
1487		want_septel=no
1488	else
1489		#
1490		# Use Septel API if present, otherwise don't
1491		#
1492		want_septel=ifpresent
1493	fi
1494])
1495
1496ac_cv_lbl_septel_api=no
1497if test "$with_septel" != no; then
1498
1499	AC_MSG_CHECKING([whether we have Septel API headers])
1500
1501	# If necessary, set default paths for Septel API headers and libraries.
1502	if test -z "$septel_root"; then
1503		septel_root=$srcdir/../septel
1504	fi
1505
1506	septel_tools_dir="$septel_root"
1507	septel_include_dir="$septel_root/INC"
1508
1509	if test -r "$septel_include_dir/msg.h"; then
1510		ac_cv_lbl_septel_api=yes
1511	fi
1512
1513	if test "$ac_cv_lbl_septel_api" = yes; then
1514		AC_MSG_RESULT([yes ($septel_include_dir)])
1515
1516		V_INCLS="$V_INCLS -I$septel_include_dir"
1517		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"
1518		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"
1519
1520		if test "$V_PCAP" != septel ; then
1521			 MODULE_C_SRC="$MODULE_C_SRC pcap-septel.c"
1522		fi
1523
1524		AC_DEFINE(HAVE_SEPTEL_API, 1, [define if you have the Septel API])
1525	else
1526		AC_MSG_RESULT(no)
1527
1528		if test "$V_PCAP" = septel; then
1529			# User requested "septel" capture type but
1530			# we couldn't find the Septel API support.
1531			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])
1532		fi
1533
1534		if test "$want_septel" = yes; then
1535			# User wanted Septel support but we couldn't find it.
1536			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])
1537		fi
1538	fi
1539fi
1540
1541# Check for Myricom SNF support.
1542AC_ARG_WITH([snf],
1543AS_HELP_STRING([--with-snf@<:@=DIR@:>@],[include Myricom SNF support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1544[
1545	if test "$withval" = no
1546	then
1547		# User explicitly doesn't want SNF
1548		want_snf=no
1549	elif test "$withval" = yes
1550	then
1551		# User wants SNF support but hasn't specified a directory.
1552		want_snf=yes
1553	else
1554		# User wants SNF support with a specified directory.
1555		want_snf=yes
1556		snf_root=$withval
1557	fi
1558],[
1559	if test "$V_PCAP" = snf; then
1560		# User requested Sniffer-only libpcap, so we'd better have
1561		# the Sniffer API.
1562		want_snf=yes
1563	elif test "xxx_only" = yes; then
1564		# User requested something-else-only pcap, so they don't
1565		# want SNF support.
1566		want_snf=no
1567	else
1568		#
1569		# Use Sniffer API if present, otherwise don't
1570		#
1571		want_snf=ifpresent
1572	fi
1573])
1574
1575AC_ARG_WITH([snf-includes],
1576AS_HELP_STRING([--with-snf-includes=IDIR],[Myricom SNF include directory, if not DIR/include]),
1577[
1578	# User wants SNF with specific header directory
1579	want_snf=yes
1580	snf_include_dir=$withval
1581],[])
1582
1583AC_ARG_WITH([snf-libraries],
1584AS_HELP_STRING([--with-snf-libraries=LDIR],[Myricom SNF library directory, if not DIR/lib]),
1585[
1586	# User wants SNF with specific lib directory
1587	want_snf=yes
1588	snf_lib_dir=$withval
1589],[])
1590
1591ac_cv_lbl_snf_api=no
1592if test "$with_snf" != no; then
1593
1594	AC_MSG_CHECKING(whether we have Myricom Sniffer API)
1595
1596	# If necessary, set default paths for Sniffer headers and libraries.
1597	if test -z "$snf_root"; then
1598		snf_root=/opt/snf
1599	fi
1600
1601	if test -z "$snf_include_dir"; then
1602		snf_include_dir="$snf_root/include"
1603	fi
1604
1605	if test -z "$snf_lib_dir"; then
1606		snf_lib_dir="$snf_root/lib"
1607		#
1608		# Handle multiarch systems.
1609		#
1610		if test -d "$snf_lib_dir/$host"
1611		then
1612			snf_lib_dir="$snf_lib_dir/$host"
1613		fi
1614	fi
1615
1616	if test -f "$snf_include_dir/snf.h"; then
1617		# We found a header; make sure we can link with the library
1618		AC_LBL_SAVE_CHECK_STATE
1619		LDFLAGS="$LDFLAGS -L$snf_lib_dir"
1620		AC_CHECK_LIB([snf], [snf_init], [ac_cv_lbl_snf_api="yes"])
1621		AC_LBL_RESTORE_CHECK_STATE
1622		if test "$ac_cv_lbl_snf_api" = no; then
1623			AC_MSG_ERROR(SNF API cannot correctly be linked; check config.log)
1624		fi
1625	fi
1626
1627	if test "$ac_cv_lbl_snf_api" = yes; then
1628		AC_MSG_RESULT([yes ($snf_root)])
1629
1630		V_INCLS="$V_INCLS -I$snf_include_dir"
1631		ADDITIONAL_LIBS="$ADDITIONAL_LIBS -L$snf_lib_dir -lsnf"
1632		ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC -L$snf_lib_dir -lsnf"
1633		LIBS_PRIVATE="$LIBS_PRIVATE -L$snf_lib_dir -lsnf"
1634
1635		if test "$V_PCAP" != snf ; then
1636			MODULE_C_SRC="$MODULE_C_SRC pcap-snf.c"
1637		fi
1638
1639		AC_DEFINE(HAVE_SNF_API, 1, [define if you have the Myricom SNF API])
1640	else
1641		AC_MSG_RESULT(no)
1642
1643		if test "$want_snf" = yes; then
1644			# User requested "snf" capture type but
1645			# we couldn't find the Sniffer API support.
1646			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])
1647		fi
1648
1649		if test "$want_snf" = yes; then
1650			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])
1651		fi
1652	fi
1653fi
1654
1655# Check for Riverbed TurboCap support.
1656AC_ARG_WITH([turbocap],
1657AS_HELP_STRING([--with-turbocap@<:@=DIR@:>@],[include Riverbed TurboCap support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1658[
1659	if test "$withval" = no
1660	then
1661		# User explicitly doesn't want TurboCap
1662		want_turbocap=no
1663	elif test "$withval" = yes
1664	then
1665		# User wants TurboCap support but hasn't specified a directory.
1666		want_turbocap=yes
1667	else
1668		# User wants TurboCap support with a specified directory.
1669		want_turbocap=yes
1670		turbocap_root=$withval
1671	fi
1672],[
1673	if test "xxx_only" = yes; then
1674		# User requested something-else-only pcap, so they don't
1675		# want TurboCap support.
1676		want_turbocap=no
1677	else
1678		#
1679		# Use TurboCap API if present, otherwise don't
1680		#
1681		want_turbocap=ifpresent
1682	fi
1683])
1684
1685ac_cv_lbl_turbocap_api=no
1686if test "$want_turbocap" != no; then
1687
1688	AC_MSG_CHECKING(whether TurboCap is supported)
1689
1690	AC_LBL_SAVE_CHECK_STATE
1691	if test ! -z "$turbocap_root"; then
1692		TURBOCAP_CFLAGS="-I$turbocap_root/include"
1693		TURBOCAP_LDFLAGS="-L$turbocap_root/lib"
1694		CFLAGS="$CFLAGS $TURBOCAP_CFLAGS"
1695		LDFLAGS="$LDFLAGS $TURBOCAP_LDFLAGS"
1696	fi
1697
1698	AC_TRY_COMPILE(
1699	[
1700	    #include <TcApi.h>
1701	],
1702	[
1703	    TC_INSTANCE a; TC_PORT b; TC_BOARD c;
1704	    TC_INSTANCE i;
1705	    (void)TcInstanceCreateByName("foo", &i);
1706	],
1707	ac_cv_lbl_turbocap_api=yes)
1708
1709	AC_LBL_RESTORE_CHECK_STATE
1710	if test $ac_cv_lbl_turbocap_api = yes; then
1711		AC_MSG_RESULT(yes)
1712
1713		MODULE_C_SRC="$MODULE_C_SRC pcap-tc.c"
1714		V_INCLS="$V_INCLS $TURBOCAP_CFLAGS"
1715		ADDITIONAL_LIBS="$ADDITIONAL_LIBS $TURBOCAP_LDFLAGS -lTcApi -lpthread -lstdc++"
1716		ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $TURBOCAP_LDFLAGS -lTcApi -lpthread -lstdc++"
1717		LIBS_PRIVATE="$LIBS_PRIVATE $TURBOCAP_LDFLAGS -lTcApi -lpthread -lstdc++"
1718
1719		AC_DEFINE(HAVE_TC_API, 1, [define if you have the TurboCap API])
1720	else
1721		AC_MSG_RESULT(no)
1722
1723		if test "$want_turbocap" = yes; then
1724			# User wanted Turbo support but we couldn't find it.
1725			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])
1726		fi
1727	fi
1728fi
1729
1730dnl
1731dnl Allow the user to enable remote capture.
1732dnl It's off by default, as that increases the attack surface of
1733dnl libpcap, exposing it to malicious servers.
1734dnl
1735AC_MSG_CHECKING([whether to enable remote packet capture])
1736AC_ARG_ENABLE([remote],
1737   [AS_HELP_STRING([--enable-remote],
1738     [enable remote packet capture @<:@default=no@:>@])],
1739   [],
1740   [enableval=no])
1741case "$enableval" in
1742yes)	AC_MSG_RESULT(yes)
1743	AC_WARN([Remote packet capture may expose libpcap-based applications])
1744	AC_WARN([to attacks by malicious remote capture servers!])
1745	#
1746	# rpcapd requires pthreads on UN*X.
1747	#
1748	if test "$ac_lbl_have_pthreads" != "found"; then
1749		AC_MSG_ERROR([rpcapd requires pthreads, but we didn't find them])
1750	fi
1751	#
1752	# It also requires crypt().
1753	# Do we have it in the system libraries?
1754	#
1755	AC_CHECK_FUNC(crypt,,
1756	    [
1757		#
1758		# No.  Do we have it in -lcrypt?
1759		#
1760		AC_CHECK_LIB(crypt, crypt,
1761		    [
1762			#
1763			# Yes; add -lcrypt to the libraries for rpcapd.
1764			#
1765			RPCAPD_LIBS="$RPCAPD_LIBS -lcrypt"
1766		    ],
1767		    [
1768			AC_MSG_ERROR([rpcapd requires crypt(), but we didn't find it])
1769		    ])
1770	    ])
1771
1772	#
1773	# OK, we have crypt().  Do we have getspnam()?
1774	#
1775	AC_CHECK_FUNCS(getspnam)
1776
1777	#
1778	# Check for various members of struct msghdr.
1779	#
1780	AC_CHECK_MEMBERS([struct msghdr.msg_control],,,
1781	    [
1782		#include "ftmacros.h"
1783		#include <sys/socket.h>
1784	    ])
1785	AC_CHECK_MEMBERS([struct msghdr.msg_flags],,,
1786	    [
1787		#include "ftmacros.h"
1788		#include <sys/socket.h>
1789	    ])
1790
1791	#
1792	# Optionally, we may want to support SSL.
1793	# Check for OpenSSL/libressl.
1794	#
1795	# First, try looking for it with pkg-config, if we have it.
1796	#
1797	# Homebrew's pkg-config does not, by default, look for
1798	# pkg-config files for packages it has installed.
1799	# Furthermore, at least for OpenSSL, they appear to be
1800	# dumped in package-specific directories whose paths are
1801	# not only package-specific but package-version-specific.
1802	#
1803	# So the only way to find openssl is to get the value of
1804	# PKG_CONFIG_PATH from "brew --env openssl" and add that
1805	# to PKG_CONFIG_PATH.  (No, we can't just assume it's under
1806	# /usr/local; Homebrew have conveniently chosen to put it
1807	# under /opt/homebrew on ARM.)
1808	#
1809	# That's the nice thing about Homebrew - it makes things easier!
1810	# Thanks!
1811	#
1812	save_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
1813	if test -n "$BREW"; then
1814		openssl_pkgconfig_dir=`$BREW --env --plain openssl | sed -n 's/PKG_CONFIG_PATH: //p'`
1815		PKG_CONFIG_PATH="$openssl_pkgconfig_dir:$PKG_CONFIG_PATH"
1816	fi
1817	PKG_CHECK_MODULE(OPENSSL, openssl,
1818	    [
1819		#
1820		# We found OpenSSL/libressl.
1821		#
1822		HAVE_OPENSSL=yes
1823		REQUIRES_PRIVATE="$REQUIRES_PRIVATE openssl"
1824	    ])
1825	PKG_CONFIG_PATH="$save_PKG_CONFIG_PATH"
1826
1827	#
1828	# If it wasn't found, and we have Homebrew installed, see
1829	# if it's in Homebrew.
1830	#
1831	if test "x$HAVE_OPENSSL" != "xyes" -a -n "$BREW"; then
1832		AC_MSG_CHECKING(for openssl in Homebrew)
1833		#
1834		# The brew man page lies when it speaks of
1835		# $BREW --prefix --installed <formula>
1836		# outputting nothing.  In Homebrew 3.3.16,
1837		# it produces output regardless of whether
1838		# the formula is installed or not, so we
1839		# send the standard output and error to
1840		# the bit bucket.
1841		#
1842		if $BREW --prefix --installed openssl >/dev/null 2>&1; then
1843			#
1844			# Yes.  Get the include directory and library
1845			# directory.  (No, we can't just assume it's
1846			# under /usr/local; Homebrew have conveniently
1847			# chosen to put it under /opt/homebrew on ARM.)
1848			#
1849			AC_MSG_RESULT(yes)
1850			HAVE_OPENSSL=yes
1851			openssl_path=`$BREW --prefix openssl`
1852			OPENSSL_CFLAGS="-I$openssl_path/include"
1853			OPENSSL_LIBS="-L$openssl_path/lib -lssl -lcrypto"
1854			OPENSSL_LIBS_STATIC="-L$openssl_path/lib -lssl -lcrypto"
1855			OPENSSL_LIBS_PRIVATE="-L$openssl_path/lib -lssl -lcrypto"
1856		else
1857			AC_MSG_RESULT(no)
1858		fi
1859	fi
1860
1861	#
1862	# If it wasn't found, and /usr/local/include and /usr/local/lib
1863	# exist, check if it's in /usr/local.  (We check whether they
1864	# exist because, if they don't exist, the compiler will warn
1865	# about that and then ignore the argument, so they test
1866	# using just the system header files and libraries.)
1867	#
1868	# We include the standard include file to 1) make sure that
1869	# it's installed (if it's just a shared library for the
1870	# benefit of existing programs, that's not useful) and 2)
1871	# because SSL_library_init() is a library routine in some
1872	# versions and a #defined wrapper around OPENSSL_init_ssl()
1873	# in others.
1874	#
1875	if test "x$HAVE_OPENSSL" != "xyes" -a -d "/usr/local/include" -a -d "/usr/local/lib"; then
1876		AC_LBL_SAVE_CHECK_STATE
1877		CFLAGS="$CFLAGS -I/usr/local/include"
1878		LIBS="$LIBS -L/usr/local/lib -lssl -lcrypto"
1879		AC_MSG_CHECKING(whether we have OpenSSL/libressl in /usr/local that we can use)
1880		AC_TRY_LINK(
1881		    [
1882#include <openssl/ssl.h>
1883		    ],
1884		    [
1885SSL_library_init();
1886return 0;
1887		    ],
1888		    [
1889			AC_MSG_RESULT(yes)
1890			HAVE_OPENSSL=yes
1891			OPENSSL_CFLAGS="-I/usr/local/include"
1892			OPENSSL_LIBS="-L/usr/local/lib -lssl -lcrypto"
1893			OPENSSL_LIBS_STATIC="-L/usr/local/lib -lssl -lcrypto"
1894			OPENSSL_LIBS_PRIVATE="-L/usr/local/lib -lssl -lcrypto"
1895		    ],
1896		    AC_MSG_RESULT(no))
1897		AC_LBL_RESTORE_CHECK_STATE
1898	fi
1899
1900	#
1901	# If it wasn't found, check if it's a system library.
1902	#
1903	# We include the standard include file to 1) make sure that
1904	# it's installed (if it's just a shared library for the
1905	# benefit of existing programs, that's not useful) and 2)
1906	# because SSL_library_init() is a library routine in some
1907	# versions and a #defined wrapper around OPENSSL_init_ssl()
1908	# in others.
1909	#
1910	if test "x$HAVE_OPENSSL" != "xyes"; then
1911		AC_LBL_SAVE_CHECK_STATE
1912		LIBS="$LIBS -lssl -lcrypto"
1913		AC_MSG_CHECKING(whether we have a system OpenSSL/libressl that we can use)
1914		AC_TRY_LINK(
1915		    [
1916#include <openssl/ssl.h>
1917		    ],
1918		    [
1919SSL_library_init();
1920return 0;
1921		    ],
1922		    [
1923			AC_MSG_RESULT(yes)
1924			HAVE_OPENSSL=yes
1925			OPENSSL_LIBS="-lssl -lcrypto"
1926			OPENSSL_LIBS_STATIC="-lssl -lcrypto"
1927			OPENSSL_LIBS_PRIVATE="-lssl -lcrypto"
1928		    ],
1929		    AC_MSG_RESULT(no))
1930		AC_LBL_RESTORE_CHECK_STATE
1931	fi
1932
1933	#
1934	# OK, did we find it?
1935	#
1936	if test "x$HAVE_OPENSSL" = "xyes"; then
1937		AC_DEFINE([HAVE_OPENSSL], [1], [Use OpenSSL])
1938		V_INCLS="$V_INCLS $OPENSSL_CFLAGS"
1939		ADDITIONAL_LIBS="$ADDITIONAL_LIBS $OPENSSL_LIBS"
1940		ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $OPENSSL_LIBS_STATIC"
1941		LIBS_PRIVATE="$LIBS_PRIVATE $OPENSSL_LIBS_PRIVATE"
1942		REQUIRES_PRIVATE="$REQUIRES_PRIVATE $OPENSSL_REQUIRES_PRIVATE"
1943		REMOTE_C_SRC="$REMOTE_C_SRC sslutils.c"
1944	else
1945		AC_MSG_NOTICE(OpenSSL not found)
1946	fi
1947
1948	AC_DEFINE(ENABLE_REMOTE,,
1949	    [Define to 1 if remote packet capture is to be supported])
1950	REMOTE_C_SRC="$REMOTE_C_SRC pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c"
1951	BUILD_RPCAPD=build-rpcapd
1952	INSTALL_RPCAPD=install-rpcapd
1953	;;
1954*)	AC_MSG_RESULT(no)
1955	;;
1956esac
1957
1958AC_MSG_CHECKING(whether to build optimizer debugging code)
1959AC_ARG_ENABLE(optimizer-dbg,
1960AS_HELP_STRING([--enable-optimizer-dbg],[build optimizer debugging code]))
1961if test "$enable_optimizer_dbg" = "yes"; then
1962	AC_DEFINE(BDEBUG,1,[Enable optimizer debugging])
1963fi
1964AC_MSG_RESULT(${enable_optimizer_dbg-no})
1965
1966AC_MSG_CHECKING(whether to build parser debugging code)
1967AC_ARG_ENABLE(yydebug,
1968AS_HELP_STRING([--enable-yydebug],[build parser debugging code]))
1969if test "$enable_yydebug" = "yes"; then
1970	AC_DEFINE(YYDEBUG,1,[Enable parser debugging])
1971fi
1972AC_MSG_RESULT(${enable_yydebug-no})
1973
1974#
1975# Look for {f}lex.
1976#
1977AC_PROG_LEX
1978if test "$LEX" = ":"; then
1979	AC_MSG_ERROR([Neither flex nor lex was found.])
1980fi
1981
1982#
1983# Make sure {f}lex supports the -P, --header-file, and --nounput flags
1984# and supports processing our scanner.l.
1985#
1986AC_CACHE_CHECK([for capable lex], tcpdump_cv_capable_lex,
1987	if $LEX -P pcap_ --header-file=/dev/null --nounput -t $srcdir/scanner.l > /dev/null 2>&1; then
1988	    tcpdump_cv_capable_lex=yes
1989	else
1990	    tcpdump_cv_capable_lex=insufficient
1991	fi)
1992if test $tcpdump_cv_capable_lex = insufficient ; then
1993	AC_MSG_ERROR([$LEX is insufficient to compile libpcap.
1994 libpcap requires Flex 2.5.31 or later, or a compatible version of lex.
1995 If a suitable version of Lex/Flex is available as a non-standard command
1996 and/or not in the PATH, you can specify it using the LEX environment
1997 variable. That said, on some systems the error can mean that Flex/Lex is
1998 actually acceptable, but m4 is not. Likewise, if a suitable version of
1999 m4 (such as GNU M4) is available but has not been detected, you can
2000 specify it using the M4 environment variable.])
2001fi
2002
2003#
2004# Look for yacc/bison/byacc.
2005# If it's Bison, we do not want -y, as 1) we will be using -o to cause
2006# the output for XXX.y to be written to XXX.c and 2) we don't want
2007# it to issue warnings about stuff not supported by POSIX YACC - we
2008# want to use that stuff, and don't care whether plain YACC supports
2009# it or not, we require either Bison or Berkeley YACC.
2010#
2011BISON_BYACC=""
2012#
2013# Look for Bison.
2014#
2015AC_CHECK_PROGS(BISON_BYACC, bison)
2016if test x"$BISON_BYACC" != x; then
2017	#
2018	# We found Bison.
2019	#
2020	# Bison prior to 2.4(.1) doesn't support "%define api.pure", so use
2021	# "%pure-parser".
2022	#
2023	bison_major_version=`$BISON_BYACC -V | sed -n 's/.* \(@<:@1-9@:>@@<:@0-9@:>@*\)\.@<:@0-9@:>@@<:@0-9.@:>@*/\1/p'`
2024	bison_minor_version=`$BISON_BYACC -V | sed -n 's/.* @<:@1-9@:>@@<:@0-9@:>@*\.\(@<:@0-9@:>@+\).*/\1/p'`
2025	if test "$bison_major_version" -lt 2 -o \
2026	    \( "$bison_major_version" -eq 2 -a "$bison_major_version" -lt 4 \)
2027	then
2028		REENTRANT_PARSER="%pure-parser"
2029	else
2030		REENTRANT_PARSER="%define api.pure"
2031	fi
2032else
2033	#
2034	# We didn't find Bison; check for Berkeley YACC, under the
2035	# names byacc and yacc.
2036	#
2037	AC_CHECK_PROGS(BISON_BYACC, byacc yacc)
2038	if test x"$BISON_BYACC" != x; then
2039		#
2040		# Make sure this is Berkeley YACC, not AT&T YACC;
2041		# the latter doesn't support reentrant parsers.
2042		# Run it with "-V"; that succeeds and reports the
2043		# version number with Berkeley YACC, but will
2044		# (probably) fail with various vendor flavors
2045		# of AT&T YACC.
2046		#
2047		# Hopefully this also eliminates any versions
2048		# of Berkeley YACC that don't support reentrant
2049		# parsers, if there are any.
2050		#
2051		AC_CACHE_CHECK([for capable yacc], tcpdump_cv_capable_yacc,
2052		    if $BISON_BYACC -V >/dev/null 2>&1; then
2053			tcpdump_cv_capable_yacc=yes
2054		    else
2055			tcpdump_cv_capable_yacc=insufficient
2056		    fi)
2057		if test $tcpdump_cv_capable_yacc = insufficient ; then
2058		    AC_MSG_ERROR([$BISON_BYACC is insufficient to compile libpcap.
2059 libpcap requires Bison, a newer version of Berkeley YACC with support
2060 for reentrant parsers, or another YACC compatible with them.])
2061		fi
2062	else
2063		#
2064		# OK, we found neither byacc nor yacc.
2065		#
2066		AC_MSG_ERROR([Neither bison, byacc, nor yacc was found.
2067 libpcap requires Bison, a newer version of Berkeley YACC with support
2068 for reentrant parsers, or another YACC compatible with them.])
2069	fi
2070
2071	#
2072	# Berkeley YACC doesn't support "%define api.pure", so use
2073	# "%pure-parser".
2074	#
2075	REENTRANT_PARSER="%pure-parser"
2076fi
2077AC_SUBST(BISON_BYACC)
2078AC_SUBST(REENTRANT_PARSER)
2079
2080#
2081# Do various checks for various OSes and versions of those OSes.
2082#
2083# Assume, by default, no support for shared libraries and V7/BSD
2084# convention for man pages (devices in section 4, file formats in
2085# section 5, miscellaneous info in section 7, administrative commands
2086# and daemons in section 8).  Individual cases can override this.
2087#
2088DYEXT="none"
2089MAN_DEVICES=4
2090MAN_FILE_FORMATS=5
2091MAN_MISC_INFO=7
2092MAN_ADMIN_COMMANDS=8
2093case "$host_os" in
2094
2095aix*)
2096	dnl Workaround to enable certain features
2097	AC_DEFINE(_SUN,1,[define on AIX to get certain functions])
2098
2099	#
2100	# AIX makes it fun to build shared and static libraries,
2101	# because they're *both* ".a" archive libraries.  We
2102	# build the static library for the benefit of the traditional
2103	# scheme of building libpcap and tcpdump in subdirectories of
2104	# the same directory, with tcpdump statically linked with the
2105	# libpcap in question, but we also build a shared library as
2106	# "libpcap.shareda" and install *it*, rather than the static
2107	# library, as "libpcap.a".
2108	#
2109	DYEXT="shareda"
2110
2111	case "$V_PCAP" in
2112
2113	dlpi)
2114		#
2115		# If we're using DLPI, applications will need to
2116		# use /lib/pse.exp if present, as we use the
2117		# STREAMS routines.
2118		#
2119		pseexe="/lib/pse.exp"
2120		AC_MSG_CHECKING(for $pseexe)
2121		if test -f $pseexe ; then
2122			AC_MSG_RESULT(yes)
2123			LIBS="-I:$pseexe"
2124		fi
2125		;;
2126
2127	bpf)
2128		#
2129		# If we're using BPF, we need "-lodm" and "-lcfg", as
2130		# we use them to load the BPF module.
2131		#
2132		LIBS="-lodm -lcfg"
2133		;;
2134	esac
2135	;;
2136
2137darwin*)
2138	DYEXT="dylib"
2139	V_CCOPT="$V_CCOPT -fno-common"
2140	AC_ARG_ENABLE(universal,
2141	AS_HELP_STRING([--disable-universal],[don't build universal on macOS]))
2142	if test "$enable_universal" != "no"; then
2143		case "$host_os" in
2144
2145		darwin[[0-7]].*)
2146			#
2147			# Pre-Tiger.  Build only for 32-bit PowerPC; no
2148			# need for any special compiler or linker flags.
2149			#
2150			;;
2151
2152		darwin8.[[0123]]|darwin8.[[0123]].*)
2153			#
2154			# Tiger, prior to Intel support.  Build
2155			# libraries and executables for 32-bit PowerPC
2156			# and 64-bit PowerPC, with 32-bit PowerPC first.
2157			# (I'm guessing that's what Apple does.)
2158			#
2159			# (The double brackets are needed because
2160			# autotools/m4 use brackets as a quoting
2161			# character; the double brackets turn into
2162			# single brackets in the generated configure
2163			# file.)
2164			#
2165			V_LIB_CCOPT_FAT="-arch ppc -arch ppc64"
2166			V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64"
2167			V_PROG_CCOPT_FAT="-arch ppc -arch ppc64"
2168			V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64"
2169			;;
2170
2171		darwin8.[[456]]|darwin8.[[456]].*)
2172			#
2173			# Tiger, subsequent to Intel support but prior
2174			# to x86-64 support.  Build libraries and
2175			# executables for 32-bit PowerPC, 64-bit
2176			# PowerPC, and 32-bit x86, with 32-bit PowerPC
2177			# first.  (I'm guessing that's what Apple does.)
2178			#
2179			# (The double brackets are needed because
2180			# autotools/m4 use brackets as a quoting
2181			# character; the double brackets turn into
2182			# single brackets in the generated configure
2183			# file.)
2184			#
2185			V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386"
2186			V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386"
2187			V_PROG_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386"
2188			V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386"
2189			;;
2190
2191		darwin8.*)
2192			#
2193			# All other Tiger, so subsequent to x86-64
2194			# support.  Build libraries and executables for
2195			# 32-bit PowerPC, 64-bit PowerPC, 32-bit x86,
2196			# and x86-64, with 32-bit PowerPC first.  (I'm
2197			# guessing that's what Apple does.)
2198			#
2199			V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2200			V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2201			V_PROG_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2202			V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2203			;;
2204
2205		darwin9.*)
2206			#
2207			# Leopard.  Build libraries for 32-bit PowerPC,
2208			# 64-bit PowerPC, 32-bit x86, and x86-64, with
2209			# 32-bit PowerPC first, and build executables
2210			# for 32-bit x86 and 32-bit PowerPC, with 32-bit
2211			# x86 first.  (That's what Apple does.)
2212			#
2213			V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2214			V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64"
2215			V_PROG_CCOPT_FAT="-arch i386 -arch ppc"
2216			V_PROG_LDFLAGS_FAT="-arch i386 -arch ppc"
2217			;;
2218
2219		darwin10.*)
2220			#
2221			# Snow Leopard.  Build libraries for x86-64,
2222			# 32-bit x86, and 32-bit PowerPC, with x86-64
2223			# first, and build executables for x86-64 and
2224			# 32-bit x86, with x86-64 first.  (That's what
2225			# Apple does, even though Snow Leopard doesn't
2226			# run on PPC, so PPC libpcap runs under Rosetta,
2227			# and Rosetta doesn't support BPF ioctls, so PPC
2228			# programs can't do live captures.)
2229			#
2230			V_LIB_CCOPT_FAT="-arch x86_64 -arch i386 -arch ppc"
2231			V_LIB_LDFLAGS_FAT="-arch x86_64 -arch i386 -arch ppc"
2232			V_PROG_CCOPT_FAT="-arch x86_64 -arch i386"
2233			V_PROG_LDFLAGS_FAT="-arch x86_64 -arch i386"
2234			;;
2235
2236		darwin1[[1-8]]*)
2237			#
2238			# Post-Snow Leopard, pre-Catalina.  Build
2239			# libraries for x86-64 and 32-bit x86, with
2240			# x86-64 first, and build executables only for
2241			# x86-64.  (That's what Apple does.)  This
2242			# requires no special flags for programs.
2243			#
2244			# We check whether we *can* build for i386 and,
2245			# if not, suggest that the user install the
2246			# /usr/include headers if they want to build
2247			# fat.
2248			#
2249			AC_MSG_CHECKING(whether building for 32-bit x86 is supported)
2250			AC_LBL_SAVE_CHECK_STATE
2251			CFLAGS="$CFLAGS -arch i386"
2252			AC_TRY_LINK(
2253			    [],
2254			    [return 0;],
2255			    [
2256				AC_MSG_RESULT(yes)
2257				V_LIB_CCOPT_FAT="-arch x86_64"
2258				V_LIB_LDFLAGS_FAT="-arch x86_64"
2259
2260				#
2261				# OpenSSL installation on macOS seems
2262				# to install only the libs for 64-bit
2263				# x86 - at least that's what Brew does:
2264				# only configure 32-bit builds if we
2265				# don't have OpenSSL.
2266				#
2267				if test "$HAVE_OPENSSL" != yes; then
2268					V_LIB_CCOPT_FAT="$V_LIB_CCOPT_FAT -arch i386"
2269					V_LIB_LDFLAGS_FAT="$V_LIB_LDFLAGS_FAT -arch i386"
2270				fi
2271			    ],
2272			    [
2273				AC_MSG_RESULT(no)
2274				V_LIB_CCOPT_FAT="-arch x86_64"
2275				V_LIB_LDFLAGS_FAT="-arch x86_64"
2276				case "$host_os" in
2277
2278				darwin18.*)
2279					#
2280					# Mojave; you need to install the
2281					# /usr/include headers to get
2282					# 32-bit x86 builds to work.
2283					#
2284					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])
2285					;;
2286
2287				*)
2288					#
2289					# Pre-Mojave; the command-line
2290					# tools should be sufficient to
2291					# enable 32-bit x86 builds.
2292					#
2293					AC_MSG_WARN([Compiling for 32-bit x86 gives an error; try installing the command-line tools])
2294					;;
2295				esac
2296			    ])
2297			AC_LBL_RESTORE_CHECK_STATE
2298			;;
2299
2300		darwin19*)
2301			#
2302			# Catalina.  Build libraries and executables
2303			# only for x86-64.  (That's what Apple does;
2304			# 32-bit x86 binaries are not supported on
2305			# Catalina.)
2306			#
2307			V_LIB_CCOPT_FAT="-arch x86_64"
2308			V_LIB_LDFLAGS_FAT="-arch x86_64"
2309			V_PROG_CCOPT_FAT="-arch x86_64"
2310			V_PROG_LDFLAGS_FAT="-arch x86_64"
2311			;;
2312
2313		darwin*)
2314			#
2315			# Post-Catalina.  Build libraries and
2316			# executables for x86-64 and ARM64.
2317			# (That's what Apple does, except they
2318			# build for arm64e, which may include
2319			# some of the pointer-checking extensions.)
2320			#
2321			# If we're building with libssl, make sure
2322			# we can build fat with it (i.e., that it
2323			# was built fat); if we can't, don't set
2324			# the target architectures, and just
2325			# build for the host we're on.
2326			#
2327			# Otherwise, just add both of them.
2328			#
2329			if test "$HAVE_OPENSSL" = yes; then
2330				AC_MSG_CHECKING(whether building fat with libssl is supported)
2331				AC_LBL_SAVE_CHECK_STATE
2332				CFLAGS="$CFLAGS -arch x86_64 -arch arm64"
2333				LDFLAGS="$LDFLAGS $OPENSSL_LIBS"
2334				AC_TRY_LINK(
2335				    [
2336					#include <openssl/ssl.h>
2337				    ],
2338				    [
2339					SSL_library_init();
2340					return 0;
2341				    ],
2342				    [
2343					AC_MSG_RESULT(yes)
2344					V_LIB_CCOPT_FAT="-arch x86_64 -arch arm64"
2345					V_LIB_LDFLAGS_FAT="-arch x86_64 -arch arm64"
2346					V_PROG_CCOPT_FAT="-arch x86_64 -arch arm64"
2347					V_PROG_LDFLAGS_FAT="-arch x86_64 -arch arm64"
2348				    ],
2349				    [AC_MSG_RESULT(no)]
2350				)
2351				AC_LBL_RESTORE_CHECK_STATE
2352			else
2353				V_LIB_CCOPT_FAT="-arch x86_64 -arch arm64"
2354				V_LIB_LDFLAGS_FAT="-arch x86_64 -arch arm64"
2355				V_PROG_CCOPT_FAT="-arch x86_64 -arch arm64"
2356				V_PROG_LDFLAGS_FAT="-arch x86_64 -arch arm64"
2357			fi
2358			;;
2359		esac
2360	fi
2361	;;
2362
2363hpux9*)
2364	AC_DEFINE(HAVE_HPUX9,1,[on HP-UX 9.x])
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.0*)
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
2384hpux10.1*)
2385
2386	#
2387	# Use System V conventions for man pages.
2388	#
2389	MAN_ADMIN_COMMANDS=1m
2390	MAN_FILE_FORMATS=4
2391	MAN_MISC_INFO=5
2392	;;
2393
2394hpux*)
2395	dnl HPUX 10.20 and above is similar to HPUX 9, but
2396	dnl not the same....
2397	dnl
2398	dnl XXX - DYEXT should be set to "sl" if this is building
2399	dnl for 32-bit PA-RISC, but should be left as "so" for
2400	dnl 64-bit PA-RISC or, I suspect, IA-64.
2401	AC_DEFINE(HAVE_HPUX10_20_OR_LATER,1,[on HP-UX 10.20 or later])
2402	if test "`uname -m`" = "ia64"; then
2403		DYEXT="so"
2404	else
2405		DYEXT="sl"
2406	fi
2407
2408	#
2409	# "-b" builds a shared library; "+h" sets the soname.
2410	#
2411	SHLIB_OPT="-b"
2412	SONAME_OPT="+h"
2413
2414	#
2415	# Use System V conventions for man pages.
2416	#
2417	MAN_FILE_FORMATS=4
2418	MAN_MISC_INFO=5
2419	;;
2420
2421irix*)
2422	#
2423	# Use IRIX conventions for man pages; they're the same as the
2424	# System V conventions, except that they use section 8 for
2425	# administrative commands and daemons.
2426	#
2427	MAN_FILE_FORMATS=4
2428	MAN_MISC_INFO=5
2429	;;
2430
2431linux*|freebsd*|netbsd*|openbsd*|dragonfly*|kfreebsd*|gnu*|haiku*|midipix*)
2432	DYEXT="so"
2433	;;
2434
2435osf*)
2436	DYEXT="so"
2437
2438	#
2439	# DEC OSF/1, a/k/a Digital UNIX, a/k/a Tru64 UNIX.
2440	# Use Tru64 UNIX conventions for man pages; they're the same as
2441	# the System V conventions except that they use section 8 for
2442	# administrative commands and daemons.
2443	#
2444	MAN_FILE_FORMATS=4
2445	MAN_MISC_INFO=5
2446	MAN_DEVICES=7
2447	;;
2448
2449sinix*)
2450	AC_MSG_CHECKING(if SINIX compiler defines sinix)
2451	AC_CACHE_VAL(ac_cv_cc_sinix_defined,
2452		AC_TRY_COMPILE(
2453		    [],
2454		    [int i = sinix;],
2455		    ac_cv_cc_sinix_defined=yes,
2456		    ac_cv_cc_sinix_defined=no))
2457	    AC_MSG_RESULT($ac_cv_cc_sinix_defined)
2458	    if test $ac_cv_cc_sinix_defined = no ; then
2459		    AC_DEFINE(sinix,1,[on sinix])
2460	    fi
2461	;;
2462
2463solaris*)
2464	AC_DEFINE(HAVE_SOLARIS,1,[On solaris])
2465
2466	DYEXT="so"
2467
2468	#
2469	# Make sure errno is thread-safe, in case we're called in
2470	# a multithreaded program.  We don't guarantee that two
2471	# threads can use the *same* pcap_t safely, but the
2472	# current version does guarantee that you can use different
2473	# pcap_t's in different threads, and even that pcap_compile()
2474	# is thread-safe (it wasn't thread-safe in some older versions).
2475	#
2476	V_CCOPT="$V_CCOPT -D_TS_ERRNO"
2477
2478	case "`uname -r`" in
2479
2480	5.12)
2481		;;
2482
2483	*)
2484		#
2485		# Use System V conventions for man pages.
2486		#
2487		MAN_ADMIN_COMMANDS=1m
2488		MAN_FILE_FORMATS=4
2489		MAN_MISC_INFO=5
2490		MAN_DEVICES=7D
2491	esac
2492	;;
2493esac
2494AC_SUBST(V_LIB_CCOPT_FAT)
2495AC_SUBST(V_LIB_LDFLAGS_FAT)
2496AC_SUBST(V_PROG_CCOPT_FAT)
2497AC_SUBST(V_PROG_LDFLAGS_FAT)
2498AC_SUBST(DYEXT)
2499AC_SUBST(MAN_DEVICES)
2500AC_SUBST(MAN_FILE_FORMATS)
2501AC_SUBST(MAN_MISC_INFO)
2502AC_SUBST(MAN_ADMIN_COMMANDS)
2503
2504AC_ARG_ENABLE(shared,
2505AS_HELP_STRING([--enable-shared],[build shared libraries @<:@default=yes, if support available@:>@]))
2506test "x$enable_shared" = "xno" && DYEXT="none"
2507
2508AC_PROG_RANLIB
2509AC_CHECK_TOOL([AR], [ar])
2510
2511AC_PROG_LN_S
2512AC_SUBST(LN_S)
2513
2514AC_LBL_DEVEL(V_CCOPT)
2515
2516#
2517# Check to see if the sockaddr struct has the 4.4 BSD sa_len member.
2518#
2519AC_CHECK_MEMBERS([struct sockaddr.sa_len],,,
2520    [
2521	#include <sys/types.h>
2522	#include <sys/socket.h>
2523    ])
2524
2525#
2526# Check to see if there's a sockaddr_storage structure.
2527#
2528AC_CHECK_TYPES(struct sockaddr_storage,,,
2529    [
2530	#include <sys/types.h>
2531	#include <sys/socket.h>
2532    ])
2533
2534#
2535# Check to see if the dl_hp_ppa_info_t struct has the HP-UX 11.00
2536# dl_module_id_1 member.
2537#
2538# NOTE: any failure means we conclude that it doesn't have that member,
2539# so if we don't have DLPI, don't have a <sys/dlpi_ext.h> header, or
2540# have one that doesn't declare a dl_hp_ppa_info_t type, we conclude
2541# it doesn't have that member (which is OK, as either we won't be
2542# using code that would use that member, or we wouldn't compile in
2543# any case).
2544#
2545AC_CHECK_MEMBERS([dl_hp_ppa_info_t.dl_module_id_1],,,
2546    [
2547	#include <sys/types.h>
2548	#include <sys/dlpi.h>
2549	#include <sys/dlpi_ext.h>
2550    ])
2551
2552#
2553# Various Linux-specific mechanisms.
2554#
2555AC_ARG_ENABLE([usb],
2556[AS_HELP_STRING([--enable-usb],[enable Linux usbmon USB capture support @<:@default=yes, if support available@:>@])],
2557    [],
2558    [enable_usb=yes])
2559
2560#
2561# If somebody requested an XXX-only pcap, that doesn't include
2562# additional mechanisms.
2563#
2564if test "xxx_only" != yes; then
2565  case "$host_os" in
2566  linux*)
2567    dnl check for USB sniffing support
2568    AC_MSG_CHECKING(for Linux usbmon USB sniffing support)
2569    if test "x$enable_usb" != "xno" ; then
2570      AC_DEFINE(PCAP_SUPPORT_LINUX_USBMON, 1, [target host supports Linux usbmon for USB sniffing])
2571      MODULE_C_SRC="$MODULE_C_SRC pcap-usb-linux.c"
2572      AC_MSG_RESULT(yes)
2573      #
2574      # Note: if the directory for special files is *EVER* somewhere
2575      # other than the UN*X standard of /dev (which will break any
2576      # software that looks for /dev/null or /dev/tty, for example,
2577      # so doing that is *REALLY* not a good idea), please provide
2578      # some mechanism to determine that directory at *run time*,
2579      # rather than *configure time*, so that it works when doing
2580      # a cross-build, and that works with *multiple* distributions,
2581      # with our without udev, and with multiple versions of udev,
2582      # with udevinfo or udevadm or any other mechanism to get the
2583      # special files directory.
2584      #
2585      # Do we have a version of <linux/compiler.h> available?
2586      # If so, we might need it for <linux/usbdevice_fs.h>.
2587      #
2588      AC_CHECK_HEADERS(linux/compiler.h)
2589      if test "$ac_cv_header_linux_compiler_h" = yes; then
2590        #
2591        # Yes - include it when testing for <linux/usbdevice_fs.h>.
2592        #
2593        AC_CHECK_HEADERS(linux/usbdevice_fs.h,,,[#include <linux/compiler.h>])
2594      else
2595        AC_CHECK_HEADERS(linux/usbdevice_fs.h)
2596      fi
2597      if test "$ac_cv_header_linux_usbdevice_fs_h" = yes; then
2598        #
2599        # OK, does it define bRequestType?  Older versions of the kernel
2600        # define fields with names like "requesttype, "request", and
2601        # "value", rather than "bRequestType", "bRequest", and
2602        # "wValue".
2603        #
2604        AC_CHECK_MEMBERS([struct usbdevfs_ctrltransfer.bRequestType],,,
2605          [
2606            AC_INCLUDES_DEFAULT
2607            #ifdef HAVE_LINUX_COMPILER_H
2608            #include <linux/compiler.h>
2609            #endif
2610            #include <linux/usbdevice_fs.h>
2611          ])
2612      fi
2613    else
2614      AC_MSG_RESULT(no)
2615    fi
2616
2617    #
2618    # Life's too short to deal with trying to get this to compile
2619    # if you don't get the right types defined with
2620    # __KERNEL_STRICT_NAMES getting defined by some other include.
2621    #
2622    # Check whether the includes Just Work.  If not, don't turn on
2623    # netfilter support.
2624    #
2625    AC_MSG_CHECKING(whether we can compile the netfilter support)
2626    AC_CACHE_VAL(ac_cv_netfilter_can_compile,
2627      AC_TRY_COMPILE([
2628AC_INCLUDES_DEFAULT
2629#include <sys/socket.h>
2630#include <netinet/in.h>
2631#include <linux/types.h>
2632
2633#include <linux/netlink.h>
2634#include <linux/netfilter.h>
2635#include <linux/netfilter/nfnetlink.h>
2636#include <linux/netfilter/nfnetlink_log.h>
2637#include <linux/netfilter/nfnetlink_queue.h>],
2638        [],
2639        ac_cv_netfilter_can_compile=yes,
2640        ac_cv_netfilter_can_compile=no))
2641    AC_MSG_RESULT($ac_cv_netfilter_can_compile)
2642    if test $ac_cv_netfilter_can_compile = yes ; then
2643      AC_DEFINE(PCAP_SUPPORT_NETFILTER, 1,
2644        [target host supports netfilter sniffing])
2645      MODULE_C_SRC="$MODULE_C_SRC pcap-netfilter-linux.c"
2646    fi
2647    ;;
2648  esac
2649fi
2650AC_SUBST(PCAP_SUPPORT_LINUX_USBMON)
2651AC_SUBST(PCAP_SUPPORT_NETFILTER)
2652
2653AC_ARG_ENABLE([netmap],
2654[AS_HELP_STRING([--enable-netmap],[enable netmap support @<:@default=yes, if support available@:>@])],
2655    [],
2656    [enable_netmap=yes])
2657
2658if test "x$enable_netmap" != "xno" ; then
2659	#
2660	# Check whether net/netmap_user.h is usable if NETMAP_WITH_LIBS is
2661	# defined; it's not usable on DragonFly BSD 4.6 if NETMAP_WITH_LIBS
2662	# is defined, for example, as it includes a nonexistent malloc.h
2663	# header.
2664	#
2665	AC_MSG_CHECKING(whether we can compile the netmap support)
2666	AC_CACHE_VAL(ac_cv_net_netmap_user_can_compile,
2667	  AC_TRY_COMPILE([
2668AC_INCLUDES_DEFAULT
2669#define NETMAP_WITH_LIBS
2670#include <net/netmap_user.h>],
2671	    [],
2672	    ac_cv_net_netmap_user_can_compile=yes,
2673	    ac_cv_net_netmap_user_can_compile=no))
2674	AC_MSG_RESULT($ac_cv_net_netmap_user_can_compile)
2675	if test $ac_cv_net_netmap_user_can_compile = yes ; then
2676	  AC_DEFINE(PCAP_SUPPORT_NETMAP, 1,
2677	    [target host supports netmap])
2678	    MODULE_C_SRC="$MODULE_C_SRC pcap-netmap.c"
2679	fi
2680	AC_SUBST(PCAP_SUPPORT_NETMAP)
2681fi
2682
2683# Check for DPDK support.
2684AC_ARG_WITH([dpdk],
2685AS_HELP_STRING([--with-dpdk@<:@=DIR@:>@],[include DPDK support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
2686[
2687	if test "$withval" = no
2688	then
2689		# User doesn't want DPDK support.
2690		want_dpdk=no
2691	elif test "$withval" = yes
2692	then
2693		# User wants DPDK support but hasn't specified a directory.
2694		want_dpdk=yes
2695	else
2696		# User wants DPDK support and has specified a directory,
2697		# so use the provided value.
2698		want_dpdk=yes
2699		dpdk_dir=$withval
2700	fi
2701],[
2702	if test "$V_PCAP" = dpdk; then
2703		# User requested DPDK-only libpcap, so we'd better have
2704		# the DPDK API.
2705		want_dpdk=yes
2706	elif test "xxx_only" = yes; then
2707		# User requested something-else-only pcap, so they don't
2708		# want DPDK support.
2709		want_dpdk=no
2710	else
2711		#
2712		# Use DPDK API if present, otherwise don't
2713		#
2714		want_dpdk=ifpresent
2715	fi
2716])
2717
2718if test "$want_dpdk" != no; then
2719	#
2720	# The user didn't explicitly say they don't want DPDK,
2721	# so see if we have it.
2722	#
2723	# We only try to find it using pkg-config; DPDK is *SO*
2724	# complicated - DPDK 19.02, for example, has about 117(!)
2725	# libraries, and the precise set of libraries required has
2726	# changed over time - so attempting to guess which libraries
2727	# you need, and hardcoding that in an attempt to find the
2728	# libraries without DPDK, rather than relying on DPDK to
2729	# tell you, with a .pc file, what libraries are needed,
2730	# is *EXTREMELY* fragile and has caused some bug reports,
2731	# so we're just not going to do it.
2732	#
2733	# If that causes a problem, the only thing we will do is
2734	# accept an alternative way of finding the appropriate
2735	# library set for the installed version of DPDK that is
2736	# as robust as pkg-config (i.e., it had better work as well
2737	# as pkg-config with *ALL* versions of DPDK that provide a
2738	# libdpdk.pc file).
2739	#
2740	# If --with-dpdk={path} was specified, add {path}/pkgconfig
2741	# to PKG_CONFIG_PATH, so we look for the .pc file there,
2742	# first.
2743	#
2744	save_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
2745	if test -n "$dpdk_dir"; then
2746		PKG_CONFIG_PATH="$dpdk_dir:$PKG_CONFIG_PATH"
2747	fi
2748	PKG_CHECK_MODULE(DPDK, libdpdk,
2749	    [
2750		found_dpdk=yes
2751	    ])
2752	PKG_CONFIG_PATH="$save_PKG_CONFIG_PATH"
2753
2754	#
2755	# Did we find DPDK?
2756	#
2757	if test "$found_dpdk" = yes; then
2758		#
2759		# Found it.
2760		#
2761		# We call rte_eth_dev_count_avail(), and older versions
2762		# of DPDK didn't have it, so check for it.
2763		#
2764		AC_LBL_SAVE_CHECK_STATE
2765		CFLAGS="$CFLAGS $DPDK_CFLAGS"
2766		LIBS="$LIBS $DPDK_LIBS"
2767		AC_CHECK_FUNC(rte_eth_dev_count_avail)
2768		AC_LBL_RESTORE_CHECK_STATE
2769	fi
2770
2771	if test "$ac_cv_func_rte_eth_dev_count_avail" = yes; then
2772		#
2773		# We found a usable DPDK.
2774		#
2775		# Check whether the rte_ether.h file defines
2776		# struct ether_addr or struct rte_ether_addr.
2777		#
2778		# ("API compatibility?  That's for losers!")
2779		#
2780		AC_LBL_SAVE_CHECK_STATE
2781		CFLAGS="$CFLAGS $DPDK_CFLAGS"
2782		LIBS="$LIBS $DPDK_LIBS"
2783		AC_CHECK_TYPES(struct rte_ether_addr,,,
2784		    [
2785			#include <rte_ether.h>
2786		    ])
2787		AC_LBL_RESTORE_CHECK_STATE
2788
2789		#
2790		# We can build with DPDK.
2791		#
2792		V_INCLS="$V_INCLS $DPDK_CFLAGS"
2793		ADDITIONAL_LIBS="$ADDITIONAL_LIBS $DPDK_LIBS"
2794		ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $DPDK_LIBS_STATIC"
2795		REQUIRES_PRIVATE="$REQUIRES_PRIVATE libdpdk"
2796		AC_DEFINE(PCAP_SUPPORT_DPDK, 1, [target host supports DPDK])
2797		if test $V_PCAP != dpdk ; then
2798			MODULE_C_SRC="$MODULE_C_SRC pcap-dpdk.c"
2799		fi
2800	else
2801		#
2802		# We didn't find a usable DPDK.
2803		# If we required it (with --with-dpdk or --with-pcap=dpdk),
2804		# fail with an appropriate message telling the user what
2805		# the problem was, otherwise note the problem with a
2806		# warning.
2807		#
2808		if test "$found_dpdk" != yes; then
2809			#
2810			# Not found with pkg-config.  Note that we
2811			# require that DPDK must be findable with
2812			# pkg-config.
2813			#
2814			if test "$V_PCAP" = dpdk; then
2815				#
2816				# User requested DPDK-only capture support.
2817				#
2818				AC_MSG_ERROR(
2819[DPDK support requested with --with-pcap=dpdk, but
2820we couldn't find DPDK with pkg-config.  Make sure that pkg-config is
2821installed, that DPDK 18.02.2 or later is installed, and that DPDK
2822provides a .pc file.])
2823			fi
2824
2825			if test "$want_dpdk" = yes; then
2826				#
2827				# User requested that libpcap include
2828				# DPDK capture support.
2829				#
2830				AC_MSG_ERROR(
2831[DPDK support requested with --with-dpdk, but we
2832couldn't find DPDK with pkg-config.  Make sure that pkg-config
2833is installed, that DPDK 18.02.2 or later is installed, and that
2834DPDK provides .pc file.])
2835			fi
2836
2837			#
2838			# User didn't indicate whether they wanted DPDK
2839			# or not; just warn why we didn't find it.
2840			#
2841			AC_MSG_WARN(
2842[We couldn't find DPDK with pkg-config.  If
2843you want DPDK support, make sure that pkg-config is installed,
2844that DPDK 18.02.2 or later is installed, and that DPDK provides a
2845.pc file.])
2846		elif test "$ac_cv_func_rte_eth_dev_count_avail" != yes; then
2847			#
2848			# Found with pkg-config, but we couldn't compile
2849			# a program that calls rte_eth_dev_count(); we
2850			# probably have the developer package installed,
2851			# but don't have a sufficiently recent version
2852			# of DPDK.  Note that we need a sufficiently
2853			# recent version of DPDK.
2854			#
2855			if test "$V_PCAP" = dpdk; then
2856				#
2857				# User requested DPDK-only capture support.
2858				#
2859				AC_MSG_ERROR(
2860[DPDK support requested with --with-pcap=dpdk, but we
2861can't compile libpcap with DPDK.  Make sure that DPDK 18.02.2 or later
2862is installed.])
2863			fi
2864
2865			if test "$want_dpdk" = yes; then
2866				#
2867				# User requested that libpcap include
2868				# DPDK capture support.
2869				#
2870				AC_MSG_ERROR(
2871[DPDK support requested with --with-dpdk, but
2872we can't compile libpcap with DPDK.  Make sure that DPDK 18.02.2
2873or later is DPDK is installed.])
2874			fi
2875
2876			#
2877			# User didn't indicate whether they wanted DPDK
2878			# or not; just warn why we didn't find it.
2879			#
2880			AC_MSG_WARN(
2881[DPDK was found, but we can't compile libpcap with it.
2882Make sure that DPDK 18.02.2 or later is installed.])
2883		fi
2884	fi
2885fi
2886AC_SUBST(PCAP_SUPPORT_DPDK)
2887
2888AC_ARG_ENABLE([bluetooth],
2889[AS_HELP_STRING([--enable-bluetooth],[enable Bluetooth support @<:@default=yes, if support available@:>@])],
2890    [],
2891    [enable_bluetooth=ifsupportavailable])
2892
2893if test "xxx_only" = yes; then
2894	# User requested something-else-only pcap, so they don't
2895	# want Bluetooth support.
2896	enable_bluetooth=no
2897fi
2898
2899if test "x$enable_bluetooth" != "xno" ; then
2900	dnl check for Bluetooth sniffing support
2901	case "$host_os" in
2902	linux*)
2903		AC_CHECK_HEADER(bluetooth/bluetooth.h,
2904		    [
2905			#
2906			# We have bluetooth.h, so we support Bluetooth
2907			# sniffing.
2908			#
2909			AC_DEFINE(PCAP_SUPPORT_BT, 1, [target host supports Bluetooth sniffing])
2910			MODULE_C_SRC="$MODULE_C_SRC pcap-bt-linux.c"
2911			AC_MSG_NOTICE(Bluetooth sniffing is supported)
2912			ac_lbl_bluetooth_available=yes
2913
2914			#
2915			# OK, does struct sockaddr_hci have an hci_channel
2916			# member?
2917			#
2918			AC_CHECK_MEMBERS([struct sockaddr_hci.hci_channel],
2919			    [
2920				#
2921				# Yes; is HCI_CHANNEL_MONITOR defined?
2922				#
2923				AC_MSG_CHECKING(if HCI_CHANNEL_MONITOR is defined)
2924				AC_CACHE_VAL(ac_cv_lbl_hci_channel_monitor_is_defined,
2925				    AC_TRY_COMPILE(
2926					[
2927					    #include <bluetooth/bluetooth.h>
2928					    #include <bluetooth/hci.h>
2929					],
2930					[
2931					    int i = HCI_CHANNEL_MONITOR;
2932					],
2933					[
2934					    AC_MSG_RESULT(yes)
2935					    AC_DEFINE(PCAP_SUPPORT_BT_MONITOR, 1,
2936					      [target host supports Bluetooth Monitor])
2937					    MODULE_C_SRC="$MODULE_C_SRC pcap-bt-monitor-linux.c"
2938					],
2939					[
2940					    AC_MSG_RESULT(no)
2941					]))
2942			    ],,
2943			    [
2944				#include <bluetooth/bluetooth.h>
2945				#include <bluetooth/hci.h>
2946			    ])
2947		    ],
2948		    [
2949			#
2950			# We don't have bluetooth.h, so we don't support
2951			# Bluetooth sniffing.
2952			#
2953			if test "x$enable_bluetooth" = "xyes" ; then
2954				AC_MSG_ERROR(Bluetooth sniffing is not supported; install bluez-lib devel to enable it)
2955			else
2956				AC_MSG_NOTICE(Bluetooth sniffing is not supported; install bluez-lib devel to enable it)
2957			fi
2958		    ])
2959		;;
2960	*)
2961		if test "x$enable_bluetooth" = "xyes" ; then
2962			AC_MSG_ERROR(no Bluetooth sniffing support implemented for $host_os)
2963		else
2964			AC_MSG_NOTICE(no Bluetooth sniffing support implemented for $host_os)
2965		fi
2966		;;
2967	esac
2968	AC_SUBST(PCAP_SUPPORT_BT)
2969fi
2970
2971AC_ARG_ENABLE([dbus],
2972[AS_HELP_STRING([--enable-dbus],[enable D-Bus capture support @<:@default=yes, if support available@:>@])],
2973    [],
2974    [enable_dbus=ifavailable])
2975
2976if test "xxx_only" = yes; then
2977	# User requested something-else-only pcap, so they don't
2978	# want D-Bus support.
2979	enable_dbus=no
2980fi
2981
2982if test "x$enable_dbus" != "xno"; then
2983	if test "x$enable_dbus" = "xyes"; then
2984		case "$host_os" in
2985
2986		darwin*)
2987			#
2988			# We don't support D-Bus sniffing on macOS; see
2989			#
2990			# https://bugs.freedesktop.org/show_bug.cgi?id=74029
2991			#
2992			# The user requested it, so fail.
2993			#
2994			AC_MSG_ERROR([Due to freedesktop.org bug 74029, D-Bus capture support is not available on macOS])
2995		esac
2996	else
2997		case "$host_os" in
2998
2999		darwin*)
3000			#
3001			# We don't support D-Bus sniffing on macOS; see
3002			#
3003			# https://bugs.freedesktop.org/show_bug.cgi?id=74029
3004			#
3005			# The user didn't explicitly request it, so just
3006			# silently refuse to enable it.
3007			#
3008			enable_dbus="no"
3009			;;
3010		esac
3011	fi
3012fi
3013
3014if test "x$enable_dbus" != "xno"; then
3015	PKG_CHECK_MODULE(DBUS, dbus-1,
3016	    [
3017		AC_LBL_SAVE_CHECK_STATE
3018		CFLAGS="$CFLAGS $DBUS_CFLAGS"
3019		LIBS="$LIBS $DBUS_LIBS"
3020		AC_MSG_CHECKING(whether the D-Bus library defines dbus_connection_read_write)
3021		AC_TRY_LINK(
3022		    [#include <string.h>
3023
3024		     #include <time.h>
3025		     #include <sys/time.h>
3026
3027		     #include <dbus/dbus.h>],
3028		    [return dbus_connection_read_write(NULL, 0);],
3029		    [
3030			AC_MSG_RESULT([yes])
3031			AC_DEFINE(PCAP_SUPPORT_DBUS, 1, [support D-Bus sniffing])
3032			MODULE_C_SRC="$MODULE_C_SRC pcap-dbus.c"
3033			V_INCLS="$V_INCLS $DBUS_CFLAGS"
3034			ADDITIONAL_LIBS="$ADDITIONAL_LIBS $DBUS_LIBS"
3035			ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $DBUS_LIBS_STATIC"
3036			REQUIRES_PRIVATE="$REQUIRES_PRIVATE dbus-1"
3037		    ],
3038		    [
3039			AC_MSG_RESULT([no])
3040			if test "x$enable_dbus" = "xyes"; then
3041			    AC_MSG_ERROR([--enable-dbus was given, but the D-Bus library doesn't define dbus_connection_read_write()])
3042			fi
3043		     ])
3044		AC_LBL_RESTORE_CHECK_STATE
3045	    ],
3046	    [
3047		if test "x$enable_dbus" = "xyes"; then
3048			AC_MSG_ERROR([--enable-dbus was given, but the dbus-1 package is not installed])
3049		fi
3050	    ])
3051	AC_SUBST(PCAP_SUPPORT_DBUS)
3052fi
3053
3054AC_ARG_ENABLE([rdma],
3055[AS_HELP_STRING([--enable-rdma],[enable RDMA capture support @<:@default=yes, if support available@:>@])],
3056    [],
3057    [enable_rdma=ifavailable])
3058
3059if test "xxx_only" = yes; then
3060	# User requested something-else-only pcap, so they don't
3061	# want RDMA support.
3062	enable_rdma=no
3063fi
3064
3065if test "x$enable_rdma" != "xno"; then
3066	PKG_CHECK_MODULE(LIBIBVERBS, libibverbs,
3067	    [
3068		found_libibverbs=yes
3069		LIBIBVERBS_REQUIRES_PRIVATE="libibverbs"
3070	    ])
3071
3072	if test "x$found_libibverbs" != "xyes"; then
3073		AC_CHECK_LIB(ibverbs, ibv_get_device_list,
3074		    [
3075			found_libibverbs=yes
3076			LIBIBVERBS_CFLAGS=""
3077			LIBIBVERBS_LIBS="-libverbs"
3078			# XXX - at least on Ubuntu 20.04, there are many more
3079			# libraries needed; is there any platform where
3080			# libibverbs is available but where pkg-config isn't
3081			# available or libibverbs doesn't use it?  If not,
3082			# we should only use pkg-config for it.
3083			LIBIBVERBS_LIBS_STATIC="-libverbs"
3084			LIBIBVERBS_LIBS_PRIVATE="-libverbs"
3085		    ]
3086		)
3087	fi
3088
3089	if test "x$found_libibverbs" = "xyes"; then
3090		AC_LBL_SAVE_CHECK_STATE
3091		CFLAGS="$CFLAGS $LIBIBVERBS_CFLAGS"
3092		LIBS="$LIBS $LIBIBVERBS_LIBS"
3093		AC_CHECK_HEADER(infiniband/verbs.h, [
3094			#
3095			# ibv_create_flow may be defined as a static inline
3096			# function in infiniband/verbs.h, so we can't
3097			# use AC_CHECK_LIB.
3098			#
3099			# Too bad autoconf has no AC_SYMBOL_EXISTS()
3100			# macro that works like CMake's check_symbol_exists()
3101			# function, to check do a compile check like
3102			# this (they do a clever trick to avoid having
3103			# to know the function's signature).
3104			#
3105			AC_MSG_CHECKING(whether libibverbs defines ibv_create_flow)
3106			AC_TRY_LINK(
3107				[
3108					#include <infiniband/verbs.h>
3109				],
3110				[
3111					(void) ibv_create_flow((struct ibv_qp *) NULL,
3112							       (struct ibv_flow_attr *) NULL);
3113				],
3114				[
3115					AC_MSG_RESULT([yes])
3116					found_usable_libibverbs=yes
3117				],
3118				[
3119					AC_MSG_RESULT([no])
3120				]
3121			)
3122		])
3123		AC_LBL_RESTORE_CHECK_STATE
3124	fi
3125
3126	if test "x$found_usable_libibverbs" = "xyes"
3127	then
3128		AC_DEFINE(PCAP_SUPPORT_RDMASNIFF, 1, [target host supports RDMA sniffing])
3129		MODULE_C_SRC="$MODULE_C_SRC pcap-rdmasniff.c"
3130		CFLAGS="$LIBIBVERBS_CFLAGS $CFLAGS"
3131		ADDITIONAL_LIBS="$LIBIBVERBS_LIBS $ADDITIONAL_LIBS"
3132		ADDITIONAL_LIBS_STATIC="$LIBIBVERBS_LIBS_STATIC $ADDITIONAL_LIBS_STATIC"
3133		LIBS_PRIVATE="$LIBIBVERBS_LIBS_PRIVATE $LIBS_PRIVATE"
3134		REQUIRES_PRIVATE="$REQUIRES_PRIVATE $LIBIBVERBS_REQUIRES_PRIVATE"
3135	fi
3136	AC_SUBST(PCAP_SUPPORT_RDMASNIFF)
3137fi
3138
3139#
3140# If this is a platform where we need to have the .pc file and
3141# pcap-config script supply an rpath option to specify the directory
3142# in which the libpcap shared library is installed, and the install
3143# prefix /usr (meaning we're not installing a system library), provide
3144# the rpath option.
3145#
3146# (We must check $prefix, as $libdir isn't necessarily /usr/lib in this
3147# case - for example, Linux distributions for 64-bit platforms that
3148# also provide support for binaries for a 32-bit version of the
3149# platform may put the 64-bit libraries, the 32-bit libraries, or both
3150# in directories other than /usr/lib.)
3151#
3152# In AIX, do we have to do this?
3153#
3154# In Darwin-based OSes, the full paths of the shared libraries with
3155# which the program was linked are stored in the executable, so we don't
3156# need to provide an rpath option.
3157#
3158# With the HP-UX linker, directories specified with -L are, by default,
3159# added to the run-time search path, so we don't need to supply them.
3160#
3161# For Tru64 UNIX, "-rpath" works with DEC's^WCompaq's^WHP's C compiler
3162# for Alpha, but isn't documented as working with GCC, and no GCC-
3163# compatible option is documented as working with the DEC compiler.
3164# If anybody needs this on Tru64/Alpha, they're welcome to figure out a
3165# way to make it work.
3166#
3167# This must *not* depend on the compiler, as, on platforms where there's
3168# a GCC-compatible compiler and a vendor compiler, we need to work with
3169# both.
3170#
3171if test "$prefix" != "/usr"; then
3172	case "$host_os" in
3173
3174	freebsd*|netbsd*|openbsd*|dragonfly*|linux*|haiku*|midipix*|gnu*)
3175		#
3176		# Platforms where the "native" C compiler is GCC or
3177		# accepts compatible command-line arguments, and the
3178		# "native" linker is the GNU linker or accepts
3179		# compatible command-line arguments.
3180		#
3181		RPATH="-Wl,-rpath,\${libdir}"
3182		;;
3183
3184	solaris*)
3185		#
3186		# Sun/Oracle's linker, the GNU linker, and
3187		# GNU-compatible linkers all support -R.
3188		#
3189		RPATH="-Wl,-R,\${libdir}"
3190		;;
3191	esac
3192fi
3193
3194AC_PROG_INSTALL
3195
3196AC_CONFIG_HEADER(config.h)
3197
3198AC_SUBST(V_SHLIB_CCOPT)
3199AC_SUBST(V_SHLIB_CMD)
3200AC_SUBST(V_SHLIB_OPT)
3201AC_SUBST(V_SONAME_OPT)
3202AC_SUBST(RPATH)
3203AC_SUBST(ADDLOBJS)
3204AC_SUBST(ADDLARCHIVEOBJS)
3205AC_SUBST(PLATFORM_C_SRC)
3206AC_SUBST(MODULE_C_SRC)
3207AC_SUBST(REMOTE_C_SRC)
3208AC_SUBST(PTHREAD_LIBS)
3209AC_SUBST(BUILD_RPCAPD)
3210AC_SUBST(INSTALL_RPCAPD)
3211AC_SUBST(RPCAPD_LIBS)
3212
3213#
3214# We're done with configuration operations; add ADDITIONAL_LIBS and
3215# ADDITIONAL_LIBS_STATIC to LIBS and LIBS_STATIC, respectively.
3216#
3217LIBS="$ADDITIONAL_LIBS $LIBS"
3218LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $LIBS_STATIC"
3219
3220AC_OUTPUT_COMMANDS([if test -f .devel; then
3221	echo timestamp > stamp-h
3222	cat $srcdir/Makefile-devel-adds >> Makefile
3223	make depend || exit 1
3224fi])
3225AC_OUTPUT(Makefile grammar.y pcap-filter.manmisc pcap-linktype.manmisc
3226	pcap-tstamp.manmisc pcap-savefile.manfile pcap.3pcap
3227	pcap_compile.3pcap pcap_datalink.3pcap pcap_dump_open.3pcap
3228	pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap
3229	pcap_list_tstamp_types.3pcap pcap_open_dead.3pcap
3230	pcap_open_offline.3pcap pcap_set_immediate_mode.3pcap
3231	pcap_set_tstamp_precision.3pcap pcap_set_tstamp_type.3pcap
3232	rpcapd/Makefile rpcapd/rpcapd.manadmin rpcapd/rpcapd-config.manfile
3233	testprogs/Makefile)
3234exit 0
3235