Enable RAW_UDP if PCAP is found

Try to get PCAP version
This commit is contained in:
Carles Fernandez 2019-06-19 21:34:23 +02:00
parent 434f7d7830
commit 34a949eb28
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
2 changed files with 36 additions and 1 deletions

View File

@ -2193,10 +2193,21 @@ endif()
find_package(PCAP)
set_package_properties(PCAP PROPERTIES
URL "https://www.tcpdump.org"
DESCRIPTION "A portable C/C++ library for network traffic capture"
PURPOSE "Used for the custom UDP IP packet source."
TYPE OPTIONAL
)
if(PCAP_FOUND AND PCAP_VERSION)
set_package_properties(PCAP PROPERTIES
DESCRIPTION "A portable C/C++ library for network traffic capture (found: ${PCAP_VERSION})"
)
else()
set_package_properties(PCAP PROPERTIES
DESCRIPTION "A portable C/C++ library for network traffic capture"
)
endif()
if(PCAP_FOUND)
set(ENABLE_RAW_UDP ON)
endif()
if(ENABLE_RAW_UDP)
message(STATUS "High-optimized custom UDP IP packet source is enabled.")
message(STATUS " You can disable it with 'cmake -DENABLE_RAW_UDP=OFF ..'")

View File

@ -48,6 +48,10 @@
# Pcap::pcap
#
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)
include(FindPkgConfig)
pkg_check_modules(PC_PCAP libpcap)
if(EXISTS $ENV{PCAPDIR})
find_path(PCAP_INCLUDE_DIR
NAMES
@ -57,6 +61,7 @@ if(EXISTS $ENV{PCAPDIR})
$ENV{PCAPDIR}
${PCAP_ROOT}/include
$ENV{PCAP_ROOT}/include
${PC_PCAP_INCLUDEDIR}
NO_DEFAULT_PATH
)
find_library(PCAP_LIBRARY
@ -66,6 +71,7 @@ if(EXISTS $ENV{PCAPDIR})
$ENV{PCAPDIR}
${PCAP_ROOT}/lib
$ENV{PCAP_ROOT}/lib
${PC_PCAP_LIBDIR}
NO_DEFAULT_PATH
)
else()
@ -76,6 +82,7 @@ else()
HINTS
${PCAP_ROOT}/include
$ENV{PCAP_ROOT}/include
${PC_PCAP_INCLUDEDIR}
)
find_library(PCAP_LIBRARY
NAMES
@ -83,6 +90,7 @@ else()
HINTS
${PCAP_ROOT}/lib
$ENV{PCAP_ROOT}/lib
${PC_PCAP_LIBDIR}
)
endif()
@ -103,8 +111,13 @@ endif()
#Functions
include(CheckFunctionExists)
include(CheckVariableExists)
set(OLD_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES})
check_variable_exists("pcap_version" HAVE_PCAP_VERSION)
check_function_exists("pcap_breakloop" HAVE_PCAP_BREAKLOOP)
check_function_exists("pcap_datalink_name_to_val" HAVE_PCAP_DATALINK_NAME_TO_VAL)
check_function_exists("pcap_datalink_val_to_name" HAVE_PCAP_DATALINK_VAL_TO_NAME)
@ -115,10 +128,21 @@ check_function_exists("pcap_lib_version" HAVE_PCAP_LIB_VERSION)
check_function_exists("pcap_list_datalinks" HAVE_PCAP_LIST_DATALINKS)
check_function_exists("pcap_open_dead" HAVE_PCAP_OPEN_DEAD)
check_function_exists("pcap_set_datalink" HAVE_PCAP_SET_DATALINK)
set(CMAKE_REQUIRED_INCLUDES ${OLD_CMAKE_REQUIRED_INCLUDES})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PCAP DEFAULT_MSG PCAP_INCLUDE_DIRS PCAP_LIBRARIES)
if(${HAVE_PCAP_VERSION})
set(PCAP_VERSION ${HAVE_PCAP_VERSION})
endif()
if(NOT PCAP_VERSION)
if(PC_PCAP_VERSION)
set(PCAP_VERSION ${PC_PCAP_VERSION})
endif()
endif()
if(PCAP_FOUND AND NOT TARGET Pcap::pcap)
add_library(Pcap::pcap SHARED IMPORTED)
set_target_properties(Pcap::pcap PROPERTIES