Commit Graph

180 Commits

Author SHA1 Message Date
Guy Harris
89fc9f2161 Make tcpdump find wpcap.dll on Windows if it's not in the system library.
See https://npcap.com/guide/npcap-devguide.html#npcap-feature-native-dll-implicitly
for details on what's being done.

Fix #1226.
2024-10-08 21:39:41 -07:00
Francois-Xavier Le Bail
49fa8ff397 Fix a typo in a comment 2024-09-30 13:59:00 +02:00
Guy Harris
2dd45475f0 cmake: treat building for another ISA as a cross-compile.
CMake appears to have the notion that a build is only a cross-compile if
the targt *operating system* is different.  This is an incorrect notion,
as even if the target is the *same* OS but a different instruction set,
you may not be able to do tests that involve compiling and running a
program.

Check whether CMAKE_GENERATOR_PLATFORM is set and has a value different
from that of CMAKE_HOST_SYSTEM_PROCESSOR and, if that's the case, set
CMAKE_CROSSCOMPILING to TRUE.

This comes from libpcap, where the equivalent change fixed issue
the-tcpdump-group/libpcap#1352.

(A different strategy may be necessary for cross-builds with UNIX
toolchains.)
2024-09-21 23:00:09 -07:00
Denis Ovsienko
2ec7e78bac CMake: Skip snprintf(3) tests when cross-compiling.
Same as in libpcap.
2024-09-18 00:22:58 +01:00
Guy Harris
fc8465a50d CMake: use pkg-config and Homebrew when looking for libcrypto.
Do the same sort of stuff that configure does, but CMake-style.
2024-07-10 12:10:42 -07:00
Guy Harris
ae83a79e03 CMake: fix a comment. [skip ci]
We're checking for both pcap_open() and pcap_findalldevs_ex().
2024-07-09 18:15:13 -07:00
Guy Harris
9ee0608e63 CMake: check for pcap_findalldevs_ex.
We do so for autotools, and we currently have separate ifdefs for
pcap_open and pcap_findalldevs_ex, rather than treating the presence of
pcap_open as an indication that we have the entire remote capture API
(the latter is what Wireshark does).
2024-07-09 17:58:39 -07:00
Guy Harris
c02b47db92 autotools, cmake: work around an Xcode 15+ issue.
There appears to be no way to build tcpdump on macOS Ventura with Xcode
15 with the system libpcap and have the resulting program run without
getting an error due to failing to find pcap_open() or
pcap_findalldevs_ex() at startup.

In particular, there appears to be no way to use __builtin_available()
to protect accesses to the routines that showed up in Sonoma, so that
the run-time linker doesn't fail if the routine in question isn't
present.  Perhaps it requires more compiler command-line arguments.

So, instead, only check for pcap_open() and pcap_findalldevs_ex() if 1)
this isn't macOS or 2) we're not building with the system libpcap.
2024-07-09 16:09:12 -07:00
Guy Harris
d5b1a160a3 Get rid of support for libpcap prior to 1.0.
This lets us remove a bunch of configure-time and compile-time tests.

Update documentation to reflect this.

WinPcap 4.1.3 is based on libpcap 1.0, but doesn't export all of the new
APIs, so it won't work with code that uses any of the other APIs, which
tcpdump does, so don't test with WinPcap.
2024-05-19 12:43:23 -07:00
Denis Ovsienko
a0ffbfba6c CMake: Get the comment about EXTRA_CFLAGS right. [skip ci]
The "testprogs" sentence applies to libpcap only.
2024-04-05 15:17:08 +01:00
Denis Ovsienko
0e04b9da80 SLL2: Translate interface indices to names on Linux only.
print-sll.c uses HAVE_NET_IF_H, which does not always work right: the
header is in POSIX.1-2001, but the result of if_indextoname() is
irrelevant if the current OS is not Linux, in which case the packet was
captured on a different host because libpcap produces DLT_LINUX_SLL2 on
Linux only.  The result can be irrelevant on Linux too, but this does
not have an easy solution.

To reduce the problem space, switch print-sll.c to check for __linux__
instead.  In tcpdump.c print the warning about interface names only if
sll2_if_print() would print interface names.  Since HAVE_NET_IF_H has no
purpose now, remove the checks for <net/if.h>.
2024-04-02 11:36:13 +01:00
Francois-Xavier Le Bail
f81ffd1754 Include <fcntl.h> unconditionally
It is used for open() which is in POSIX.1-2001, POSIX.1-2008.

libpcap has included <fcntl.h> unconditionally since at least 1999.
2024-03-29 06:11:55 +00:00
Francois-Xavier Le Bail
94a3708f00 Include <config.h> unconditionally
Builds using Autotools or CMake generate config.h, thus remove the
'#ifdef HAVE_CONFIG_H'/'#endif'.

