Skip to content

Commit d5b1a16

Browse files
committed
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.
1 parent 074d10a commit d5b1a16

14 files changed

+112
-735
lines changed

.appveyor.yml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,23 @@ matrix:
1010
fast_finish: true
1111

1212
install:
13-
- appveyor DownloadFile https://www.winpcap.org/install/bin/WpdPack_4_1_2.zip
14-
- 7z x .\WpdPack_4_1_2.zip -oc:\projects\libpcap\Win32
1513
- appveyor DownloadFile https://npcap.com/dist/npcap-sdk-1.12.zip
1614
- 7z x .\npcap-sdk-1.12.zip -oc:\projects\libpcap\Win32\npcap-sdk-1.12
1715

1816
environment:
1917
matrix:
20-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
21-
GENERATOR: "Visual Studio 14 2015"
22-
SDK: WpdPack
23-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
24-
GENERATOR: "Visual Studio 14 2015 Win64"
25-
SDK: WpdPack
2618
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
2719
GENERATOR: "Visual Studio 14 2015"
2820
SDK: npcap-sdk-1.12
2921
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
3022
GENERATOR: "Visual Studio 14 2015 Win64"
3123
SDK: npcap-sdk-1.12
32-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
33-
GENERATOR: "Visual Studio 15 2017"
34-
SDK: WpdPack
35-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
36-
GENERATOR: "Visual Studio 15 2017 Win64"
37-
SDK: WpdPack
3824
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
3925
GENERATOR: "Visual Studio 15 2017"
4026
SDK: npcap-sdk-1.12
4127
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
4228
GENERATOR: "Visual Studio 15 2017 Win64"
4329
SDK: npcap-sdk-1.12
44-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
45-
GENERATOR: "Visual Studio 16 2019"
46-
PLATFORM: Win32
47-
SDK: WpdPack
48-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
49-
GENERATOR: "Visual Studio 16 2019"
50-
PLATFORM: x64
51-
SDK: WpdPack
5230
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
5331
GENERATOR: "Visual Studio 16 2019"
5432
PLATFORM: Win32
@@ -57,14 +35,6 @@ environment:
5735
GENERATOR: "Visual Studio 16 2019"
5836
PLATFORM: x64
5937
SDK: npcap-sdk-1.12
60-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
61-
GENERATOR: "Visual Studio 17 2022"
62-
PLATFORM: Win32
63-
SDK: WpdPack
64-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
65-
GENERATOR: "Visual Studio 17 2022"
66-
PLATFORM: x64
67-
SDK: WpdPack
6838
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
6939
GENERATOR: "Visual Studio 17 2022"
7040
PLATFORM: Win32

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
3333
Add --print-sampling to print every Nth packet instead of all.
3434
Add --lengths option to print the captured and original packet lengths.
3535
Source code:
36+
Drop support for building with versions of libpcap that don't
37+
support all the libpcap 1.0 APIs.
3638
Use %zu when printing a sizeof to squelch compiler warnings
3739
Remove unused missing/snprintf.c.
3840
Remove unused missing/strdup.c.

CMakeLists.txt

Lines changed: 39 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -658,113 +658,62 @@ set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
658658
#
659659
check_include_file(pcap/pcap-inttypes.h HAVE_PCAP_PCAP_INTTYPES_H)
660660

661-
#
662-
# At compile time HAVE_PCAP_FINDALLDEVS depends on HAVE_PCAP_IF_T.
663-
#
664-
cmake_push_check_state()
665-
set(CMAKE_EXTRA_INCLUDE_FILES pcap.h)
666-
check_type_size(pcap_if_t PCAP_IF_T)
667-
cmake_pop_check_state()
668-
669661
#
670662
# Check for various functions in libpcap/WinPcap/Npcap.
671663
#
672664
cmake_push_check_state()
673665
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES})
674666

