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