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 find_path( PCAP_INCLUDE_DIR
17 "${PCAP_HINTS}/include"
20 find_library( PCAP_LIBRARY
29 include( FindPackageHandleStandardArgs )
30 find_package_handle_standard_args( PCAP DEFAULT_MSG PCAP_INCLUDE_DIR PCAP_LIBRARY )
33 set( PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR} )
34 set( PCAP_LIBRARIES ${PCAP_LIBRARY} )
36 set( PCAP_INCLUDE_DIRS )
41 include( CMakePushCheckState )
42 include( CheckFunctionExists )
43 include( CheckVariableExists )
45 cmake_push_check_state()
46 set( CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS} )
47 set( CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} )
49 check_function_exists( "pcap_open_dead" HAVE_PCAP_OPEN_DEAD )
50 check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE )
52 # Note: for pcap_breakloop() and pcap_findalldevs(), the autoconf script
53 # checks for more than just whether the function exists, it also checks
54 # for whether pcap.h declares it; Mac OS X software/security updates can
55 # update libpcap without updating the headers.
57 check_function_exists( "pcap_breakloop" HAVE_PCAP_BREAKLOOP )
58 /* FIXME: The code (at least) in dumpcap assumes that PCAP_CREATE is not
59 * available on Windows */
61 check_function_exists( "pcap_create" HAVE_PCAP_CREATE )
63 check_function_exists( "pcap_datalink_name_to_val" HAVE_PCAP_DATALINK_NAME_TO_VAL )
64 check_function_exists( "pcap_datalink_val_to_description" HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION )
65 check_function_exists( "pcap_datalink_val_to_name" HAVE_PCAP_DATALINK_VAL_TO_NAME )
66 check_function_exists( "pcap_findalldevs" HAVE_PCAP_FINDALLDEVS )
67 check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS )
68 check_function_exists( "pcap_get_selectable_fd" HAVE_PCAP_GET_SELECTABLE_FD )
69 check_function_exists( "pcap_lib_version" HAVE_PCAP_LIB_VERSION )
70 check_function_exists( "pcap_list_datalinks" HAVE_PCAP_LIST_DATALINKS )
71 check_function_exists( "pcap_set_datalink" HAVE_PCAP_SET_DATALINK )
72 check_function_exists( "bpf_image" HAVE_BPF_IMAGE )
74 check_function_exists( "pcap_open" H_PCAP_OPEN )
75 check_function_exists( "pcap_findalldevs_ex" H_FINDALLDEVS_EX )
76 check_function_exists( "pcap_createsrcstr" H_CREATESRCSTR )
77 if( H_PCAP_OPEN AND H_FINDALLDEVS_EX AND H_CREATESRCSTR )
78 set( HAVE_PCAP_REMOTE 1 )
82 cmake_pop_check_state()
84 mark_as_advanced( PCAP_LIBRARIES PCAP_INCLUDE_DIRS )