675667
#
676-
# Check for "pcap_list_datalinks()" and use a substitute version if
677-
# it's not present. If it is present, check for "pcap_free_datalinks()";
678-
# if it's not present, we don't replace it for now. (We could do so
679-
# on UN*X, but not on Windows, where hilarity ensues if a program
680-
# built with one version of the MSVC support library tries to free
681-
# something allocated by a library built with another version of
682-
# the MSVC support library.)
683-
#
684-
check_function_exists(pcap_list_datalinks HAVE_PCAP_LIST_DATALINKS)
685-
if(HAVE_PCAP_LIST_DATALINKS)
686-
check_function_exists(pcap_free_datalinks HAVE_PCAP_FREE_DATALINKS)
687-
endif(HAVE_PCAP_LIST_DATALINKS)
688-
668+
# Do we have the new open API? Check for pcap_create() and for
669+
# pcap_statustostr(), and assume that, if we have both of them,
670+
# we also have pcap_activate() and the other new routines
671+
# introduced in libpcap 1.0.
689672
#
690-
# Check for "pcap_datalink_name_to_val()", and use a substitute
691-
# version if it's not present. If it is present, check for
692-
# "pcap_datalink_val_to_description()", and if we don't have it,
693-
# use a substitute version.
673+
# We require those routines, so fail if we don't find it.
694674
#
695-
check_function_exists(pcap_datalink_name_to_val HAVE_PCAP_DATALINK_NAME_TO_VAL)
696-
if(HAVE_PCAP_DATALINK_NAME_TO_VAL)
697-
check_function_exists(pcap_datalink_val_to_description HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
698-
endif(HAVE_PCAP_DATALINK_NAME_TO_VAL)
675+
check_function_exists(pcap_create HAVE_PCAP_CREATE)
676+
if(NOT HAVE_PCAP_CREATE)
677+
if(WIN32)
678+
MESSAGE(FATAL_ERROR "libpcap is too old; 1.0 or later is required")
679+
else(WIN32)
680+
MESSAGE(FATAL_ERROR "libpcap is too old; 1.0 or later is required - if you're using WinPcap, try Npcap")
681+
endif(WIN32)
682+
endif(NOT HAVE_PCAP_CREATE)
699683

700-
#
701-
# Check for "pcap_set_datalink()"; you can't substitute for it if
702-
# it's absent (it has hooks into libpcap), so just define the
703-
# HAVE_ value if it's there.
704-
#
705-
check_function_exists(pcap_set_datalink HAVE_PCAP_SET_DATALINK)
684+
if(WIN32)
685+
#
686+
# We check for pcap_statustostr() as well, because WinPcap 4.1.3
687+
# screwed up and exported pcap_create() but not other routines
688+
# such as pcap_statustostr(), even though it defined them and
689+
# even though you really want pcap_statustostr() to get strings
690+
# corresponding to some of the status returns from the new routines.)
691+
#
692+
check_function_exists(pcap_statustostr HAVE_PCAP_STATUSTOSTR)
693+
if(NOT HAVE_PCAP_STATUSTOSTR)
694+
MESSAGE(FATAL_ERROR "pcap_create is available, but pcap_statustostr isn't - if you're using WinPcap, try Npcap ")
695+
endif(NOT HAVE_PCAP_STATUSTOSTR)
696+
endif(WIN32)
706697

707698
#
708-
# Check for "pcap_breakloop()"; you can't substitute for it if
709-
# it's absent (it has hooks into the live capture routines),
710-
# so just define the HAVE_ value if it's there.
699+
# OK, do we have pcap_set_tstamp_type? If so, assume we have
700+
# pcap_list_tstamp_types and pcap_free_tstamp_types as well.
711701
#
712-
check_function_exists(pcap_breakloop HAVE_PCAP_BREAKLOOP)
702+
check_function_exists(pcap_set_tstamp_type HAVE_PCAP_SET_TSTAMP_TYPE)
713703

714704
#
715-
# Check for "pcap_dump_ftell()"; we use a substitute version
716-
# if it's not present.
705+
# And do we have pcap_set_tstamp_precision? If so, we assume
706+
# we also have pcap_open_offline_with_tstamp_precision.
717707
#
718-
check_function_exists(pcap_dump_ftell HAVE_PCAP_DUMP_FTELL)
719-
720-
#
721-
# Do we have the new open API? Check for pcap_create() and for
722-
# pcap_statustostr(), and assume that, if we have both of them,
723-
# we also have pcap_activate() and the other new routines
724-
# introduced in libpcap 1.0.0. (We check for pcap_statustostr()
725-
# as well, because WinPcap 4.1.3 screwed up and exported pcap_create()
726-
# but not other routines such as pcap_statustostr(), even though it
727-
# defined them and even though you really want pcap_statustostr() to
728-
# get strings corresponding to some of the status returns from the
729-
# new routines.)
730-
#
731-
check_function_exists(pcap_statustostr HAVE_PCAP_STATUSTOSTR)
732-
#
733-
# If we don't have pcap_statustostr(), don't check for pcap_create(),
734-
# so we pretend we don't have it.
735-
#
736-
if(HAVE_PCAP_STATUSTOSTR)
737-
check_function_exists(pcap_create HAVE_PCAP_CREATE)
738-
endif(HAVE_PCAP_STATUSTOSTR)
739-
if(HAVE_PCAP_CREATE)
740-
#
741-
# OK, do we have pcap_set_tstamp_type? If so, assume we have
742-
# pcap_list_tstamp_types and pcap_free_tstamp_types as well.
743-
#
744-
check_function_exists(pcap_set_tstamp_type HAVE_PCAP_SET_TSTAMP_TYPE)
745-
746-
#
747-
# And do we have pcap_set_tstamp_precision? If so, we assume
748-
# we also have pcap_open_offline_with_tstamp_precision.
749-
#
750-
check_function_exists(pcap_set_tstamp_precision HAVE_PCAP_SET_TSTAMP_PRECISION)
751-
endif(HAVE_PCAP_CREATE)
708+
check_function_exists(pcap_set_tstamp_precision HAVE_PCAP_SET_TSTAMP_PRECISION)
752709

753710
#
754711
# Check for a miscellaneous collection of functions which we use
755712
# if we have them.
756713
#
757-
check_function_exists(pcap_findalldevs HAVE_PCAP_FINDALLDEVS)
758-
check_function_exists(pcap_dump_flush HAVE_PCAP_DUMP_FLUSH)
759-
check_function_exists(pcap_lib_version HAVE_PCAP_LIB_VERSION)
760-
if(NOT HAVE_PCAP_LIB_VERSION)
761-
# Check for the pcap_version string variable and set HAVE_PCAP_VERSION
762-
endif(NOT HAVE_PCAP_LIB_VERSION)
763-
check_function_exists(pcap_setdirection HAVE_PCAP_SETDIRECTION)
764714
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_SET_IMMEDIATE_MODE)
765715
check_function_exists(pcap_dump_ftell64 HAVE_PCAP_DUMP_FTELL64)
766716
check_function_exists(pcap_open HAVE_PCAP_OPEN)
767-
check_function_exists(pcap_findalldevs_ex HAVE_PCAP_FINDALLDEVS_EX)
768717