Remove also the 'add_definitions(-DHAVE_CONFIG_H)' in CMakeLists.txt.
2024-03-28 05:34:34 +00:00
Denis Ovsienko
e1bcb7941d Simplify the checks for snprintf().
Do not check that the function is just available: first, it is in C99,
so the check almost certainly is a waste of time; second, the source
requires the function unconditionally; third, the subsequent "snprintf()
is suitable" check implies the "snprintf() is available" part anyway.
2024-03-27 23:46:15 +00:00
Denis Ovsienko
3d215c6db5 Do not define _SUN on AIX. [skip ci]
Setting the macro makes no difference on AIX 7.1, see also libpcap
commit be724d5.
2024-03-26 20:59:44 +00:00
Denis Ovsienko
a9c7cf8848 Disregard setlinebuf(3), always use setvbuf(3).
As most setlinebuf(3) man pages mention, setlinebuf() is a shorthand for
setvbuf().  The latter is in C99, but the former is not, so it is most
logical to use setvbuf() in all cases and to lose another build-time
check.
2024-03-25 15:09:00 +00:00
Denis Ovsienko
b29858253c Fix Sun C invocation from CMake.
cc: Can not use -xc99 with -pedantic
2024-03-15 00:08:55 -07:00
Francois-Xavier Le Bail
170cbc8c6d Autoconf, CMake: Get the size of a void * and a time_t
With this change we know:
whether this is a 32-bit or 64-bit build ;
whether the time_t size is 32-bit or 64-bit.

At least with CMake, the SIZEOF values could be 0, if somebody's
doing a fat build on macOS and that includes both 32-bit and 64-bit
instruction sets.
2024-03-14 16:19:01 +01:00
Francois-Xavier Le Bail
656bd18c72 Autoconf, CMake: Add a warning flag (-Wundef) 2024-03-07 06:39:23 +00:00
Denis Ovsienko
f32255ba13 Fix propagation of cc_werr_cflags() output. [skip ci]
Same as in libpcap.  It is not the propagation that tcpdump needs from
this change, but the proper application of compiler options.
2024-03-04 11:43:20 +00:00
Denis Ovsienko
569372be9e Retire most of IRIX support.
In parsenfsfh.c keep IRIX-specific code that is not specific to
*compiling* on IRIX.  Do not touch AC_LBL_LIBRARY_NET yet.
2024-01-28 16:48:31 +00:00
Denis Ovsienko
630f9bcaa8 Retire Tru64 UNIX support.
See also commit 6008cb8.
2024-01-28 11:35:15 +00:00
Francois-Xavier Le Bail
5ee91ef4b6 Replace some command name 'Tcpdump' with 'tcpdump'
[skip ci]
2023-12-20 21:03:50 +01:00
Guy Harris
6193b88600 CMake: attempt to suppress deprecation errors.
Yes, we should probably fix them at some point, but not Right This
Instant.

This should squelch the warnings in #1087, but leave that open, pending
a decision on which release of CMake to require on non-Windows
platforms.
2023-11-25 22:12:59 -08:00
Josh Soref
38050da48e Fix spelling
* account
* address
* adjacency
* alignment
* anymore
* ascii
* assumption
* blithely
* canonical
* compound
* consecutive
* control
* diagnostics
* disassociation
* fairly
* fallthrough
* greatest
* identification
* multihop
* multiplexed
* nonexistent
* notifiable
* notwithstanding
* number
* polynomial
* preexisting
* proprietary
* quenches
* reassociation
* redefinition
* refresh
* solicitation
* specifying
* support
* the
* unacceptable

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-08-20 07:19:40 +00:00
Francois-Xavier Le Bail
d6734adaa3 Fix a typo in a comment
[skip ci]
2023-08-13 09:59:12 +02:00
Francois-Xavier Le Bail
7cba9309f3 Fix a typo in a comment
[skip ci]
2023-06-25 19:22:16 +02:00
Guy Harris
e0787e5d8c gre, erspan: add an ERSPAN dissector and have the GRE dissector call it.
This is from the OpenBSD tcpdump.

Fixes #1040.

Sort the .c list in CMakeLists.txt while we're at it.
2023-06-07 15:20:16 -07:00
Guy Harris
6c8a3facc7 Add support for dissecting RFC 2332 NHRP.
This is from the OpenBSD tcpdump.
2023-04-11 04:11:49 -07:00
Denis Ovsienko
161c18fa34 Untangle detection of pcap_findalldevs().
tcpdump.c requires both HAVE_PCAP_IF_T and HAVE_PCAP_FINDALLDEVS to
manage the code that depends on pcap_findalldevs().  Other than that,
the Autoconf and CMake checks that produce these two macros do not
relate directly, so having the check for pcap_if_t conditional on the
check for pcap_findalldevs() is an unnecessary complication.

