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