wireshark/cmake/modules/FindPCAP.cmake

97 lines
3.0 KiB
CMake
Raw Normal View History

#
# - Find pcap and winpcap
# Find the native PCAP includes and library
#
# PCAP_INCLUDE_DIRS - where to find pcap.h, etc.
# PCAP_LIBRARIES - List of libraries when using pcap.
# PCAP_FOUND - True if pcap found.
include( FindWSWinLibs )
FindWSWinLibs( "WpdPack" "PCAP_HINTS" )
# The 64-bit wpcap.lib is under /x64
set ( _PLATFORM_SUBDIR "" )
if( WIN32 AND "${WIRESHARK_TARGET_PLATFORM}" STREQUAL "win64" )
set ( _PLATFORM_SUBDIR "/x64" )
endif()
find_path( PCAP_INCLUDE_DIR
NAMES
pcap/pcap.h
pcap.h
HINTS
"${PCAP_HINTS}/include"
)
find_library( PCAP_LIBRARY
NAMES
pcap
wpcap
HINTS
"${PCAP_HINTS}/lib${_PLATFORM_SUBDIR}"
)
include( FindPackageHandleStandardArgs )
find_package_handle_standard_args( PCAP DEFAULT_MSG PCAP_INCLUDE_DIR PCAP_LIBRARY )
if( PCAP_FOUND )
set( PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR} )
set( PCAP_LIBRARIES ${PCAP_LIBRARY} )
else()
set( PCAP_INCLUDE_DIRS )
set( PCAP_LIBRARIES )
endif()
#Functions
include( CMakePushCheckState )
include( CheckFunctionExists )
include( CheckVariableExists )
cmake_push_check_state()
set( CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS} )
set( CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} )
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
# checks for more than just whether the function exists, it also checks
# for whether pcap.h declares it; Mac OS X software/security updates can
# update libpcap without updating the headers.
#
check_function_exists( "pcap_breakloop" HAVE_PCAP_BREAKLOOP )
Move more capture device handling to the caputils library. Move the code to open capture devices and get properties of capture devices there, joining the code to get a list of capture devices. This lets us do a better job of handling pcap_create() in WinPcap, including handling both WinPcap with pcap_create() and WinPcap without pcap_create() at run time, just in case somebody tries using WinPcap 3.x with a Wireshark built with WinPcap 4.x. It also could make it easier to use libpcap/WinPcap directly in Wireshark and TShark, if we have versions of libpcap/WinPcap that run small helper utilities to do privileged functions, allowing programs using them never to need elevated privileges themselves. That might make it easier to fix some issues with running TShark when not saving to a file (we could avoid the file entirely) and with delays when stopping a capture in Wireshark (Wireshark could stop writing to the file as soon as you click the stop button, rather than letting dumpcap do so when the signal gets to it). It might also make it easier to handle future versions of libpcap/WinPcap that support using pcap_create()/pcap_activate() for remote captures, and other future extensions to libpcap/WinPcap. Rename some XXX_linktype routines to XXX_datalink to indicate that they work with DLT_ values rather than LINKTYPE_ values; future versions of libpcap might use LINKTYPE_ values in newer APIs. Check for pcap_create() on all platforms in CMake. Change-Id: Ia12e1692c96ec945c07a135d246958771a29c817 Reviewed-on: https://code.wireshark.org/review/13062 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-01-05 21:54:02 +00:00
check_function_exists( "pcap_create" HAVE_PCAP_CREATE )
if( HAVE_PCAP_CREATE OR WIN32 )
#
# If we have pcap_create(), we have pcap_set_buffer_size(), and
# can set the capture buffer size.
#
# Otherwise, if this is Windows, we have pcap_setbuff(), and can
# set the capture buffer size.
#
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_setsampling" HAVE_PCAP_SETSAMPLING )
check_function_exists( "pcap_set_tstamp_precision" HAVE_PCAP_SET_TSTAMP_PRECISION )
# Remote pcap checks
check_function_exists( "pcap_open" HAVE_PCAP_OPEN )
if( HAVE_PCAP_OPEN )
set( HAVE_PCAP_REMOTE 1 )
set( HAVE_REMOTE 1 )
endif()
cmake_pop_check_state()
mark_as_advanced( PCAP_LIBRARIES PCAP_INCLUDE_DIRS )