Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mfontanini committed Mar 24, 2017
2 parents 7607610 + 799ba2b commit 7f8644c
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 27 deletions.
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions include/tins/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
/* Have WPA2Decrypter callbacks */
#cmakedefine TINS_HAVE_WPA2_CALLBACKS

/* Have libpcap */
#cmakedefine TINS_HAVE_PCAP

#endif // TINS_CONFIG_H
3 changes: 3 additions & 0 deletions include/tins/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "constants.h"
#include "pdu.h"
#include "hw_address.h"
#include "macros.h"

/**
* \cond
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion include/tins/offline_packet_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -154,6 +157,9 @@ class TINS_API OfflinePacketFilter {
mutable bpf_program filter_;
std::string string_filter_;
};

} // Tins

#endif // TINS_HAVE_PCAP

#endif // TINS_OFFLINE_PACKET_FILTER_H
11 changes: 8 additions & 3 deletions include/tins/packet_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -220,6 +222,9 @@ class TINS_API PacketWriter {
pcap_t* handle_;
pcap_dumper_t* dumper_;
};
}

} // Tins

#endif // TINS_HAVE_PCAP

#endif // TINS_PACKET_WRITER_H
5 changes: 5 additions & 0 deletions include/tins/pktap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down Expand Up @@ -111,4 +114,6 @@ class TINS_API PKTAP : public PDU {

} // Tins

#endif // TINS_HAVE_PCAP

#endif // TINS_PKTAP_H
7 changes: 6 additions & 1 deletion include/tins/ppi.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "endianness.h"
#include "small_uint.h"

#ifdef TINS_HAVE_PCAP

namespace Tins {

/**
Expand Down Expand Up @@ -135,6 +137,9 @@ class TINS_API PPI : public PDU {
ppi_header header_;
byte_array data_;
};
}

} // Tins

#endif // TINS_HAVE_PCAP

#endif // TINS_PPI_H
8 changes: 6 additions & 2 deletions include/tins/sniffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#ifndef TINS_SNIFFER_H
#define TINS_SNIFFER_H


#include <pcap.h>
#include <string>
#include <memory>
#include <stdexcept>
Expand All @@ -44,6 +42,10 @@
#include "exceptions.h"
#include "internals.h"

#ifdef TINS_HAVE_PCAP

#include <pcap.h>

namespace Tins {
class SnifferIterator;
class SnifferConfiguration;
Expand Down Expand Up @@ -645,4 +647,6 @@ void Tins::BaseSniffer::sniff_loop(Functor function, uint32_t max_packets) {

} // Tins

#endif // TINS_HAVE_PCAP

#endif // TINS_SNIFFER_H
7 changes: 6 additions & 1 deletion include/tins/tcp_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -385,4 +388,6 @@ bool TCPStreamFollower::callback(PDU& pdu,

} // Tins

#endif // TINS_HAVE_PCAP

#endif // TINS_TCP_STREAM_H
30 changes: 21 additions & 9 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ INCLUDE_DIRECTORIES(
${PCAP_INCLUDE_DIR}
)

ADD_LIBRARY(
tins ${LIBTINS_TYPE}
set(SOURCES
arp.cpp
bootp.cpp
handshake_capturer.cpp
Expand Down Expand Up @@ -43,27 +42,21 @@ 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
tcp_ip/data_tracker.cpp
tcp_ip/stream.cpp
tcp_ip/stream_follower.cpp
tcp_ip/stream_identifier.cpp
tcp_stream.cpp
timestamp.cpp
udp.cpp
utils.cpp
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ SNAP* SessionKeys::ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) con
counter[14] = (total_sz >> 8) & 0xff;
counter[15] = total_sz & 0xff;

if (dot11.subtype() == Dot11::QOS_DATA_DATA) {
const uint32_t offset = (dot11.from_ds() && dot11.to_ds()) ? 30 : 24;
AAD[offset] = static_cast<const Dot11QoSData&>(dot11).qos_control() & 0x0f;
counter[1] = AAD[offset];
}

AES_encrypt(counter, MIC, &ctx);
xor_range(MIC, AAD, MIC, 16);
AES_encrypt(MIC, MIC, &ctx);
Expand Down
6 changes: 5 additions & 1 deletion src/internals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
9 changes: 6 additions & 3 deletions tests/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Loading

0 comments on commit 7f8644c

Please sign in to comment.