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