xref: /freebsd/contrib/libpcap/configure.ac (revision 148a8da8)
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#	http://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.64)
18
19AC_INIT(pcap, m4_esyscmd_s([cat VERSION]))
20AC_CONFIG_SRCDIR(pcap.c)
21AC_SUBST(PACKAGE_NAME)
22
23AC_CANONICAL_SYSTEM
24
25AC_LBL_C_INIT_BEFORE_CC(V_CCOPT, V_INCLS)
26#
27# Try to enable as many C99 features as we can.
28# At minimum, we want C++/C99-style // comments.
29#
30AC_PROG_CC_C99
31AC_LBL_C_INIT(V_CCOPT, V_INCLS)
32AC_LBL_SHLIBS_INIT
33AC_LBL_C_INLINE
34
35#
36# Try to arrange for large file support.
37#
38AC_SYS_LARGEFILE
39AC_FUNC_FSEEKO
40
41dnl
42dnl Even if <net/bpf.h> were, on all OSes that support BPF, fixed to
43dnl include <sys/ioccom.h>, and we were to drop support for older
44dnl releases without that fix, so that pcap-bpf.c doesn't need to
45dnl include <sys/ioccom.h>, the test program in "AC_LBL_FIXINCLUDES"
46dnl in "aclocal.m4" uses it, so we would still have to test for it
47dnl and set "HAVE_SYS_IOCCOM_H" if we have it, otherwise
48dnl "AC_LBL_FIXINCLUDES" wouldn't work on some platforms such as Solaris.
49dnl
50AC_CHECK_HEADERS(sys/ioccom.h sys/sockio.h limits.h)
51AC_CHECK_HEADERS(netpacket/packet.h)
52AC_CHECK_HEADERS(net/pfvar.h, , , [#include <sys/types.h>
53#include <sys/socket.h>
54#include <net/if.h>])
55if test "$ac_cv_header_net_pfvar_h" = yes; then
56	#
57	# Check for various PF actions.
58	#
59	AC_MSG_CHECKING(whether net/pfvar.h defines PF_NAT through PF_NORDR)
60	AC_TRY_COMPILE(
61	    [#include <sys/types.h>
62	    #include <sys/socket.h>
63	    #include <net/if.h>
64	    #include <net/pfvar.h>],
65	    [return PF_NAT+PF_NONAT+PF_BINAT+PF_NOBINAT+PF_RDR+PF_NORDR;],
66	    [
67		AC_MSG_RESULT(yes)
68		AC_DEFINE(HAVE_PF_NAT_THROUGH_PF_NORDR, 1,
69		    [define if net/pfvar.h defines PF_NAT through PF_NORDR])
70	    ],
71	    AC_MSG_RESULT(no))
72fi
73
74case "$host_os" in
75linux*|uclinux*)
76	AC_CHECK_HEADERS(linux/sockios.h linux/if_bonding.h,,,
77	[
78#include <sys/socket.h>
79#include <linux/if.h>
80	])
81	;;
82esac
83
84AC_LBL_FIXINCLUDES
85
86AC_CHECK_FUNCS(strerror strerror_r strerror_s strlcpy strlcat)
87
88needsnprintf=no
89AC_CHECK_FUNCS(vsnprintf snprintf,,
90	[needsnprintf=yes])
91if test $needsnprintf = yes; then
92	AC_LIBOBJ([snprintf])
93fi
94
95needstrtok_r=no
96AC_CHECK_FUNCS(strtok_r,,
97	[needstrtok_r=yes])
98if test $needstrtok_r = yes; then
99	AC_LIBOBJ([strtok_r])
100fi
101
102#
103# Do we have ffs(), and is it declared in <strings.h>?
104#
105AC_CHECK_FUNCS(ffs)
106if test "$ac_cv_func_ffs" = yes; then
107	#
108	# We have ffs(); is it declared in <strings.h>?
109	#
110	# This test fails if we don't have <strings.h> or if we do
111	# but it doesn't declare ffs().
112	#
113	AC_CHECK_DECL(ffs,
114	    [
115		AC_DEFINE(STRINGS_H_DECLARES_FFS,,
116		    [Define to 1 if strings.h declares `ffs'])
117	    ],,
118	    [
119#include <strings.h>
120	    ])
121fi
122
123#
124# Do this before checking for ether_hostton(), as it's a
125# "getaddrinfo()-ish function".
126#
127AC_LBL_LIBRARY_NET
128
129#
130# Check for reentrant versions of getnetbyname_r(), as provided by
131# Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
132# If we don't find one, we just use getnetbyname(), which uses
133# thread-specific data on many platforms, but doesn't use it on
134# NetBSD or OpenBSD, and may not use it on older versions of other
135# platforms.
136#
137# Only do the check if we have a declaration of getnetbyname_r();
138# without it, we can't check which API it has.  (We assume that
139# if there's a declaration, it has a prototype, so that the API
140# can be checked.)
141#
142AC_CHECK_DECL(getnetbyname_r,
143    [
144	AC_MSG_CHECKING([for the Linux getnetbyname_r()])
145	AC_TRY_LINK(
146	    [#include <netdb.h>],
147	    [
148		struct netent netent_buf;
149		char buf[1024];
150		struct netent *resultp;
151		int h_errnoval;
152
153		return getnetbyname_r((const char *)0, &netent_buf, buf, sizeof buf, &resultp, &h_errnoval);
154	    ],
155	    [
156		AC_MSG_RESULT(yes)
157		AC_DEFINE(HAVE_LINUX_GETNETBYNAME_R, 1,
158		    [define if we have the Linux getnetbyname_r()])
159	    ],
160	    [
161		AC_MSG_RESULT(no)
162
163		AC_MSG_CHECKING([for Solaris/IRIX getnetbyname_r()])
164		AC_TRY_LINK(
165		    [#include <netdb.h>],
166		    [
167			struct netent netent_buf;
168			char buf[1024];
169
170			return getnetbyname_r((const char *)0, &netent_buf, buf, (int)sizeof buf) != NULL;
171		    ],
172		    [
173			AC_MSG_RESULT(yes)
174			AC_DEFINE(HAVE_SOLARIS_IRIX_GETNETBYNAME_R, 1,
175			    [define if we have the Solaris/IRIX getnetbyname_r()])
176		    ],
177		    [
178			AC_MSG_RESULT(no)
179
180			AC_MSG_CHECKING([for AIX getnetbyname_r()])
181			AC_TRY_LINK(
182			    [#include <netdb.h>],
183			    [
184				struct netent netent_buf;
185				struct netent_data net_data;
186
187				return getnetbyname_r((const char *)0, &netent_buf, &net_data);
188			    ],
189			    [
190				AC_MSG_RESULT(yes)
191				AC_DEFINE(HAVE_AIX_GETNETBYNAME_R, 1,
192				    [define if we have the AIX getnetbyname_r()])
193			    ],
194			    [
195				AC_MSG_RESULT(no)
196			    ])
197		    ])
198	    ])
199    ],,[#include <netdb.h>])
200
201#
202# Check for reentrant versions of getprotobyname_r(), as provided by
203# Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
204# If we don't find one, we just use getprotobyname(), which uses
205# thread-specific data on many platforms, but doesn't use it on
206# NetBSD or OpenBSD, and may not use it on older versions of other
207# platforms.
208#
209# Only do the check if we have a declaration of getprotobyname_r();
210# without it, we can't check which API it has.  (We assume that
211# if there's a declaration, it has a prototype, so that the API
212# can be checked.)
213#
214AC_CHECK_DECL(getprotobyname_r,
215    [
216	AC_MSG_CHECKING([for the Linux getprotobyname_r()])
217	AC_TRY_LINK(
218	    [#include <netdb.h>],
219	    [
220		struct protoent protoent_buf;
221		char buf[1024];
222		struct protoent *resultp;
223
224		return getprotobyname_r((const char *)0, &protoent_buf, buf, sizeof buf, &resultp);
225	    ],
226	    [
227		AC_MSG_RESULT(yes)
228		AC_DEFINE(HAVE_LINUX_GETPROTOBYNAME_R, 1,
229		    [define if we have the Linux getprotobyname_r()])
230	    ],
231	    [
232		AC_MSG_RESULT(no)
233
234		AC_MSG_CHECKING([for Solaris/IRIX getprotobyname_r()])
235		AC_TRY_LINK(
236		    [#include <netdb.h>],
237		    [
238			struct protoent protoent_buf;
239			char buf[1024];
240
241			return getprotobyname_r((const char *)0, &protoent_buf, buf, (int)sizeof buf) != NULL;
242		    ],
243		    [
244			AC_MSG_RESULT(yes)
245			AC_DEFINE(HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R, 1,
246			    [define if we have the Solaris/IRIX getprotobyname_r()])
247		    ],
248		    [
249			AC_MSG_RESULT(no)
250
251			AC_MSG_CHECKING([for AIX getprotobyname_r()])
252			AC_TRY_LINK(
253			    [#include <netdb.h>],
254			    [
255				struct protoent protoent_buf;
256				struct protoent_data proto_data;
257
258				return getprotobyname_r((const char *)0, &protoent_buf, &proto_data);
259			    ],
260			    [
261				AC_MSG_RESULT(yes)
262				AC_DEFINE(HAVE_AIX_GETPROTOBYNAME_R, 1,
263				    [define if we have the AIX getprotobyname_r()])
264			    ],
265			    [
266				AC_MSG_RESULT(no)
267			    ])
268		    ])
269	    ])
270    ],,[#include <netdb.h>])
271
272#
273# You are in a twisty little maze of UN*Xes, all different.
274# Some might not have ether_hostton().
275# Some might have it and declare it in <net/ethernet.h>.
276# Some might have it and declare it in <netinet/ether.h>
277# Some might have it and declare it in <sys/ethernet.h>.
278# Some might have it and declare it in <arpa/inet.h>.
279# Some might have it and declare it in <netinet/if_ether.h>.
280# Some might have it and not declare it in any header file.
281#
282# Before you is a C compiler.
283#
284AC_CHECK_FUNCS(ether_hostton)
285if test "$ac_cv_func_ether_hostton" = yes; then
286	#
287	# OK, we have ether_hostton().  Is it declared in <net/ethernet.h>?
288	#
289	# This test fails if we don't have <net/ethernet.h> or if we do
290	# but it doesn't declare ether_hostton().
291	#
292	AC_CHECK_DECL(ether_hostton,
293	    [
294		AC_DEFINE(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON,,
295		    [Define to 1 if net/ethernet.h declares `ether_hostton'])
296	    ],,
297	    [
298#include <net/ethernet.h>
299	    ])
300	#
301	# Did that succeed?
302	#
303	if test "$ac_cv_have_decl_ether_hostton" != yes; then
304		#
305		# No, how about <netinet/ether.h>, as on Linux?
306		#
307		# This test fails if we don't have <netinet/ether.h>
308		# or if we do but it doesn't declare ether_hostton().
309		#
310		# Unset ac_cv_have_decl_ether_hostton so we don't
311		# treat the previous failure as a cached value and
312		# suppress the next test.
313		#
314		unset ac_cv_have_decl_ether_hostton
315		AC_CHECK_DECL(ether_hostton,
316		    [
317			AC_DEFINE(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON,,
318			    [Define to 1 if netinet/ether.h declares `ether_hostton'])
319		    ],,
320		    [
321#include <netinet/ether.h>
322		    ])
323	fi
324	#
325	# Did that succeed?
326	#
327	if test "$ac_cv_have_decl_ether_hostton" != yes; then
328		#
329		# No, how about <sys/ethernet.h>, as on Solaris 10
330		# and later?
331		#
332		# This test fails if we don't have <sys/ethernet.h>
333		# or if we do but it doesn't declare ether_hostton().
334		#
335		# Unset ac_cv_have_decl_ether_hostton so we don't
336		# treat the previous failure as a cached value and
337		# suppress the next test.
338		#
339		unset ac_cv_have_decl_ether_hostton
340		AC_CHECK_DECL(ether_hostton,
341		    [
342			AC_DEFINE(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON,,
343			    [Define to 1 if sys/ethernet.h declares `ether_hostton'])
344		    ],,
345		    [
346#include <sys/ethernet.h>
347		    ])
348	fi
349	#
350	# Did that succeed?
351	#
352	if test "$ac_cv_have_decl_ether_hostton" != yes; then
353		#
354		# No, how about <arpa/inet.h>, as in AIX?
355		#
356		# This test fails if we don't have <arpa/inet.h>
357		# (if we have ether_hostton(), we should have
358		# networking, and if we have networking, we should
359		# have <arapa/inet.h>) or if we do but it doesn't
360		# declare ether_hostton().
361		#
362		# Unset ac_cv_have_decl_ether_hostton so we don't
363		# treat the previous failure as a cached value and
364		# suppress the next test.
365		#
366		unset ac_cv_have_decl_ether_hostton
367		AC_CHECK_DECL(ether_hostton,
368		    [
369			AC_DEFINE(ARPA_INET_H_DECLARES_ETHER_HOSTTON,,
370			    [Define to 1 if arpa/inet.h declares `ether_hostton'])
371		    ],,
372		    [
373#include <arpa/inet.h>
374		    ])
375	fi
376	#
377	# Did that succeed?
378	#
379	if test "$ac_cv_have_decl_ether_hostton" != yes; then
380		#
381		# No, how about <netinet/if_ether.h>?
382		# On some platforms, it requires <net/if.h> and
383		# <netinet/in.h>, and we always include it with
384		# both of them, so test it with both of them.
385		#
386		# This test fails if we don't have <netinet/if_ether.h>
387		# and the headers we include before it, or if we do but
388		# <netinet/if_ether.h> doesn't declare ether_hostton().
389		#
390		# Unset ac_cv_have_decl_ether_hostton so we don't
391		# treat the previous failure as a cached value and
392		# suppress the next test.
393		#
394		unset ac_cv_have_decl_ether_hostton
395		AC_CHECK_DECL(ether_hostton,
396		    [
397			AC_DEFINE(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON,,
398			    [Define to 1 if netinet/if_ether.h declares `ether_hostton'])
399		    ],,
400		    [
401#include <sys/types.h>
402#include <sys/socket.h>
403#include <net/if.h>
404#include <netinet/in.h>
405#include <netinet/if_ether.h>
406		    ])
407	fi
408	#
409	# After all that, is ether_hostton() declared?
410	#
411	if test "$ac_cv_have_decl_ether_hostton" = yes; then
412		#
413		# Yes.
414		#
415		AC_DEFINE(HAVE_DECL_ETHER_HOSTTON, 1,
416		    [Define to 1 if you have the declaration of `ether_hostton'])
417        else
418		#
419		# No, we'll have to declare it ourselves.
420		# Do we have "struct ether_addr" if we include
421		# <netinet/if_ether.h>?
422		#
423		AC_CHECK_TYPES(struct ether_addr,,,
424		    [
425			#include <sys/types.h>
426			#include <sys/socket.h>
427			#include <net/if.h>
428			#include <netinet/in.h>
429			#include <netinet/if_ether.h>
430		    ])
431	fi
432fi
433
434#
435# For various things that might use pthreads.
436#
437AC_CHECK_HEADER(pthread.h,
438    [
439	#
440	# OK, we have pthread.h.  Do we have pthread_create in the
441	# system libraries?
442	#
443	AC_CHECK_FUNC(pthread_create,
444	    [
445		#
446		# Yes.
447		#
448		ac_lbl_have_pthreads="found"
449	    ],
450	    [
451		#
452		# No - do we have it in -lpthreads?
453		#
454		AC_CHECK_LIB(pthreads, pthread_create,
455		    [
456			#
457			# Yes - add -lpthreads.
458			#
459			ac_lbl_have_pthreads="found"
460			PTHREAD_LIBS="$PTHREAD_LIBS -lpthreads"
461		    ],
462		    [
463			#
464			# No - do we have it in -lpthread?
465			#
466			AC_CHECK_LIB(pthread, pthread_create,
467			    [
468				#
469				# Yes - add -lpthread.
470				#
471                                ac_lbl_have_pthreads="found"
472				PTHREAD_LIBS="$PTHREAD_LIBS -lpthread"
473			    ],
474			    [
475				#
476				# No.
477				#
478				ac_lbl_have_pthreads="not found"
479			    ])
480		    ])
481	    ])
482    ],
483    [
484	#
485	# We didn't find pthread.h.
486	#
487	ac_lbl_have_pthreads="not found"
488    ]
489)
490
491dnl to pacify those who hate protochain insn
492AC_MSG_CHECKING(if --disable-protochain option is specified)
493AC_ARG_ENABLE(protochain,
494AC_HELP_STRING([--disable-protochain],[disable \"protochain\" insn]))
495case "x$enable_protochain" in
496xyes)	enable_protochain=enabled	;;
497xno)	enable_protochain=disabled	;;
498x)	enable_protochain=enabled	;;
499esac
500
501if test "$enable_protochain" = "disabled"; then
502	AC_DEFINE(NO_PROTOCHAIN,1,[do not use protochain])
503fi
504AC_MSG_RESULT(${enable_protochain})
505
506#
507# valgrindtest directly uses the native capture mechanism, but
508# only tests with BPF and PF_PACKET sockets; only enable it if
509# we have BPF or PF_PACKET sockets.
510#
511VALGRINDTEST_SRC=
512
513#
514# SITA support is mutually exclusive with native capture support;
515# "--with-sita" selects SITA support.
516#
517AC_ARG_WITH(sita,
518AC_HELP_STRING([--with-sita],[include SITA support]),
519[
520	if test ! "x$withval" = "xno" ; then
521		AC_DEFINE(SITA,1,[include ACN support])
522		AC_MSG_NOTICE(Enabling SITA ACN support)
523		V_PCAP=sita
524	fi
525],
526[
527AC_ARG_WITH(pcap,
528AC_HELP_STRING([--with-pcap=TYPE],[use packet capture TYPE]))
529if test ! -z "$with_pcap" ; then
530	V_PCAP="$withval"
531else
532	#
533	# Check for a bunch of headers for various packet
534	# capture mechanisms.
535	#
536	AC_CHECK_HEADERS(net/bpf.h)
537	if test "$ac_cv_header_net_bpf_h" = yes; then
538		#
539		# Does it define BIOCSETIF?
540		# I.e., is it a header for an LBL/BSD-style capture
541		# mechanism, or is it just a header for a BPF filter
542		# engine?  Some versions of Arch Linux, for example,
543		# have a net/bpf.h that doesn't define BIOCSETIF;
544		# as it's a Linux, it should use packet sockets,
545		# instead.
546		#
547		# We need:
548		#
549		#  sys/types.h, because FreeBSD 10's net/bpf.h
550		#  requires that various BSD-style integer types
551		#  be defined;
552		#
553		#  sys/ioctl.h and, if we have it, sys/ioccom.h,
554		#  because net/bpf.h defines ioctls;
555		#
556		#  net/if.h, because it defines some structures
557		#  used in ioctls defined by net/bpf.h;
558		#
559		#  sys/socket.h, because OpenBSD 5.9's net/bpf.h
560		#  defines some structure fields as being
561		#  struct sockaddrs;
562		#
563		# and net/bpf.h doesn't necessarily include all
564		# of those headers itself.
565		#
566		AC_MSG_CHECKING(if net/bpf.h defines BIOCSETIF)
567		AC_CACHE_VAL(ac_cv_lbl_bpf_h_defines_biocsetif,
568			AC_TRY_COMPILE(
569[
570#include <sys/types.h>
571#include <sys/ioctl.h>
572#include <sys/socket.h>
573#ifdef HAVE_SYS_IOCCOM_H
574#include <sys/ioccom.h>
575#endif
576#include <net/bpf.h>
577#include <net/if.h>
578],
579			[u_int i = BIOCSETIF;],
580			ac_cv_lbl_bpf_h_defines_biocsetif=yes,
581			ac_cv_lbl_bpf_h_defines_biocsetif=no))
582		AC_MSG_RESULT($ac_cv_lbl_bpf_h_defines_biocsetif)
583	fi
584	AC_CHECK_HEADERS(net/pfilt.h net/enet.h)
585	AC_CHECK_HEADERS(net/nit.h sys/net/nit.h)
586	AC_CHECK_HEADERS(linux/socket.h net/raw.h sys/dlpi.h)
587
588	if test "$ac_cv_lbl_bpf_h_defines_biocsetif" = yes; then
589		#
590		# BPF.
591		# Check this before DLPI, so that we pick BPF on
592		# Solaris 11 and later.
593		#
594		V_PCAP=bpf
595
596		#
597		# We have BPF, so build valgrindtest with "make test"
598		# on macOS and FreeBSD (add your OS once there's a
599		# valgrind for it).
600		#
601		case "$host_os" in
602
603		freebsd*|darwin*|linux*)
604			VALGRINDTEST_SRC=valgrindtest.c
605			;;
606		esac
607	elif test "$ac_cv_header_linux_socket_h" = yes; then
608		#
609		# No prizes for guessing this one.
610		#
611		V_PCAP=linux
612
613		#
614		# XXX - this won't work with older kernels that have
615		# SOCK_PACKET sockets but not PF_PACKET sockets.
616		#
617		VALGRINDTEST_SRC=valgrindtest.c
618	elif test "$ac_cv_header_net_pfilt_h" = yes; then
619	        #
620	        # DEC OSF/1, Digital UNIX, Tru64 UNIX
621        	#
622		V_PCAP=pf
623	elif test "$ac_cv_header_net_enet_h" = yes; then
624		#
625		# Stanford Enetfilter.
626		#
627		V_PCAP=enet
628	elif test "$ac_cv_header_net_nit_h" = yes; then
629		#
630		# SunOS 4.x STREAMS NIT.
631		#
632		V_PCAP=snit
633	elif test "$ac_cv_header_sys_net_nit_h" = yes; then
634		#
635		# Pre-SunOS 4.x non-STREAMS NIT.
636		#
637		V_PCAP=nit
638	elif test "$ac_cv_header_net_raw_h" = yes; then
639		#
640		# IRIX snoop.
641		#
642		V_PCAP=snoop
643	elif test "$ac_cv_header_sys_dlpi_h" = yes; then
644		#
645		# DLPI on pre-Solaris 11 SunOS 5, HP-UX, possibly others.
646		#
647		V_PCAP=dlpi
648	else
649		#
650		# Nothing we support.
651		#
652		V_PCAP=null
653		AC_MSG_WARN(cannot determine packet capture interface)
654		AC_MSG_WARN((see the INSTALL doc for more info))
655	fi
656fi
657AC_MSG_CHECKING(packet capture type)
658AC_MSG_RESULT($V_PCAP)
659AC_SUBST(VALGRINDTEST_SRC)
660
661#
662# Do capture-mechanism-dependent tests.
663#
664case "$V_PCAP" in
665dlpi)
666	#
667	# Needed for common functions used by pcap-[dlpi,libdlpi].c
668	#
669 	SSRC="dlpisubs.c"
670
671	#
672	# Checks for some header files.
673	#
674	AC_CHECK_HEADERS(sys/bufmod.h sys/dlpi_ext.h)
675
676	#
677	# Checks to see if Solaris has the public libdlpi(3LIB) library.
678	# Note: The existence of /usr/include/libdlpi.h does not mean it is the
679	# public libdlpi(3LIB) version. Before libdlpi was made public, a
680	# private version also existed, which did not have the same APIs.
681	# Due to a gcc bug, the default search path for 32-bit libraries does
682	# not include /lib, we add it explicitly here.
683	# [http://bugs.opensolaris.org/view_bug.do?bug_id=6619485].
684	# Also, due to the bug above applications that link to libpcap with
685	# libdlpi will have to add "-L/lib" option to "configure".
686	#
687	saved_ldflags=$LDFLAGS
688	LDFLAGS="$LIBS -L/lib"
689	AC_CHECK_LIB(dlpi, dlpi_walk,
690		[
691			LIBS="-ldlpi $LIBS"
692			V_PCAP=libdlpi
693			AC_DEFINE(HAVE_LIBDLPI,1,[if libdlpi exists])
694		],
695		V_PCAP=dlpi)
696	LDFLAGS=$saved_ldflags
697
698	#
699	# Checks whether <sys/dlpi.h> is usable, to catch weird SCO
700	# versions of DLPI.
701	#
702	AC_MSG_CHECKING(whether <sys/dlpi.h> is usable)
703	AC_CACHE_VAL(ac_cv_sys_dlpi_usable,
704		AC_TRY_COMPILE(
705		    [
706			#include <sys/types.h>
707			#include <sys/time.h>
708			#include <sys/dlpi.h>
709		    ],
710		    [int i = DL_PROMISC_PHYS;],
711		    ac_cv_sys_dlpi_usable=yes,
712		    ac_cv_sys_dlpi_usable=no))
713	AC_MSG_RESULT($ac_cv_sys_dlpi_usable)
714	if test $ac_cv_sys_dlpi_usable = no ; then
715		AC_MSG_ERROR(<sys/dlpi.h> is not usable on this system; it probably has a non-standard DLPI)
716	fi
717
718	#
719	# Check to see if Solaris has the dl_passive_req_t struct defined
720	# in <sys/dlpi.h>.
721	# This check is for DLPI support for passive modes.
722	# See dlpi(7P) for more details.
723	#
724	AC_CHECK_TYPES(dl_passive_req_t,,,
725	    [
726		#include <sys/types.h>
727		#include <sys/dlpi.h>
728	    ])
729	;;
730
731linux)
732	#
733	# Do we have the wireless extensions?
734	#
735	AC_CHECK_HEADERS(linux/wireless.h, [], [],
736	[
737#include <sys/socket.h>
738#include <linux/if.h>
739#include <linux/types.h>
740	])
741
742	#
743	# Do we have libnl?
744	#
745	AC_ARG_WITH(libnl,
746	AC_HELP_STRING([--without-libnl],[disable libnl support @<:@default=yes, on Linux, if present@:>@]),
747		with_libnl=$withval,with_libnl=if_available)
748
749	if test x$with_libnl != xno ; then
750		have_any_nl="no"
751
752                incdir=-I/usr/include/libnl3
753                libnldir=
754                case "$with_libnl" in
755
756                yes|if_available)
757                  ;;
758
759                *)
760                  if test -d $withval; then
761                    libnldir=-L${withval}/lib/.libs
762                    incdir=-I${withval}/include
763                  fi
764                  ;;
765                esac
766
767		#
768		# Try libnl 3.x first.
769		#
770		AC_CHECK_LIB(nl-3, nl_socket_alloc,
771		[
772			#
773			# Yes, we have libnl 3.x.
774			#
775			LIBS="${libnldir} -lnl-genl-3 -lnl-3 $LIBS"
776			AC_DEFINE(HAVE_LIBNL,1,[if libnl exists])
777			AC_DEFINE(HAVE_LIBNL_3_x,1,[if libnl exists and is version 3.x])
778			AC_DEFINE(HAVE_LIBNL_NLE,1,[libnl has NLE_FAILURE])
779			AC_DEFINE(HAVE_LIBNL_SOCKETS,1,[libnl has new-style socket api])
780			V_INCLS="$V_INCLS ${incdir}"
781			have_any_nl="yes"
782		],[], ${incdir} ${libnldir} -lnl-genl-3 -lnl-3 )
783
784		if test x$have_any_nl = xno ; then
785			#
786			# Try libnl 2.x
787			#
788			AC_CHECK_LIB(nl, nl_socket_alloc,
789			[
790				#
791				# Yes, we have libnl 2.x.
792				#
793				LIBS="${libnldir} -lnl-genl -lnl $LIBS"
794				AC_DEFINE(HAVE_LIBNL,1,[if libnl exists])
795				AC_DEFINE(HAVE_LIBNL_2_x,1,[if libnl exists and is version 2.x])
796				AC_DEFINE(HAVE_LIBNL_NLE,1,[libnl has NLE_FAILURE])
797				AC_DEFINE(HAVE_LIBNL_SOCKETS,1,[libnl has new-style socket api])
798				have_any_nl="yes"
799			])
800		fi
801
802		if test x$have_any_nl = xno ; then
803			#
804			# No, we don't; do we have libnl 1.x?
805			#
806			AC_CHECK_LIB(nl, nl_handle_alloc,
807			[
808				#
809				# Yes.
810				#
811				LIBS="${libnldir} -lnl $LIBS"
812				AC_DEFINE(HAVE_LIBNL,1,[if libnl exists])
813				have_any_nl="yes"
814			])
815		fi
816
817		if test x$have_any_nl = xno ; then
818			#
819			# No, we don't have libnl at all.
820			#
821			if test x$with_libnl = xyes ; then
822				AC_MSG_ERROR([libnl support requested but libnl not found])
823			fi
824		fi
825	fi
826
827	AC_CHECK_HEADERS(linux/ethtool.h,,,
828	    [
829AC_INCLUDES_DEFAULT
830#include <linux/types.h>
831	    ])
832
833	#
834	# Check to see if struct tpacket_stats is defined in
835	# <linux/if_packet.h>.  If so, then pcap-linux.c can use this
836	# to report proper statistics.
837	#
838	# -Scott Barron
839	#
840	AC_CHECK_TYPES(struct tpacket_stats,,,
841	    [
842		#include <linux/if_packet.h>
843	    ])
844
845	#
846	# Check to see if the tpacket_auxdata struct has a tp_vlan_tci member.
847	#
848	# NOTE: any failure means we conclude that it doesn't have that
849	# member, so if we don't have tpacket_auxdata, we conclude it
850	# doesn't have that member (which is OK, as either we won't be
851	# using code that would use that member, or we wouldn't compile
852	# in any case).
853	AC_CHECK_MEMBERS([struct tpacket_auxdata.tp_vlan_tci],,,
854	    [
855		#include <sys/types.h>
856		#include <linux/if_packet.h>
857	    ])
858	;;
859
860bpf)
861	#
862	# Check whether we have the *BSD-style ioctls.
863	#
864	AC_CHECK_HEADERS(net/if_media.h)
865
866	#
867	# Check whether we have struct BPF_TIMEVAL.
868	#
869	AC_CHECK_TYPES(struct BPF_TIMEVAL,,,
870	    [
871		#include <sys/types.h>
872		#include <sys/ioctl.h>
873		#ifdef HAVE_SYS_IOCCOM_H
874		#include <sys/ioccom.h>
875		#endif
876		#include <net/bpf.h>
877	    ])
878	;;
879
880dag)
881	#
882	# --with-pcap=dag is the only way to get here, and it means
883	# "DAG support but nothing else"
884	#
885	V_DEFS="$V_DEFS -DDAG_ONLY"
886	xxx_only=yes
887	;;
888
889septel)
890	#
891	# --with-pcap=septel is the only way to get here, and it means
892	# "Septel support but nothing else"
893	#
894	V_DEFS="$V_DEFS -DSEPTEL_ONLY"
895	xxx_only=yes
896	;;
897
898snf)
899	#
900	# --with-pcap=snf is the only way to get here, and it means
901	# "SNF support but nothing else"
902	#
903	V_DEFS="$V_DEFS -DSNF_ONLY"
904	xxx_only=yes
905	;;
906
907null)
908	;;
909
910*)
911	AC_MSG_ERROR($V_PCAP is not a valid pcap type)
912	;;
913esac
914
915dnl
916dnl Now figure out how we get a list of interfaces and addresses,
917dnl if we support capturing.  Don't bother if we don't support
918dnl capturing.
919dnl
920if test "$V_PCAP" != null
921then
922	AC_CHECK_FUNC(getifaddrs,[
923		#
924		# We have "getifaddrs()"; make sure we have <ifaddrs.h>
925		# as well, just in case some platform is really weird.
926		#
927		AC_CHECK_HEADER(ifaddrs.h,[
928		    #
929		    # We have the header, so we use "getifaddrs()" to
930		    # get the list of interfaces.
931		    #
932		    V_FINDALLDEVS=fad-getad.c
933		],[
934		    #
935		    # We don't have the header - give up.
936		    # XXX - we could also fall back on some other
937		    # mechanism, but, for now, this'll catch this
938		    # problem so that we can at least try to figure
939		    # out something to do on systems with "getifaddrs()"
940		    # but without "ifaddrs.h", if there is something
941		    # we can do on those systems.
942		    #
943		    AC_MSG_ERROR([Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.])
944		])
945	],[
946		#
947		# Well, we don't have "getifaddrs()", at least not with the
948		# libraries with which we've decided we need to link
949		# libpcap with, so we have to use some other mechanism.
950		#
951		# Note that this may happen on Solaris, which has
952		# getifaddrs(), but in -lsocket, not in -lxnet, so we
953		# won't find it if we link with -lxnet, which we want
954		# to do for other reasons.
955		#
956		# For now, we use either the SIOCGIFCONF ioctl or the
957		# SIOCGLIFCONF ioctl, preferring the latter if we have
958		# it; the latter is a Solarisism that first appeared
959		# in Solaris 8.  (Solaris's getifaddrs() appears to
960		# be built atop SIOCGLIFCONF; using it directly
961		# avoids a not-all-that-useful middleman.)
962		#
963		AC_MSG_CHECKING(whether we have SIOCGLIFCONF)
964		AC_CACHE_VAL(ac_cv_lbl_have_siocglifconf,
965		    AC_TRY_COMPILE(
966			[#include <sys/param.h>
967			#include <sys/file.h>
968			#include <sys/ioctl.h>
969			#include <sys/socket.h>
970			#include <sys/sockio.h>],
971			[ioctl(0, SIOCGLIFCONF, (char *)0);],
972			ac_cv_lbl_have_siocglifconf=yes,
973			ac_cv_lbl_have_siocglifconf=no))
974		AC_MSG_RESULT($ac_cv_lbl_have_siocglifconf)
975		if test $ac_cv_lbl_have_siocglifconf = yes ; then
976			V_FINDALLDEVS=fad-glifc.c
977		else
978			V_FINDALLDEVS=fad-gifc.c
979		fi
980	])
981fi
982])
983
984dnl check for hardware timestamp support
985case "$host_os" in
986linux*)
987	AC_CHECK_HEADERS([linux/net_tstamp.h])
988	;;
989*)
990	AC_MSG_NOTICE(no hardware timestamp support implemented for $host_os)
991	;;
992esac
993
994AC_ARG_ENABLE([packet-ring],
995[AC_HELP_STRING([--enable-packet-ring],[enable packet ring support on Linux @<:@default=yes@:>@])],
996,enable_packet_ring=yes)
997
998if test "x$enable_packet_ring" != "xno" ; then
999	AC_DEFINE(PCAP_SUPPORT_PACKET_RING, 1, [use packet ring capture support on Linux if available])
1000	AC_SUBST(PCAP_SUPPORT_PACKET_RING)
1001fi
1002
1003#
1004# Check for socklen_t.
1005#
1006AC_CHECK_TYPES(socklen_t,,,
1007    [
1008	#include <sys/types.h>
1009	#include <sys/socket.h>
1010    ])
1011
1012AC_ARG_ENABLE(ipv6,
1013AC_HELP_STRING([--enable-ipv6],[build IPv6-capable version @<:@default=yes@:>@]),
1014    [],
1015    [enable_ipv6=yes])
1016if test "$enable_ipv6" != "no"; then
1017	#
1018	# We've already made sure we have getaddrinfo above in
1019	# AC_LBL_LIBRARY_NET.
1020	#
1021	AC_DEFINE(INET6,1,[IPv6])
1022fi
1023
1024# Check for Endace DAG card support.
1025AC_ARG_WITH([dag],
1026AC_HELP_STRING([--with-dag@<:@=DIR@:>@],[include Endace DAG support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1027[
1028	if test "$withval" = no
1029	then
1030		# User doesn't want DAG support.
1031		want_dag=no
1032	elif test "$withval" = yes
1033	then
1034		# User wants DAG support but hasn't specified a directory.
1035		want_dag=yes
1036	else
1037		# User wants DAG support and has specified a directory, so use the provided value.
1038		want_dag=yes
1039		dag_root=$withval
1040	fi
1041],[
1042	if test "$V_PCAP" = dag; then
1043		# User requested DAG-only libpcap, so we'd better have
1044		# the DAG API.
1045		want_dag=yes
1046	elif test "xxx_only" = yes; then
1047		# User requested something-else-only pcap, so they don't
1048		# want DAG support.
1049		want_dag=no
1050	else
1051		#
1052		# Use DAG API if present, otherwise don't
1053		#
1054		want_dag=ifpresent
1055	fi
1056])
1057
1058AC_ARG_WITH([dag-includes],
1059AC_HELP_STRING([--with-dag-includes=IDIR],[Endace DAG include directory, if not DIR/include]),
1060[
1061	# User wants DAG support and has specified a header directory, so use the provided value.
1062	want_dag=yes
1063	dag_include_dir=$withval
1064],[])
1065
1066AC_ARG_WITH([dag-libraries],
1067AC_HELP_STRING([--with-dag-libraries=LDIR],[Endace DAG library directory, if not DIR/lib]),
1068[
1069	# User wants DAG support and has specified a library directory, so use the provided value.
1070	want_dag=yes
1071	dag_lib_dir=$withval
1072],[])
1073
1074if test "$want_dag" != no; then
1075
1076	# If necessary, set default paths for DAG API headers and libraries.
1077	if test -z "$dag_root"; then
1078		dag_root=/usr/local
1079	fi
1080
1081	if test -z "$dag_include_dir"; then
1082		dag_include_dir="$dag_root/include"
1083	fi
1084
1085	if test -z "$dag_lib_dir"; then
1086		dag_lib_dir="$dag_root/lib"
1087	fi
1088
1089	V_INCLS="$V_INCLS -I$dag_include_dir"
1090
1091	AC_CHECK_HEADERS([dagapi.h])
1092
1093	if test "$ac_cv_header_dagapi_h" = yes; then
1094
1095		if test $V_PCAP != dag ; then
1096			 SSRC="$SSRC pcap-dag.c"
1097		fi
1098
1099		# Check for various DAG API functions.
1100		# Don't need to save and restore LIBS to prevent -ldag being
1101		# included if there's a found-action (arg 3).
1102		saved_ldflags=$LDFLAGS
1103		LDFLAGS="-L$dag_lib_dir"
1104		AC_CHECK_LIB([dag], [dag_attach_stream],
1105		    [],
1106		    [AC_MSG_ERROR(DAG library lacks streams support)])
1107		AC_CHECK_LIB([dag], [dag_attach_stream64], [dag_large_streams="1"], [dag_large_streams="0"])
1108		AC_CHECK_LIB([dag],[dag_get_erf_types], [
1109			AC_DEFINE(HAVE_DAG_GET_ERF_TYPES, 1, [define if you have dag_get_erf_types()])])
1110		AC_CHECK_LIB([dag],[dag_get_stream_erf_types], [
1111			AC_DEFINE(HAVE_DAG_GET_STREAM_ERF_TYPES, 1, [define if you have dag_get_stream_erf_types()])])
1112
1113		LDFLAGS=$saved_ldflags
1114
1115		#
1116		# We assume that if we have libdag we have libdagconf,
1117		# as they're installed at the same time from the same
1118		# package.
1119		#
1120		LIBS="$LIBS -ldag -ldagconf"
1121		LDFLAGS="$LDFLAGS -L$dag_lib_dir"
1122
1123		if test "$dag_large_streams" = 1; then
1124			AC_DEFINE(HAVE_DAG_LARGE_STREAMS_API, 1, [define if you have large streams capable DAG API])
1125			AC_CHECK_LIB([vdag],[vdag_set_device_info], [ac_dag_have_vdag="1"], [ac_dag_have_vdag="0"])
1126			if test "$ac_dag_have_vdag" = 1; then
1127				AC_DEFINE(HAVE_DAG_VDAG, 1, [define if you have vdag_set_device_info()])
1128				if test "$ac_lbl_have_pthreads" != "found"; then
1129					AC_MSG_ERROR([DAG requires pthreads, but we didn't find them])
1130				fi
1131				LIBS="$LIBS $PTHREAD_LIBS"
1132			fi
1133		fi
1134
1135		AC_DEFINE(HAVE_DAG_API, 1, [define if you have the DAG API])
1136	else
1137
1138		if test "$V_PCAP" = dag; then
1139			# User requested "dag" capture type but we couldn't
1140			# find the DAG API support.
1141			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])
1142		fi
1143
1144		if test "$want_dag" = yes; then
1145	        	# User wanted DAG support but we couldn't find it.
1146			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])
1147		fi
1148	fi
1149fi
1150
1151AC_ARG_WITH(septel,
1152AC_HELP_STRING([--with-septel@<:@=DIR@:>@],[include Septel support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1153[
1154	if test "$withval" = no
1155	then
1156		want_septel=no
1157	elif test "$withval" = yes
1158	then
1159		want_septel=yes
1160		septel_root=
1161	else
1162		want_septel=yes
1163		septel_root=$withval
1164	fi
1165],[
1166	if test "$V_PCAP" = septel; then
1167		# User requested Septel-only libpcap, so we'd better have
1168		# the Septel API.
1169		want_septel=yes
1170	elif test "xxx_only" = yes; then
1171		# User requested something-else-only pcap, so they don't
1172		# want Septel support.
1173		want_septel=no
1174	else
1175		#
1176		# Use Septel API if present, otherwise don't
1177		#
1178		want_septel=ifpresent
1179	fi
1180])
1181
1182ac_cv_lbl_septel_api=no
1183if test "$with_septel" != no; then
1184
1185	AC_MSG_CHECKING([whether we have Septel API headers])
1186
1187	# If necessary, set default paths for Septel API headers and libraries.
1188	if test -z "$septel_root"; then
1189		septel_root=$srcdir/../septel
1190	fi
1191
1192	septel_tools_dir="$septel_root"
1193	septel_include_dir="$septel_root/INC"
1194
1195	if test -r "$septel_include_dir/msg.h"; then
1196		ac_cv_lbl_septel_api=yes
1197	fi
1198
1199	if test "$ac_cv_lbl_septel_api" = yes; then
1200		AC_MSG_RESULT([yes ($septel_include_dir)])
1201
1202		V_INCLS="$V_INCLS -I$septel_include_dir"
1203		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"
1204		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"
1205
1206		if test "$V_PCAP" != septel ; then
1207			 SSRC="$SSRC pcap-septel.c"
1208		fi
1209
1210		AC_DEFINE(HAVE_SEPTEL_API, 1, [define if you have the Septel API])
1211	else
1212		AC_MSG_RESULT(no)
1213
1214		if test "$V_PCAP" = septel; then
1215			# User requested "septel" capture type but
1216			# we couldn't find the Septel API support.
1217			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])
1218		fi
1219
1220		if test "$want_septel" = yes; then
1221	        	# User wanted Septel support but we couldn't find it.
1222			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])
1223		fi
1224	fi
1225fi
1226
1227# Check for Myricom SNF support.
1228AC_ARG_WITH([snf],
1229AC_HELP_STRING([--with-snf@<:@=DIR@:>@],[include Myricom SNF support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1230[
1231	if test "$withval" = no
1232	then
1233		# User explicitly doesn't want SNF
1234		want_snf=no
1235	elif test "$withval" = yes
1236	then
1237		# User wants SNF support but hasn't specified a directory.
1238		want_snf=yes
1239	else
1240		# User wants SNF support with a specified directory.
1241		want_snf=yes
1242		snf_root=$withval
1243	fi
1244],[
1245	if test "$V_PCAP" = snf; then
1246		# User requested Sniffer-only libpcap, so we'd better have
1247		# the Sniffer API.
1248		want_snf=yes
1249	elif test "xxx_only" = yes; then
1250		# User requested something-else-only pcap, so they don't
1251		# want SNF support.
1252		want_snf=no
1253	else
1254		#
1255		# Use Sniffer API if present, otherwise don't
1256		#
1257		want_snf=ifpresent
1258	fi
1259])
1260
1261AC_ARG_WITH([snf-includes],
1262AC_HELP_STRING([--with-snf-includes=IDIR],[Myricom SNF include directory, if not DIR/include]),
1263[
1264	# User wants SNF with specific header directory
1265	want_snf=yes
1266	snf_include_dir=$withval
1267],[])
1268
1269AC_ARG_WITH([snf-libraries],
1270AC_HELP_STRING([--with-snf-libraries=LDIR],[Myricom SNF library directory, if not DIR/lib]),
1271[
1272	# User wants SNF with specific lib directory
1273	want_snf=yes
1274	snf_lib_dir=$withval
1275],[])
1276
1277ac_cv_lbl_snf_api=no
1278if test "$with_snf" != no; then
1279
1280	AC_MSG_CHECKING(whether we have Myricom Sniffer API)
1281
1282	# If necessary, set default paths for Sniffer headers and libraries.
1283	if test -z "$snf_root"; then
1284		snf_root=/opt/snf
1285	fi
1286
1287	if test -z "$snf_include_dir"; then
1288		snf_include_dir="$snf_root/include"
1289	fi
1290
1291	if test -z "$snf_lib_dir"; then
1292		snf_lib_dir="$snf_root/lib"
1293	fi
1294
1295	if test -f "$snf_include_dir/snf.h"; then
1296		# We found a header; make sure we can link with the library
1297		saved_ldflags=$LDFLAGS
1298		LDFLAGS="$LDFLAGS -L$snf_lib_dir"
1299		AC_CHECK_LIB([snf], [snf_init], [ac_cv_lbl_snf_api="yes"])
1300		LDFLAGS="$saved_ldflags"
1301		if test "$ac_cv_lbl_snf_api" = no; then
1302			AC_MSG_ERROR(SNF API cannot correctly be linked; check config.log)
1303		fi
1304	fi
1305
1306	if test "$ac_cv_lbl_snf_api" = yes; then
1307		AC_MSG_RESULT([yes ($snf_root)])
1308
1309		V_INCLS="$V_INCLS -I$snf_include_dir"
1310		LIBS="$LIBS -lsnf"
1311		LDFLAGS="$LDFLAGS -L$snf_lib_dir"
1312
1313		if test "$V_PCAP" != snf ; then
1314			SSRC="$SSRC pcap-snf.c"
1315		fi
1316
1317		AC_DEFINE(HAVE_SNF_API, 1, [define if you have the Myricom SNF API])
1318	else
1319		AC_MSG_RESULT(no)
1320
1321		if test "$want_snf" = yes; then
1322			# User requested "snf" capture type but
1323			# we couldn't find the Sniffer API support.
1324			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])
1325		fi
1326
1327		if test "$want_snf" = yes; then
1328			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])
1329		fi
1330	fi
1331fi
1332
1333# Check for Riverbed TurboCap support.
1334AC_ARG_WITH([turbocap],
1335AC_HELP_STRING([--with-turbocap@<:@=DIR@:>@],[include Riverbed TurboCap support (located in directory DIR, if supplied).  @<:@default=yes, if present@:>@]),
1336[
1337	if test "$withval" = no
1338	then
1339		# User explicitly doesn't want TurboCap
1340		want_turbocap=no
1341	elif test "$withval" = yes
1342	then
1343		# User wants TurboCap support but hasn't specified a directory.
1344		want_turbocap=yes
1345	else
1346		# User wants TurboCap support with a specified directory.
1347		want_turbocap=yes
1348		turbocap_root=$withval
1349	fi
1350],[
1351	if test "xxx_only" = yes; then
1352		# User requested something-else-only pcap, so they don't
1353		# want TurboCap support.
1354		want_turbocap=no
1355	else
1356		#
1357		# Use TurboCap API if present, otherwise don't
1358		#
1359		want_turbocap=ifpresent
1360	fi
1361])
1362
1363ac_cv_lbl_turbocap_api=no
1364if test "$want_turbocap" != no; then
1365
1366	AC_MSG_CHECKING(whether TurboCap is supported)
1367
1368	save_CFLAGS="$CFLAGS"
1369	save_LIBS="$LIBS"
1370	if test ! -z "$turbocap_root"; then
1371		TURBOCAP_CFLAGS="-I$turbocap_root/include"
1372		TURBOCAP_LIBS="-L$turbocap_root/lib"
1373		CFLAGS="$CFLAGS $TURBOCAP_CFLAGS"
1374	fi
1375
1376	AC_TRY_COMPILE(
1377	[
1378	    #include <TcApi.h>
1379	],
1380	[
1381	    TC_INSTANCE a; TC_PORT b; TC_BOARD c;
1382	    TC_INSTANCE i;
1383	    (void)TcInstanceCreateByName("foo", &i);
1384	],
1385	ac_cv_lbl_turbocap_api=yes)
1386
1387	CFLAGS="$save_CFLAGS"
1388	if test $ac_cv_lbl_turbocap_api = yes; then
1389		AC_MSG_RESULT(yes)
1390
1391		SSRC="$SSRC pcap-tc.c"
1392		V_INCLS="$V_INCLS $TURBOCAP_CFLAGS"
1393		LIBS="$LIBS $TURBOCAP_LIBS -lTcApi -lpthread -lstdc++"
1394
1395		AC_DEFINE(HAVE_TC_API, 1, [define if you have the TurboCap API])
1396	else
1397		AC_MSG_RESULT(no)
1398
1399		if test "$want_turbocap" = yes; then
1400	        	# User wanted Turbo support but we couldn't find it.
1401			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])
1402		fi
1403	fi
1404fi
1405
1406dnl
1407dnl Allow the user to enable remote capture.
1408dnl It's off by default, as that increases the attack surface of
1409dnl libpcap, exposing it to malicious servers.
1410dnl
1411AC_MSG_CHECKING([whether to enable remote packet capture])
1412AC_ARG_ENABLE(remote,
1413[  --enable-remote         enable remote packet capture @<:@default=no@:>@
1414  --disable-remote        disable remote packet capture],,
1415   enableval=no)
1416case "$enableval" in
1417yes)	AC_MSG_RESULT(yes)
1418	AC_WARN([Remote packet capture may expose libpcap-based applications])
1419	AC_WARN([to attacks by malicious remote capture servers!])
1420	#
1421	# rpcapd requires pthreads on UN*X.
1422	#
1423	if test "$ac_lbl_have_pthreads" != "found"; then
1424		AC_MSG_ERROR([rpcapd requires pthreads, but we didn't find them])
1425	fi
1426	#
1427	# It also requires crypt().
1428	# Do we have it in the system libraries?
1429	#
1430	AC_CHECK_FUNC(crypt,,
1431	    [
1432		#
1433		# No.  Do we have it in -lcrypt?
1434		#
1435		AC_CHECK_LIB(crypt, crypt,
1436		    [
1437			#
1438			# Yes; add -lcrypt to the libraries for rpcapd.
1439			#
1440			RPCAPD_LIBS="$RPCAPD_LIBS -lcrypt"
1441		    ],
1442		    [
1443			AC_MSG_ERROR([rpcapd requires crypt(), but we didn't find it])
1444		    ])
1445	    ])
1446
1447	#
1448	# OK, we have crypt().  Do we have getspnam()?
1449	#
1450	AC_CHECK_FUNCS(getspnam)
1451
1452	#
1453	# Check for various members of struct msghdr.
1454	#
1455	AC_CHECK_MEMBERS([struct msghdr.msg_control],,,
1456	    [
1457		#include "ftmacros.h"
1458		#include <sys/socket.h>
1459	    ])
1460	AC_CHECK_MEMBERS([struct msghdr.msg_flags],,,
1461	    [
1462		#include "ftmacros.h"
1463		#include <sys/socket.h>
1464	    ])
1465
1466	AC_DEFINE(ENABLE_REMOTE,,
1467	    [Define to 1 if remote packet capture is to be supported])
1468	SSRC="$SSRC pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c"
1469	BUILD_RPCAPD=build-rpcapd
1470	INSTALL_RPCAPD=install-rpcapd
1471	;;
1472*)	AC_MSG_RESULT(no)
1473	;;
1474esac
1475
1476AC_MSG_CHECKING(whether to build optimizer debugging code)
1477AC_ARG_ENABLE(optimizer-dbg,
1478AC_HELP_STRING([--enable-optimizer-dbg],[build optimizer debugging code]))
1479if test "$enable_optimizer_dbg" = "yes"; then
1480	AC_DEFINE(BDEBUG,1,[Enable optimizer debugging])
1481fi
1482AC_MSG_RESULT(${enable_optimizer_dbg-no})
1483
1484AC_MSG_CHECKING(whether to build parser debugging code)
1485AC_ARG_ENABLE(yydebug,
1486AC_HELP_STRING([--enable-yydebug],[build parser debugging code]))
1487if test "$enable_yydebug" = "yes"; then
1488	AC_DEFINE(YYDEBUG,1,[Enable parser debugging])
1489fi
1490AC_MSG_RESULT(${enable_yydebug-no})
1491
1492#
1493# Look for {f}lex.
1494#
1495AC_PROG_LEX
1496if test "$LEX" = ":"; then
1497	AC_MSG_ERROR([Neither flex nor lex was found.])
1498fi
1499
1500#
1501# Make sure {f}lex supports the -P, --header-file, and --nounput flags
1502# and supports processing our scanner.l.
1503#
1504AC_CACHE_CHECK([for capable lex], tcpdump_cv_capable_lex,
1505	if $LEX -P pcap_ --header-file=/dev/null --nounput -t $srcdir/scanner.l > /dev/null 2>&1; then
1506	    tcpdump_cv_capable_lex=yes
1507	else
1508	    tcpdump_cv_capable_lex=insufficient
1509	fi)
1510if test $tcpdump_cv_capable_lex = insufficient ; then
1511	AC_MSG_ERROR([$LEX is insufficient to compile libpcap.
1512 libpcap requires Flex 2.5.31 or later, or a compatible version of lex.])
1513fi
1514
1515#
1516# Look for yacc/bison/byacc.
1517#
1518AC_PROG_YACC
1519
1520#
1521# Make sure it supports the -p flag and supports processing our
1522# grammar.y.
1523#
1524AC_CACHE_CHECK([for capable yacc/bison], tcpdump_cv_capable_yacc,
1525	if $YACC -p pcap_ -o /dev/null $srcdir/grammar.y >/dev/null 2>&1; then
1526	    tcpdump_cv_capable_yacc=yes
1527	else
1528	    tcpdump_cv_capable_yacc=insufficient
1529	fi)
1530if test $tcpdump_cv_capable_yacc = insufficient ; then
1531	AC_MSG_ERROR([$YACC is insufficient to compile libpcap.
1532 libpcap requires Bison, Berkeley YACC, or another YACC compatible with them.])
1533fi
1534
1535#
1536# Do various checks for various OSes and versions of those OSes.
1537#
1538# Assume, by default, no support for shared libraries and V7/BSD
1539# convention for man pages (file formats in section 5, miscellaneous
1540# info in section 7, administrative commands and daemons in section 8).
1541# Individual cases can override this.
1542#
1543DYEXT="none"
1544MAN_FILE_FORMATS=5
1545MAN_MISC_INFO=7
1546MAN_ADMIN_COMMANDS=8
1547case "$host_os" in
1548
1549aix*)
1550	dnl Workaround to enable certain features
1551	AC_DEFINE(_SUN,1,[define on AIX to get certain functions])
1552
1553	#
1554	# AIX makes it fun to build shared and static libraries,
1555	# because they're *both* ".a" archive libraries.  We
1556	# build the static library for the benefit of the traditional
1557	# scheme of building libpcap and tcpdump in subdirectories of
1558	# the same directory, with tcpdump statically linked with the
1559	# libpcap in question, but we also build a shared library as
1560	# "libpcap.shareda" and install *it*, rather than the static
1561	# library, as "libpcap.a".
1562	#
1563	DYEXT="shareda"
1564
1565	case "$V_PCAP" in
1566
1567	dlpi)
1568		#
1569		# If we're using DLPI, applications will need to
1570		# use /lib/pse.exp if present, as we use the
1571		# STREAMS routines.
1572		#
1573		pseexe="/lib/pse.exp"
1574		AC_MSG_CHECKING(for $pseexe)
1575		if test -f $pseexe ; then
1576			AC_MSG_RESULT(yes)
1577			LIBS="-I:$pseexe"
1578		fi
1579		;;
1580
1581	bpf)
1582		#
1583		# If we're using BPF, we need "-lodm" and "-lcfg", as
1584		# we use them to load the BPF module.
1585		#
1586		LIBS="-lodm -lcfg"
1587		;;
1588	esac
1589	;;
1590
1591darwin*)
1592	DYEXT="dylib"
1593	V_CCOPT="$V_CCOPT -fno-common"
1594	AC_ARG_ENABLE(universal,
1595	AC_HELP_STRING([--disable-universal],[don't build universal on macOS]))
1596	if test "$enable_universal" != "no"; then
1597		case "$host_os" in
1598
1599		darwin[0-7].*)
1600			#
1601			# Pre-Tiger.  Build only for 32-bit PowerPC; no
1602			# need for any special compiler or linker flags.
1603			#
1604			;;
1605
1606		darwin8.[0123]*)
1607			#
1608			# Tiger, prior to Intel support.  Build for 32-bit
1609			# PowerPC and 64-bit PowerPC, with 32-bit PowerPC
1610			# first.  (I'm guessing that's what Apple does.)
1611			#
1612			V_CCOPT="$V_CCOPT -arch ppc -arch ppc64"
1613			LDFLAGS="$LDFLAGS -arch ppc -arch ppc64"
1614			;;
1615
1616		darwin8.[456]*)
1617			#
1618			# Tiger, subsequent to Intel support but prior to
1619			# x86-64 support.  Build for 32-bit PowerPC, 64-bit
1620			# PowerPC, and x86, with 32-bit PowerPC first.
1621			# (I'm guessing that's what Apple does.)
1622			#
1623			V_CCOPT="$V_CCOPT -arch ppc -arch ppc64 -arch i386"
1624			LDFLAGS="$LDFLAGS -arch ppc -arch ppc64 -arch i386"
1625			;;
1626
1627		darwin8.*)
1628			#
1629			# All other Tiger, so subsequent to x86-64
1630			# support. Build for 32-bit PowerPC, 64-bit
1631			# PowerPC, x86, and x86-64, and with 32-bit PowerPC
1632			# first.  (I'm guessing that's what Apple does.)
1633			#
1634			V_CCOPT="$V_CCOPT -arch ppc -arch ppc64 -arch i386 -arch x86_64"
1635			LDFLAGS="$LDFLAGS -arch ppc -arch ppc64 -arch i386 -arch x86_64"
1636			;;
1637
1638		darwin9.*)
1639			#
1640			# Leopard.  Build for 32-bit PowerPC, 64-bit
1641			# PowerPC, x86, and x86-64, with 32-bit PowerPC
1642			# first.  (That's what Apple does.)
1643			#
1644			V_CCOPT="$V_CCOPT -arch ppc -arch ppc64 -arch i386 -arch x86_64"
1645			LDFLAGS="$LDFLAGS -arch ppc -arch ppc64 -arch i386 -arch x86_64"
1646			;;
1647
1648		darwin10.*)
1649			#
1650			# Snow Leopard.  Build for x86-64, x86, and
1651			# 32-bit PowerPC, with x86-64 first.  (That's
1652			# what Apple does, even though Snow Leopard
1653			# doesn't run on PPC, so PPC libpcap runs under
1654			# Rosetta, and Rosetta doesn't support BPF
1655			# ioctls, so PPC programs can't do live
1656			# captures.)
1657			#
1658			V_CCOPT="$V_CCOPT -arch x86_64 -arch i386 -arch ppc"
1659			LDFLAGS="$LDFLAGS -arch x86_64 -arch i386 -arch ppc"
1660			;;
1661
1662		darwin*)
1663			#
1664			# Post-Snow Leopard.  Build for x86-64 and
1665			# x86, with x86-64 first.  (That's probably what
1666			# Apple does, given that Rosetta is gone.)
1667			# XXX - update if and when Apple drops support
1668			# for 32-bit x86 code.
1669			#
1670			V_CCOPT="$V_CCOPT -arch x86_64 -arch i386"
1671			LDFLAGS="$LDFLAGS -arch x86_64 -arch i386"
1672			;;
1673		esac
1674	fi
1675	;;
1676
1677hpux9*)
1678	AC_DEFINE(HAVE_HPUX9,1,[on HP-UX 9.x])
1679
1680	#
1681	# Use System V conventions for man pages.
1682	#
1683	MAN_ADMIN_COMMANDS=1m
1684	MAN_FILE_FORMATS=4
1685	MAN_MISC_INFO=5
1686	;;
1687
1688hpux10.0*)
1689
1690	#
1691	# Use System V conventions for man pages.
1692	#
1693	MAN_ADMIN_COMMANDS=1m
1694	MAN_FILE_FORMATS=4
1695	MAN_MISC_INFO=5
1696	;;
1697
1698hpux10.1*)
1699
1700	#
1701	# Use System V conventions for man pages.
1702	#
1703	MAN_ADMIN_COMMANDS=1m
1704	MAN_FILE_FORMATS=4
1705	MAN_MISC_INFO=5
1706	;;
1707
1708hpux*)
1709	dnl HPUX 10.20 and above is similar to HPUX 9, but
1710	dnl not the same....
1711	dnl
1712	dnl XXX - DYEXT should be set to "sl" if this is building
1713	dnl for 32-bit PA-RISC, but should be left as "so" for
1714	dnl 64-bit PA-RISC or, I suspect, IA-64.
1715	AC_DEFINE(HAVE_HPUX10_20_OR_LATER,1,[on HP-UX 10.20 or later])
1716	if test "`uname -m`" = "ia64"; then
1717		DYEXT="so"
1718	else
1719		DYEXT="sl"
1720	fi
1721
1722	#
1723	# "-b" builds a shared library; "+h" sets the soname.
1724	#
1725	SHLIB_OPT="-b"
1726	SONAME_OPT="+h"
1727
1728	#
1729	# Use System V conventions for man pages.
1730	#
1731	MAN_FILE_FORMATS=4
1732	MAN_MISC_INFO=5
1733	;;
1734
1735irix*)
1736	#
1737	# Use IRIX conventions for man pages; they're the same as the
1738	# System V conventions, except that they use section 8 for
1739	# administrative commands and daemons.
1740	#
1741	MAN_FILE_FORMATS=4
1742	MAN_MISC_INFO=5
1743	;;
1744
1745linux*|freebsd*|netbsd*|openbsd*|dragonfly*|kfreebsd*|gnu*)
1746	DYEXT="so"
1747
1748	#
1749	# Compiler assumed to be GCC; run-time linker may require a -R
1750	# flag.
1751	#
1752	if test "$libdir" != "/usr/lib"; then
1753		V_RFLAGS=-Wl,-R$libdir
1754	fi
1755	;;
1756
1757osf*)
1758	DYEXT="so"
1759
1760	#
1761	# DEC OSF/1, a/k/a Digial UNIX, a/k/a Tru64 UNIX.
1762	# Use Tru64 UNIX conventions for man pages; they're the same as
1763	# the System V conventions except that they use section 8 for
1764	# administrative commands and daemons.
1765	#
1766	MAN_FILE_FORMATS=4
1767	MAN_MISC_INFO=5
1768	;;
1769
1770sinix*)
1771	AC_MSG_CHECKING(if SINIX compiler defines sinix)
1772	AC_CACHE_VAL(ac_cv_cc_sinix_defined,
1773		AC_TRY_COMPILE(
1774		    [],
1775		    [int i = sinix;],
1776		    ac_cv_cc_sinix_defined=yes,
1777		    ac_cv_cc_sinix_defined=no))
1778	    AC_MSG_RESULT($ac_cv_cc_sinix_defined)
1779	    if test $ac_cv_cc_sinix_defined = no ; then
1780		    AC_DEFINE(sinix,1,[on sinix])
1781	    fi
1782	;;
1783
1784solaris*)
1785	AC_DEFINE(HAVE_SOLARIS,1,[On solaris])
1786
1787	DYEXT="so"
1788
1789	#
1790	# Make sure errno is thread-safe, in case we're called in
1791	# a multithreaded program.  We don't guarantee that two
1792	# threads can use the *same* pcap_t safely, but the
1793	# current version does guarantee that you can use different
1794	# pcap_t's in different threads, and even that pcap_compile()
1795	# is thread-safe (it wasn't thread-safe in some older versions).
1796	#
1797	V_CCOPT="$V_CCOPT -D_TS_ERRNO"
1798
1799	case "`uname -r`" in
1800
1801	5.12)
1802		;;
1803
1804	*)
1805		#
1806		# Use System V conventions for man pages.
1807		#
1808		MAN_ADMIN_COMMANDS=1m
1809		MAN_FILE_FORMATS=4
1810		MAN_MISC_INFO=5
1811	esac
1812	;;
1813esac
1814
1815AC_ARG_ENABLE(shared,
1816AC_HELP_STRING([--enable-shared],[build shared libraries @<:@default=yes, if support available@:>@]))
1817test "x$enable_shared" = "xno" && DYEXT="none"
1818
1819AC_PROG_RANLIB
1820AC_CHECK_TOOL([AR], [ar])
1821
1822AC_PROG_LN_S
1823AC_SUBST(LN_S)
1824
1825AC_LBL_DEVEL(V_CCOPT)
1826
1827#
1828# Check to see if the sockaddr struct has the 4.4 BSD sa_len member.
1829#
1830AC_CHECK_MEMBERS([struct sockaddr.sa_len],,,
1831    [
1832	#include <sys/types.h>
1833	#include <sys/socket.h>
1834    ])
1835
1836#
1837# Check to see if there's a sockaddr_storage structure.
1838#
1839AC_CHECK_TYPES(struct sockaddr_storage,,,
1840    [
1841	#include <sys/types.h>
1842	#include <sys/socket.h>
1843    ])
1844
1845#
1846# Check to see if the dl_hp_ppa_info_t struct has the HP-UX 11.00
1847# dl_module_id_1 member.
1848#
1849# NOTE: any failure means we conclude that it doesn't have that member,
1850# so if we don't have DLPI, don't have a <sys/dlpi_ext.h> header, or
1851# have one that doesn't declare a dl_hp_ppa_info_t type, we conclude
1852# it doesn't have that member (which is OK, as either we won't be
1853# using code that would use that member, or we wouldn't compile in
1854# any case).
1855#
1856AC_CHECK_MEMBERS([dl_hp_ppa_info_t.dl_module_id_1],,,
1857    [
1858	#include <sys/types.h>
1859	#include <sys/dlpi.h>
1860	#include <sys/dlpi_ext.h>
1861    ])
1862
1863AC_LBL_UNALIGNED_ACCESS
1864
1865AC_SUBST(V_CCOPT)
1866AC_SUBST(V_DEFS)
1867AC_SUBST(V_FINDALLDEVS)
1868AC_SUBST(V_INCLS)
1869AC_SUBST(V_LEX)
1870AC_SUBST(V_PCAP)
1871AC_SUBST(V_SHLIB_CCOPT)
1872AC_SUBST(V_SHLIB_CMD)
1873AC_SUBST(V_SHLIB_OPT)
1874AC_SUBST(V_SONAME_OPT)
1875AC_SUBST(V_RPATH_OPT)
1876AC_SUBST(V_YACC)
1877AC_SUBST(ADDLOBJS)
1878AC_SUBST(ADDLARCHIVEOBJS)
1879AC_SUBST(SSRC)
1880AC_SUBST(DYEXT)
1881AC_SUBST(MAN_FILE_FORMATS)
1882AC_SUBST(MAN_MISC_INFO)
1883AC_SUBST(MAN_ADMIN_COMMANDS)
1884AC_SUBST(PTHREAD_LIBS)
1885AC_SUBST(BUILD_RPCAPD)
1886AC_SUBST(INSTALL_RPCAPD)
1887AC_SUBST(RPCAPD_LIBS)
1888AC_SUBST(EXTRA_NETWORK_LIBS)
1889
1890AC_ARG_ENABLE([usb],
1891[AC_HELP_STRING([--enable-usb],[enable USB capture support @<:@default=yes, if support available@:>@])],
1892    [],
1893    [enable_usb=yes])
1894
1895if test "xxx_only" = yes; then
1896	# User requested something-else-only pcap, so they don't
1897	# want USB support.
1898	enable_usb=no
1899fi
1900
1901if test "x$enable_usb" != "xno" ; then
1902   dnl check for USB sniffing support
1903   AC_MSG_CHECKING(for USB sniffing support)
1904   case "$host_os" in
1905   linux*)
1906	AC_DEFINE(PCAP_SUPPORT_USB, 1, [target host supports USB sniffing])
1907	USB_SRC=pcap-usb-linux.c
1908	AC_MSG_RESULT(yes)
1909	ac_usb_dev_name=`udevinfo -q name -p /sys/class/usb_device/usbmon 2>/dev/null`
1910	if test $? -ne 0 ; then
1911	  ac_usb_dev_name="usbmon"
1912	fi
1913	AC_DEFINE_UNQUOTED(LINUX_USB_MON_DEV, "/dev/$ac_usb_dev_name", [path for device for USB sniffing])
1914	AC_MSG_NOTICE(Device for USB sniffing is /dev/$ac_usb_dev_name)
1915	#
1916	# Do we have a version of <linux/compiler.h> available?
1917	# If so, we might need it for <linux/usbdevice_fs.h>.
1918	#
1919	AC_CHECK_HEADERS(linux/compiler.h)
1920	if test "$ac_cv_header_linux_compiler_h" = yes; then
1921	  #
1922	  # Yes - include it when testing for <linux/usbdevice_fs.h>.
1923	  #
1924	  AC_CHECK_HEADERS(linux/usbdevice_fs.h,,,[#include <linux/compiler.h>])
1925	else
1926	  AC_CHECK_HEADERS(linux/usbdevice_fs.h)
1927	fi
1928	if test "$ac_cv_header_linux_usbdevice_fs_h" = yes; then
1929	  #
1930	  # OK, does it define bRequestType?  Older versions of the kernel
1931	  # define fields with names like "requesttype, "request", and
1932	  # "value", rather than "bRequestType", "bRequest", and
1933	  # "wValue".
1934	  #
1935	  AC_CHECK_MEMBERS([struct usbdevfs_ctrltransfer.bRequestType],,,
1936	      [
1937		  AC_INCLUDES_DEFAULT
1938		  #ifdef HAVE_LINUX_COMPILER_H
1939		  #include <linux/compiler.h>
1940		  #endif
1941		  #include <linux/usbdevice_fs.h>
1942	      ])
1943	fi
1944	;;
1945    freebsd*)
1946	#
1947	# This just uses BPF in FreeBSD 8.4 and later; we don't need
1948	# to check for anything special for capturing.
1949	#
1950	AC_MSG_RESULT([yes, in FreeBSD 8.4 and later])
1951	;;
1952
1953    *)
1954	AC_MSG_RESULT(no)
1955	;;
1956esac
1957fi
1958AC_SUBST(PCAP_SUPPORT_USB)
1959AC_SUBST(USB_SRC)
1960
1961dnl check for netfilter sniffing support
1962if test "xxx_only" != yes; then
1963	AC_MSG_CHECKING(whether the platform could support netfilter sniffing)
1964	case "$host_os" in
1965	linux*)
1966		AC_MSG_RESULT(yes)
1967		#
1968		# Life's too short to deal with trying to get this to compile
1969		# if you don't get the right types defined with
1970		# __KERNEL_STRICT_NAMES getting defined by some other include.
1971		#
1972		# Check whether the includes Just Work.  If not, don't turn on
1973		# netfilter support.
1974		#
1975		AC_MSG_CHECKING(whether we can compile the netfilter support)
1976		AC_CACHE_VAL(ac_cv_netfilter_can_compile,
1977		  AC_TRY_COMPILE([
1978AC_INCLUDES_DEFAULT
1979#include <sys/socket.h>
1980#include <netinet/in.h>
1981#include <linux/types.h>
1982
1983#include <linux/netlink.h>
1984#include <linux/netfilter.h>
1985#include <linux/netfilter/nfnetlink.h>
1986#include <linux/netfilter/nfnetlink_log.h>
1987#include <linux/netfilter/nfnetlink_queue.h>],
1988		    [],
1989		    ac_cv_netfilter_can_compile=yes,
1990		    ac_cv_netfilter_can_compile=no))
1991		AC_MSG_RESULT($ac_cv_netfilter_can_compile)
1992		if test $ac_cv_netfilter_can_compile = yes ; then
1993		  AC_DEFINE(PCAP_SUPPORT_NETFILTER, 1,
1994		    [target host supports netfilter sniffing])
1995		  NETFILTER_SRC=pcap-netfilter-linux.c
1996		fi
1997		;;
1998	*)
1999		AC_MSG_RESULT(no)
2000		;;
2001	esac
2002fi
2003AC_SUBST(PCAP_SUPPORT_NETFILTER)
2004AC_SUBST(NETFILTER_SRC)
2005
2006AC_ARG_ENABLE([netmap],
2007[AC_HELP_STRING([--enable-netmap],[enable netmap support @<:@default=yes, if support available@:>@])],
2008    [],
2009    [enable_netmap=yes])
2010
2011if test "x$enable_netmap" != "xno" ; then
2012	#
2013	# Check whether net/netmap_user.h is usable if NETMAP_WITH_LIBS is
2014	# defined; it's not usable on DragonFly BSD 4.6 if NETMAP_WITH_LIBS
2015	# is defined, for example, as it includes a non-existent malloc.h
2016	# header.
2017	#
2018	AC_MSG_CHECKING(whether we can compile the netmap support)
2019	AC_CACHE_VAL(ac_cv_net_netmap_user_can_compile,
2020	  AC_TRY_COMPILE([
2021AC_INCLUDES_DEFAULT
2022#define NETMAP_WITH_LIBS
2023#include <net/netmap_user.h>],
2024	    [],
2025	    ac_cv_net_netmap_user_can_compile=yes,
2026	    ac_cv_net_netmap_user_can_compile=no))
2027	AC_MSG_RESULT($ac_cv_net_netmap_user_can_compile)
2028	if test $ac_cv_net_netmap_user_can_compile = yes ; then
2029	  AC_DEFINE(PCAP_SUPPORT_NETMAP, 1,
2030	    [target host supports netmap])
2031	    NETMAP_SRC=pcap-netmap.c
2032	fi
2033	AC_SUBST(PCAP_SUPPORT_NETMAP)
2034	AC_SUBST(NETMAP_SRC)
2035fi
2036
2037
2038AC_ARG_ENABLE([bluetooth],
2039[AC_HELP_STRING([--enable-bluetooth],[enable Bluetooth support @<:@default=yes, if support available@:>@])],
2040    [],
2041    [enable_bluetooth=ifsupportavailable])
2042
2043if test "xxx_only" = yes; then
2044	# User requested something-else-only pcap, so they don't
2045	# want Bluetooth support.
2046	enable_bluetooth=no
2047fi
2048
2049if test "x$enable_bluetooth" != "xno" ; then
2050	dnl check for Bluetooth sniffing support
2051	case "$host_os" in
2052	linux*)
2053		AC_CHECK_HEADER(bluetooth/bluetooth.h,
2054		    [
2055			#
2056			# We have bluetooth.h, so we support Bluetooth
2057			# sniffing.
2058			#
2059			AC_DEFINE(PCAP_SUPPORT_BT, 1, [target host supports Bluetooth sniffing])
2060			BT_SRC=pcap-bt-linux.c
2061			AC_MSG_NOTICE(Bluetooth sniffing is supported)
2062			ac_lbl_bluetooth_available=yes
2063
2064			#
2065			# OK, does struct sockaddr_hci have an hci_channel
2066			# member?
2067			#
2068			AC_CHECK_MEMBERS([struct sockaddr_hci.hci_channel],
2069			    [
2070				#
2071				# Yes; is HCI_CHANNEL_MONITOR defined?
2072				#
2073				AC_MSG_CHECKING(if HCI_CHANNEL_MONITOR is defined)
2074				AC_CACHE_VAL(ac_cv_lbl_hci_channel_monitor_is_defined,
2075				    AC_TRY_COMPILE(
2076					[
2077					    #include <bluetooth/bluetooth.h>
2078					    #include <bluetooth/hci.h>
2079					],
2080					[
2081					    u_int i = HCI_CHANNEL_MONITOR;
2082					],
2083					[
2084					    AC_MSG_RESULT(yes)
2085					    AC_DEFINE(PCAP_SUPPORT_BT_MONITOR,,
2086					      [target host supports Bluetooth Monitor])
2087					    BT_MONITOR_SRC=pcap-bt-monitor-linux.c
2088					],
2089					[
2090					    AC_MSG_RESULT(no)
2091					]))
2092			    ],,
2093			    [
2094				#include <bluetooth/bluetooth.h>
2095				#include <bluetooth/hci.h>
2096			    ])
2097		    ],
2098		    [
2099			#
2100			# We don't have bluetooth.h, so we don't support
2101			# Bluetooth sniffing.
2102			#
2103			if test "x$enable_bluetooth" = "xyes" ; then
2104				AC_MSG_ERROR(Bluetooth sniffing is not supported; install bluez-lib devel to enable it)
2105			else
2106				AC_MSG_NOTICE(Bluetooth sniffing is not supported; install bluez-lib devel to enable it)
2107			fi
2108		    ])
2109		;;
2110	*)
2111		if test "x$enable_bluetooth" = "xyes" ; then
2112			AC_MSG_ERROR(no Bluetooth sniffing support implemented for $host_os)
2113		else
2114			AC_MSG_NOTICE(no Bluetooth sniffing support implemented for $host_os)
2115		fi
2116		;;
2117	esac
2118	AC_SUBST(PCAP_SUPPORT_BT)
2119	AC_SUBST(BT_SRC)
2120	AC_SUBST(BT_MONITOR_SRC)
2121fi
2122
2123AC_ARG_ENABLE([dbus],
2124[AC_HELP_STRING([--enable-dbus],[enable D-Bus capture support @<:@default=yes, if support available@:>@])],
2125    [],
2126    [enable_dbus=ifavailable])
2127
2128if test "xxx_only" = yes; then
2129	# User requested something-else-only pcap, so they don't
2130	# want D-Bus support.
2131	enable_dbus=no
2132fi
2133
2134if test "x$enable_dbus" != "xno"; then
2135	if test "x$enable_dbus" = "xyes"; then
2136		case "$host_os" in
2137
2138		darwin*)
2139			#
2140			# We don't support D-Bus sniffing on macOS; see
2141			#
2142			# https://bugs.freedesktop.org/show_bug.cgi?id=74029
2143			#
2144			# The user requested it, so fail.
2145			#
2146			AC_MSG_ERROR([Due to freedesktop.org bug 74029, D-Bus capture support is not available on macOS])
2147		esac
2148	else
2149		case "$host_os" in
2150
2151		darwin*)
2152			#
2153			# We don't support D-Bus sniffing on macOS; see
2154			#
2155			# https://bugs.freedesktop.org/show_bug.cgi?id=74029
2156			#
2157			# The user dind't explicitly request it, so just
2158			# silently refuse to enable it.
2159			#
2160			enable_dbus="no"
2161			;;
2162		esac
2163	fi
2164fi
2165
2166if test "x$enable_dbus" != "xno"; then
2167	AC_CHECK_PROG([PKGCONFIG], [pkg-config], [pkg-config], [no])
2168	if test "x$PKGCONFIG" != "xno"; then
2169		AC_MSG_CHECKING([for D-Bus])
2170		if "$PKGCONFIG" dbus-1; then
2171			AC_MSG_RESULT([yes])
2172			DBUS_CFLAGS=`"$PKGCONFIG" --cflags dbus-1`
2173			DBUS_LIBS=`"$PKGCONFIG" --libs dbus-1`
2174			save_CFLAGS="$CFLAGS"
2175			save_LIBS="$LIBS"
2176			CFLAGS="$CFLAGS $DBUS_CFLAGS"
2177			LIBS="$LIBS $DBUS_LIBS"
2178			AC_MSG_CHECKING(whether the D-Bus library defines dbus_connection_read_write)
2179			AC_TRY_LINK(
2180			    [#include <string.h>
2181
2182			     #include <time.h>
2183			     #include <sys/time.h>
2184
2185			     #include <dbus/dbus.h>],
2186			    [return dbus_connection_read_write(NULL, 0);],
2187			    [
2188				AC_MSG_RESULT([yes])
2189				AC_DEFINE(PCAP_SUPPORT_DBUS, 1, [support D-Bus sniffing])
2190				DBUS_SRC=pcap-dbus.c
2191				V_INCLS="$V_INCLS $DBUS_CFLAGS"
2192			    ],
2193			    [
2194				AC_MSG_RESULT([no])
2195				if test "x$enable_dbus" = "xyes"; then
2196				    AC_MSG_ERROR([--enable-dbus was given, but the D-Bus library doesn't define dbus_connection_read_write()])
2197				fi
2198				LIBS="$save_LIBS"
2199			     ])
2200			CFLAGS="$save_CFLAGS"
2201		else
2202			AC_MSG_RESULT([no])
2203			if test "x$enable_dbus" = "xyes"; then
2204				AC_MSG_ERROR([--enable-dbus was given, but the dbus-1 package is not installed])
2205			fi
2206		fi
2207	fi
2208	AC_SUBST(PCAP_SUPPORT_DBUS)
2209	AC_SUBST(DBUS_SRC)
2210fi
2211
2212AC_ARG_ENABLE([rdma],
2213[AC_HELP_STRING([--enable-rdma],[enable RDMA capture support @<:@default=yes, if support available@:>@])],
2214    [],
2215    [enable_rdmasniff=ifavailable])
2216
2217if test "xxx_only" = yes; then
2218	# User requested something-else-only pcap, so they don't
2219	# want RDMA support.
2220	enable_rdmasniff=no
2221fi
2222
2223if test "x$enable_rdmasniff" != "xno"; then
2224	AC_CHECK_LIB(ibverbs, ibv_get_device_list, [
2225		AC_CHECK_HEADER(infiniband/verbs.h, [
2226			#
2227			# ibv_create_flow may be defined as a static inline
2228			# function in infiniband/verbs.h, so we can't
2229			# use AC_CHECK_LIB.
2230			#
2231			# Too bad autoconf has no AC_SYMBOL_EXISTS()
2232			# macro that works like CMake's check_symbol_exists()
2233			# function, to check do a compile check like
2234			# this (they do a clever trick to avoid having
2235			# to know the function's signature).
2236			#
2237			AC_MSG_CHECKING(whether libibverbs defines ibv_create_flow)
2238			AC_TRY_LINK(
2239				[
2240					#include <infiniband/verbs.h>
2241				],
2242				[
2243					(void) ibv_create_flow((struct ibv_qp *) NULL,
2244							       (struct ibv_flow_attr *) NULL);
2245				],
2246				[
2247					AC_MSG_RESULT([yes])
2248					AC_DEFINE(PCAP_SUPPORT_RDMASNIFF, , [target host supports RDMA sniffing])
2249					RDMA_SRC=pcap-rdmasniff.c
2250					LIBS="-libverbs $LIBS"
2251				],
2252				[
2253					AC_MSG_RESULT([no])
2254				]
2255			)
2256		])
2257	])
2258	AC_SUBST(PCAP_SUPPORT_RDMASNIFF)
2259	AC_SUBST(RDMA_SRC)
2260fi
2261
2262AC_PROG_INSTALL
2263
2264AC_CONFIG_HEADER(config.h)
2265
2266AC_OUTPUT_COMMANDS([if test -f .devel; then
2267	echo timestamp > stamp-h
2268	cat $srcdir/Makefile-devel-adds >> Makefile
2269	make depend
2270fi])
2271AC_OUTPUT(Makefile pcap-filter.manmisc pcap-linktype.manmisc
2272	pcap-tstamp.manmisc pcap-savefile.manfile pcap.3pcap
2273	pcap_compile.3pcap pcap_datalink.3pcap pcap_dump_open.3pcap
2274	pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap
2275	pcap_list_tstamp_types.3pcap pcap_open_dead.3pcap
2276	pcap_open_offline.3pcap pcap_set_tstamp_precision.3pcap
2277	pcap_set_tstamp_type.3pcap rpcapd/Makefile rpcapd/rpcapd.manadmin
2278	testprogs/Makefile)
2279exit 0
2280