2 # - Find pcap and winpcap
3 # Find the native PCAP includes and library
5 # PCAP_INCLUDE_DIRS - where to find pcap.h, etc.
6 # PCAP_LIBRARIES - List of libraries when using pcap.
7 # PCAP_FOUND - True if pcap found.
9 include( FindWSWinLibs )
10 FindWSWinLibs( "WpdPack" "PCAP_HINTS" )
12 # The 64-bit wpcap.lib is under /x64
13 set ( _PLATFORM_SUBDIR "" )
14 if( WIN32 AND "${WIRESHARK_TARGET_PLATFORM}" STREQUAL "win64" )
15 set ( _PLATFORM_SUBDIR "/x64" )
18 find_path( PCAP_INCLUDE_DIR
23 "${PCAP_HINTS}/include"
26 find_library( PCAP_LIBRARY
31 "${PCAP_HINTS}/lib${_PLATFORM_SUBDIR}"
35 include( FindPackageHandleStandardArgs )
36 find_package_handle_standard_args( PCAP DEFAULT_MSG PCAP_INCLUDE_DIR PCAP_LIBRARY )
39 set( PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR} )
40 set( PCAP_LIBRARIES ${PCAP_LIBRARY} )
42 set( PCAP_INCLUDE_DIRS )
48 include( CMakePushCheckState )
49 include( CheckFunctionExists )
50 include( CheckVariableExists )
52 cmake_push_check_state()
53 set( CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS} )
54 set( CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} )
56 check_function_exists( "pcap_open_dead" HAVE_PCAP_OPEN_DEAD )
57 check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE )
59 # Note: for pcap_breakloop() and pcap_findalldevs(), the autoconf script
60 # checks for more than just whether the function exists, it also checks
61 # for whether pcap.h declares it; macOS software/security updates can
62 # update libpcap without updating the headers.
64 check_function_exists( "pcap_breakloop" HAVE_PCAP_BREAKLOOP )
65 check_function_exists( "pcap_create" HAVE_PCAP_CREATE )
66 if( HAVE_PCAP_CREATE OR WIN32 )
68 # If we have pcap_create(), we have pcap_set_buffer_size(), and
69 # can set the capture buffer size.
71 # Otherwise, if this is Windows, we have pcap_setbuff(), and can
72 # set the capture buffer size.
74 set( CAN_SET_CAPTURE_BUFFER_SIZE TRUE )
76 check_function_exists( "pcap_datalink_name_to_val" HAVE_PCAP_DATALINK_NAME_TO_VAL )
77 check_function_exists( "pcap_datalink_val_to_description" HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION )
78 check_function_exists( "pcap_datalink_val_to_name" HAVE_PCAP_DATALINK_VAL_TO_NAME )
79 check_function_exists( "pcap_findalldevs" HAVE_PCAP_FINDALLDEVS )
80 check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS )
81 check_function_exists( "pcap_get_selectable_fd" HAVE_PCAP_GET_SELECTABLE_FD )
82 check_function_exists( "pcap_lib_version" HAVE_PCAP_LIB_VERSION )
83 check_function_exists( "pcap_list_datalinks" HAVE_PCAP_LIST_DATALINKS )
84 check_function_exists( "pcap_set_datalink" HAVE_PCAP_SET_DATALINK )
85 check_function_exists( "bpf_image" HAVE_BPF_IMAGE )
86 check_function_exists( "pcap_setsampling" HAVE_PCAP_SETSAMPLING )
87 check_function_exists( "pcap_set_tstamp_precision" HAVE_PCAP_SET_TSTAMP_PRECISION )
89 check_function_exists( "pcap_open" HAVE_PCAP_OPEN )
91 set( HAVE_PCAP_REMOTE 1 )
95 cmake_pop_check_state()
98 mark_as_advanced( PCAP_LIBRARIES PCAP_INCLUDE_DIRS )