mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Allow configuring pcap timestamp precision
This commit is contained in:
@@ -75,6 +75,7 @@ include(CheckFunctionExists)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
|
||||
check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
|
||||
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE)
|
||||
check_function_exists(pcap_set_tstamp_precision HAVE_PCAP_TIMESTAMP_PRECISION)
|
||||
set(CMAKE_REQUIRED_LIBRARIES)
|
||||
|
||||
mark_as_advanced(
|
||||
|
||||
@@ -350,14 +350,11 @@ private:
|
||||
friend class SnifferConfiguration;
|
||||
|
||||
void set_snap_len(unsigned snap_len);
|
||||
|
||||
void set_buffer_size(unsigned buffer_size);
|
||||
|
||||
void set_promisc_mode(bool promisc_enabled);
|
||||
|
||||
void set_rfmon(bool rfmon_enabled);
|
||||
|
||||
void set_immediate_mode(bool enabled);
|
||||
void set_timestamp_precision(int value);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -586,6 +583,12 @@ public:
|
||||
* \param enabled The immediate mode option value.
|
||||
*/
|
||||
void set_immediate_mode(bool enabled);
|
||||
|
||||
/**
|
||||
* Sets the timestamp precision value
|
||||
* \param value The timestamp option value.
|
||||
*/
|
||||
void set_timestamp_precision(int value);
|
||||
protected:
|
||||
friend class Sniffer;
|
||||
friend class FileSniffer;
|
||||
@@ -596,7 +599,8 @@ protected:
|
||||
RFMON = 4,
|
||||
PACKET_FILTER = 8,
|
||||
IMMEDIATE_MODE = 16,
|
||||
DIRECTION = 32
|
||||
DIRECTION = 32,
|
||||
TIMESTAMP_PRECISION = 64,
|
||||
};
|
||||
|
||||
void configure_sniffer_pre_activation(Sniffer& sniffer) const;
|
||||
@@ -613,6 +617,7 @@ protected:
|
||||
bool rfmon_;
|
||||
bool immediate_mode_;
|
||||
pcap_direction_t direction_;
|
||||
int timestamp_precision_;
|
||||
};
|
||||
|
||||
template <typename Functor>
|
||||
|
||||
@@ -4,6 +4,10 @@ IF(HAVE_PCAP_IMMEDIATE_MODE)
|
||||
ADD_DEFINITIONS("-DHAVE_PCAP_IMMEDIATE_MODE=1")
|
||||
ENDIF()
|
||||
|
||||
IF(HAVE_PCAP_TIMESTAMP_PRECISION)
|
||||
ADD_DEFINITIONS("-DHAVE_PCAP_TIMESTAMP_PRECISION=1")
|
||||
ENDIF()
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${LIBTINS_INCLUDE_DIR}
|
||||
${OPENSSL_INCLUDE_DIR}
|
||||
|
||||
@@ -359,6 +359,16 @@ void Sniffer::set_immediate_mode(bool enabled) {
|
||||
#endif // HAVE_PCAP_IMMEDIATE_MODE
|
||||
}
|
||||
|
||||
void Sniffer::set_timestamp_precision(int value) {
|
||||
// This function exists as of libpcap version 1.5.0.
|
||||
#ifdef HAVE_PCAP_TIMESTAMP_PRECISION
|
||||
int result = pcap_set_tstamp_precision(get_pcap_handle(), value);
|
||||
if (result == PCAP_ERROR_TSTAMP_PRECISION_NOTSUP) {
|
||||
throw pcap_error("Timestamp precision not supported");
|
||||
}
|
||||
#endif // HAVE_PCAP_TIMESTAMP_PRECISION
|
||||
}
|
||||
|
||||
void Sniffer::set_rfmon(bool rfmon_enabled) {
|
||||
#ifndef _WIN32
|
||||
if (pcap_can_set_rfmon(get_pcap_handle()) == 1) {
|
||||
@@ -408,7 +418,8 @@ const unsigned SnifferConfiguration::DEFAULT_TIMEOUT = 1000;
|
||||
|
||||
SnifferConfiguration::SnifferConfiguration()
|
||||
: flags_(0), snap_len_(DEFAULT_SNAP_LEN), buffer_size_(0), timeout_(DEFAULT_TIMEOUT),
|
||||
promisc_(false), rfmon_(false), immediate_mode_(false), direction_(PCAP_D_INOUT) {
|
||||
promisc_(false), rfmon_(false), immediate_mode_(false), direction_(PCAP_D_INOUT),
|
||||
timestamp_precision_(0) {
|
||||
|
||||
}
|
||||
|
||||
@@ -427,6 +438,9 @@ void SnifferConfiguration::configure_sniffer_pre_activation(Sniffer& sniffer) co
|
||||
if ((flags_ & IMMEDIATE_MODE) != 0) {
|
||||
sniffer.set_immediate_mode(immediate_mode_);
|
||||
}
|
||||
if ((flags_ & TIMESTAMP_PRECISION) != 0) {
|
||||
sniffer.set_timestamp_precision(timestamp_precision_);
|
||||
}
|
||||
}
|
||||
|
||||
void SnifferConfiguration::configure_sniffer_pre_activation(FileSniffer& sniffer) const {
|
||||
@@ -486,6 +500,11 @@ void SnifferConfiguration::set_immediate_mode(bool enabled) {
|
||||
immediate_mode_ = enabled;
|
||||
}
|
||||
|
||||
void SnifferConfiguration::set_timestamp_precision(int value) {
|
||||
flags_ |= TIMESTAMP_PRECISION;
|
||||
timestamp_precision_ = value;
|
||||
}
|
||||
|
||||
void SnifferConfiguration::set_direction(pcap_direction_t direction) {
|
||||
direction_ = direction;
|
||||
flags_ |= DIRECTION;
|
||||
|
||||
Reference in New Issue
Block a user