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