More importantly, in the CMake case this places the check_type_size()
for pcap_if_t into a context with CMAKE_REQUIRED_LIBRARIES already set
to PCAP_LIBRARIES.  This works only if check_type_size() does not have
to check for <sys/types.h>, <stdint.h> or <stddef.h> implicitly.  This
was the case so long as another check_type_size() before the
CMAKE_REQUIRED_LIBRARIES change made the implicit checks and cached the
results, but removing that earlier instance resulted in a warning:

  Policy CMP0075 is not set: Include file check macros honor
  CMAKE_REQUIRED_LIBRARIES.  Run "cmake --help-policy CMP0075" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  CMAKE_REQUIRED_LIBRARIES is set to:

    /usr/lib/x86_64-linux-gnu/libpcap.so

  For compatibility with CMake 3.11 and below this check is ignoring it.

To fix that, in both Autoconf and CMake make the two checks separate and
unconditional and place the check for pcap_if_t where it fits better.
In CMake remove the earlier workaround with in6_addr.
2023-02-25 18:02:18 +00:00
Guy Harris
008b90f611 CMake: balance cmake_push_check_state() and cmake_pop_check_state().
We didn't completely pop the check state after we finished the checks
for libpcap.
2023-02-22 22:38:19 -08:00
Denis Ovsienko
10b807441e Detect OS IPv6 support using AF_INET6 only.
tcpdump source code has not been using struct in6_addr since commit
0c9cfdc in 2019, so lose the conditional structure declaration, which is
a no-op.

Since commit de7c619 in 2015 netdissect-stdinc.h on Windows defines
HAVE_OS_IPV6_SUPPORT if AF_INET6 if defined, which makes it equivalent
to AF_INET6.  On Unix-like systems taking struct in6_addr out of scope
would make HAVE_OS_IPV6_SUPPORT equivalent to AF_INET6, thus after
removing struct in6_addr remove HAVE_OS_IPV6_SUPPORT together with
Autoconf and CMake checks that define it.  Leave an unrelated CMake
workaround in place for later debugging.

On Windows do not define AF_INET6 if it is not defined, which makes
AF_INET6 a universal indicator of the OS IPv6 support on all supported
OSes.  The few remaining use cases that genuinely need AF_INET6 use it
to make OS API calls, so if the macro is not defined, it most likely
means such an API call in the best case would return just a well-formed
error status.  With this in mind, in win32_gethostbyaddr() and
ip6addr_string() guard all IPv6-specific code with #ifdef AF_INET6.  In
tcpdump.c add a comment to note why a guard is not required for
Casper-specific conditional code that uses AF_INET6.

This way when the OS does not support IPv6, IPv6 addresses will not
resolve to names, which is expected.  Other than that, tcpdump should be
able to process IPv6 addresses the usual way regardless if the OS would
be able to process the packets with these addresses.
2023-02-22 20:05:58 +00:00
Denis Ovsienko
afe133ecef Do not substitute strdup().
libpcap has been using strdup() for a long time too, but never
substituted it under the assumption the function is available in all
supported OSes, see libpcap commit cb71eef from 2006.  The only
exception to that is Windows, which can have a different name for the
function, but both libpcap and tcpdump for that already use a separate
workaround, which does not involve the substitution.

