@@ -658,113 +658,62 @@ set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
658658#
659659check_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#
672664cmake_push_check_state()
673665set (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)
764714check_function_exists(pcap_set_immediate_mode HAVE_PCAP_SET_IMMEDIATE_MODE)
765715check_function_exists(pcap_dump_ftell64 HAVE_PCAP_DUMP_FTELL64)
766716check_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)
790739endif (NOT HAVE_PCAP_SET_PARSER_DEBUG)
791740
792741check_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+ #
793749check_function_exists(bpf_dump HAVE_BPF_DUMP)
794750
795751cmake_pop_check_state()
@@ -1271,17 +1227,6 @@ set(TCPDUMP_SOURCE_LIST_C fptype.c tcpdump.c)
12711227if (NOT HAVE_BPF_DUMP)
12721228 set (TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} bpf_dump.c)
12731229endif (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
12861231set (PROJECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} ${TCPDUMP_SOURCE_LIST_C} )
12871232
0 commit comments