mirror of
https://github.com/mfontanini/libtins
synced 2026-01-22 18:25:57 +01:00
Allow disabling pcap packet capture
This commit is contained in:
@@ -49,8 +49,14 @@ SET(LIBTINS_VERSION "${LIBTINS_VERSION_MAJOR}.${LIBTINS_VERSION_MINOR}")
|
||||
# Required Packages
|
||||
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
|
||||
|
||||
# Allow disabling packet capture mechanism
|
||||
OPTION(LIBTINS_ENABLE_PCAP "Enable capturing packets via libpcap" ON)
|
||||
|
||||
# Look for libpcap
|
||||
FIND_PACKAGE(PCAP REQUIRED)
|
||||
IF(LIBTINS_ENABLE_PCAP)
|
||||
FIND_PACKAGE(PCAP REQUIRED)
|
||||
SET(TINS_HAVE_PCAP ON)
|
||||
ENDIF()
|
||||
|
||||
# Set some Windows specific flags
|
||||
IF(WIN32)
|
||||
@@ -194,10 +200,10 @@ ENDIF(WIN32)
|
||||
|
||||
OPTION(LIBTINS_USE_PCAP_SENDPACKET "Use pcap_sendpacket to send l2 packets"
|
||||
${USE_PCAP_SENDPACKET_DEFAULT})
|
||||
IF(LIBTINS_USE_PCAP_SENDPACKET)
|
||||
IF(LIBTINS_ENABLE_PCAP AND LIBTINS_USE_PCAP_SENDPACKET)
|
||||
SET(TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET ON)
|
||||
MESSAGE(STATUS "Using pcap_sendpacket to send l2 packets.")
|
||||
ENDIF(LIBTINS_USE_PCAP_SENDPACKET)
|
||||
ENDIF()
|
||||
|
||||
# Add a target to generate API documentation using Doxygen
|
||||
FIND_PACKAGE(Doxygen QUIET)
|
||||
@@ -255,8 +261,12 @@ ADD_CUSTOM_TARGET(uninstall
|
||||
# Add subdirectories
|
||||
# ******************
|
||||
ADD_SUBDIRECTORY(include)
|
||||
ADD_SUBDIRECTORY(examples)
|
||||
ADD_SUBDIRECTORY(src)
|
||||
IF(LIBTINS_ENABLE_PCAP)
|
||||
ADD_SUBDIRECTORY(examples)
|
||||
ELSE()
|
||||
MESSAGE(STATUS "Not building examples as pcap support is disabled")
|
||||
ENDIF()
|
||||
|
||||
# Only include googletest if the git submodule has been fetched
|
||||
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt")
|
||||
|
||||
@@ -28,4 +28,7 @@
|
||||
/* Have WPA2Decrypter callbacks */
|
||||
#cmakedefine TINS_HAVE_WPA2_CALLBACKS
|
||||
|
||||
/* Have libpcap */
|
||||
#cmakedefine TINS_HAVE_PCAP
|
||||
|
||||
#endif // TINS_CONFIG_H
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "constants.h"
|
||||
#include "pdu.h"
|
||||
#include "hw_address.h"
|
||||
#include "macros.h"
|
||||
|
||||
/**
|
||||
* \cond
|
||||
@@ -124,8 +125,10 @@ PDU* pdu_from_flag(Constants::Ethernet::e flag, const uint8_t* buffer,
|
||||
uint32_t size, bool rawpdu_on_no_match = true);
|
||||
PDU* pdu_from_flag(Constants::IP::e flag, const uint8_t* buffer,
|
||||
uint32_t size, bool rawpdu_on_no_match = true);
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
PDU* pdu_from_dlt_flag(int flag, const uint8_t* buffer,
|
||||
uint32_t size, bool rawpdu_on_no_match = true);
|
||||
#endif // TINS_HAVE_PCAP
|
||||
PDU* pdu_from_flag(PDU::PDUType type, const uint8_t* buffer, uint32_t size);
|
||||
|
||||
Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag);
|
||||
|
||||
@@ -32,9 +32,12 @@
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include "data_link_type.h"
|
||||
#include "macros.h"
|
||||
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
|
||||
#include "data_link_type.h"
|
||||
|
||||
namespace Tins {
|
||||
|
||||
class PDU;
|
||||
@@ -154,6 +157,9 @@ private:
|
||||
mutable bpf_program filter_;
|
||||
std::string string_filter_;
|
||||
};
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // TINS_HAVE_PCAP
|
||||
|
||||
#endif // TINS_OFFLINE_PACKET_FILTER_H
|
||||
|
||||
@@ -33,11 +33,13 @@
|
||||
#include "utils.h"
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <pcap.h>
|
||||
#include "data_link_type.h"
|
||||
#include "macros.h"
|
||||
#include "cxxstd.h"
|
||||
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
#include <pcap.h>
|
||||
#include "data_link_type.h"
|
||||
|
||||
struct timeval;
|
||||
|
||||
namespace Tins {
|
||||
@@ -220,6 +222,9 @@ private:
|
||||
pcap_t* handle_;
|
||||
pcap_dumper_t* dumper_;
|
||||
};
|
||||
}
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // TINS_HAVE_PCAP
|
||||
|
||||
#endif // TINS_PACKET_WRITER_H
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
|
||||
// This class is only available if pcap is enabled
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
|
||||
namespace Tins {
|
||||
|
||||
/**
|
||||
@@ -111,4 +114,6 @@ private:
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // TINS_HAVE_PCAP
|
||||
|
||||
#endif // TINS_PKTAP_H
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "endianness.h"
|
||||
#include "small_uint.h"
|
||||
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
|
||||
namespace Tins {
|
||||
|
||||
/**
|
||||
@@ -135,6 +137,9 @@ private:
|
||||
ppi_header header_;
|
||||
byte_array data_;
|
||||
};
|
||||
}
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // TINS_HAVE_PCAP
|
||||
|
||||
#endif // TINS_PPI_H
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
#ifndef TINS_SNIFFER_H
|
||||
#define TINS_SNIFFER_H
|
||||
|
||||
|
||||
#include <pcap.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
@@ -44,6 +42,10 @@
|
||||
#include "exceptions.h"
|
||||
#include "internals.h"
|
||||
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
|
||||
#include <pcap.h>
|
||||
|
||||
namespace Tins {
|
||||
class SnifferIterator;
|
||||
class SnifferConfiguration;
|
||||
@@ -645,4 +647,6 @@ void Tins::BaseSniffer::sniff_loop(Functor function, uint32_t max_packets) {
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // TINS_HAVE_PCAP
|
||||
|
||||
#endif // TINS_SNIFFER_H
|
||||
|
||||
@@ -36,13 +36,16 @@
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <stdint.h>
|
||||
#include "sniffer.h"
|
||||
#include "macros.h"
|
||||
#include "tcp.h"
|
||||
#include "utils.h"
|
||||
#include "ip.h"
|
||||
#include "ip_address.h"
|
||||
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
|
||||
#include "sniffer.h"
|
||||
|
||||
namespace Tins {
|
||||
class Sniffer;
|
||||
class RawPDU;
|
||||
@@ -385,4 +388,6 @@ bool TCPStreamFollower::callback(PDU& pdu,
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // TINS_HAVE_PCAP
|
||||
|
||||
#endif // TINS_TCP_STREAM_H
|
||||
|
||||
@@ -14,8 +14,7 @@ INCLUDE_DIRECTORIES(
|
||||
${PCAP_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
ADD_LIBRARY(
|
||||
tins ${LIBTINS_TYPE}
|
||||
set(SOURCES
|
||||
arp.cpp
|
||||
bootp.cpp
|
||||
handshake_capturer.cpp
|
||||
@@ -43,19 +42,14 @@ ADD_LIBRARY(
|
||||
loopback.cpp
|
||||
mpls.cpp
|
||||
network_interface.cpp
|
||||
offline_packet_filter.cpp
|
||||
packet_sender.cpp
|
||||
packet_writer.cpp
|
||||
ppi.cpp
|
||||
pdu.cpp
|
||||
pktap.cpp
|
||||
radiotap.cpp
|
||||
address_range.cpp
|
||||
rawpdu.cpp
|
||||
rsn_information.cpp
|
||||
sll.cpp
|
||||
snap.cpp
|
||||
sniffer.cpp
|
||||
tcp.cpp
|
||||
tcp_ip/ack_tracker.cpp
|
||||
tcp_ip/flow.cpp
|
||||
@@ -63,7 +57,6 @@ ADD_LIBRARY(
|
||||
tcp_ip/stream.cpp
|
||||
tcp_ip/stream_follower.cpp
|
||||
tcp_ip/stream_identifier.cpp
|
||||
tcp_stream.cpp
|
||||
timestamp.cpp
|
||||
udp.cpp
|
||||
utils.cpp
|
||||
@@ -77,9 +70,28 @@ ADD_LIBRARY(
|
||||
dot11/dot11_control.cpp
|
||||
)
|
||||
|
||||
SET(PCAP_DEPENDENT_SOURCES
|
||||
sniffer.cpp
|
||||
packet_writer.cpp
|
||||
pktap.cpp
|
||||
tcp_stream.cpp
|
||||
offline_packet_filter.cpp
|
||||
ppi.cpp
|
||||
)
|
||||
|
||||
IF(LIBTINS_ENABLE_PCAP)
|
||||
message(STATUS "SETTING TO ${PCAP_DEPENDENT_SOURCES}")
|
||||
SET(SOURCES ${SOURCES} ${PCAP_DEPENDENT_SOURCES})
|
||||
ENDIF()
|
||||
|
||||
ADD_LIBRARY(
|
||||
tins ${LIBTINS_TYPE}
|
||||
${SOURCES}
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES(tins ${PCAP_LIBRARY} ${OPENSSL_LIBRARIES} ${LIBTINS_OS_LIBS})
|
||||
|
||||
SET_TARGET_PROPERTIES(tins PROPERTIES OUTPUT_NAME tins )
|
||||
SET_TARGET_PROPERTIES(tins PROPERTIES OUTPUT_NAME tins)
|
||||
SET_TARGET_PROPERTIES(tins PROPERTIES VERSION ${LIBTINS_VERSION} SOVERSION ${LIBTINS_VERSION} )
|
||||
|
||||
# Install instructions for this target
|
||||
|
||||
@@ -28,7 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "internals.h"
|
||||
#include <pcap.h>
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
#include <pcap.h>
|
||||
#endif // TINS_HAVE_PCAP
|
||||
#include "ip.h"
|
||||
#include "ethernetII.h"
|
||||
#include "ieee802_3.h"
|
||||
@@ -179,6 +181,7 @@ Tins::PDU* pdu_from_flag(Constants::IP::e flag,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
PDU* pdu_from_dlt_flag(int flag,
|
||||
const uint8_t* buffer,
|
||||
uint32_t size,
|
||||
@@ -208,6 +211,7 @@ PDU* pdu_from_dlt_flag(int flag,
|
||||
return rawpdu_on_no_match ? new RawPDU(buffer, size) : 0;
|
||||
};
|
||||
}
|
||||
#endif // TINS_HAVE_PCAP
|
||||
|
||||
Tins::PDU* pdu_from_flag(PDU::PDUType type, const uint8_t* buffer, uint32_t size) {
|
||||
switch(type) {
|
||||
|
||||
@@ -2,6 +2,6 @@ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
INCLUDE_DIRECTORIES(${gtest_INCLUDE_DIRS})
|
||||
ADD_SUBDIRECTORY(src)
|
||||
|
||||
IF (ENABLE_ACTIVE_TESTS)
|
||||
IF (ENABLE_ACTIVE_TESTS AND LIBTINS_ENABLE_PCAP)
|
||||
ADD_SUBDIRECTORY(active_tests)
|
||||
ENDIF()
|
||||
@@ -75,9 +75,7 @@ CREATE_TEST(loopback)
|
||||
CREATE_TEST(matches_response)
|
||||
CREATE_TEST(mpls)
|
||||
CREATE_TEST(network_interface)
|
||||
CREATE_TEST(offline_packet_filter)
|
||||
CREATE_TEST(pdu)
|
||||
CREATE_TEST(ppi)
|
||||
CREATE_TEST(pppoe)
|
||||
CREATE_TEST(radiotap)
|
||||
CREATE_TEST(rc4_eapol)
|
||||
@@ -87,11 +85,16 @@ CREATE_TEST(snap)
|
||||
CREATE_TEST(stp)
|
||||
CREATE_TEST(tcp)
|
||||
CREATE_TEST(tcp_ip)
|
||||
CREATE_TEST(tcp_stream)
|
||||
CREATE_TEST(udp)
|
||||
CREATE_TEST(utils)
|
||||
CREATE_TEST(wep_decrypt)
|
||||
|
||||
IF(LIBTINS_ENABLE_PCAP)
|
||||
CREATE_TEST(offline_packet_filter)
|
||||
CREATE_TEST(ppi)
|
||||
CREATE_TEST(tcp_stream)
|
||||
ENDIF()
|
||||
|
||||
IF(LIBTINS_ENABLE_WPA2)
|
||||
CREATE_TEST(wpa2_decrypt)
|
||||
ENDIF()
|
||||
Reference in New Issue
Block a user