Let's take this as a proof that strdup() substitution in tcpdump is dead
code, and remove it.
2023-02-19 11:33:13 +00:00
Denis Ovsienko
a69de5a4d9 Do not require vsnprintf().
The check for vsnprintf() has been in the configure script since commit
8cb054c in 2000, and the only actual use of the function was in the
"#ifndef HAVE_SNPRINTF" block in missing/snprintf.c until commit 1ed63b5
in 2019.  Since then tcpdump does not require vsnprintf() in any way.
2023-02-17 08:56:15 +00:00
Denis Ovsienko
e03799cb9f Require a proof of suitable snprintf(3) implementation.
My earlier commit fbd4415 did a wrong thing because it caused a failure
to fail in "make check" on Solaris 9, whereas the right thing to do when
printf() does not work as expected would be to fail the build with a
useful error message.   Implement that by testing snprintf() in Autoconf
and CMake (assume that in a given libc implementation all functions in
the printf() family have the same level of support for conversion
specifications).  Return 18 tests from the conditional space back into
TESTLIST.
2023-02-16 20:55:56 +00:00
Guy Harris
31762a4eb3 CMake: improve the comment before project(tcpdump C). [skip ci]
Note that, even if there weren't horrible consequences to either 1)
having no C++ compiler, 2) setting an instruction set bit width in
CFLAGS but not in CXXFLAGS, or 3) having C and C++ compilers with
different default instruction set bit-widths, specifying that we're
C-only avoids wasting time looking for a C++ compiler.
2023-02-15 15:10:35 -08:00
Guy Harris
6eb61d130b configure, CMake: remove -fPIC hacks for Haiku.
As of llvm12_clang-12.0.1-5, Clang defaults to generating PIC, just as
GCC does, and the entire matrix now works.
2023-02-14 16:07:22 -08:00
Guy Harris
93a3b993be CMake: try to fix the Haiku build.
If we set CMAKE_C_FLAGS_INIT to "-fPIC" before setting the project, that
initializes CMAKE_C_FLAGS to "-fPIC" *before* prepending the contents of
the CFLAGS environment variable, and *before* doing any tests that
depend on linking, in the project() command, so it 1) adds -fPIC before
doing those tests, so they don't fail due to the object files being
unfit to link into an executable, and 2) adds the contents of CFLAGS to
CMAKE_C_FLAGS, so the user can set CFLAGS and have it affect the build.

This requires CMake 3.7 or later, so we set 3.7 as the minimum required
on Haiku.

This should fix some of #996, although more needs to be done.
2023-02-13 12:34:42 -08:00
Guy Harris
21f46b9600 CMake: give up on Clang on Haiku.
Haiku bug 18258 makes it too painful to beat the configuration process
into submission.
2023-02-12 16:03:09 -08:00
Guy Harris
f37c5e5639 CMake: force -fPIC on Haiku, as we do with autotools.
This, and 64f81903ba, address some of the
issues in #996; in particular, they fix link errors.
2023-02-12 13:32:39 -08:00
Guy Harris
af51eea290 configure, CMakeLists.txt: don't check for snprintf().
It's specified by the C90 standard (and, as I remember, by the C89
standard, although I no longer have my paper copy); no need to worry
about ancient environments that lack it, and we have some cases where we
call it in code not protected by #ifdef HAVE_STRFTIME/#endif and haven't
seen any reports of problems.
2023-01-30 12:46:44 -08:00
Denis Ovsienko
d6e3ebf92c Fixup a comment in CMakeLists.txt. [skip ci] 2023-01-15 22:48:59 +00:00
David Karoly
bdece165ac CMake: search for gethostbyaddr() in libnetwork 2023-01-14 13:24:12 -08:00
Guy Harris
ed6d4f3054 CMake: set man page section numbers.
We use both MAN_FILE_FORMATS and MAN_MISC_INFO in tcpdump.1; set them

Also set _SUN on AIX, as we do with the configure script.
2023-01-09 03:57:42 -08:00
Denis Ovsienko
d74c65c5a7 CMake: Fix a typo in a comment. [skip ci] 2023-01-01 17:12:39 +00:00
Francois-Xavier Le Bail
9b05cc18ec cmake: Update the minimum required version to 2.8.12 (except Windows)
Windows minimum required is already 3.12.

This change avoids this warning:
CMake Deprecation Warning at CMakeLists.txt:7 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

(Same as in libpcap.)
2022-11-25 15:56:21 +01:00
Francois-Xavier Le Bail
e91ca695c3 Remove a trailing space
[skip ci]
2022-09-30 08:54:19 +02:00
Guy Harris
d58b413e83 cmake: expand a comment. [skip ci]
The requirement for setting the run-time path in an executable is not
unique to NetBSD; it also appears in the other BSDs, Linux, and Solaris.
2022-09-26 00:40:50 -07:00
Guy Harris
dcfed11c0b cmake: prevent stripping of the rpath on installation.
This should fix issue #1008.
2022-09-25 14:35:38 -07:00
Guy Harris
fe762c04a6 Handle DLT_PFLOG on all OSes.
Don't pad the pflog header with BPF_WORDALIGN(); round up to a multiple
of 4, instead, as that's what all but FreeBSD do, and FreeBSD used to do
that and should go back to doing so (kern/261566).

Don't rely on the OS's pflog include files to define direction types,
reason types, action types, or the layout of the header; instead, define
them ourselves in a header of our own, with #ifs to select the ones that
are only on some platforms.  That way, it'll handle some fields and
field values (the ones common to all OSes with pflog) on all OSes, even
ones without pflog.

That also expands the set of direction, reason, and action codes to what
various *BSDs and Darwin support.

Also, handle all the different AF_INET6 values in various *BSDs and
Darwin.
2022-01-29 22:30:33 -08:00