1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Detect if pcap version defines pcap_set_immediate_mode.

This commit is contained in:
Matias Fontanini
2015-06-14 11:23:32 -07:00
parent c42c18f5df
commit b451a9eae0
3 changed files with 11 additions and 0 deletions

View File

@@ -18,6 +18,7 @@
# PCAP_LIBRARY The libpcap library (possibly includes a thread # PCAP_LIBRARY The libpcap library (possibly includes a thread
# library e.g. required by pf_ring's libpcap) # library e.g. required by pf_ring's libpcap)
# HAVE_PF_RING If a found version of libpcap supports PF_RING # HAVE_PF_RING If a found version of libpcap supports PF_RING
# HAVE_PCAP_IMMEDIATE_MODE If the version of libpcap found supports immediate mode
find_path(PCAP_ROOT_DIR find_path(PCAP_ROOT_DIR
NAMES include/pcap.h NAMES include/pcap.h
@@ -73,6 +74,7 @@ endif (NOT PCAP_LINKS_SOLO)
include(CheckFunctionExists) include(CheckFunctionExists)
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
check_function_exists(pcap_get_pfring_id HAVE_PF_RING) check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE)
set(CMAKE_REQUIRED_LIBRARIES) set(CMAKE_REQUIRED_LIBRARIES)
mark_as_advanced( mark_as_advanced(

View File

@@ -1,5 +1,9 @@
SET(LIBTINS_INCLUDE_DIR ../include/tins/) SET(LIBTINS_INCLUDE_DIR ../include/tins/)
IF(HAVE_PCAP_IMMEDIATE_MODE)
ADD_DEFINITIONS("-DHAVE_PCAP_IMMEDIATE_MODE=1")
ENDIF()
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
${LIBTINS_INCLUDE_DIR} ${LIBTINS_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}

View File

@@ -343,9 +343,14 @@ void Sniffer::set_promisc_mode(bool promisc_enabled)
void Sniffer::set_immediate_mode(bool enabled) void Sniffer::set_immediate_mode(bool enabled)
{ {
// As of libpcap version 1.5.0 this function exists. Before, it was
// technically always immediate mode since capture used TPACKET_V1/2
// which doesn't do packet buffering.
#ifdef HAVE_PCAP_IMMEDIATE_MODE
if (pcap_set_immediate_mode(get_pcap_handle(), enabled)) { if (pcap_set_immediate_mode(get_pcap_handle(), enabled)) {
throw runtime_error(pcap_geterr(get_pcap_handle())); throw runtime_error(pcap_geterr(get_pcap_handle()));
} }
#endif // HAVE_PCAP_IMMEDIATE_MODE
} }
void Sniffer::set_rfmon(bool rfmon_enabled) void Sniffer::set_rfmon(bool rfmon_enabled)