diff options
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/modules/FindPCAP.cmake | 114 |
1 files changed, 61 insertions, 53 deletions
diff --git a/cmake/modules/FindPCAP.cmake b/cmake/modules/FindPCAP.cmake index 6e0393ba26..8955345579 100644 --- a/cmake/modules/FindPCAP.cmake +++ b/cmake/modules/FindPCAP.cmake @@ -182,36 +182,75 @@ if(PCAP_FOUND) set( CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS} ) set( CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} ) + include(CheckSymbolExists) + if(WIN32) - # Prepopulate some values. WinPcap and Npcap always have these and - # compilation checks on Windows can be slow. - set(HAVE_PCAP_OPEN_DEAD TRUE) + # + # Make sure we have at least the WinPcap 3.1 SDK, because we + # we require at least libpcap 0.8's APIs. 3.1 is based on + # libpcap 0.9.2, but 3.0 is based on a pre-0.8 snapshot of + # libpcap. + # + # We check whether pcap_lib_version is defined in the pcap header, + # using it as a proxy for all the 0.8 API's. if not, we fail. + # + check_symbol_exists( pcap_lib_version ${PCAP_INCLUDE_DIR}/pcap.h HAVE_PCAP_LIB_VERSION ) + if( NOT HAVE_PCAP_LIB_VERSION ) + message(FATAL_ERROR "You need WinPcap 3.1 or later, or Npcap") + endif( NOT HAVE_PCAP_LIB_VERSION ) + + # + # Prepopulate some values. WinPcap 3.1 and later, and Npcap, have these + # in their SDK, and compilation checks on Windows can be slow. We check + # whether they're present at run time, when we load wpcap.dll, and work + # around their absence or report an error. + # set(HAVE_PCAP_FREECODE TRUE) - set(HAVE_PCAP_BREAKLOOP TRUE) set(HAVE_PCAP_CREATE TRUE) - set(HAVE_PCAP_DATALINK_NAME_TO_VAL TRUE) - set(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION TRUE) - set(HAVE_PCAP_DATALINK_VAL_TO_NAME TRUE) - set(HAVE_PCAP_FINDALLDEVS TRUE) set(HAVE_PCAP_FREE_DATALINKS TRUE) - set(HAVE_PCAP_LIB_VERSION TRUE) - set(HAVE_PCAP_LIST_DATALINKS TRUE) - set(HAVE_PCAP_SET_DATALINK TRUE) - set(HAVE_BPF_IMAGE TRUE) set(HAVE_PCAP_OPEN TRUE) set(HAVE_PCAP_SETSAMPLING TRUE) + else(WIN32) + # + # Make sure we have at least libpcap 0.8, because we we require at + # least libpcap 0.8's APIs. + # + # We check whether pcap_lib_version is defined in the pcap header, + # using it as a proxy for all the 0.8 API's. if not, we fail. + # + check_symbol_exists( pcap_lib_version ${PCAP_INCLUDE_DIR}/pcap.h HAVE_PCAP_LIB_VERSION ) + if( NOT HAVE_PCAP_LIB_VERSION ) + message(FATAL_ERROR "You need libpcap 0.8 or later") + endif( NOT HAVE_PCAP_LIB_VERSION ) + + check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE ) + check_function_exists( "pcap_create" HAVE_PCAP_CREATE ) + check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS ) + check_function_exists( "pcap_open" HAVE_PCAP_OPEN ) + if( HAVE_PCAP_OPEN ) + # + # XXX - this *should* be checked for independently of checking + # for pcap_open(), as you might have pcap_setsampling() without + # remote capture support. + # + # However, 1) the sampling options are treated as remote options + # in the GUI and and 2) having pcap_setsampling() doesn't mean + # you have sampling support. libpcap needs a way to indicate + # whether a given device supports sampling, and the GUI should + # be changed to decouple them. + # + # (Actually, libpcap needs a general mechanism to offer options + # for particular devices, and Wireshark needs to use that + # mechanism. The former is a work in progress.) + # + # (Note: another work in progress is support for remote + # capturing using pcap_create()/pcap_activate(), which we + # also need to support once it's available.) + # + check_function_exists( "pcap_setsampling" HAVE_PCAP_SETSAMPLING ) + endif( HAVE_PCAP_OPEN ) endif(WIN32) - check_function_exists( "pcap_open_dead" HAVE_PCAP_OPEN_DEAD ) - check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE ) - # - # Note: for pcap_breakloop() and pcap_findalldevs(), the autoconf script - # checked for more than just whether the function exists, it also checked - # for whether pcap.h declares it; macOS software/security updates can - # update libpcap without updating the headers. - # - check_function_exists( "pcap_breakloop" HAVE_PCAP_BREAKLOOP ) - check_function_exists( "pcap_create" HAVE_PCAP_CREATE ) if( HAVE_PCAP_CREATE ) # # If we have pcap_create(), we have pcap_set_buffer_size(), and @@ -222,42 +261,11 @@ if(PCAP_FOUND) # set( CAN_SET_CAPTURE_BUFFER_SIZE TRUE ) endif() - check_function_exists( "pcap_datalink_name_to_val" HAVE_PCAP_DATALINK_NAME_TO_VAL ) - check_function_exists( "pcap_datalink_val_to_description" HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION ) - check_function_exists( "pcap_datalink_val_to_name" HAVE_PCAP_DATALINK_VAL_TO_NAME ) - check_function_exists( "pcap_findalldevs" HAVE_PCAP_FINDALLDEVS ) - check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS ) - check_function_exists( "pcap_get_selectable_fd" HAVE_PCAP_GET_SELECTABLE_FD ) - check_function_exists( "pcap_lib_version" HAVE_PCAP_LIB_VERSION ) - check_function_exists( "pcap_list_datalinks" HAVE_PCAP_LIST_DATALINKS ) - check_function_exists( "pcap_set_datalink" HAVE_PCAP_SET_DATALINK ) - check_function_exists( "bpf_image" HAVE_BPF_IMAGE ) check_function_exists( "pcap_set_tstamp_precision" HAVE_PCAP_SET_TSTAMP_PRECISION ) check_function_exists( "pcap_set_tstamp_type" HAVE_PCAP_SET_TSTAMP_TYPE ) # Remote pcap checks - check_function_exists( "pcap_open" HAVE_PCAP_OPEN ) if( HAVE_PCAP_OPEN ) set( HAVE_PCAP_REMOTE 1 ) - # - # XXX - this *should* be checked for independently of checking - # for pcap_open(), as you might have pcap_setsampling() without - # remote capture support. - # - # However, 1) the sampling options are treated as remote options - # in the GUI and and 2) having pcap_setsampling() doesn't mean - # you have sampling support. libpcap needs a way to indicate - # whether a given device supports sampling, and the GUI should - # be changed to decouple them. - # - # (Actually, libpcap needs a general mechanism to offer options - # for particular devices, and Wireshark needs to use that - # mechanism. The former is a work in progress.) - # - # (Note: another work in progress is support for remote - # capturing using pcap_create()/pcap_activate(), which we - # also need to support once it's available.) - # - check_function_exists( "pcap_setsampling" HAVE_PCAP_SETSAMPLING ) endif() cmake_pop_check_state() |