769718
#
770719
# On Windows, check for pcap_wsockinit(); if we don't have it, check for
@@ -790,6 +739,13 @@ if(NOT HAVE_PCAP_SET_PARSER_DEBUG)
790739
endif(NOT HAVE_PCAP_SET_PARSER_DEBUG)
791740

792741
check_function_exists(pcap_set_optimizer_debug HAVE_PCAP_SET_OPTIMIZER_DEBUG)
742+
743+
#
744+
# bpf_dump() moved from tcpdump to libpcap in libpcap 0.6, but not all
745+
# versions of libpcap didn't pick that change up; the OpenBSD libpcap
746+
# picked up most of the new APIs from versions up to 1.0, but didn't
747+
# pick up bpf_dump(), so we need to provide it if it's absent.
748+
#
793749
check_function_exists(bpf_dump HAVE_BPF_DUMP)
794750

795751
cmake_pop_check_state()
@@ -1271,17 +1227,6 @@ set(TCPDUMP_SOURCE_LIST_C fptype.c tcpdump.c)
12711227
if(NOT HAVE_BPF_DUMP)
12721228
set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} bpf_dump.c)
12731229
endif(NOT HAVE_BPF_DUMP)
1274-
if(NOT HAVE_PCAP_DUMP_FTELL)
1275-
set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/pcap_dump_ftell.c)
1276-
endif(NOT HAVE_PCAP_DUMP_FTELL)
1277-
1278-
if(NOT HAVE_PCAP_LIST_DATALINKS)
1279-
set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/datalinks.c)
1280-
endif(NOT HAVE_PCAP_LIST_DATALINKS)
1281-
1282-
if((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
1283-
set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/dlnames.c)
1284-
endif((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
12851230

12861231
set(PROJECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} ${TCPDUMP_SOURCE_LIST_C})
12871232

INSTALL.md

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
# tcpdump installation notes
2-
If you have not built libpcap, and your system does not have libpcap
3-
installed, install libpcap first. Your system might provide a version
4-
of libpcap that can be installed; if so, to compile tcpdump you might
5-
need to install a "developer" version of libpcap as well as the
6-
"run-time" version. You can also install The Tcpdump Group version of
7-
libpcap; see [this file](README.md) for the location.
8-
9-
You will need a C99 compiler to build tcpdump. The build system
10-
will abort if your compiler is not C99 compliant. If this happens, use
11-
the generally available GNU C compiler (GCC) or Clang.
12-
13-
After libpcap has been built (either install it with `make install` or
14-
make sure both the libpcap and tcpdump source trees are in the same
15-
directory), do the following steps:
2+
3+
## Installing libpcap
4+
5+
Tcpdump requires libpcap.
6+
7+
### On UN*Xes
8+
9+
Your system might provide a version of libpcap that can be installed, or
10+
that is installed by default; if so, to compile tcpdump you might need
11+
to install a "developer" version of libpcap as well as the "run-time"
12+
version, even if the "run-time" version has already been installed.
13+
14+
If your system does not provide libpcap, or provides a version that does
15+
not support all of the libpcap 1.0 APIs, you will need to download the
16+
source for The Tcpdump Group version of libpcap; see [this
17+
file](README.md) for the location, and build and install that version.
18+
Either install libpcap with `make install` or make sure both the libpcap
19+
and tcpdump source trees are in the same directory.
20+
21+
### On Windows
22+
23+
You will need to install both Npcap and the Npcap SDK; see [this
24+
file](README.windows.md) for information on that.
25+
26+
## Building tcpdump
27+
28+
You will need a C99 compiler to build tcpdump and, if necessary, to
29+
build libpcap. The build system will abort if your compiler is not C99
30+
compliant. If this happens, use the generally available GNU C compiler
31+
(GCC) or Clang.
32+
33+
Once you have a version of libpcap with which you can build tcpdump, do
34+
the following steps:
1635

1736
* If you build from a git clone rather than from a release archive,
1837
run `./autogen.sh` (a shell script). The autogen.sh script will

Makefile.in

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,9 @@ EXTRA_DIST = \
358358
install-sh \
359359
instrument-functions.c \
360360
makemib \
361-
missing/datalinks.c \
362-
missing/dlnames.c \
363361
missing/getopt_long.c \
364362
missing/getopt_long.h \
365363
missing/getservent.c \
366-
missing/pcap_dump_ftell.c \
367364
missing/strlcat.c \
368365
missing/strlcpy.c \
369366
missing/strsep.c \
@@ -390,10 +387,6 @@ $(LIBNETDISSECT): $(LIBNETDISSECT_OBJ)
390387
$(AR) cr $@ $(LIBNETDISSECT_OBJ)
391388
$(RANLIB) $@
392389

393-
datalinks.o: $(srcdir)/missing/datalinks.c
394-
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/datalinks.c
395-
dlnames.o: $(srcdir)/missing/dlnames.c
396-
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/dlnames.c
397390
getservent.o: $(srcdir)/missing/getservent.c
398391
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/getservent.c
399392
getopt_long.o: $(srcdir)/missing/getopt_long.c
@@ -404,8 +397,6 @@ strlcpy.o: $(srcdir)/missing/strlcpy.c
404397
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcpy.c
405398
strsep.o: $(srcdir)/missing/strsep.c
406399
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strsep.c
407-
pcap_dump_ftell.o: $(srcdir)/missing/pcap_dump_ftell.c
408-
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/pcap_dump_ftell.c
409400

410401
install: all
411402
[ -d $(DESTDIR)$(bindir) ] || \

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ In the past tcpdump certainly or likely worked on the following platforms:
5656

5757
### Dependency on libpcap
5858
tcpdump uses libpcap, a system-independent interface for user-level
59-
packet capture. Before building tcpdump, you must first retrieve and
60-
build libpcap.
59+
packet capture. If your operating system does not provide libpcap, or
60+
if it provides a libpcap that does not support the APIs from libpcap 1.0
61+
or later, you must first retrieve and build libpcap before building
62+
tcpdump,
6163

6264
Once libpcap is built (either install it or make sure it's in
6365
`../libpcap`), you can build tcpdump using the procedure in the

build.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ fi
9696
run_after_echo "$MAKE_BIN" install
9797
print_so_deps "$TCPDUMP_BIN"
9898
run_after_echo "$TCPDUMP_BIN" -h
99-
# The "-D" flag depends on HAVE_PCAP_FINDALLDEVS and it would not be difficult
100-
# to run the command below only if the macro is defined. That said, it seems
101-
# more useful to run it anyway: every system that currently runs this script
102-
# has pcap_findalldevs(), thus if the macro isn't defined, it means something
103-
# went wrong in the build process (as was observed with GCC, CMake and the
104-
# system libpcap on Solaris 11).
10599
run_after_echo "$TCPDUMP_BIN" -D
106100
if [ "$CIRRUS_CI" = true ]; then
107101
# Likewise for the "-J" flag and HAVE_PCAP_SET_TSTAMP_TYPE.

0 commit comments

Comments
 (0)