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