From ab763f25a4c19b32def39dd5ff7cbc30b91eda82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20P=C3=A9an?= Date: Sun, 16 Apr 2017 14:53:06 -0700 Subject: [PATCH 01/73] Add CMake options LIBTINS_BUILD_EXAMPLES/TESTS --- CMakeLists.txt | 62 ++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f57162b..710b6a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1) PROJECT(libtins) +OPTION(LIBTINS_BUILD_EXAMPLES "Build examples" ON) +OPTION(LIBTINS_BUILD_TESTS "Build tests" ON) + # Compile in release mode by default IF(NOT CMAKE_BUILD_TYPE) MESSAGE(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.") @@ -262,36 +265,41 @@ ADD_CUSTOM_TARGET(uninstall # ****************** ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(src) -IF(LIBTINS_ENABLE_PCAP) - ADD_SUBDIRECTORY(examples) -ELSE() - MESSAGE(STATUS "Not building examples as pcap support is disabled") + +IF(LIBTINS_BUILD_EXAMPLES) + IF(LIBTINS_ENABLE_PCAP) + ADD_SUBDIRECTORY(examples) + ELSE() + MESSAGE(STATUS "Not building examples as pcap support is disabled") + ENDIF() ENDIF() -# Only include googletest if the git submodule has been fetched -IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt") - # Enable tests and add the test directory - MESSAGE(STATUS "Tests have been enabled") - SET(GOOGLETEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/googletest) - SET(GOOGLETEST_INCLUDE ${GOOGLETEST_ROOT}/googletest/include) - SET(GOOGLETEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest) - SET(GOOGLETEST_LIBRARY ${GOOGLETEST_BINARY_DIR}/googletest) +IF(LIBTINS_BUILD_TESTS) + # Only include googletest if the git submodule has been fetched + IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt") + # Enable tests and add the test directory + MESSAGE(STATUS "Tests have been enabled") + SET(GOOGLETEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/googletest) + SET(GOOGLETEST_INCLUDE ${GOOGLETEST_ROOT}/googletest/include) + SET(GOOGLETEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest) + SET(GOOGLETEST_LIBRARY ${GOOGLETEST_BINARY_DIR}/googletest) - ExternalProject_Add( - googletest - DOWNLOAD_COMMAND "" - SOURCE_DIR ${GOOGLETEST_ROOT} - BINARY_DIR ${GOOGLETEST_BINARY_DIR} - CMAKE_CACHE_ARGS "-DBUILD_GTEST:bool=ON" "-DBUILD_GMOCK:bool=OFF" - "-Dgtest_force_shared_crt:bool=ON" - INSTALL_COMMAND "" - ) - # Make sure we build googletest before anything else - ADD_DEPENDENCIES(tins googletest) - ENABLE_TESTING() - ADD_SUBDIRECTORY(tests) -ELSE() - MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it") + ExternalProject_Add( + googletest + DOWNLOAD_COMMAND "" + SOURCE_DIR ${GOOGLETEST_ROOT} + BINARY_DIR ${GOOGLETEST_BINARY_DIR} + CMAKE_CACHE_ARGS "-DBUILD_GTEST:bool=ON" "-DBUILD_GMOCK:bool=OFF" + "-Dgtest_force_shared_crt:bool=ON" + INSTALL_COMMAND "" + ) + # Make sure we build googletest before anything else + ADD_DEPENDENCIES(tins googletest) + ENABLE_TESTING() + ADD_SUBDIRECTORY(tests) + ELSE() + MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it") + ENDIF() ENDIF() # ********************************** From 6b3875ae39cf7f2757255ec16c17f9a7adc8c2a2 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 29 Apr 2017 09:22:04 -0700 Subject: [PATCH 02/73] Bump version to 4.0 Next release will be a major one --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 710b6a9..29d7d2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,8 +45,8 @@ ELSE(LIBTINS_BUILD_SHARED) ENDIF(LIBTINS_BUILD_SHARED) # The version number. -SET(LIBTINS_VERSION_MAJOR 3) -SET(LIBTINS_VERSION_MINOR 5) +SET(LIBTINS_VERSION_MAJOR 4) +SET(LIBTINS_VERSION_MINOR 0) SET(LIBTINS_VERSION "${LIBTINS_VERSION_MAJOR}.${LIBTINS_VERSION_MINOR}") # Required Packages From 8838ddf921c2d53173be12e4a6d1ffb2cab755a0 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 29 Apr 2017 09:27:08 -0700 Subject: [PATCH 03/73] Add parent PDU member to PDU class Now this is a bidirectional list of PDUs --- include/tins/pdu.h | 23 ++++++++++++++++++++--- src/CMakeLists.txt | 1 - src/pdu.cpp | 14 ++++++++++++-- tests/src/pdu_test.cpp | 17 ++++++++++++++++- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/include/tins/pdu.h b/include/tins/pdu.h index ab006ef..bde9a1b 100644 --- a/include/tins/pdu.h +++ b/include/tins/pdu.h @@ -231,8 +231,11 @@ public: * \param rhs The PDU to be moved. */ PDU(PDU &&rhs) TINS_NOEXCEPT - : inner_pdu_(0) { + : inner_pdu_(0), parent_pdu_(0) { std::swap(inner_pdu_, rhs.inner_pdu_); + if (inner_pdu_) { + inner_pdu_->parent_pdu(this); + } } /** @@ -242,6 +245,10 @@ public: */ PDU& operator=(PDU &&rhs) TINS_NOEXCEPT { std::swap(inner_pdu_, rhs.inner_pdu_); + rhs.inner_pdu_ = 0; + if (inner_pdu_) { + inner_pdu_->parent_pdu(this); + } return* this; } #endif @@ -274,11 +281,19 @@ public: /** * \brief Getter for the inner PDU. - * \return The current inner PDU. Might be 0. + * \return The current inner PDU. Might be a null pointer. */ PDU* inner_pdu() const { return inner_pdu_; } + + /** + * Getter for the parent PDU + * \return The current parent PDU. Might be a null pointer. + */ + PDU* parent_pdu() const { + return parent_pdu_; + } /** * \brief Releases the inner PDU. @@ -314,7 +329,6 @@ public: */ void inner_pdu(const PDU& next_pdu); - /** * \brief Serializes the whole chain of PDU's, including this one. * @@ -505,7 +519,10 @@ protected: */ virtual void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) = 0; private: + void parent_pdu(PDU* parent); + PDU* inner_pdu_; + PDU* parent_pdu_; }; /** diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 63e78af..82a7ae0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -80,7 +80,6 @@ SET(PCAP_DEPENDENT_SOURCES ) IF(LIBTINS_ENABLE_PCAP) - message(STATUS "SETTING TO ${PCAP_DEPENDENT_SOURCES}") SET(SOURCES ${SOURCES} ${PCAP_DEPENDENT_SOURCES}) ENDIF() diff --git a/src/pdu.cpp b/src/pdu.cpp index f772da3..50899d9 100644 --- a/src/pdu.cpp +++ b/src/pdu.cpp @@ -49,12 +49,12 @@ PDU::metadata::metadata(uint32_t header_size, PDUType current_type, PDUType next // PDU PDU::PDU() -: inner_pdu_() { +: inner_pdu_(), parent_pdu_() { } PDU::PDU(const PDU& other) -: inner_pdu_(0) { +: inner_pdu_(), parent_pdu_() { copy_inner_pdu(other); } @@ -101,6 +101,9 @@ bool PDU::matches_response(const uint8_t* /*ptr*/, uint32_t /*total_sz*/) const void PDU::inner_pdu(PDU* next_pdu) { delete inner_pdu_; inner_pdu_ = next_pdu; + if (inner_pdu_) { + inner_pdu_->parent_pdu(this); + } } void PDU::inner_pdu(const PDU& next_pdu) { @@ -110,6 +113,9 @@ void PDU::inner_pdu(const PDU& next_pdu) { PDU* PDU::release_inner_pdu() { PDU* result = 0; swap(result, inner_pdu_); + if (result) { + result->parent_pdu(0); + } return result; } @@ -132,4 +138,8 @@ void PDU::serialize(uint8_t* buffer, uint32_t total_sz, const PDU* parent) { write_serialization(buffer, total_sz, parent); } +void PDU::parent_pdu(PDU* parent) { + parent_pdu_ = parent; +} + } // Tins diff --git a/tests/src/pdu_test.cpp b/tests/src/pdu_test.cpp index 5d6df86..209f982 100644 --- a/tests/src/pdu_test.cpp +++ b/tests/src/pdu_test.cpp @@ -17,7 +17,7 @@ public: }; TEST_F(PDUTest, FindPDU) { - IP ip = IP("192.168.0.1") / TCP(22, 52) / RawPDU("Test"); + IP ip = IP("192.168.0.1") / TCP(22, 52) / RawPDU("Test"); EXPECT_TRUE(ip.find_pdu() != NULL); EXPECT_TRUE(ip.find_pdu() != NULL); EXPECT_FALSE(ip.find_pdu() != NULL); @@ -28,6 +28,21 @@ TEST_F(PDUTest, FindPDU) { EXPECT_THROW(ip.rfind_pdu(), pdu_not_found); } +TEST_F(PDUTest, PDURelationship) { + IP packet = IP("192.168.0.1") / TCP(22, 52) / RawPDU("Test"); + IP* ip = packet.find_pdu(); + TCP* tcp = packet.find_pdu(); + RawPDU* raw = packet.find_pdu(); + + ASSERT_TRUE(ip != 0); + ASSERT_TRUE(tcp != 0); + ASSERT_TRUE(raw != 0); + + EXPECT_EQ(0, ip->parent_pdu()); + EXPECT_EQ(ip, tcp->parent_pdu()); + EXPECT_EQ(tcp, raw->parent_pdu()); +} + TEST_F(PDUTest, OperatorConcat) { std::string raw_payload = "Test"; IP ip = IP("192.168.0.1") / TCP(22, 52) / RawPDU(raw_payload); From 4eb4dfe5fa2628825cf2b73a77b04e53ac33b2cc Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 29 Apr 2017 09:53:33 -0700 Subject: [PATCH 04/73] Remove parent parameter from write_serialization This is no longer needed as each PDU knows its parent PDU already --- include/tins/arp.h | 2 +- include/tins/bootp.h | 2 +- include/tins/dhcp.h | 2 +- include/tins/dhcpv6.h | 2 +- include/tins/dns.h | 2 +- include/tins/dot11/dot11_base.h | 2 +- include/tins/dot1q.h | 2 +- include/tins/dot3.h | 2 +- include/tins/eapol.h | 8 +------- include/tins/ethernetII.h | 2 +- include/tins/icmp.h | 11 ++--------- include/tins/icmpv6.h | 2 +- include/tins/ip.h | 4 ++-- include/tins/ipsec.h | 4 ++-- include/tins/ipv6.h | 2 +- include/tins/llc.h | 2 +- include/tins/loopback.h | 2 +- include/tins/mpls.h | 2 +- include/tins/pdu.h | 10 +++------- include/tins/pdu_cacher.h | 2 +- include/tins/pktap.h | 2 +- include/tins/ppi.h | 2 +- include/tins/pppoe.h | 2 +- include/tins/radiotap.h | 2 +- include/tins/rawpdu.h | 2 +- include/tins/sll.h | 2 +- include/tins/snap.h | 2 +- include/tins/stp.h | 2 +- include/tins/tcp.h | 2 +- include/tins/udp.h | 2 +- src/arp.cpp | 2 +- src/bootp.cpp | 2 +- src/dhcp.cpp | 4 ++-- src/dhcpv6.cpp | 2 +- src/dns.cpp | 2 +- src/dot11/dot11_base.cpp | 2 +- src/dot1q.cpp | 2 +- src/dot3.cpp | 2 +- src/eapol.cpp | 2 +- src/ethernetII.cpp | 2 +- src/icmp.cpp | 2 +- src/icmpv6.cpp | 4 ++-- src/ip.cpp | 10 ++++------ src/ipsec.cpp | 4 ++-- src/ipv6.cpp | 2 +- src/llc.cpp | 2 +- src/loopback.cpp | 2 +- src/mpls.cpp | 4 ++-- src/pdu.cpp | 12 ++++++------ src/pktap.cpp | 2 +- src/ppi.cpp | 2 +- src/pppoe.cpp | 2 +- src/radiotap.cpp | 2 +- src/rawpdu.cpp | 2 +- src/sll.cpp | 2 +- src/snap.cpp | 2 +- src/stp.cpp | 2 +- src/tcp.cpp | 3 ++- src/udp.cpp | 3 ++- tests/src/allocators_test.cpp | 3 +-- 60 files changed, 79 insertions(+), 97 deletions(-) diff --git a/include/tins/arp.h b/include/tins/arp.h index 159500c..f6a17c0 100644 --- a/include/tins/arp.h +++ b/include/tins/arp.h @@ -334,7 +334,7 @@ private: uint32_t target_ip_address; } TINS_END_PACK; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); arp_header header_; }; diff --git a/include/tins/bootp.h b/include/tins/bootp.h index 7d27175..18b3cb5 100644 --- a/include/tins/bootp.h +++ b/include/tins/bootp.h @@ -332,7 +332,7 @@ protected: */ vend_type& vend() { return vend_; } - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); /** * Struct that represents the Bootp datagram. diff --git a/include/tins/dhcp.h b/include/tins/dhcp.h index ea8aec5..d60da12 100644 --- a/include/tins/dhcp.h +++ b/include/tins/dhcp.h @@ -509,7 +509,7 @@ public: private: static const uint32_t MAX_DHCP_SIZE; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); template T search_and_convert(OptionTypes opt) const { diff --git a/include/tins/dhcpv6.h b/include/tins/dhcpv6.h index 9acb438..9c79293 100644 --- a/include/tins/dhcpv6.h +++ b/include/tins/dhcpv6.h @@ -890,7 +890,7 @@ public: return new DHCPv6(*this); } private: - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *); + void write_serialization(uint8_t* buffer, uint32_t total_sz); void write_option(const option& option, Memory::OutputMemoryStream& stream) const; options_type::const_iterator search_option_iterator(OptionTypes type) const; options_type::iterator search_option_iterator(OptionTypes type); diff --git a/include/tins/dns.h b/include/tins/dns.h index 7dcd77b..37eb0e0 100644 --- a/include/tins/dns.h +++ b/include/tins/dns.h @@ -1030,7 +1030,7 @@ private: uint8_t* update_dname(uint8_t* ptr, uint32_t threshold, uint32_t offset); static void inline_convert_v4(uint32_t value, char* output); static bool contains_dname(uint16_t type); - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); void add_record(const resource& resource, const sections_type& sections); dns_header header_; diff --git a/include/tins/dot11/dot11_base.h b/include/tins/dot11/dot11_base.h index aa4d38e..5d8cf4a 100644 --- a/include/tins/dot11/dot11_base.h +++ b/include/tins/dot11/dot11_base.h @@ -554,7 +554,7 @@ private: Dot11(const dot11_header* header_ptr); void internal_add_option(const option& opt); - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); options_type::const_iterator search_option_iterator(OptionTypes type) const; options_type::iterator search_option_iterator(OptionTypes type); diff --git a/include/tins/dot1q.h b/include/tins/dot1q.h index 7499d04..0e7a08b 100644 --- a/include/tins/dot1q.h +++ b/include/tins/dot1q.h @@ -197,7 +197,7 @@ public: */ bool matches_response(const uint8_t* ptr, uint32_t total_sz) const; private: - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); TINS_BEGIN_PACK struct dot1q_header { diff --git a/include/tins/dot3.h b/include/tins/dot3.h index 1c6f248..81c75b3 100644 --- a/include/tins/dot3.h +++ b/include/tins/dot3.h @@ -199,7 +199,7 @@ private: uint16_t length; } TINS_END_PACK; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); dot3_header header_; }; diff --git a/include/tins/eapol.h b/include/tins/eapol.h index a24ad3a..0a2ce5f 100644 --- a/include/tins/eapol.h +++ b/include/tins/eapol.h @@ -185,13 +185,7 @@ protected: */ virtual void write_body(Memory::OutputMemoryStream& stream) = 0; private: - /** - * \brief Serialices this EAPOL PDU. - * \param buffer The buffer in which the PDU will be serialized. - * \param total_sz The size available in the buffer. - * \param parent The PDU that's one level below this one on the stack. - */ - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); eapol_header header_; }; diff --git a/include/tins/ethernetII.h b/include/tins/ethernetII.h index 8fda537..ddea06a 100644 --- a/include/tins/ethernetII.h +++ b/include/tins/ethernetII.h @@ -208,7 +208,7 @@ private: uint16_t payload_type; } TINS_END_PACK; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); ethernet_header header_; }; diff --git a/include/tins/icmp.h b/include/tins/icmp.h index c357a37..9249a3a 100644 --- a/include/tins/icmp.h +++ b/include/tins/icmp.h @@ -493,15 +493,8 @@ private: } un; } TINS_END_PACK; - void checksum(uint16_t new_check); - - /** \brief Serialices this ICMP PDU. - * \param buffer The buffer in which the PDU will be serialized. - * \param total_sz The size available in the buffer. - * \param parent The PDU that's one level below this one on the stack. - */ - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); - + void checksum(uint16_t new_check); + void write_serialization(uint8_t* buffer, uint32_t total_sz); uint32_t get_adjusted_inner_pdu_size() const; void try_parse_extensions(Memory::InputMemoryStream& stream); bool are_extensions_allowed() const; diff --git a/include/tins/icmpv6.h b/include/tins/icmpv6.h index 9cb3dad..85a4122 100644 --- a/include/tins/icmpv6.h +++ b/include/tins/icmpv6.h @@ -1559,7 +1559,7 @@ private: } TINS_END_PACK; void internal_add_option(const option& option); - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); bool has_options() const; void write_option(const option& opt, Memory::OutputMemoryStream& stream); void parse_options(Memory::InputMemoryStream& stream); diff --git a/include/tins/ip.h b/include/tins/ip.h index f951fca..94fc18b 100644 --- a/include/tins/ip.h +++ b/include/tins/ip.h @@ -756,10 +756,10 @@ private: void head_len(small_uint<4> new_head_len); void tot_len(uint16_t new_tot_len); - void prepare_for_serialize(const PDU* parent); + void prepare_for_serialize(); void internal_add_option(const option& option); void init_ip_fields(); - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); void write_option(const option& opt, Memory::OutputMemoryStream& stream); void add_route_option(option_identifier id, const generic_route_option_type& data); generic_route_option_type search_route_option(option_identifier id) const; diff --git a/include/tins/ipsec.h b/include/tins/ipsec.h index 6eebd8b..b4ca2a6 100644 --- a/include/tins/ipsec.h +++ b/include/tins/ipsec.h @@ -168,7 +168,7 @@ private: uint32_t spi, seq_number; }; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *); + void write_serialization(uint8_t* buffer, uint32_t total_sz); ipsec_header header_; byte_array icv_; @@ -258,7 +258,7 @@ private: uint32_t spi, seq_number; }; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *); + void write_serialization(uint8_t* buffer, uint32_t total_sz); ipsec_header header_; }; diff --git a/include/tins/ipv6.h b/include/tins/ipv6.h index 7998467..5b951f7 100644 --- a/include/tins/ipv6.h +++ b/include/tins/ipv6.h @@ -320,7 +320,7 @@ public: */ const ext_header* search_header(ExtensionHeader id) const; private: - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); void set_last_next_header(uint8_t value); static void write_header(const ext_header& header, Memory::OutputMemoryStream& stream); static bool is_extension_header(uint8_t header_id); diff --git a/include/tins/llc.h b/include/tins/llc.h index e7c73a3..98bc7e4 100644 --- a/include/tins/llc.h +++ b/include/tins/llc.h @@ -401,7 +401,7 @@ private: typedef std::vector field_type; typedef std::list field_list; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); llchdr header_; uint8_t control_field_length_; diff --git a/include/tins/loopback.h b/include/tins/loopback.h index f242486..3b5d541 100644 --- a/include/tins/loopback.h +++ b/include/tins/loopback.h @@ -117,7 +117,7 @@ public: void send(PacketSender& sender, const NetworkInterface& iface); #endif // BSD private: - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); uint32_t family_; }; diff --git a/include/tins/mpls.h b/include/tins/mpls.h index 9da8419..11c056d 100644 --- a/include/tins/mpls.h +++ b/include/tins/mpls.h @@ -147,7 +147,7 @@ private: uint8_t ttl; } TINS_END_PACK; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); mpls_header header_; }; diff --git a/include/tins/pdu.h b/include/tins/pdu.h index bde9a1b..1e79467 100644 --- a/include/tins/pdu.h +++ b/include/tins/pdu.h @@ -494,19 +494,16 @@ protected: * is calculated. * * By default, this method does nothing - * - * \param parent The parent PDU. */ - virtual void prepare_for_serialize(const PDU* parent); + virtual void prepare_for_serialize(); /** * \brief Serializes this PDU and propagates this action to child PDUs. * * \param buffer The buffer in which to store this PDU's serialization. * \param total_sz The total size of the buffer. - * \param parent The parent PDU. Will be 0 if there's the parent does not exist. */ - void serialize(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void serialize(uint8_t* buffer, uint32_t total_sz); /** * \brief Serializes this TCP PDU. @@ -515,9 +512,8 @@ protected: * serialization. * \param buffer The buffer in which the PDU will be serialized. * \param total_sz The size available in the buffer. - * \param parent The PDU that's one level below this one on the stack. Might be 0. */ - virtual void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) = 0; + virtual void write_serialization(uint8_t* buffer, uint32_t total_sz) = 0; private: void parent_pdu(PDU* parent); diff --git a/include/tins/pdu_cacher.h b/include/tins/pdu_cacher.h index ebab9b1..9e27c71 100644 --- a/include/tins/pdu_cacher.h +++ b/include/tins/pdu_cacher.h @@ -144,7 +144,7 @@ public: return cached_.pdu_type(); } private: - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) { + void write_serialization(uint8_t* buffer, uint32_t total_sz) { if (cached_serialization_.size() != total_sz) { cached_serialization_ = cached_.serialize(); } diff --git a/include/tins/pktap.h b/include/tins/pktap.h index 52f9c25..88f2216 100644 --- a/include/tins/pktap.h +++ b/include/tins/pktap.h @@ -107,7 +107,7 @@ private: uint8_t ecommand[20]; }; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); pktap_header header_; }; diff --git a/include/tins/ppi.h b/include/tins/ppi.h index 96dd734..8f6934e 100644 --- a/include/tins/ppi.h +++ b/include/tins/ppi.h @@ -125,7 +125,7 @@ public: return new PPI(*this); } private: - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *); + void write_serialization(uint8_t* buffer, uint32_t total_sz); void parse_80211(const uint8_t* buffer, uint32_t total_sz); struct ppi_header { diff --git a/include/tins/pppoe.h b/include/tins/pppoe.h index 75a2d58..42842a0 100644 --- a/include/tins/pppoe.h +++ b/include/tins/pppoe.h @@ -390,7 +390,7 @@ public: */ std::string generic_error() const; private: - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *); + void write_serialization(uint8_t* buffer, uint32_t total_sz); template void add_tag_iterable(TagTypes id, const T& data) { diff --git a/include/tins/radiotap.h b/include/tins/radiotap.h index 61bf599..c1a9c6a 100644 --- a/include/tins/radiotap.h +++ b/include/tins/radiotap.h @@ -486,7 +486,7 @@ private: } TINS_END_PACK; void init(); - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); uint32_t find_extra_flag_fields_size(const uint8_t* buffer, uint32_t total_sz); template diff --git a/include/tins/rawpdu.h b/include/tins/rawpdu.h index fde9de6..872b29c 100644 --- a/include/tins/rawpdu.h +++ b/include/tins/rawpdu.h @@ -201,7 +201,7 @@ public: return new RawPDU(*this); } private: - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); payload_type payload_; }; diff --git a/include/tins/sll.h b/include/tins/sll.h index 0f05365..62a7444 100644 --- a/include/tins/sll.h +++ b/include/tins/sll.h @@ -174,7 +174,7 @@ private: uint16_t protocol; } TINS_END_PACK; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *); + void write_serialization(uint8_t* buffer, uint32_t total_sz); sll_header header_; }; diff --git a/include/tins/snap.h b/include/tins/snap.h index 18740e5..5687a7d 100644 --- a/include/tins/snap.h +++ b/include/tins/snap.h @@ -177,7 +177,7 @@ private: uint16_t eth_type; } TINS_END_PACK; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); snap_header snap_; }; diff --git a/include/tins/stp.h b/include/tins/stp.h index f927855..45ef83d 100644 --- a/include/tins/stp.h +++ b/include/tins/stp.h @@ -305,7 +305,7 @@ private: static bpdu_id_type convert(const pvt_bpdu_id& id); static pvt_bpdu_id convert(const bpdu_id_type& id); - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); stp_header header_; }; diff --git a/include/tins/tcp.h b/include/tins/tcp.h index 257caa5..68d3f85 100644 --- a/include/tins/tcp.h +++ b/include/tins/tcp.h @@ -610,7 +610,7 @@ private: } void internal_add_option(const option& option); - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); void checksum(uint16_t new_check); void update_options_size(); options_type::const_iterator search_option_iterator(OptionTypes type) const; diff --git a/include/tins/udp.h b/include/tins/udp.h index 041f1d5..aaabe7b 100644 --- a/include/tins/udp.h +++ b/include/tins/udp.h @@ -191,7 +191,7 @@ private: uint16_t check; } TINS_END_PACK; - void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent); + void write_serialization(uint8_t* buffer, uint32_t total_sz); udp_header header_; }; diff --git a/src/arp.cpp b/src/arp.cpp index e4ed5e2..462aad9 100644 --- a/src/arp.cpp +++ b/src/arp.cpp @@ -113,7 +113,7 @@ uint32_t ARP::header_size() const { return sizeof(header_); } -void ARP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void ARP::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); stream.write(header_); } diff --git a/src/bootp.cpp b/src/bootp.cpp index 0611ec8..666ed63 100644 --- a/src/bootp.cpp +++ b/src/bootp.cpp @@ -115,7 +115,7 @@ void BootP::vend(const vend_type& newvend_) { vend_ = newvend_; } -void BootP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) { +void BootP::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); stream.write(bootp_); stream.write(vend_.begin(), vend_.end()); diff --git a/src/dhcp.cpp b/src/dhcp.cpp index 99e132a..e5cd5cb 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -247,7 +247,7 @@ uint32_t DHCP::header_size() const { return static_cast(BootP::header_size() - vend().size() + size_); } -void DHCP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) { +void DHCP::write_serialization(uint8_t* buffer, uint32_t total_sz) { if (size_) { vend_type& result = BootP::vend(); result.resize(size_); @@ -261,7 +261,7 @@ void DHCP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* pa stream.write(it->data_ptr(), it->data_size()); } } - BootP::write_serialization(buffer, total_sz, parent); + BootP::write_serialization(buffer, total_sz); } } // Tins diff --git a/src/dhcpv6.cpp b/src/dhcpv6.cpp index db2e4b9..4354a4c 100644 --- a/src/dhcpv6.cpp +++ b/src/dhcpv6.cpp @@ -161,7 +161,7 @@ bool DHCPv6::matches_response(const uint8_t* ptr, uint32_t total_sz) const { return false; } -void DHCPv6::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void DHCPv6::write_serialization(uint8_t* buffer, uint32_t total_sz) { const uint32_t required_size = is_relay_message() ? 2 : 4; OutputMemoryStream stream(buffer, total_sz); stream.write(header_data_, required_size); diff --git a/src/dns.cpp b/src/dns.cpp index 48cb06f..b2bd97d 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -386,7 +386,7 @@ uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const { return end_ptr - start_ptr; } -void DNS::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) { +void DNS::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); stream.write(header_); stream.write(records_data_.begin(), records_data_.end()); diff --git a/src/dot11/dot11_base.cpp b/src/dot11/dot11_base.cpp index 82765eb..cc71d47 100644 --- a/src/dot11/dot11_base.cpp +++ b/src/dot11/dot11_base.cpp @@ -213,7 +213,7 @@ void Dot11::send(PacketSender& sender, const NetworkInterface& iface) { } #endif // _WIN32 -void Dot11::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) { +void Dot11::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); stream.write(header_); write_ext_header(stream); diff --git a/src/dot1q.cpp b/src/dot1q.cpp index 2a3c74a..d561957 100644 --- a/src/dot1q.cpp +++ b/src/dot1q.cpp @@ -105,7 +105,7 @@ uint32_t Dot1Q::trailer_size() const { } } -void Dot1Q::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void Dot1Q::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); if (inner_pdu()) { Constants::Ethernet::e flag; diff --git a/src/dot3.cpp b/src/dot3.cpp index ec0113b..4d53d02 100644 --- a/src/dot3.cpp +++ b/src/dot3.cpp @@ -134,7 +134,7 @@ bool Dot3::matches_response(const uint8_t* ptr, uint32_t total_sz) const { return false; } -void Dot3::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) { +void Dot3::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); header_.length = Endian::host_to_be(size() - sizeof(header_)); stream.write(header_); diff --git a/src/eapol.cpp b/src/eapol.cpp index ae8ebe1..1401be2 100644 --- a/src/eapol.cpp +++ b/src/eapol.cpp @@ -106,7 +106,7 @@ void EAPOL::type(uint8_t new_type) { header_.type = new_type; } -void EAPOL::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void EAPOL::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); length(total_sz - 4); stream.write(header_); diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index d5a19e8..dc81c67 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -161,7 +161,7 @@ bool EthernetII::matches_response(const uint8_t* ptr, uint32_t total_sz) const { return false; } -void EthernetII::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) { +void EthernetII::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); if (inner_pdu()) { Constants::Ethernet::e flag; diff --git a/src/icmp.cpp b/src/icmp.cpp index 63bb299..4aa9e68 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -216,7 +216,7 @@ void ICMP::use_length_field(bool value) { header_.un.rfc4884.length = value ? 1 : 0; } -void ICMP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void ICMP::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); // If extensions are allowed and we have to set the length field diff --git a/src/icmpv6.cpp b/src/icmpv6.cpp index 0dc4d76..ceeb909 100644 --- a/src/icmpv6.cpp +++ b/src/icmpv6.cpp @@ -281,7 +281,7 @@ bool ICMPv6::matches_response(const uint8_t* ptr, uint32_t total_sz) const { return false; } -void ICMPv6::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) { +void ICMPv6::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); // If extensions are allowed and we have to set the length field @@ -361,7 +361,7 @@ void ICMPv6::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* ); } - const Tins::IPv6* ipv6 = tins_cast(parent); + const Tins::IPv6* ipv6 = tins_cast(parent_pdu()); if (ipv6) { uint32_t checksum = Utils::pseudoheader_checksum( ipv6->src_addr(), diff --git a/src/ip.cpp b/src/ip.cpp index 125d2b3..67f1b04 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -418,14 +418,14 @@ PDU* IP::recv_response(PacketSender& sender, const NetworkInterface &) { return sender.recv_l3(*this, 0, sizeof(link_addr), type); } -void IP::prepare_for_serialize(const PDU* parent) { - if (!parent && header_.saddr == 0) { +void IP::prepare_for_serialize() { + if (!parent_pdu()&& header_.saddr == 0) { NetworkInterface iface(dst_addr()); src_addr(iface.addresses().ip_addr); } } -void IP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) { +void IP::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); checksum(0); if (inner_pdu()) { @@ -446,12 +446,10 @@ void IP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* pare uint16_t original_frag_off = header_.frag_off; #if __FreeBSD__ || defined(__FreeBSD_kernel__) || __APPLE__ - if (!parent) { + if (!parent_pdu()) { total_sz = Endian::host_to_be(total_sz); header_.frag_off = Endian::be_to_host(header_.frag_off); } - #else - Internals::unused(parent); #endif tot_len(total_sz); head_len(static_cast(header_size() / sizeof(uint32_t))); diff --git a/src/ipsec.cpp b/src/ipsec.cpp index d136447..dde3007 100644 --- a/src/ipsec.cpp +++ b/src/ipsec.cpp @@ -94,7 +94,7 @@ uint32_t IPSecAH::header_size() const { return static_cast(sizeof(header_) + icv_.size()); } -void IPSecAH::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void IPSecAH::write_serialization(uint8_t* buffer, uint32_t total_sz) { if (inner_pdu()) { next_header(Internals::pdu_flag_to_ip_type(inner_pdu()->pdu_type())); } @@ -131,7 +131,7 @@ uint32_t IPSecESP::header_size() const { return sizeof(header_); } -void IPSecESP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void IPSecESP::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream output(buffer, total_sz); output.write(header_); } diff --git a/src/ipv6.cpp b/src/ipv6.cpp index f346c30..1f855b8 100644 --- a/src/ipv6.cpp +++ b/src/ipv6.cpp @@ -243,7 +243,7 @@ bool IPv6::matches_response(const uint8_t* ptr, uint32_t total_sz) const { return false; } -void IPv6::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) { +void IPv6::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); if (inner_pdu()) { uint8_t new_flag = Internals::pdu_flag_to_ip_type(inner_pdu()->pdu_type()); diff --git a/src/llc.cpp b/src/llc.cpp index 43d3aa4..cb9ee68 100644 --- a/src/llc.cpp +++ b/src/llc.cpp @@ -196,7 +196,7 @@ void LLC::clear_information_fields() { information_fields_.clear(); } -void LLC::write_serialization(uint8_t* buffer, uint32_t total_sz, const Tins::PDU* /*parent*/) { +void LLC::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); if (inner_pdu() && inner_pdu()->pdu_type() == PDU::STP) { dsap(0x42); diff --git a/src/loopback.cpp b/src/loopback.cpp index 62345eb..9b473ab 100644 --- a/src/loopback.cpp +++ b/src/loopback.cpp @@ -90,7 +90,7 @@ uint32_t Loopback::header_size() const { return sizeof(family_); } -void Loopback::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void Loopback::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); #ifndef _WIN32 if (tins_cast(inner_pdu())) { diff --git a/src/mpls.cpp b/src/mpls.cpp index f7ffd42..0fce533 100644 --- a/src/mpls.cpp +++ b/src/mpls.cpp @@ -91,10 +91,10 @@ uint32_t MPLS::header_size() const { return sizeof(header_); } -void MPLS::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) { +void MPLS::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); // If we have a parent PDU, we might set the bottom-of-stack field - if (parent) { + if (parent_pdu()) { // We'll set it if we either don't have a child or we have one and it's not MPLS if (!inner_pdu() || inner_pdu()->pdu_type() != PDU::MPLS) { bottom_of_stack(1); diff --git a/src/pdu.cpp b/src/pdu.cpp index 50899d9..989bd37 100644 --- a/src/pdu.cpp +++ b/src/pdu.cpp @@ -73,7 +73,7 @@ void PDU::copy_inner_pdu(const PDU& pdu) { } } -void PDU::prepare_for_serialize(const PDU* /*parent*/) { +void PDU::prepare_for_serialize() { } uint32_t PDU::size() const { @@ -121,21 +121,21 @@ PDU* PDU::release_inner_pdu() { PDU::serialization_type PDU::serialize() { vector buffer(size()); - serialize(&buffer[0], static_cast(buffer.size()), 0); + serialize(&buffer[0], static_cast(buffer.size())); return buffer; } -void PDU::serialize(uint8_t* buffer, uint32_t total_sz, const PDU* parent) { +void PDU::serialize(uint8_t* buffer, uint32_t total_sz) { uint32_t sz = header_size() + trailer_size(); // Must not happen... #ifdef TINS_DEBUG assert(total_sz >= sz); #endif - prepare_for_serialize(parent); + prepare_for_serialize(); if (inner_pdu_) { - inner_pdu_->serialize(buffer + header_size(), total_sz - sz, this); + inner_pdu_->serialize(buffer + header_size(), total_sz - sz); } - write_serialization(buffer, total_sz, parent); + write_serialization(buffer, total_sz); } void PDU::parent_pdu(PDU* parent) { diff --git a/src/pktap.cpp b/src/pktap.cpp index 280346f..d475664 100644 --- a/src/pktap.cpp +++ b/src/pktap.cpp @@ -65,7 +65,7 @@ uint32_t PKTAP::header_size() const { return sizeof(header_); } -void PKTAP::write_serialization(uint8_t* /*buffer*/, uint32_t /*total_sz*/, const PDU* /*parent*/) { +void PKTAP::write_serialization(uint8_t* /*buffer*/, uint32_t /*total_sz*/) { throw pdu_not_serializable(); } diff --git a/src/ppi.cpp b/src/ppi.cpp index 1246570..89155bb 100644 --- a/src/ppi.cpp +++ b/src/ppi.cpp @@ -94,7 +94,7 @@ uint32_t PPI::header_size() const { return static_cast(sizeof(header_) + data_.size()); } -void PPI::write_serialization(uint8_t* /*buffer*/, uint32_t /*total_sz*/, const PDU *) { +void PPI::write_serialization(uint8_t* /*buffer*/, uint32_t /*total_sz*/) { throw pdu_not_serializable(); } diff --git a/src/pppoe.cpp b/src/pppoe.cpp index c991691..2439f87 100644 --- a/src/pppoe.cpp +++ b/src/pppoe.cpp @@ -108,7 +108,7 @@ uint32_t PPPoE::header_size() const { return sizeof(header_) + tags_size_; } -void PPPoE::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void PPPoE::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); if (tags_size_ > 0) { payload_length(tags_size_); diff --git a/src/radiotap.cpp b/src/radiotap.cpp index 69326dc..a994583 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -507,7 +507,7 @@ bool RadioTap::matches_response(const uint8_t* ptr, uint32_t total_sz) const { return false; } -void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) { +void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); uint8_t* buffer_start = buffer; radio_.it_len = Endian::host_to_le(header_size()); diff --git a/src/rawpdu.cpp b/src/rawpdu.cpp index 07a3196..cf056f8 100644 --- a/src/rawpdu.cpp +++ b/src/rawpdu.cpp @@ -48,7 +48,7 @@ uint32_t RawPDU::header_size() const { return static_cast(payload_.size()); } -void RawPDU::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void RawPDU::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); stream.write(payload_.begin(), payload_.end()); } diff --git a/src/sll.cpp b/src/sll.cpp index 72ca2e5..9279da5 100644 --- a/src/sll.cpp +++ b/src/sll.cpp @@ -81,7 +81,7 @@ uint32_t SLL::header_size() const { return sizeof(header_); } -void SLL::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void SLL::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); if (inner_pdu()) { Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type( diff --git a/src/snap.cpp b/src/snap.cpp index bf1d327..6b15fc8 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -91,7 +91,7 @@ uint32_t SNAP::header_size() const { return sizeof(snap_); } -void SNAP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) { +void SNAP::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); if (inner_pdu()) { Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type( diff --git a/src/stp.cpp b/src/stp.cpp index e8fd603..77a8028 100644 --- a/src/stp.cpp +++ b/src/stp.cpp @@ -106,7 +106,7 @@ void STP::bridge_id(const bpdu_id_type& id) { header_.bridge_id = convert(id); } -void STP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) { +void STP::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); stream.write(header_); } diff --git a/src/tcp.cpp b/src/tcp.cpp index b295e09..beb0d55 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -295,7 +295,7 @@ uint32_t TCP::header_size() const { return sizeof(header_) + total_options_size_; } -void TCP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) { +void TCP::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); // Set checksum to 0, we'll calculate it at the end checksum(0); @@ -311,6 +311,7 @@ void TCP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* par } uint32_t check = 0; + const PDU* parent = parent_pdu(); if (const Tins::IP* ip_packet = tins_cast(parent)) { check = Utils::pseudoheader_checksum( ip_packet->src_addr(), diff --git a/src/udp.cpp b/src/udp.cpp index 318eb46..b52fd55 100644 --- a/src/udp.cpp +++ b/src/udp.cpp @@ -117,7 +117,7 @@ uint32_t pseudoheader_checksum(IPv4Address source_ip, IPv4Address dest_ip, uint3 return checksum; } -void UDP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) { +void UDP::write_serialization(uint8_t* buffer, uint32_t total_sz) { OutputMemoryStream stream(buffer, total_sz); // Set checksum to 0, we'll calculate it at the end header_.check = 0; @@ -129,6 +129,7 @@ void UDP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* par } stream.write(header_); uint32_t checksum = 0; + const PDU* parent = parent_pdu(); if (const Tins::IP* ip_packet = tins_cast(parent)) { checksum = Utils::pseudoheader_checksum( ip_packet->src_addr(), diff --git a/tests/src/allocators_test.cpp b/tests/src/allocators_test.cpp index e298f8c..b50a9d3 100644 --- a/tests/src/allocators_test.cpp +++ b/tests/src/allocators_test.cpp @@ -52,8 +52,7 @@ public: DummyPDU* clone() const { return new DummyPDU(*this); } uint32_t header_size() const { return (uint32_t)buffer.size(); } PDUType pdu_type() const { return pdu_flag; } - void write_serialization(uint8_t* data, uint32_t, const PDU *) - { + void write_serialization(uint8_t* data, uint32_t) { std::copy(buffer.begin(), buffer.end(), data); } From 2c6ef2a5c05dce8553872fa65aa92a82956bed63 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 29 Apr 2017 09:56:26 -0700 Subject: [PATCH 05/73] Update license date to 2017 --- LICENSE | 2 +- examples/arpmonitor.cpp | 2 +- examples/arpspoofing.cpp | 2 +- examples/beacon_display.cpp | 2 +- examples/defragmenter.cpp | 2 +- examples/dns_queries.cpp | 2 +- examples/dns_spoof.cpp | 2 +- examples/dns_stats.cpp | 2 +- examples/http_requests.cpp | 2 +- examples/portscan.cpp | 2 +- examples/stream_dump.cpp | 2 +- examples/tcp_connection_close.cpp | 2 +- examples/traceroute.cpp | 2 +- examples/wps_detect.cpp | 2 +- include/tins/address_range.h | 2 +- include/tins/arp.h | 2 +- include/tins/bootp.h | 2 +- include/tins/constants.h | 2 +- include/tins/crypto.h | 2 +- include/tins/cxxstd.h | 2 +- include/tins/data_link_type.h | 2 +- include/tins/dhcp.h | 2 +- include/tins/dhcpv6.h | 2 +- include/tins/dns.h | 2 +- include/tins/dot11.h | 2 +- include/tins/dot11/dot11_assoc.h | 2 +- include/tins/dot11/dot11_auth.h | 2 +- include/tins/dot11/dot11_base.h | 2 +- include/tins/dot11/dot11_beacon.h | 2 +- include/tins/dot11/dot11_control.h | 2 +- include/tins/dot11/dot11_data.h | 2 +- include/tins/dot11/dot11_mgmt.h | 2 +- include/tins/dot11/dot11_probe.h | 2 +- include/tins/dot1q.h | 2 +- include/tins/dot3.h | 2 +- include/tins/eapol.h | 2 +- include/tins/endianness.h | 2 +- include/tins/ethernetII.h | 2 +- include/tins/exceptions.h | 2 +- include/tins/handshake_capturer.h | 2 +- include/tins/hw_address.h | 2 +- include/tins/icmp.h | 2 +- include/tins/icmp_extension.h | 2 +- include/tins/icmpv6.h | 2 +- include/tins/ieee802_3.h | 2 +- include/tins/internals.h | 2 +- include/tins/ip.h | 2 +- include/tins/ip_address.h | 2 +- include/tins/ip_reassembler.h | 2 +- include/tins/ipsec.h | 2 +- include/tins/ipv6.h | 2 +- include/tins/ipv6_address.h | 2 +- include/tins/llc.h | 2 +- include/tins/loopback.h | 2 +- include/tins/macros.h | 2 +- include/tins/memory_helpers.h | 2 +- include/tins/mpls.h | 2 +- include/tins/network_interface.h | 2 +- include/tins/offline_packet_filter.h | 2 +- include/tins/packet.h | 2 +- include/tins/packet_sender.h | 2 +- include/tins/packet_writer.h | 2 +- include/tins/pdu.h | 2 +- include/tins/pdu_allocator.h | 2 +- include/tins/pdu_cacher.h | 2 +- include/tins/pdu_option.h | 2 +- include/tins/pktap.h | 2 +- include/tins/ppi.h | 2 +- include/tins/pppoe.h | 2 +- include/tins/radiotap.h | 2 +- include/tins/rawpdu.h | 2 +- include/tins/rsn_information.h | 2 +- include/tins/sll.h | 2 +- include/tins/small_uint.h | 2 +- include/tins/snap.h | 2 +- include/tins/sniffer.h | 2 +- include/tins/stp.h | 2 +- include/tins/tcp.h | 2 +- include/tins/tcp_ip/ack_tracker.h | 2 +- include/tins/tcp_ip/data_tracker.h | 2 +- include/tins/tcp_ip/flow.h | 2 +- include/tins/tcp_ip/stream.h | 2 +- include/tins/tcp_ip/stream_follower.h | 2 +- include/tins/tcp_ip/stream_identifier.h | 2 +- include/tins/tcp_stream.h | 2 +- include/tins/timestamp.h | 2 +- include/tins/tins.h | 2 +- include/tins/udp.h | 2 +- include/tins/utils.h | 2 +- src/address_range.cpp | 2 +- src/arp.cpp | 2 +- src/bootp.cpp | 2 +- src/crypto.cpp | 2 +- src/dhcp.cpp | 2 +- src/dhcpv6.cpp | 2 +- src/dns.cpp | 2 +- src/dot11/dot11_assoc.cpp | 2 +- src/dot11/dot11_auth.cpp | 2 +- src/dot11/dot11_base.cpp | 2 +- src/dot11/dot11_beacon.cpp | 2 +- src/dot11/dot11_control.cpp | 2 +- src/dot11/dot11_data.cpp | 2 +- src/dot11/dot11_mgmt.cpp | 2 +- src/dot11/dot11_probe.cpp | 2 +- src/dot1q.cpp | 2 +- src/dot3.cpp | 2 +- src/eapol.cpp | 2 +- src/ethernetII.cpp | 2 +- src/handshake_capturer.cpp | 2 +- src/icmp.cpp | 2 +- src/icmp_extension.cpp | 2 +- src/icmpv6.cpp | 2 +- src/internals.cpp | 2 +- src/ip.cpp | 2 +- src/ip_address.cpp | 2 +- src/ip_reassembler.cpp | 2 +- src/ipsec.cpp | 2 +- src/ipv6.cpp | 2 +- src/ipv6_address.cpp | 2 +- src/llc.cpp | 2 +- src/loopback.cpp | 2 +- src/mpls.cpp | 2 +- src/network_interface.cpp | 2 +- src/offline_packet_filter.cpp | 2 +- src/packet_sender.cpp | 2 +- src/packet_writer.cpp | 2 +- src/pdu.cpp | 2 +- src/pktap.cpp | 2 +- src/ppi.cpp | 2 +- src/pppoe.cpp | 2 +- src/radiotap.cpp | 2 +- src/rawpdu.cpp | 2 +- src/rsn_information.cpp | 2 +- src/sll.cpp | 2 +- src/snap.cpp | 2 +- src/sniffer.cpp | 2 +- src/stp.cpp | 2 +- src/tcp.cpp | 2 +- src/tcp_ip/ack_tracker.cpp | 2 +- src/tcp_ip/data_tracker.cpp | 2 +- src/tcp_ip/flow.cpp | 2 +- src/tcp_ip/stream.cpp | 2 +- src/tcp_ip/stream_follower.cpp | 2 +- src/tcp_ip/stream_identifier.cpp | 2 +- src/tcp_stream.cpp | 2 +- src/timestamp.cpp | 2 +- src/udp.cpp | 2 +- src/utils.cpp | 2 +- tests/active_tests/include/active_test.h | 2 +- tests/active_tests/include/active_test_runner.h | 2 +- tests/active_tests/include/configuration.h | 2 +- tests/active_tests/include/ipv4_tests.h | 2 +- tests/active_tests/include/packet_capturer.h | 2 +- tests/active_tests/include/tcp_tests.h | 2 +- tests/active_tests/include/test_utils.h | 2 +- tests/active_tests/include/utils_tests.h | 2 +- tests/active_tests/src/active_test.cpp | 2 +- tests/active_tests/src/active_test_runner.cpp | 2 +- tests/active_tests/src/configuration.cpp | 2 +- tests/active_tests/src/ipv4_tests.cpp | 2 +- tests/active_tests/src/main.cpp | 2 +- tests/active_tests/src/packet_capturer.cpp | 2 +- tests/active_tests/src/tcp_tests.cpp | 2 +- tests/active_tests/src/test_utils.cpp | 2 +- tests/active_tests/src/utils_test.cpp | 2 +- 165 files changed, 165 insertions(+), 165 deletions(-) diff --git a/LICENSE b/LICENSE index 092b6eb..c4009ed 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2012-2014, Matias Fontanini +Copyright (c) 2012-2017, Matias Fontanini All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/examples/arpmonitor.cpp b/examples/arpmonitor.cpp index 20d4008..16911a4 100644 --- a/examples/arpmonitor.cpp +++ b/examples/arpmonitor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/arpspoofing.cpp b/examples/arpspoofing.cpp index 997bc9f..7a7c756 100644 --- a/examples/arpspoofing.cpp +++ b/examples/arpspoofing.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/beacon_display.cpp b/examples/beacon_display.cpp index f84186c..5d3ccd1 100644 --- a/examples/beacon_display.cpp +++ b/examples/beacon_display.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/defragmenter.cpp b/examples/defragmenter.cpp index d2ef4ae..6665b89 100644 --- a/examples/defragmenter.cpp +++ b/examples/defragmenter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/dns_queries.cpp b/examples/dns_queries.cpp index a395b0c..b9cc8c0 100644 --- a/examples/dns_queries.cpp +++ b/examples/dns_queries.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/dns_spoof.cpp b/examples/dns_spoof.cpp index ab97c43..b3e4bdf 100644 --- a/examples/dns_spoof.cpp +++ b/examples/dns_spoof.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/dns_stats.cpp b/examples/dns_stats.cpp index a2da49d..c08111f 100644 --- a/examples/dns_stats.cpp +++ b/examples/dns_stats.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/http_requests.cpp b/examples/http_requests.cpp index a748967..9597220 100644 --- a/examples/http_requests.cpp +++ b/examples/http_requests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/portscan.cpp b/examples/portscan.cpp index 31db51e..63affe3 100644 --- a/examples/portscan.cpp +++ b/examples/portscan.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/stream_dump.cpp b/examples/stream_dump.cpp index ebb43ef..f413626 100644 --- a/examples/stream_dump.cpp +++ b/examples/stream_dump.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/tcp_connection_close.cpp b/examples/tcp_connection_close.cpp index 714a378..1298fdf 100644 --- a/examples/tcp_connection_close.cpp +++ b/examples/tcp_connection_close.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/traceroute.cpp b/examples/traceroute.cpp index cb78e3c..09a7991 100644 --- a/examples/traceroute.cpp +++ b/examples/traceroute.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/wps_detect.cpp b/examples/wps_detect.cpp index d61cae3..9f4e8ca 100644 --- a/examples/wps_detect.cpp +++ b/examples/wps_detect.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/address_range.h b/include/tins/address_range.h index 070f296..fb10cf6 100644 --- a/include/tins/address_range.h +++ b/include/tins/address_range.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/arp.h b/include/tins/arp.h index f6a17c0..4fdf53b 100644 --- a/include/tins/arp.h +++ b/include/tins/arp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/bootp.h b/include/tins/bootp.h index 18b3cb5..7d88936 100644 --- a/include/tins/bootp.h +++ b/include/tins/bootp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/constants.h b/include/tins/constants.h index 6fdcba3..c5d2a70 100644 --- a/include/tins/constants.h +++ b/include/tins/constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/crypto.h b/include/tins/crypto.h index 850f831..4207f9d 100644 --- a/include/tins/crypto.h +++ b/include/tins/crypto.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/cxxstd.h b/include/tins/cxxstd.h index 5ea4723..e37e9a5 100644 --- a/include/tins/cxxstd.h +++ b/include/tins/cxxstd.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/data_link_type.h b/include/tins/data_link_type.h index cf6843a..b502fd5 100644 --- a/include/tins/data_link_type.h +++ b/include/tins/data_link_type.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dhcp.h b/include/tins/dhcp.h index d60da12..7fe33d1 100644 --- a/include/tins/dhcp.h +++ b/include/tins/dhcp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dhcpv6.h b/include/tins/dhcpv6.h index 9c79293..9af14a6 100644 --- a/include/tins/dhcpv6.h +++ b/include/tins/dhcpv6.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dns.h b/include/tins/dns.h index 37eb0e0..0ce1314 100644 --- a/include/tins/dns.h +++ b/include/tins/dns.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dot11.h b/include/tins/dot11.h index 4e79832..1dcb03a 100644 --- a/include/tins/dot11.h +++ b/include/tins/dot11.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dot11/dot11_assoc.h b/include/tins/dot11/dot11_assoc.h index 76fade8..3cbdf73 100644 --- a/include/tins/dot11/dot11_assoc.h +++ b/include/tins/dot11/dot11_assoc.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dot11/dot11_auth.h b/include/tins/dot11/dot11_auth.h index f58f6a9..fe4cb6d 100644 --- a/include/tins/dot11/dot11_auth.h +++ b/include/tins/dot11/dot11_auth.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dot11/dot11_base.h b/include/tins/dot11/dot11_base.h index 5d8cf4a..3f0fba4 100644 --- a/include/tins/dot11/dot11_base.h +++ b/include/tins/dot11/dot11_base.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dot11/dot11_beacon.h b/include/tins/dot11/dot11_beacon.h index 2edf7ee..5c59c54 100644 --- a/include/tins/dot11/dot11_beacon.h +++ b/include/tins/dot11/dot11_beacon.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dot11/dot11_control.h b/include/tins/dot11/dot11_control.h index 2a421eb..e5abb61 100644 --- a/include/tins/dot11/dot11_control.h +++ b/include/tins/dot11/dot11_control.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dot11/dot11_data.h b/include/tins/dot11/dot11_data.h index 5ecd9a9..0c1bd37 100644 --- a/include/tins/dot11/dot11_data.h +++ b/include/tins/dot11/dot11_data.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dot11/dot11_mgmt.h b/include/tins/dot11/dot11_mgmt.h index 09ad501..e7dda2b 100644 --- a/include/tins/dot11/dot11_mgmt.h +++ b/include/tins/dot11/dot11_mgmt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dot11/dot11_probe.h b/include/tins/dot11/dot11_probe.h index fa7db64..eccd5f7 100644 --- a/include/tins/dot11/dot11_probe.h +++ b/include/tins/dot11/dot11_probe.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dot1q.h b/include/tins/dot1q.h index 0e7a08b..b25b877 100644 --- a/include/tins/dot1q.h +++ b/include/tins/dot1q.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/dot3.h b/include/tins/dot3.h index 81c75b3..019a1de 100644 --- a/include/tins/dot3.h +++ b/include/tins/dot3.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/eapol.h b/include/tins/eapol.h index 0a2ce5f..afe8ae3 100644 --- a/include/tins/eapol.h +++ b/include/tins/eapol.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/endianness.h b/include/tins/endianness.h index dad1c33..9303e81 100644 --- a/include/tins/endianness.h +++ b/include/tins/endianness.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/ethernetII.h b/include/tins/ethernetII.h index ddea06a..bbf3aca 100644 --- a/include/tins/ethernetII.h +++ b/include/tins/ethernetII.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/exceptions.h b/include/tins/exceptions.h index 6db106b..0b6405a 100644 --- a/include/tins/exceptions.h +++ b/include/tins/exceptions.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/handshake_capturer.h b/include/tins/handshake_capturer.h index 978a08d..113cb7c 100644 --- a/include/tins/handshake_capturer.h +++ b/include/tins/handshake_capturer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/hw_address.h b/include/tins/hw_address.h index 543b2a1..fde80d4 100644 --- a/include/tins/hw_address.h +++ b/include/tins/hw_address.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/icmp.h b/include/tins/icmp.h index 9249a3a..135e3c4 100644 --- a/include/tins/icmp.h +++ b/include/tins/icmp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/icmp_extension.h b/include/tins/icmp_extension.h index 4193368..99ade0a 100644 --- a/include/tins/icmp_extension.h +++ b/include/tins/icmp_extension.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/icmpv6.h b/include/tins/icmpv6.h index 85a4122..c1b58d1 100644 --- a/include/tins/icmpv6.h +++ b/include/tins/icmpv6.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/ieee802_3.h b/include/tins/ieee802_3.h index efeb683..18f69a1 100644 --- a/include/tins/ieee802_3.h +++ b/include/tins/ieee802_3.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/internals.h b/include/tins/internals.h index b0b031e..3e78030 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/ip.h b/include/tins/ip.h index 94fc18b..c2c0682 100644 --- a/include/tins/ip.h +++ b/include/tins/ip.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/ip_address.h b/include/tins/ip_address.h index 8b7eff4..01055f4 100644 --- a/include/tins/ip_address.h +++ b/include/tins/ip_address.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/ip_reassembler.h b/include/tins/ip_reassembler.h index 52bb615..51a521f 100644 --- a/include/tins/ip_reassembler.h +++ b/include/tins/ip_reassembler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/ipsec.h b/include/tins/ipsec.h index b4ca2a6..198b7ea 100644 --- a/include/tins/ipsec.h +++ b/include/tins/ipsec.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/ipv6.h b/include/tins/ipv6.h index 5b951f7..727bd2b 100644 --- a/include/tins/ipv6.h +++ b/include/tins/ipv6.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/ipv6_address.h b/include/tins/ipv6_address.h index 992727a..e04e240 100644 --- a/include/tins/ipv6_address.h +++ b/include/tins/ipv6_address.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/llc.h b/include/tins/llc.h index 98bc7e4..4b2ae33 100644 --- a/include/tins/llc.h +++ b/include/tins/llc.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/loopback.h b/include/tins/loopback.h index 3b5d541..125dba2 100644 --- a/include/tins/loopback.h +++ b/include/tins/loopback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/macros.h b/include/tins/macros.h index e687296..c3da983 100644 --- a/include/tins/macros.h +++ b/include/tins/macros.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/memory_helpers.h b/include/tins/memory_helpers.h index f1afc2b..0e7f0e8 100644 --- a/include/tins/memory_helpers.h +++ b/include/tins/memory_helpers.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/mpls.h b/include/tins/mpls.h index 11c056d..404d1fc 100644 --- a/include/tins/mpls.h +++ b/include/tins/mpls.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/network_interface.h b/include/tins/network_interface.h index b31308d..896d60a 100644 --- a/include/tins/network_interface.h +++ b/include/tins/network_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/offline_packet_filter.h b/include/tins/offline_packet_filter.h index d1c3b07..3a76c56 100644 --- a/include/tins/offline_packet_filter.h +++ b/include/tins/offline_packet_filter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/packet.h b/include/tins/packet.h index 13450f7..b96a2f1 100644 --- a/include/tins/packet.h +++ b/include/tins/packet.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/packet_sender.h b/include/tins/packet_sender.h index a5caa2c..130a9b2 100644 --- a/include/tins/packet_sender.h +++ b/include/tins/packet_sender.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/packet_writer.h b/include/tins/packet_writer.h index 5daea6d..ef9f2c9 100644 --- a/include/tins/packet_writer.h +++ b/include/tins/packet_writer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/pdu.h b/include/tins/pdu.h index 1e79467..6fad174 100644 --- a/include/tins/pdu.h +++ b/include/tins/pdu.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/pdu_allocator.h b/include/tins/pdu_allocator.h index e64d80f..30b9f33 100644 --- a/include/tins/pdu_allocator.h +++ b/include/tins/pdu_allocator.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/pdu_cacher.h b/include/tins/pdu_cacher.h index 9e27c71..0e8ccdc 100644 --- a/include/tins/pdu_cacher.h +++ b/include/tins/pdu_cacher.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/pdu_option.h b/include/tins/pdu_option.h index 63be671..97d704f 100644 --- a/include/tins/pdu_option.h +++ b/include/tins/pdu_option.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/pktap.h b/include/tins/pktap.h index 88f2216..ce88f84 100644 --- a/include/tins/pktap.h +++ b/include/tins/pktap.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/ppi.h b/include/tins/ppi.h index 8f6934e..b24d8cf 100644 --- a/include/tins/ppi.h +++ b/include/tins/ppi.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/pppoe.h b/include/tins/pppoe.h index 42842a0..40b1b80 100644 --- a/include/tins/pppoe.h +++ b/include/tins/pppoe.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/radiotap.h b/include/tins/radiotap.h index c1a9c6a..0855146 100644 --- a/include/tins/radiotap.h +++ b/include/tins/radiotap.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/rawpdu.h b/include/tins/rawpdu.h index 872b29c..056d412 100644 --- a/include/tins/rawpdu.h +++ b/include/tins/rawpdu.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/rsn_information.h b/include/tins/rsn_information.h index 359aad5..13a4325 100644 --- a/include/tins/rsn_information.h +++ b/include/tins/rsn_information.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/sll.h b/include/tins/sll.h index 62a7444..5a802bd 100644 --- a/include/tins/sll.h +++ b/include/tins/sll.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/small_uint.h b/include/tins/small_uint.h index 8f40c91..7e04cb3 100644 --- a/include/tins/small_uint.h +++ b/include/tins/small_uint.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/snap.h b/include/tins/snap.h index 5687a7d..3035254 100644 --- a/include/tins/snap.h +++ b/include/tins/snap.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/sniffer.h b/include/tins/sniffer.h index 7b1cc5e..a3c7144 100644 --- a/include/tins/sniffer.h +++ b/include/tins/sniffer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/stp.h b/include/tins/stp.h index 45ef83d..29c0711 100644 --- a/include/tins/stp.h +++ b/include/tins/stp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/tcp.h b/include/tins/tcp.h index 68d3f85..0f11fa4 100644 --- a/include/tins/tcp.h +++ b/include/tins/tcp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/tcp_ip/ack_tracker.h b/include/tins/tcp_ip/ack_tracker.h index 606f089..69700f5 100644 --- a/include/tins/tcp_ip/ack_tracker.h +++ b/include/tins/tcp_ip/ack_tracker.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/tcp_ip/data_tracker.h b/include/tins/tcp_ip/data_tracker.h index 9736687..461c2cd 100644 --- a/include/tins/tcp_ip/data_tracker.h +++ b/include/tins/tcp_ip/data_tracker.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/tcp_ip/flow.h b/include/tins/tcp_ip/flow.h index 81c65f9..d157e13 100644 --- a/include/tins/tcp_ip/flow.h +++ b/include/tins/tcp_ip/flow.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/tcp_ip/stream.h b/include/tins/tcp_ip/stream.h index 1ea21ac..ea86de8 100644 --- a/include/tins/tcp_ip/stream.h +++ b/include/tins/tcp_ip/stream.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/tcp_ip/stream_follower.h b/include/tins/tcp_ip/stream_follower.h index 6648329..5283b75 100644 --- a/include/tins/tcp_ip/stream_follower.h +++ b/include/tins/tcp_ip/stream_follower.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/tcp_ip/stream_identifier.h b/include/tins/tcp_ip/stream_identifier.h index bfa85c5..9f6c019 100644 --- a/include/tins/tcp_ip/stream_identifier.h +++ b/include/tins/tcp_ip/stream_identifier.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/tcp_stream.h b/include/tins/tcp_stream.h index 42ae322..0952176 100644 --- a/include/tins/tcp_stream.h +++ b/include/tins/tcp_stream.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/timestamp.h b/include/tins/timestamp.h index 274ae7d..503dc15 100644 --- a/include/tins/timestamp.h +++ b/include/tins/timestamp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/tins.h b/include/tins/tins.h index 2756476..86ff7bf 100644 --- a/include/tins/tins.h +++ b/include/tins/tins.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/udp.h b/include/tins/udp.h index aaabe7b..c50245b 100644 --- a/include/tins/udp.h +++ b/include/tins/udp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/tins/utils.h b/include/tins/utils.h index 2d5b709..7beff5d 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/address_range.cpp b/src/address_range.cpp index 89df754..a016ed9 100644 --- a/src/address_range.cpp +++ b/src/address_range.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/arp.cpp b/src/arp.cpp index 462aad9..80d11d8 100644 --- a/src/arp.cpp +++ b/src/arp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/bootp.cpp b/src/bootp.cpp index 666ed63..8ba8e57 100644 --- a/src/bootp.cpp +++ b/src/bootp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/crypto.cpp b/src/crypto.cpp index bc8adb4..eafcf4b 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dhcp.cpp b/src/dhcp.cpp index e5cd5cb..fcd4eec 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dhcpv6.cpp b/src/dhcpv6.cpp index 4354a4c..1904bcb 100644 --- a/src/dhcpv6.cpp +++ b/src/dhcpv6.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dns.cpp b/src/dns.cpp index b2bd97d..1ccea4c 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dot11/dot11_assoc.cpp b/src/dot11/dot11_assoc.cpp index 1bc1045..23edbd2 100644 --- a/src/dot11/dot11_assoc.cpp +++ b/src/dot11/dot11_assoc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dot11/dot11_auth.cpp b/src/dot11/dot11_auth.cpp index 7da33b0..d8af8ce 100644 --- a/src/dot11/dot11_auth.cpp +++ b/src/dot11/dot11_auth.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dot11/dot11_base.cpp b/src/dot11/dot11_base.cpp index cc71d47..0417064 100644 --- a/src/dot11/dot11_base.cpp +++ b/src/dot11/dot11_base.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dot11/dot11_beacon.cpp b/src/dot11/dot11_beacon.cpp index 5c7753e..0c742f8 100644 --- a/src/dot11/dot11_beacon.cpp +++ b/src/dot11/dot11_beacon.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dot11/dot11_control.cpp b/src/dot11/dot11_control.cpp index 83ab999..dc4ba95 100644 --- a/src/dot11/dot11_control.cpp +++ b/src/dot11/dot11_control.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dot11/dot11_data.cpp b/src/dot11/dot11_data.cpp index a389d32..d346a6d 100644 --- a/src/dot11/dot11_data.cpp +++ b/src/dot11/dot11_data.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dot11/dot11_mgmt.cpp b/src/dot11/dot11_mgmt.cpp index 54a3507..9c42ff9 100644 --- a/src/dot11/dot11_mgmt.cpp +++ b/src/dot11/dot11_mgmt.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dot11/dot11_probe.cpp b/src/dot11/dot11_probe.cpp index a29cc21..dd06f06 100644 --- a/src/dot11/dot11_probe.cpp +++ b/src/dot11/dot11_probe.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dot1q.cpp b/src/dot1q.cpp index d561957..5fca01c 100644 --- a/src/dot1q.cpp +++ b/src/dot1q.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/dot3.cpp b/src/dot3.cpp index 4d53d02..d4241a0 100644 --- a/src/dot3.cpp +++ b/src/dot3.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/eapol.cpp b/src/eapol.cpp index 1401be2..1cb74e6 100644 --- a/src/eapol.cpp +++ b/src/eapol.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index dc81c67..df85505 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/handshake_capturer.cpp b/src/handshake_capturer.cpp index 13dc266..80b0029 100644 --- a/src/handshake_capturer.cpp +++ b/src/handshake_capturer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/icmp.cpp b/src/icmp.cpp index 4aa9e68..8695ccb 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/icmp_extension.cpp b/src/icmp_extension.cpp index d00b37a..095c127 100644 --- a/src/icmp_extension.cpp +++ b/src/icmp_extension.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/icmpv6.cpp b/src/icmpv6.cpp index ceeb909..78cb7f5 100644 --- a/src/icmpv6.cpp +++ b/src/icmpv6.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/internals.cpp b/src/internals.cpp index 6c39b22..7f9b384 100644 --- a/src/internals.cpp +++ b/src/internals.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/ip.cpp b/src/ip.cpp index 67f1b04..ded12e5 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/ip_address.cpp b/src/ip_address.cpp index e0e97d3..f1a7d44 100644 --- a/src/ip_address.cpp +++ b/src/ip_address.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/ip_reassembler.cpp b/src/ip_reassembler.cpp index 6bb735f..61c9578 100644 --- a/src/ip_reassembler.cpp +++ b/src/ip_reassembler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/ipsec.cpp b/src/ipsec.cpp index dde3007..688053b 100644 --- a/src/ipsec.cpp +++ b/src/ipsec.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/ipv6.cpp b/src/ipv6.cpp index 1f855b8..ba766a0 100644 --- a/src/ipv6.cpp +++ b/src/ipv6.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/ipv6_address.cpp b/src/ipv6_address.cpp index 9954777..3833df3 100644 --- a/src/ipv6_address.cpp +++ b/src/ipv6_address.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/llc.cpp b/src/llc.cpp index cb9ee68..371aa01 100644 --- a/src/llc.cpp +++ b/src/llc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/loopback.cpp b/src/loopback.cpp index 9b473ab..20899cf 100644 --- a/src/loopback.cpp +++ b/src/loopback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/mpls.cpp b/src/mpls.cpp index 0fce533..d982b33 100644 --- a/src/mpls.cpp +++ b/src/mpls.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/network_interface.cpp b/src/network_interface.cpp index 2c0e9a1..47c75cc 100644 --- a/src/network_interface.cpp +++ b/src/network_interface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/offline_packet_filter.cpp b/src/offline_packet_filter.cpp index e909bff..74710b0 100644 --- a/src/offline_packet_filter.cpp +++ b/src/offline_packet_filter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/packet_sender.cpp b/src/packet_sender.cpp index 919c402..e95bdd2 100644 --- a/src/packet_sender.cpp +++ b/src/packet_sender.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/packet_writer.cpp b/src/packet_writer.cpp index f6f7eaf..5e74b9e 100644 --- a/src/packet_writer.cpp +++ b/src/packet_writer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/pdu.cpp b/src/pdu.cpp index 989bd37..203b070 100644 --- a/src/pdu.cpp +++ b/src/pdu.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/pktap.cpp b/src/pktap.cpp index d475664..60df8a6 100644 --- a/src/pktap.cpp +++ b/src/pktap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/ppi.cpp b/src/ppi.cpp index 89155bb..51bd00f 100644 --- a/src/ppi.cpp +++ b/src/ppi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/pppoe.cpp b/src/pppoe.cpp index 2439f87..e936906 100644 --- a/src/pppoe.cpp +++ b/src/pppoe.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/radiotap.cpp b/src/radiotap.cpp index a994583..1477360 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/rawpdu.cpp b/src/rawpdu.cpp index cf056f8..1559c01 100644 --- a/src/rawpdu.cpp +++ b/src/rawpdu.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/rsn_information.cpp b/src/rsn_information.cpp index cc58616..55c67ba 100644 --- a/src/rsn_information.cpp +++ b/src/rsn_information.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/sll.cpp b/src/sll.cpp index 9279da5..289b6fd 100644 --- a/src/sll.cpp +++ b/src/sll.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/snap.cpp b/src/snap.cpp index 6b15fc8..33010f1 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/sniffer.cpp b/src/sniffer.cpp index 11de400..68bbe44 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/stp.cpp b/src/stp.cpp index 77a8028..4592cec 100644 --- a/src/stp.cpp +++ b/src/stp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/tcp.cpp b/src/tcp.cpp index beb0d55..6a7ffe2 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/tcp_ip/ack_tracker.cpp b/src/tcp_ip/ack_tracker.cpp index 9d3e326..101a28e 100644 --- a/src/tcp_ip/ack_tracker.cpp +++ b/src/tcp_ip/ack_tracker.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/tcp_ip/data_tracker.cpp b/src/tcp_ip/data_tracker.cpp index 8b922c4..9256de2 100644 --- a/src/tcp_ip/data_tracker.cpp +++ b/src/tcp_ip/data_tracker.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/tcp_ip/flow.cpp b/src/tcp_ip/flow.cpp index 2aeee4a..0742d56 100644 --- a/src/tcp_ip/flow.cpp +++ b/src/tcp_ip/flow.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/tcp_ip/stream.cpp b/src/tcp_ip/stream.cpp index 3e62ace..90561cd 100644 --- a/src/tcp_ip/stream.cpp +++ b/src/tcp_ip/stream.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/tcp_ip/stream_follower.cpp b/src/tcp_ip/stream_follower.cpp index 63c7c71..c471f32 100644 --- a/src/tcp_ip/stream_follower.cpp +++ b/src/tcp_ip/stream_follower.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/tcp_ip/stream_identifier.cpp b/src/tcp_ip/stream_identifier.cpp index bee1d13..1ddf80c 100644 --- a/src/tcp_ip/stream_identifier.cpp +++ b/src/tcp_ip/stream_identifier.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/tcp_stream.cpp b/src/tcp_stream.cpp index d2cafde..cddcabf 100644 --- a/src/tcp_stream.cpp +++ b/src/tcp_stream.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/timestamp.cpp b/src/timestamp.cpp index 9d2517d..f69d3a0 100644 --- a/src/timestamp.cpp +++ b/src/timestamp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/udp.cpp b/src/udp.cpp index b52fd55..74cd93d 100644 --- a/src/udp.cpp +++ b/src/udp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/utils.cpp b/src/utils.cpp index cd23685..dd4a8c1 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/include/active_test.h b/tests/active_tests/include/active_test.h index f4ffd39..97bb780 100644 --- a/tests/active_tests/include/active_test.h +++ b/tests/active_tests/include/active_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/include/active_test_runner.h b/tests/active_tests/include/active_test_runner.h index dfa8705..3d38173 100644 --- a/tests/active_tests/include/active_test_runner.h +++ b/tests/active_tests/include/active_test_runner.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/include/configuration.h b/tests/active_tests/include/configuration.h index 8ec9d31..0bfca92 100644 --- a/tests/active_tests/include/configuration.h +++ b/tests/active_tests/include/configuration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/include/ipv4_tests.h b/tests/active_tests/include/ipv4_tests.h index 5eab0cd..779f950 100644 --- a/tests/active_tests/include/ipv4_tests.h +++ b/tests/active_tests/include/ipv4_tests.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/include/packet_capturer.h b/tests/active_tests/include/packet_capturer.h index 83134d7..c09d43e 100644 --- a/tests/active_tests/include/packet_capturer.h +++ b/tests/active_tests/include/packet_capturer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/include/tcp_tests.h b/tests/active_tests/include/tcp_tests.h index 36375dc..a7ae5bd 100644 --- a/tests/active_tests/include/tcp_tests.h +++ b/tests/active_tests/include/tcp_tests.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/include/test_utils.h b/tests/active_tests/include/test_utils.h index 5d1302b..cd50221 100644 --- a/tests/active_tests/include/test_utils.h +++ b/tests/active_tests/include/test_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/include/utils_tests.h b/tests/active_tests/include/utils_tests.h index 9f517af..959d46b 100644 --- a/tests/active_tests/include/utils_tests.h +++ b/tests/active_tests/include/utils_tests.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/src/active_test.cpp b/tests/active_tests/src/active_test.cpp index 6fac5aa..f6b0a0a 100644 --- a/tests/active_tests/src/active_test.cpp +++ b/tests/active_tests/src/active_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/src/active_test_runner.cpp b/tests/active_tests/src/active_test_runner.cpp index b0f84f4..6ce9815 100644 --- a/tests/active_tests/src/active_test_runner.cpp +++ b/tests/active_tests/src/active_test_runner.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/src/configuration.cpp b/tests/active_tests/src/configuration.cpp index d751051..a44d278 100644 --- a/tests/active_tests/src/configuration.cpp +++ b/tests/active_tests/src/configuration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/src/ipv4_tests.cpp b/tests/active_tests/src/ipv4_tests.cpp index 6d22d4c..3e55fad 100644 --- a/tests/active_tests/src/ipv4_tests.cpp +++ b/tests/active_tests/src/ipv4_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/src/main.cpp b/tests/active_tests/src/main.cpp index 4f9100d..cffad27 100644 --- a/tests/active_tests/src/main.cpp +++ b/tests/active_tests/src/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/src/packet_capturer.cpp b/tests/active_tests/src/packet_capturer.cpp index 1d09abb..cf05c6e 100644 --- a/tests/active_tests/src/packet_capturer.cpp +++ b/tests/active_tests/src/packet_capturer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/src/tcp_tests.cpp b/tests/active_tests/src/tcp_tests.cpp index 57f4484..5ca520a 100644 --- a/tests/active_tests/src/tcp_tests.cpp +++ b/tests/active_tests/src/tcp_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/src/test_utils.cpp b/tests/active_tests/src/test_utils.cpp index 2370149..769327c 100644 --- a/tests/active_tests/src/test_utils.cpp +++ b/tests/active_tests/src/test_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/tests/active_tests/src/utils_test.cpp b/tests/active_tests/src/utils_test.cpp index e9fa257..5f3ff5e 100644 --- a/tests/active_tests/src/utils_test.cpp +++ b/tests/active_tests/src/utils_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Matias Fontanini + * Copyright (c) 2017, Matias Fontanini * All rights reserved. * * Redistribution and use in source and binary forms, with or without From c7273ddd30f2954714c334d29d9c509a77223289 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 29 Apr 2017 11:23:15 -0700 Subject: [PATCH 06/73] Add PDU iterator class --- include/tins/pdu_iterator.h | 312 ++++++++++++++++++++++++++++++++ include/tins/tins.h | 1 + src/CMakeLists.txt | 1 + src/pdu_iterator.cpp | 104 +++++++++++ tests/src/CMakeLists.txt | 1 + tests/src/pdu_iterator_test.cpp | 55 ++++++ 6 files changed, 474 insertions(+) create mode 100644 include/tins/pdu_iterator.h create mode 100644 src/pdu_iterator.cpp create mode 100644 tests/src/pdu_iterator_test.cpp diff --git a/include/tins/pdu_iterator.h b/include/tins/pdu_iterator.h new file mode 100644 index 0000000..abc5685 --- /dev/null +++ b/include/tins/pdu_iterator.h @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_PDU_ITERATOR_H +#define TINS_PDU_ITERATOR_H + +#include + +namespace Tins { + +class PDU; +class Packet; + +/** + * Base class for PDU iterators + */ +template +class PDUIteratorBase { +public: + /** + * Iterator's category + */ + typedef std::bidirectional_iterator_tag iterator_category; + + /** + * Iterator difference type + */ + typedef std::ptrdiff_t difference_type; + + /** + * Advances this iterator + */ + Concrete& operator++() { + advance(); + return static_cast(*this); + } + + /** + * Advances this iterator + */ + Concrete operator++(int) { + Concrete output = static_cast(*this); + advance(); + return output; + } + + /** + * Moves this iterator back + */ + Concrete& operator--() { + retreat(); + return static_cast(*this); + } + + /** + * Moves this iterator back + */ + Concrete operator--(int) { + Concrete output = static_cast(*this); + retreat(); + return output; + } +private: + void advance() { + Concrete& self = static_cast(*this); + self = Concrete(self->inner_pdu()); + } + + void retreat() { + Concrete& self = static_cast(*this); + self = Concrete(self->parent_pdu()); + } +}; + +/** + * Compares iterators for equality + * + * \param lhs The left hand side iterator to be compared + * \param rhs The right hand side iterator to be compared + */ +template +bool operator==(const PDUIteratorBase& lhs, const PDUIteratorBase& rhs) { + const PDU* lhs_pdu = &*static_cast(lhs); + const PDU* rhs_pdu = &*static_cast(rhs); + return lhs_pdu == rhs_pdu; +} + +/** + * Compares iterators for equality + * + * \param lhs The left hand side iterator to be compared + * \param rhs The right hand side iterator to be compared + */ +template +bool operator!=(const PDUIteratorBase& lhs, const PDUIteratorBase& rhs) { + return !(lhs == rhs); +} + +/** + * Iterator class for PDUs + */ +class PDUIterator : public PDUIteratorBase { +public: + /** + * The used pointer type + */ + typedef PDU* pointer; + + /** + * The used reference type + */ + typedef PDU& reference; + + /** + * The used value type + */ + typedef PDU& value_type; + + /** + * Constructs an iterator using a PDU + * + * \param pdu The PDU to be used for iteration + */ + PDUIterator(pointer pdu); + + /** + * Get the stored PDU pointer + */ + pointer operator->(); + + /** + * Get the stored PDU pointer + */ + pointer operator->() const; + + /** + * Dereference and get the stored PDU + */ + value_type operator*(); + + /** + * Dereference and get the stored PDU + */ + const value_type operator*() const; +private: + pointer pdu_; +}; + +/** + * Const iterator class for PDUs + */ +class ConstPDUIterator : public PDUIteratorBase { +public: + /** + * The used pointer type + */ + typedef const PDU* pointer; + + /** + * The used reference type + */ + typedef const PDU& reference; + + /** + * The used value type + */ + typedef const PDU& value_type; + + /** + * Constructs an iterator using a PDU + * + * \param pdu The PDU to be used for iteration + */ + ConstPDUIterator(pointer pdu); + + /** + * Construct from a PDU iterator + */ + ConstPDUIterator(PDUIterator iterator); + + /** + * Get the stored PDU pointer + */ + pointer operator->() const; + + /** + * Dereference and get the stored PDU + */ + value_type operator*() const; +private: + pointer pdu_; +}; + +/* + * \brief PDU iterator class + * + * This class allows iterating all PDUs in a packet. + * + * Note that this keeps pointers to the original PDUs so you need to guarantee that they're + * still in scope while you iterate them. + */ +template +class PDUIteratorRange { +public: + /** + * Constructs a PDU iterator range + * + * \param start The beginning of the range + * \param end The end of the range + */ + PDUIteratorRange(Iterator start, Iterator end) + : start_(start), end_(end) { + + } + + template + PDUIteratorRange(const PDUIteratorRange& other) + : start_(&*other.begin()), end_(&*other.end()) { + + } + + /* + * Gets the beginning of the range + */ + Iterator begin() { + return start_; + } + + /* + * Gets the beginning of the range + */ + Iterator begin() const { + return start_; + } + + /* + * Gets the end of the range + */ + Iterator end() { + return end_; + } + + /* + * Gets the end of the range + */ + Iterator end() const { + return end_; + } +private: + Iterator start_; + Iterator end_; +}; + +/** + * Creates an iterator range out of a PDU + */ +PDUIteratorRange iterate_pdus(PDU* pdu); + +/** + * Creates an iterator range out of a PDU + */ +PDUIteratorRange iterate_pdus(PDU& pdu); + +/** + * Creates an iterator range out of a PDU + */ +PDUIteratorRange iterate_pdus(Packet& packet); + +/** + * Creates an iterator range out of a PDU + */ +PDUIteratorRange iterate_pdus(const PDU* pdu); + +/** + * Creates an iterator range out of a PDU + */ +PDUIteratorRange iterate_pdus(const PDU& pdu); + +/** + * Creates an iterator range out of a packet + */ +PDUIteratorRange iterate_pdus(const Packet& packet); + +} // Tins + +#endif // TINS_PDU_ITERATOR_H diff --git a/include/tins/tins.h b/include/tins/tins.h index 86ff7bf..55a5efd 100644 --- a/include/tins/tins.h +++ b/include/tins/tins.h @@ -74,5 +74,6 @@ #include "ipsec.h" #include "ip_reassembler.h" #include "ppi.h" +#include "pdu_iterator.h" #endif // TINS_TINS_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 82a7ae0..6f1dd91 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,6 +46,7 @@ set(SOURCES pdu.cpp radiotap.cpp address_range.cpp + pdu_iterator.cpp rawpdu.cpp rsn_information.cpp sll.cpp diff --git a/src/pdu_iterator.cpp b/src/pdu_iterator.cpp new file mode 100644 index 0000000..12c154d --- /dev/null +++ b/src/pdu_iterator.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "pdu_iterator.h" +#include "pdu.h" +#include "packet.h" + +namespace Tins { + +// PDUIterator +PDUIterator::PDUIterator(pointer pdu) +: pdu_(pdu) { + +} + +PDUIterator::pointer PDUIterator::operator->() { + return pdu_; +} + +PDUIterator::pointer PDUIterator::operator->() const { + return pdu_; +} + +PDUIterator::value_type PDUIterator::operator*() { + return *pdu_; +} + +const PDUIterator::value_type PDUIterator::operator*() const { + return *pdu_; +} + +// ConstPDUIterator + +ConstPDUIterator::ConstPDUIterator(pointer pdu) +: pdu_(pdu) { + +} + +ConstPDUIterator::ConstPDUIterator(PDUIterator iterator) +: pdu_(&*iterator) { + +} + +ConstPDUIterator::pointer ConstPDUIterator::operator->() const { + return pdu_; +} + +ConstPDUIterator::value_type ConstPDUIterator::operator*() const { + return *pdu_; +} + +// Helpers + +PDUIteratorRange iterate_pdus(PDU* pdu) { + return PDUIteratorRange(pdu, 0); +} + +PDUIteratorRange iterate_pdus(PDU& pdu) { + return PDUIteratorRange(&pdu, 0); +} + +PDUIteratorRange iterate_pdus(Packet& packet) { + return PDUIteratorRange(packet.pdu(), 0); +} + +PDUIteratorRange iterate_pdus(const PDU* pdu) { + return PDUIteratorRange(pdu, 0); +} + +PDUIteratorRange iterate_pdus(const PDU& pdu) { + return PDUIteratorRange(&pdu, 0); +} + +PDUIteratorRange iterate_pdus(const Packet& packet) { + return PDUIteratorRange(packet.pdu(), 0); +} + +} // Tins diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt index e2b5dca..d35244c 100644 --- a/tests/src/CMakeLists.txt +++ b/tests/src/CMakeLists.txt @@ -76,6 +76,7 @@ CREATE_TEST(matches_response) CREATE_TEST(mpls) CREATE_TEST(network_interface) CREATE_TEST(pdu) +CREATE_TEST(pdu_iterator) CREATE_TEST(pppoe) CREATE_TEST(radiotap) CREATE_TEST(rc4_eapol) diff --git a/tests/src/pdu_iterator_test.cpp b/tests/src/pdu_iterator_test.cpp new file mode 100644 index 0000000..22fa529 --- /dev/null +++ b/tests/src/pdu_iterator_test.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include "ip.h" +#include "tcp.h" +#include "rawpdu.h" +#include "pdu_iterator.h" + +using std::distance; +using std::map; + +using namespace Tins; + +class PDUIteratorTest : public testing::Test { +public: + template + void test() { + IP ip = IP("1.2.3.4", "4.3.2.1") / TCP(22, 23) / RawPDU("asd"); + map pdu_types; + pdu_types[0] = PDU::IP; + pdu_types[1] = PDU::TCP; + pdu_types[2] = PDU::RAW; + + PDUIteratorRange range = iterate_pdus(ip); + EXPECT_EQ(3, distance(range.begin(), range.end())); + + size_t iteration = 0; + for (Iterator iter = range.begin(); iter != range.end(); iter++) { + EXPECT_EQ(pdu_types[iteration], iter->pdu_type()); + EXPECT_EQ(pdu_types[iteration], (*iter).pdu_type()); + ++iteration; + } + + Iterator iter = range.begin(); + ++iter; + iter++; + --iter; + iter--; + EXPECT_EQ(PDU::IP, iter->pdu_type()); + EXPECT_EQ(iter, range.begin()); + EXPECT_NE(iter, range.end()); + + const PDU& pdu = *iterate_pdus(ip).begin(); + EXPECT_EQ(PDU::IP, pdu.pdu_type()); + EXPECT_GT(const_cast(pdu).serialize().size(), 0); + } +}; + +TEST_F(PDUIteratorTest, Range) { + test(); +} + +TEST_F(PDUIteratorTest, RangeConst) { + test(); +} From 6f681f6519995bbfc1bf3c869bbde54382e8cd58 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 09:25:03 -0700 Subject: [PATCH 07/73] Move smart_ptr definition into new file detail/smart_ptr.h --- include/tins/CMakeLists.txt | 1 + include/tins/cxxstd.h | 11 ----- include/tins/detail/CMakeLists.txt | 6 +++ include/tins/detail/smart_ptr.h | 51 ++++++++++++++++++++++ src/utils.cpp | 1 + tests/src/dot11/ack_test.cpp | 2 +- tests/src/dot11/assoc_request_test.cpp | 2 +- tests/src/dot11/assoc_response_test.cpp | 2 +- tests/src/dot11/authentication_test.cpp | 2 +- tests/src/dot11/beacon_test.cpp | 2 +- tests/src/dot11/block_ack_request_test.cpp | 2 +- tests/src/dot11/cf_end_ack_test.cpp | 2 +- tests/src/dot11/cf_end_test.cpp | 2 +- tests/src/dot11/data_test.cpp | 2 +- tests/src/dot11/deauthentication_test.cpp | 2 +- tests/src/dot11/disassoc_test.cpp | 2 +- tests/src/dot11/probe_request_test.cpp | 2 +- tests/src/dot11/probe_response_test.cpp | 2 +- tests/src/dot11/ps_poll_test.cpp | 2 +- tests/src/dot11/reassoc_request_test.cpp | 2 +- tests/src/dot11/reassoc_response_test.cpp | 2 +- tests/src/dot11/rts_test.cpp | 2 +- 22 files changed, 76 insertions(+), 28 deletions(-) create mode 100644 include/tins/detail/CMakeLists.txt create mode 100644 include/tins/detail/smart_ptr.h diff --git a/include/tins/CMakeLists.txt b/include/tins/CMakeLists.txt index 54f8c42..1f55d3a 100644 --- a/include/tins/CMakeLists.txt +++ b/include/tins/CMakeLists.txt @@ -6,3 +6,4 @@ INSTALL( ) ADD_SUBDIRECTORY(dot11) ADD_SUBDIRECTORY(tcp_ip) +ADD_SUBDIRECTORY(detail) diff --git a/include/tins/cxxstd.h b/include/tins/cxxstd.h index e37e9a5..d191c54 100644 --- a/include/tins/cxxstd.h +++ b/include/tins/cxxstd.h @@ -32,8 +32,6 @@ #include "config.h" -#include - #ifdef __GXX_EXPERIMENTAL_CXX0X__ #define TINS_CXXSTD_GCC_FIX 1 #else @@ -48,15 +46,6 @@ namespace Tins{ namespace Internals { -template -struct smart_ptr { -#if TINS_IS_CXX11 - typedef std::unique_ptr type; -#else - typedef std::auto_ptr type; -#endif -}; - template void unused(const T&) { } } } diff --git a/include/tins/detail/CMakeLists.txt b/include/tins/detail/CMakeLists.txt new file mode 100644 index 0000000..5d57beb --- /dev/null +++ b/include/tins/detail/CMakeLists.txt @@ -0,0 +1,6 @@ +FILE(GLOB INCLUDE_FILES "*.h") +INSTALL( + FILES ${INCLUDE_FILES} + DESTINATION include/tins/detail + COMPONENT Headers +) diff --git a/include/tins/detail/smart_ptr.h b/include/tins/detail/smart_ptr.h new file mode 100644 index 0000000..48b07d8 --- /dev/null +++ b/include/tins/detail/smart_ptr.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_SMART_PTR_H +#define TINS_SMART_PTR_H + +#include +#include "../cxxstd.h" + +namespace Tins { +namespace Internals { + +template +struct smart_ptr { +#if TINS_IS_CXX11 + typedef std::unique_ptr type; +#else + typedef std::auto_ptr type; +#endif +}; + +} // Internals +} // Tins + +#endif // TINS_SMART_PTR_H diff --git a/src/utils.cpp b/src/utils.cpp index dd4a8c1..c849e17 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -68,6 +68,7 @@ #include "cxxstd.h" #include "hw_address.h" #include "memory_helpers.h" +#include "detail/smart_ptr.h" using std::string; using std::set; diff --git a/tests/src/dot11/ack_test.cpp b/tests/src/dot11/ack_test.cpp index e78f532..e85f9f5 100644 --- a/tests/src/dot11/ack_test.cpp +++ b/tests/src/dot11/ack_test.cpp @@ -3,7 +3,7 @@ #include #include "tests/dot11.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/assoc_request_test.cpp b/tests/src/dot11/assoc_request_test.cpp index a2e3f3d..bfca902 100644 --- a/tests/src/dot11/assoc_request_test.cpp +++ b/tests/src/dot11/assoc_request_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_mgmt.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/assoc_response_test.cpp b/tests/src/dot11/assoc_response_test.cpp index 765194e..28eaa82 100644 --- a/tests/src/dot11/assoc_response_test.cpp +++ b/tests/src/dot11/assoc_response_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_mgmt.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/authentication_test.cpp b/tests/src/dot11/authentication_test.cpp index 7fe5fdf..718e140 100644 --- a/tests/src/dot11/authentication_test.cpp +++ b/tests/src/dot11/authentication_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_mgmt.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/beacon_test.cpp b/tests/src/dot11/beacon_test.cpp index fc9ee2b..76fc7d2 100644 --- a/tests/src/dot11/beacon_test.cpp +++ b/tests/src/dot11/beacon_test.cpp @@ -5,7 +5,7 @@ #include #include "rsn_information.h" #include "tests/dot11_mgmt.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/block_ack_request_test.cpp b/tests/src/dot11/block_ack_request_test.cpp index 6686d66..02a8470 100644 --- a/tests/src/dot11/block_ack_request_test.cpp +++ b/tests/src/dot11/block_ack_request_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/cf_end_ack_test.cpp b/tests/src/dot11/cf_end_ack_test.cpp index 4d4d721..d0a282c 100644 --- a/tests/src/dot11/cf_end_ack_test.cpp +++ b/tests/src/dot11/cf_end_ack_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_control.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/cf_end_test.cpp b/tests/src/dot11/cf_end_test.cpp index 15f102e..2172840 100644 --- a/tests/src/dot11/cf_end_test.cpp +++ b/tests/src/dot11/cf_end_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_control.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/data_test.cpp b/tests/src/dot11/data_test.cpp index 140062f..8866df9 100644 --- a/tests/src/dot11/data_test.cpp +++ b/tests/src/dot11/data_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_data.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/deauthentication_test.cpp b/tests/src/dot11/deauthentication_test.cpp index 9bfb377..4452899 100644 --- a/tests/src/dot11/deauthentication_test.cpp +++ b/tests/src/dot11/deauthentication_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_mgmt.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/disassoc_test.cpp b/tests/src/dot11/disassoc_test.cpp index 619ccef..0867809 100644 --- a/tests/src/dot11/disassoc_test.cpp +++ b/tests/src/dot11/disassoc_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_mgmt.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/probe_request_test.cpp b/tests/src/dot11/probe_request_test.cpp index 403bede..b620794 100644 --- a/tests/src/dot11/probe_request_test.cpp +++ b/tests/src/dot11/probe_request_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_mgmt.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/probe_response_test.cpp b/tests/src/dot11/probe_response_test.cpp index c530992..2d8a705 100644 --- a/tests/src/dot11/probe_response_test.cpp +++ b/tests/src/dot11/probe_response_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_mgmt.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/ps_poll_test.cpp b/tests/src/dot11/ps_poll_test.cpp index a7bb92c..eaff858 100644 --- a/tests/src/dot11/ps_poll_test.cpp +++ b/tests/src/dot11/ps_poll_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_control.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/reassoc_request_test.cpp b/tests/src/dot11/reassoc_request_test.cpp index 1f10ee8..1a9ea11 100644 --- a/tests/src/dot11/reassoc_request_test.cpp +++ b/tests/src/dot11/reassoc_request_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_mgmt.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/reassoc_response_test.cpp b/tests/src/dot11/reassoc_response_test.cpp index c9a05c4..2c55896 100644 --- a/tests/src/dot11/reassoc_response_test.cpp +++ b/tests/src/dot11/reassoc_response_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_mgmt.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; diff --git a/tests/src/dot11/rts_test.cpp b/tests/src/dot11/rts_test.cpp index b01e0bb..741a4a8 100644 --- a/tests/src/dot11/rts_test.cpp +++ b/tests/src/dot11/rts_test.cpp @@ -4,7 +4,7 @@ #include #include "tests/dot11_control.h" - +#include "detail/smart_ptr.h" using namespace std; using namespace Tins; From 22c72955f5b7d5fdfa00c98dd01db6dcd7ba1381 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 09:25:57 -0700 Subject: [PATCH 08/73] Remove Storage template parameter from HWAddress, move impl to cpp This is a breaking ABI change. This might break some forward declarations and hopefully no one was actually using the Storage type for anything. --- include/tins/hw_address.h | 143 ++++++++++++-------------------------- src/CMakeLists.txt | 1 + src/hw_address.cpp | 88 +++++++++++++++++++++++ 3 files changed, 134 insertions(+), 98 deletions(-) create mode 100644 src/hw_address.cpp diff --git a/include/tins/hw_address.h b/include/tins/hw_address.h index fde80d4..853822a 100644 --- a/include/tins/hw_address.h +++ b/include/tins/hw_address.h @@ -31,15 +31,32 @@ #define TINS_HWADDRESS_H #include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include "cxxstd.h" namespace Tins { +namespace Internals { + +// Defined in hw_address.cpp +/** + * \cond + */ +std::string hw_address_to_string(const uint8_t* ptr, size_t count); + +void string_to_hw_address(const std::string& hw_addr, uint8_t* output, size_t output_size); + +bool hw_address_equal_compare(const uint8_t* start1, const uint8_t* end1, + const uint8_t* start2); + +bool hw_address_lt_compare(const uint8_t* start1, const uint8_t* end1, + const uint8_t* start2, const uint8_t* end2); + +/** + * \endcond + */ +} // Internals /** * \class HWAddress @@ -61,15 +78,13 @@ namespace Tins { * } * \endcode */ -template +template class HWAddress { public: /** * \brief The type of the elements stored in the hardware address. - * - * This is the same as the template parameter Storage. */ - typedef Storage storage_type; + typedef uint8_t storage_type; /** * \brief The random access iterator type. @@ -90,7 +105,7 @@ public: /** * \brief The broadcast address. */ - static const HWAddress broadcast; + static const HWAddress broadcast; /** * \brief Constructor from a const storage_type*. @@ -109,10 +124,10 @@ public: */ HWAddress(const storage_type* ptr = 0) { if (ptr) { - std::copy(ptr, ptr + address_size, buffer_); + std::memcpy(buffer_, ptr, address_size); } else { - std::fill(begin(), end(), storage_type()); + std::memset(buffer_, 0, address_size); } } @@ -128,7 +143,7 @@ public: * \param address The hex-notation address to be parsed. */ HWAddress(const std::string& address) { - convert(address, buffer_); + Internals::string_to_hw_address(address, buffer_, n); } /** @@ -146,7 +161,7 @@ public: */ template HWAddress(const char (&address)[i]) { - convert(address, buffer_); + Internals::string_to_hw_address(address, buffer_, n); } /** @@ -163,18 +178,15 @@ public: */ template HWAddress(const HWAddress& rhs) { - // Fill extra bytes - std::fill( - // Copy as most as we can - std::copy( - rhs.begin(), - rhs.begin() + std::min(i, n), - begin() - ), - end(), - 0 - ); - + size_t copy_threshold = i < n ? i : n; + for (size_t index = 0; index < n; ++index) { + if (index < copy_threshold) { + buffer_[index] = rhs[index]; + } + else { + buffer_[index] = storage_type(); + } + } } /** @@ -225,7 +237,7 @@ public: * \return bool indicating whether addresses are equal. */ bool operator==(const HWAddress& rhs) const { - return std::equal(begin(), end(), rhs.begin()); + return Internals::hw_address_equal_compare(begin(), end(), rhs.begin()); } /** @@ -247,7 +259,7 @@ public: * \return bool indicating whether this address is less-than rhs. */ bool operator<(const HWAddress& rhs) const { - return std::lexicographical_compare(begin(), end(), rhs.begin(), rhs.end()); + return Internals::hw_address_lt_compare(begin(), end(), rhs.begin(), rhs.end()); } /** @@ -300,9 +312,7 @@ public: * \return std::string containing the hex-notation address. */ std::string to_string() const { - std::ostringstream oss; - oss <<* this; - return oss.str(); + return Internals::hw_address_to_string(buffer_, size()); } /** @@ -331,13 +341,7 @@ public: * \return std::ostream& pointing to the os parameter. */ friend std::ostream& operator<<(std::ostream& os, const HWAddress& addr) { - std::transform( - addr.begin(), - addr.end() - 1, - std::ostream_iterator(os, ":"), - &HWAddress::storage_to_string - ); - return os << storage_to_string(addr.begin()[HWAddress::address_size - 1]); + return os << addr.to_string(); } /** @@ -363,9 +367,6 @@ public: return output; } private: - template - static void convert(const std::string& hw_addr, OutputIterator output); - static HWAddress make_broadcast_address() { // Build a buffer made of n 0xff bytes uint8_t buffer[n]; @@ -375,65 +376,11 @@ private: return HWAddress(buffer); } - static std::string storage_to_string(storage_type element) { - std::ostringstream oss; - oss << std::hex; - if (element < 0x10) { - oss << '0'; - } - oss << (unsigned)element; - return oss.str(); - } - storage_type buffer_[n]; }; -template -template -void HWAddress::convert(const std::string& hw_addr, - OutputIterator output) { - unsigned i(0); - size_t count(0); - storage_type tmp; - while (i < hw_addr.size() && count < n) { - const unsigned end = i+2; - tmp = storage_type(); - while (i < end) { - if (hw_addr[i] >= 'a' && hw_addr[i] <= 'f') { - tmp = (tmp << 4) | (hw_addr[i] - 'a' + 10); - } - else if (hw_addr[i] >= 'A' && hw_addr[i] <= 'F') { - tmp = (tmp << 4) | (hw_addr[i] - 'A' + 10); - } - else if (hw_addr[i] >= '0' && hw_addr[i] <= '9') { - tmp = (tmp << 4) | (hw_addr[i] - '0'); - } - else if (hw_addr[i] == ':') { - break; - } - else { - throw std::runtime_error("Invalid byte found"); - } - i++; - } - *(output++) = tmp; - count++; - if (i < hw_addr.size()) { - if (hw_addr[i] == ':') { - i++; - } - else { - throw std::runtime_error("Invalid separator"); - } - } - } - while (count++ < n) { - *(output++) = storage_type(); - } -} - -template -const HWAddress HWAddress::broadcast = make_broadcast_address(); +template +const HWAddress HWAddress::broadcast = make_broadcast_address(); } // namespace Tins diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6f1dd91..04d069b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,6 +28,7 @@ set(SOURCES dot1q.cpp eapol.cpp ethernetII.cpp + hw_address.cpp icmp_extension.cpp icmp.cpp icmpv6.cpp diff --git a/src/hw_address.cpp b/src/hw_address.cpp new file mode 100644 index 0000000..93780c8 --- /dev/null +++ b/src/hw_address.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include "hw_address.h" + +using std::string; +using std::ostream; +using std::hex; +using std::ostringstream; +using std::lexicographical_compare; +using std::equal; + +namespace Tins { +namespace Internals { + +void storage_to_string(ostream& output, uint8_t value) { + output << hex; + if (value < 0x10) { + output << '0'; + } + output << (unsigned)value; +} + +string hw_address_to_string(const uint8_t* ptr, size_t count) { + ostringstream output; + for (size_t i = 0; i < count; ++i) { + if (i != 0) { + output << ":"; + } + storage_to_string(output, ptr[i]); + } + return output.str(); +} + +void string_to_hw_address(const string& hw_addr, uint8_t* output, size_t output_size) { + unsigned i = 0; + size_t count = 0; + uint8_t tmp; + while (i < hw_addr.size() && count < output_size) { + const unsigned end = i+2; + tmp = 0; + while (i < end) { + if (hw_addr[i] >= 'a' && hw_addr[i] <= 'f') { + tmp = (tmp << 4) | (hw_addr[i] - 'a' + 10); + } + else if (hw_addr[i] >= 'A' && hw_addr[i] <= 'F') { + tmp = (tmp << 4) | (hw_addr[i] - 'A' + 10); + } + else if (hw_addr[i] >= '0' && hw_addr[i] <= '9') { + tmp = (tmp << 4) | (hw_addr[i] - '0'); + } + else if (hw_addr[i] == ':') { + break; + } + else { + throw std::runtime_error("Invalid byte found"); + } + i++; + } + *(output++) = tmp; + count++; + if (i < hw_addr.size()) { + if (hw_addr[i] == ':') { + i++; + } + else { + throw std::runtime_error("Invalid separator"); + } + } + } + while (count++ < output_size) { + *(output++) = 0; + } +} + +bool hw_address_equal_compare(const uint8_t* start1, const uint8_t* end1, + const uint8_t* start2) { + return equal(start1, end1, start2); +} + +bool hw_address_lt_compare(const uint8_t* start1, const uint8_t* end1, + const uint8_t* start2, const uint8_t* end2) { + return lexicographical_compare(start1, end1, start2, end2); +} + +} // Internals +} // Tins From 3e7d30e01c9b54fac2f13fc0787e41a54ad86fd3 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 09:28:00 -0700 Subject: [PATCH 09/73] Don't include heavy STL headers like in header files This provides a considerable compilation time reduction and most of these were just using std::copy/fill which can be replaced by memcpy/memset, as all of their uses were applied to POD types --- examples/traceroute.cpp | 1 + include/tins/bootp.h | 18 ++++++++---------- include/tins/internals.h | 2 -- include/tins/ip_address.h | 2 +- include/tins/ipv6_address.h | 6 ++---- include/tins/memory_helpers.h | 5 ++--- include/tins/pdu_cacher.h | 4 ++-- include/tins/pdu_option.h | 16 +++------------- include/tins/utils.h | 2 +- src/dhcp.cpp | 1 + src/handshake_capturer.cpp | 1 + src/icmpv6.cpp | 1 + src/ip_address.cpp | 1 + src/ipv6_address.cpp | 8 +++++++- 14 files changed, 31 insertions(+), 37 deletions(-) diff --git a/examples/traceroute.cpp b/examples/traceroute.cpp index 09a7991..9a4da46 100644 --- a/examples/traceroute.cpp +++ b/examples/traceroute.cpp @@ -35,6 +35,7 @@ #define _GLIBCXX_USE_NANOSLEEP #include +#include #include #include #include diff --git a/include/tins/bootp.h b/include/tins/bootp.h index 7d88936..eaf3f1c 100644 --- a/include/tins/bootp.h +++ b/include/tins/bootp.h @@ -31,7 +31,6 @@ #define TINS_BOOTP_H #include -#include #include #include "pdu.h" #include "macros.h" @@ -268,15 +267,14 @@ public: */ template void chaddr(const HWAddress& new_chaddr) { - // Copy the new addr - uint8_t* end = std::copy( - new_chaddr.begin(), - new_chaddr.begin() + std::min(n, sizeof(bootp_.chaddr)), - bootp_.chaddr - ); - // Fill what's left with zeros - if (end < bootp_.chaddr + chaddr_type::address_size) { - std::fill(end, bootp_.chaddr + chaddr_type::address_size, 0); + size_t copy_threshold = std::min(n, sizeof(bootp_.chaddr)); + for (size_t i = 0; i < copy_threshold; ++i) { + if (i < copy_threshold) { + bootp_.chaddr[i] = new_chaddr[i]; + } + else { + bootp_.chaddr[i] = 0; + } } } diff --git a/include/tins/internals.h b/include/tins/internals.h index 3e78030..17f4cc4 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -33,8 +33,6 @@ #if TINS_IS_CXX11 #include #endif - -#include #include #include #include "constants.h" diff --git a/include/tins/ip_address.h b/include/tins/ip_address.h index 01055f4..bfbcb6c 100644 --- a/include/tins/ip_address.h +++ b/include/tins/ip_address.h @@ -31,7 +31,7 @@ #define TINS_IPADDRESS_H #include -#include +#include #include #include "cxxstd.h" #include "macros.h" diff --git a/include/tins/ipv6_address.h b/include/tins/ipv6_address.h index e04e240..87ba039 100644 --- a/include/tins/ipv6_address.h +++ b/include/tins/ipv6_address.h @@ -32,6 +32,7 @@ #include #include +#include #include #include "cxxstd.h" #include "macros.h" @@ -203,10 +204,7 @@ public: * \param addr The parameter to be written. * \return std::ostream& pointing to the os parameter. */ - friend std::ostream& operator<<(std::ostream& os, const IPv6Address& addr) { - return os << addr.to_string(); - } - + friend std::ostream& operator<<(std::ostream& os, const IPv6Address& addr); /** * Applies a mask to an address diff --git a/include/tins/memory_helpers.h b/include/tins/memory_helpers.h index 0e7f0e8..5828365 100644 --- a/include/tins/memory_helpers.h +++ b/include/tins/memory_helpers.h @@ -32,7 +32,6 @@ #include #include -#include #include #include "exceptions.h" #include "ip_address.h" @@ -213,7 +212,7 @@ public: if (TINS_UNLIKELY(size_ < length)) { throw serialization_error(); } - std::copy(start, end, buffer_); + std::memcpy(buffer_, &*start, length); skip(length); } @@ -238,7 +237,7 @@ public: if (TINS_UNLIKELY(size_ < size)) { throw serialization_error(); } - std::fill(buffer_, buffer_ + size, value); + std::memset(buffer_, value, size); skip(size); } diff --git a/include/tins/pdu_cacher.h b/include/tins/pdu_cacher.h index 0e8ccdc..ab37d45 100644 --- a/include/tins/pdu_cacher.h +++ b/include/tins/pdu_cacher.h @@ -30,7 +30,7 @@ #ifndef TINS_PDU_CACHER_H #define TINS_PDU_CACHER_H -#include +#include #include "pdu.h" #include "macros.h" @@ -148,7 +148,7 @@ private: if (cached_serialization_.size() != total_sz) { cached_serialization_ = cached_.serialize(); } - std::copy(cached_serialization_.begin(), cached_serialization_.end(), buffer); + std::memcpy(buffer, &*cached_serialization_.begin(), cached_serialization_.size()); } cached_type cached_; diff --git a/include/tins/pdu_option.h b/include/tins/pdu_option.h index 97d704f..dc1ecdd 100644 --- a/include/tins/pdu_option.h +++ b/include/tins/pdu_option.h @@ -33,9 +33,7 @@ #include #include #include -#include #include -#include #include #include "exceptions.h" #include "endianness.h" @@ -375,11 +373,7 @@ public: rhs.real_size_ = 0; } else { - std::copy( - rhs.data_ptr(), - rhs.data_ptr() + rhs.data_size(), - payload_.small_buffer - ); + std::memcpy(payload_.small_buffer, rhs.data_ptr(), rhs.data_size()); } return* this; } @@ -516,16 +510,12 @@ private: template void set_payload_contents(ForwardIterator start, ForwardIterator end) { size_t total_size = std::distance(start, end); - if (total_size > std::numeric_limits::max()) { + if (total_size > 65535) { throw option_payload_too_large(); } real_size_ = static_cast(total_size); if (real_size_ <= small_buffer_size) { - std::copy( - start, - end, - payload_.small_buffer - ); + std::memcpy(payload_.small_buffer, &*start, total_size); } else { payload_.big_buffer_ptr = new data_type[real_size_]; diff --git a/include/tins/utils.h b/include/tins/utils.h index 7beff5d..1ac877d 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -48,7 +48,7 @@ class NetworkInterface; class PacketSender; class PDU; class IPv6Address; -template +template class HWAddress; /** diff --git a/src/dhcp.cpp b/src/dhcp.cpp index fcd4eec..46dd78f 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -29,6 +29,7 @@ #include #include +#include #include "endianness.h" #include "dhcp.h" #include "ethernetII.h" diff --git a/src/handshake_capturer.cpp b/src/handshake_capturer.cpp index 80b0029..86aa726 100644 --- a/src/handshake_capturer.cpp +++ b/src/handshake_capturer.cpp @@ -31,6 +31,7 @@ #ifdef TINS_HAVE_DOT11 +#include #include "dot11/dot11_data.h" using std::max_element; diff --git a/src/icmpv6.cpp b/src/icmpv6.cpp index 78cb7f5..52475eb 100644 --- a/src/icmpv6.cpp +++ b/src/icmpv6.cpp @@ -28,6 +28,7 @@ */ #include +#include #include "icmpv6.h" #include "ipv6.h" #include "rawpdu.h" diff --git a/src/ip_address.cpp b/src/ip_address.cpp index f1a7d44..659f736 100644 --- a/src/ip_address.cpp +++ b/src/ip_address.cpp @@ -35,6 +35,7 @@ #endif // _WIN32 #include #include +#include #include "ip_address.h" #include "endianness.h" #include "address_range.h" diff --git a/src/ipv6_address.cpp b/src/ipv6_address.cpp index 3833df3..3d32128 100644 --- a/src/ipv6_address.cpp +++ b/src/ipv6_address.cpp @@ -27,7 +27,6 @@ * */ -#include #include "macros.h" #ifndef _WIN32 #include @@ -38,14 +37,17 @@ #include #include #endif +#include #include #include +#include #include "ipv6_address.h" #include "address_range.h" #include "exceptions.h" using std::fill; using std::string; +using std::ostream; namespace Tins { @@ -132,6 +134,10 @@ bool IPv6Address::is_multicast() const { return multicast_range.contains(*this); } +ostream& operator<<(ostream& os, const IPv6Address& addr) { + return os << addr.to_string(); +} + IPv6Address operator&(const IPv6Address& lhs, const IPv6Address& rhs) { IPv6Address output = lhs; IPv6Address::iterator addr_iter = output.begin(); From 07f000f65aad01ae5b6305d4775f6689c348deb5 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 09:36:50 -0700 Subject: [PATCH 10/73] Move type traits into a separate file --- include/tins/detail/type_traits.h | 83 +++++++++++++++++++++++++++++++ include/tins/internals.h | 36 +------------- include/tins/utils.h | 3 +- src/icmp.cpp | 1 + src/utils.cpp | 1 + 5 files changed, 88 insertions(+), 36 deletions(-) create mode 100644 include/tins/detail/type_traits.h diff --git a/include/tins/detail/type_traits.h b/include/tins/detail/type_traits.h new file mode 100644 index 0000000..c2bfb38 --- /dev/null +++ b/include/tins/detail/type_traits.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_TYPE_TRAITS_H +#define TINS_TYPE_TRAITS_H + +#include + +namespace Tins { +namespace Internals { +/** + * \cond + */ + +template +struct enable_if { + typedef T type; +}; + +template +struct enable_if { + +}; + +template +struct is_unsigned_integral { + static const bool value = false; +}; + +template<> +struct is_unsigned_integral { + static const bool value = true; +}; + +template<> +struct is_unsigned_integral { + static const bool value = true; +}; + +template<> +struct is_unsigned_integral { + static const bool value = true; +}; + +template<> +struct is_unsigned_integral { + static const bool value = true; +}; + +/** + * \endcond + */ + +} // Internals +} // Tins + +#endif // TINS_TYPE_TRAITS_H diff --git a/include/tins/internals.h b/include/tins/internals.h index 17f4cc4..a4304e5 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -39,6 +39,7 @@ #include "pdu.h" #include "hw_address.h" #include "macros.h" +#include "detail/type_traits.h" /** * \cond @@ -109,16 +110,6 @@ void skip_line(std::istream& input); bool from_hex(const std::string& str, uint32_t& result); bool from_hex(const std::string& str, std::string& result); -template -struct enable_if { - typedef T type; -}; - -template -struct enable_if { - -}; - 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, @@ -199,31 +190,6 @@ inline bool is_dot3(const uint8_t* ptr, size_t sz) { return (sz >= 13 && ptr[12] < 8); } -template -struct is_unsigned_integral { - static const bool value = false; -}; - -template<> -struct is_unsigned_integral { - static const bool value = true; -}; - -template<> -struct is_unsigned_integral { - static const bool value = true; -}; - -template<> -struct is_unsigned_integral { - static const bool value = true; -}; - -template<> -struct is_unsigned_integral { - static const bool value = true; -}; - #if TINS_IS_CXX11 && !defined(_MSC_VER) // Template metaprogramming trait to determine if a functor can accept another parameter as an argument diff --git a/include/tins/utils.h b/include/tins/utils.h index 1ac877d..0e9c341 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -37,7 +37,8 @@ #include #include "ip_address.h" #include "ipv6_address.h" -#include "internals.h" +#include "pdu.h" +#include "detail/type_traits.h" // Fix for Windows interface define on combaseapi.h #undef interface diff --git a/src/icmp.cpp b/src/icmp.cpp index 8695ccb..3404c77 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -36,6 +36,7 @@ #include "utils.h" #include "exceptions.h" #include "icmp.h" +#include "internals.h" #include "memory_helpers.h" using std::memset; diff --git a/src/utils.cpp b/src/utils.cpp index c849e17..3a6e0b9 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -68,6 +68,7 @@ #include "cxxstd.h" #include "hw_address.h" #include "memory_helpers.h" +#include "internals.h" #include "detail/smart_ptr.h" using std::string; From 730e69463c105e8d7f1e0633370d370069a47768 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 09:40:40 -0700 Subject: [PATCH 11/73] Include detail/type_traits.h rather than internals.h on pdu_option --- include/tins/pdu_option.h | 2 +- src/crypto.cpp | 1 + src/icmpv6.cpp | 1 + src/ip.cpp | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/tins/pdu_option.h b/include/tins/pdu_option.h index dc1ecdd..efb45a6 100644 --- a/include/tins/pdu_option.h +++ b/include/tins/pdu_option.h @@ -37,10 +37,10 @@ #include #include "exceptions.h" #include "endianness.h" -#include "internals.h" #include "ip_address.h" #include "ipv6_address.h" #include "hw_address.h" +#include "detail/type_traits.h" namespace Tins { /** diff --git a/src/crypto.cpp b/src/crypto.cpp index eafcf4b..9ffd2c1 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -38,6 +38,7 @@ #endif // TINS_HAVE_WPA2_DECRYPTION #include "dot11/dot11_data.h" #include "dot11/dot11_beacon.h" +#include "internals.h" #include "exceptions.h" using std::string; diff --git a/src/icmpv6.cpp b/src/icmpv6.cpp index 52475eb..7426efd 100644 --- a/src/icmpv6.cpp +++ b/src/icmpv6.cpp @@ -36,6 +36,7 @@ #include "constants.h" #include "exceptions.h" #include "memory_helpers.h" +#include "internals.h" using std::memset; using std::vector; diff --git a/src/ip.cpp b/src/ip.cpp index ded12e5..3bcbdb3 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -46,6 +46,7 @@ #include "exceptions.h" #include "pdu_allocator.h" #include "memory_helpers.h" +#include "internals.h" using std::list; using std::min; From 92bda42ac1fdae2b570cfa0817c274d39a242800 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 09:45:06 -0700 Subject: [PATCH 12/73] Move sniffer callback traits into detail/type_traits.h --- include/tins/detail/type_traits.h | 38 +++++++++++++++++++++++++++++++ include/tins/internals.h | 33 --------------------------- include/tins/sniffer.h | 2 +- src/sniffer.cpp | 1 + 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/include/tins/detail/type_traits.h b/include/tins/detail/type_traits.h index c2bfb38..23aebf8 100644 --- a/include/tins/detail/type_traits.h +++ b/include/tins/detail/type_traits.h @@ -31,6 +31,10 @@ #define TINS_TYPE_TRAITS_H #include +#include "cxxstd.h" +#if TINS_IS_CXX11 + #include +#endif namespace Tins { namespace Internals { @@ -73,6 +77,40 @@ struct is_unsigned_integral { static const bool value = true; }; +#if TINS_IS_CXX11 && !defined(_MSC_VER) + +// Template metaprogramming trait to determine if a functor can accept another parameter as an argument +template +struct accepts_type : std::false_type { }; + +template +struct accepts_type()(std::declval

()) ), bool>::value + >::type +> : std::true_type { }; + +// use enable_if to invoke the Packet&& version of the sniff_loop handler if possible - otherwise fail to old behavior +template +bool invoke_loop_cb(Functor& f, Packet& p, + typename std::enable_if::value, bool>::type* = 0) { + return f(std::move(p)); +} + +template +bool invoke_loop_cb(Functor& f, Packet& p, + typename std::enable_if::value && accepts_type::value, bool>::type* = 0) { + return f(p); +} + +template +bool invoke_loop_cb(Functor& f, Packet& p, + typename std::enable_if::value && !accepts_type::value, bool>::type* = 0) { + return f(*p.pdu()); +} + +#endif + /** * \endcond */ diff --git a/include/tins/internals.h b/include/tins/internals.h index a4304e5..38c75ca 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -30,9 +30,6 @@ #ifndef TINS_INTERNALS_H #define TINS_INTERNALS_H -#if TINS_IS_CXX11 -#include -#endif #include #include #include "constants.h" @@ -190,36 +187,6 @@ inline bool is_dot3(const uint8_t* ptr, size_t sz) { return (sz >= 13 && ptr[12] < 8); } -#if TINS_IS_CXX11 && !defined(_MSC_VER) - -// Template metaprogramming trait to determine if a functor can accept another parameter as an argument -template -struct accepts_type : std::false_type { }; - -template -struct accepts_type()(std::declval

()) ), bool>::value - >::type -> : std::true_type { }; - -// use enable_if to invoke the Packet&& version of the sniff_loop handler if possible - otherwise fail to old behavior -template -bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if::value, bool>::type* = 0) { - return f(std::move(p)); -} - -template -bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if::value && accepts_type::value, bool>::type* = 0) { - return f(p); -} - -template -bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if::value && !accepts_type::value, bool>::type* = 0) { - return f(*p.pdu()); -} -#endif - } // namespace Internals } // namespace Tins /** diff --git a/include/tins/sniffer.h b/include/tins/sniffer.h index a3c7144..2cd2ec0 100644 --- a/include/tins/sniffer.h +++ b/include/tins/sniffer.h @@ -40,7 +40,7 @@ #include "cxxstd.h" #include "macros.h" #include "exceptions.h" -#include "internals.h" +#include "detail/type_traits.h" #ifdef TINS_HAVE_PCAP diff --git a/src/sniffer.cpp b/src/sniffer.cpp index 68bbe44..2b95872 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -45,6 +45,7 @@ #include "pktap.h" #include "sll.h" #include "ppi.h" +#include "internals.h" using std::string; using std::runtime_error; From ab517873237bdeb3e16d241c93c28817277fecf2 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 09:53:11 -0700 Subject: [PATCH 13/73] Move Internals::byte_array into crypto.cpp --- include/tins/internals.h | 51 ---------------------------------------- src/crypto.cpp | 47 +++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 52 deletions(-) diff --git a/include/tins/internals.h b/include/tins/internals.h index 38c75ca..f2d30f2 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -52,57 +52,6 @@ class ICMPExtensionsStructure; namespace Internals { -template -class byte_array { -public: - typedef uint8_t* iterator; - typedef const uint8_t* const_iterator; - - byte_array() { - std::fill(begin(), end(), 0); - } - - template - byte_array(InputIterator start, InputIterator last) { - std::copy(start, last, data); - } - - template - byte_array(InputIterator start) { - std::copy(start, n, data); - } - - uint8_t& operator[](size_t i) { - return data[i]; - } - - uint8_t operator[](size_t i) const{ - return data[i]; - } - - iterator begin() { - return data; - } - - iterator end() { - return data + n; - } - - const_iterator begin() const { - return data; - } - - const_iterator end() const { - return data + n; - } - - size_t size() const { - return n; - } -private: - uint8_t data[n]; -}; - void skip_line(std::istream& input); bool from_hex(const std::string& str, uint32_t& result); bool from_hex(const std::string& str, std::string& result); diff --git a/src/crypto.cpp b/src/crypto.cpp index 9ffd2c1..4bf3071 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -38,8 +38,8 @@ #endif // TINS_HAVE_WPA2_DECRYPTION #include "dot11/dot11_data.h" #include "dot11/dot11_beacon.h" -#include "internals.h" #include "exceptions.h" +#include "detail/type_traits.h" using std::string; using std::make_pair; @@ -52,6 +52,51 @@ using std::fill; using std::runtime_error; namespace Tins { +namespace Internals { + +template +class byte_array { +public: + typedef uint8_t* iterator; + typedef const uint8_t* const_iterator; + + byte_array() { + std::memset(data, 0, size()); + } + + uint8_t& operator[](size_t i) { + return data[i]; + } + + uint8_t operator[](size_t i) const{ + return data[i]; + } + + iterator begin() { + return data; + } + + iterator end() { + return data + n; + } + + const_iterator begin() const { + return data; + } + + const_iterator end() const { + return data + n; + } + + size_t size() const { + return n; + } +private: + uint8_t data[n]; +}; + +} // Internals + namespace Crypto { WEPDecrypter::WEPDecrypter() From 28fa1b2f7ebbf16a031fe712d1f34b1bc17a5ebc Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 10:11:04 -0700 Subject: [PATCH 14/73] Move internal crypto stuff from the header into the source file --- include/tins/crypto.h | 73 +-------- src/crypto.cpp | 353 ++++++++++++++++++++++++------------------ 2 files changed, 201 insertions(+), 225 deletions(-) diff --git a/include/tins/crypto.h b/include/tins/crypto.h index 4207f9d..fd9c299 100644 --- a/include/tins/crypto.h +++ b/include/tins/crypto.h @@ -34,14 +34,10 @@ #include #include -#include #include #ifdef TINS_HAVE_WPA2_CALLBACKS #include #endif // TINS_HAVE_WPA2_CALLBACKS -#include "utils.h" -#include "snap.h" -#include "rawpdu.h" #include "macros.h" #include "handshake_capturer.h" @@ -50,11 +46,11 @@ namespace Tins { class PDU; class Dot11; class Dot11Data; +class SNAP; +class RawPDU; namespace Crypto { -struct RC4Key; - #ifdef TINS_HAVE_WPA2_DECRYPTION namespace WPA2 { @@ -131,7 +127,6 @@ public: private: SNAP* ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) const; SNAP* tkip_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) const; - RC4Key generate_rc4_key(const Dot11Data& dot11, const RawPDU& raw) const; ptk_type ptk_; bool is_ccmp_; @@ -177,27 +172,6 @@ private: } // WPA2 #endif // TINS_HAVE_WPA2_DECRYPTION -/** - * \brief RC4 Key abstraction. - */ -struct RC4Key { - static const size_t data_size = 256; - - /** - * \brief Initializes the key using the provided iterator range. - * - * \param start The start of the range. - * \param end The end of the range. - */ - template - RC4Key(ForwardIterator start, ForwardIterator end); - - /** - * The actual key data. - */ - uint8_t data[data_size]; -}; - /** * \brief Decrypts WEP-encrypted traffic. */ @@ -499,20 +473,6 @@ private: decrypter_type decrypter_; }; -/** - * \brief Performs RC4 encription/decryption of the given byte range, - * using the provided key. - * - * The decrypted range will be copied to the OutputIterator provided. - * - * \param start The beginning of the range. - * \param start The end of the range. - * \param key The key to be used. - * \param output The iterator in which to write the output. - */ -template -void rc4(ForwardIterator start, ForwardIterator end, RC4Key& key, OutputIterator output); - /** * \brief Wrapper function to create a DecrypterProxy using a * WEPDecrypter as the Decrypter template parameter. @@ -570,35 +530,6 @@ DecrypterProxy make_wep_decrypter_proxy(const Functor& fu return DecrypterProxy(functor); } -// RC4 stuff - -template -RC4Key::RC4Key(ForwardIterator start, ForwardIterator end) { - for (size_t i = 0; i < data_size; ++i) { - data[i] = static_cast(i); - } - size_t j = 0; - ForwardIterator iter = start; - for (size_t i = 0; i < data_size; ++i) { - j = (j + data[i] + *iter++) % 256; - if(iter == end) { - iter = start; - } - std::swap(data[i], data[j]); - } -} - -template -void rc4(ForwardIterator start, ForwardIterator end, RC4Key& key, OutputIterator output) { - size_t i = 0, j = 0; - while (start != end) { - i = (i + 1) % RC4Key::data_size; - j = (j + key.data[i]) % RC4Key::data_size; - std::swap(key.data[i], key.data[j]); - *output++ = *start++ ^ key.data[(key.data[i] + key.data[j]) % RC4Key::data_size]; - } -} - } // Crypto } // Tins diff --git a/src/crypto.cpp b/src/crypto.cpp index 4bf3071..a3a9d9b 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -31,17 +31,22 @@ #ifdef TINS_HAVE_DOT11 +#include #ifdef TINS_HAVE_WPA2_DECRYPTION #include #include #include #endif // TINS_HAVE_WPA2_DECRYPTION +#include "snap.h" +#include "rawpdu.h" #include "dot11/dot11_data.h" #include "dot11/dot11_beacon.h" #include "exceptions.h" +#include "utils.h" #include "detail/type_traits.h" using std::string; +using std::vector; using std::make_pair; using std::equal; using std::copy; @@ -99,95 +104,7 @@ private: namespace Crypto { -WEPDecrypter::WEPDecrypter() -: key_buffer_(4) { - -} - -void WEPDecrypter::add_password(const address_type& addr, const string& password) { - passwords_[addr] = password; - key_buffer_.resize(max(3 + password.size(), key_buffer_.size())); -} - -void WEPDecrypter::remove_password(const address_type& addr) { - passwords_.erase(addr); -} - -bool WEPDecrypter::decrypt(PDU& pdu) { - Dot11Data* dot11 = pdu.find_pdu(); - if (dot11) { - RawPDU* raw = dot11->find_pdu(); - if (raw) { - address_type addr; - if (!dot11->from_ds() && !dot11->to_ds()) { - addr = dot11->addr3(); - } - else if (!dot11->from_ds() && dot11->to_ds()) { - addr = dot11->addr1(); - } - else if (dot11->from_ds() && !dot11->to_ds()) { - addr = dot11->addr2(); - } - else { - // ???? - addr = dot11->addr3(); - } - passwords_type::iterator it = passwords_.find(addr); - if (it != passwords_.end()) { - dot11->inner_pdu(decrypt(*raw, it->second)); - // If its valid, then return true - if (dot11->inner_pdu()) { - // it's no longer encrypted. - dot11->wep(0); - return true; - } - } - } - } - return false; -} - -PDU* WEPDecrypter::decrypt(RawPDU& raw, const string& password) { - RawPDU::payload_type& pload = raw.payload(); - // We require at least the IV, the encrypted checksum and something to decrypt - if (pload.size() <= 8) { - return 0; - } - copy(pload.begin(), pload.begin() + 3, key_buffer_.begin()); - copy(password.begin(), password.end(), key_buffer_.begin() + 3); - - // Generate the key - RC4Key key(key_buffer_.begin(), key_buffer_.begin() + password.size() + 3); - rc4(pload.begin() + 4, pload.end(), key, pload.begin()); - uint32_t payload_size = static_cast(pload.size() - 8); - uint32_t crc = Utils::crc32(&pload[0], payload_size); - if (pload[pload.size() - 8] != (crc & 0xff) || - pload[pload.size() - 7] != ((crc >> 8) & 0xff) || - pload[pload.size() - 6] != ((crc >> 16) & 0xff) || - pload[pload.size() - 5] != ((crc >> 24) & 0xff)) { - return 0; - } - - try { - return new SNAP(&pload[0], payload_size); - } - catch (exception_base&) { - return 0; - } -} - -#ifdef TINS_HAVE_WPA2_DECRYPTION -// WPA2Decrypter - -using WPA2::SessionKeys; - -const HWAddress<6>& min(const HWAddress<6>& lhs, const HWAddress<6>& rhs) { - return lhs < rhs ? lhs : rhs; -} - -const HWAddress<6>& max(const HWAddress<6>& lhs, const HWAddress<6>& rhs) { - return lhs < rhs ? rhs : lhs; -} +// Helper stuff template void xor_range(InputIterator1 src1, InputIterator2 src2, OutputIterator dst, size_t sz) { @@ -287,6 +204,198 @@ uint16_t lower_byte(uint16_t value) { return value & 0xff; } +// RC4 classes/functions + +struct RC4Key { + static const size_t data_size = 256; + + template + RC4Key(ForwardIterator start, ForwardIterator end) { + for (size_t i = 0; i < data_size; ++i) { + data[i] = static_cast(i); + } + size_t j = 0; + ForwardIterator iter = start; + for (size_t i = 0; i < data_size; ++i) { + j = (j + data[i] + *iter++) % 256; + if(iter == end) { + iter = start; + } + std::swap(data[i], data[j]); + } + } + + static RC4Key from_packet(const Dot11Data& dot11, const RawPDU& raw, + const vector& ptk) { + const RawPDU::payload_type& pload = raw.payload(); + const uint8_t* tk = &ptk[0] + 32; + Internals::byte_array<16> rc4_key; + uint16_t ppk[6]; + const Dot11::address_type addr = dot11.addr2(); + // Phase 1 + ppk[0] = join_bytes(pload[4], pload[5]); + ppk[1] = join_bytes(pload[6], pload[7]); + ppk[2] = join_bytes(addr[1], addr[0]); + ppk[3] = join_bytes(addr[3], addr[2]); + ppk[4] = join_bytes(addr[5], addr[4]); + + for (size_t i = 0; i < 4; ++i) { + ppk[0] += sbox(ppk[4] ^ join_bytes(tk[1], tk[0])); + ppk[1] += sbox(ppk[0] ^ join_bytes(tk[5], tk[4])); + ppk[2] += sbox(ppk[1] ^ join_bytes(tk[9], tk[8])); + ppk[3] += sbox(ppk[2] ^ join_bytes(tk[13], tk[12])); + ppk[4] += sbox(ppk[3] ^ join_bytes(tk[1], tk[0])) + 2*i; + ppk[0] += sbox(ppk[4] ^ join_bytes(tk[3], tk[2])); + ppk[1] += sbox(ppk[0] ^ join_bytes(tk[7], tk[6])); + ppk[2] += sbox(ppk[1] ^ join_bytes(tk[11], tk[10])); + ppk[3] += sbox(ppk[2] ^ join_bytes(tk[15], tk[14])); + ppk[4] += sbox(ppk[3] ^ join_bytes(tk[3], tk[2])) + 2*i + 1; + } + + // Phase 2, step 1 + ppk[5] = ppk[4] + join_bytes(pload[0], pload[2]); + + // Phase 2, step 2 + ppk[0] += sbox(ppk[5] ^ join_bytes(tk[1], tk[0])); + ppk[1] += sbox(ppk[0] ^ join_bytes(tk[3], tk[2])); + ppk[2] += sbox(ppk[1] ^ join_bytes(tk[5], tk[4])); + ppk[3] += sbox(ppk[2] ^ join_bytes(tk[7], tk[6])); + ppk[4] += sbox(ppk[3] ^ join_bytes(tk[9], tk[8])); + ppk[5] += sbox(ppk[4] ^ join_bytes(tk[11], tk[10])); + + ppk[0] += rotate(ppk[5] ^ join_bytes(tk[13], tk[12])); + ppk[1] += rotate(ppk[0] ^ join_bytes(tk[15], tk[14])); + ppk[2] += rotate(ppk[1]); + ppk[3] += rotate(ppk[2]); + ppk[4] += rotate(ppk[3]); + ppk[5] += rotate(ppk[4]); + + // Phase 2, step 3 + rc4_key[0] = upper_byte(join_bytes(pload[0], pload[2])); + rc4_key[1] = (rc4_key[0] | 0x20) & 0x7f; + rc4_key[2] = lower_byte(join_bytes(pload[0], pload[2])); + rc4_key[3] = lower_byte((ppk[5] ^ join_bytes(tk[1], tk[0])) >> 1); + rc4_key[4] = lower_byte(ppk[0]); + rc4_key[5] = upper_byte(ppk[0]); + rc4_key[6] = lower_byte(ppk[1]); + rc4_key[7] = upper_byte(ppk[1]); + rc4_key[8] = lower_byte(ppk[2]); + rc4_key[9] = upper_byte(ppk[2]); + rc4_key[10] = lower_byte(ppk[3]); + rc4_key[11] = upper_byte(ppk[3]); + rc4_key[12] = lower_byte(ppk[4]); + rc4_key[13] = upper_byte(ppk[4]); + rc4_key[14] = lower_byte(ppk[5]); + rc4_key[15] = upper_byte(ppk[5]); + return RC4Key(rc4_key.begin(), rc4_key.end()); + } + + uint8_t data[data_size]; +}; + +template +void rc4(ForwardIterator start, ForwardIterator end, RC4Key& key, OutputIterator output) { + size_t i = 0, j = 0; + while (start != end) { + i = (i + 1) % RC4Key::data_size; + j = (j + key.data[i]) % RC4Key::data_size; + std::swap(key.data[i], key.data[j]); + *output++ = *start++ ^ key.data[(key.data[i] + key.data[j]) % RC4Key::data_size]; + } +} + +// WEPDecrypter + +WEPDecrypter::WEPDecrypter() +: key_buffer_(4) { + +} + +void WEPDecrypter::add_password(const address_type& addr, const string& password) { + passwords_[addr] = password; + key_buffer_.resize(max(3 + password.size(), key_buffer_.size())); +} + +void WEPDecrypter::remove_password(const address_type& addr) { + passwords_.erase(addr); +} + +bool WEPDecrypter::decrypt(PDU& pdu) { + Dot11Data* dot11 = pdu.find_pdu(); + if (dot11) { + RawPDU* raw = dot11->find_pdu(); + if (raw) { + address_type addr; + if (!dot11->from_ds() && !dot11->to_ds()) { + addr = dot11->addr3(); + } + else if (!dot11->from_ds() && dot11->to_ds()) { + addr = dot11->addr1(); + } + else if (dot11->from_ds() && !dot11->to_ds()) { + addr = dot11->addr2(); + } + else { + // ???? + addr = dot11->addr3(); + } + passwords_type::iterator it = passwords_.find(addr); + if (it != passwords_.end()) { + dot11->inner_pdu(decrypt(*raw, it->second)); + // If its valid, then return true + if (dot11->inner_pdu()) { + // it's no longer encrypted. + dot11->wep(0); + return true; + } + } + } + } + return false; +} + +PDU* WEPDecrypter::decrypt(RawPDU& raw, const string& password) { + RawPDU::payload_type& pload = raw.payload(); + // We require at least the IV, the encrypted checksum and something to decrypt + if (pload.size() <= 8) { + return 0; + } + copy(pload.begin(), pload.begin() + 3, key_buffer_.begin()); + copy(password.begin(), password.end(), key_buffer_.begin() + 3); + + // Generate the key + RC4Key key(key_buffer_.begin(), key_buffer_.begin() + password.size() + 3); + rc4(pload.begin() + 4, pload.end(), key, pload.begin()); + uint32_t payload_size = static_cast(pload.size() - 8); + uint32_t crc = Utils::crc32(&pload[0], payload_size); + if (pload[pload.size() - 8] != (crc & 0xff) || + pload[pload.size() - 7] != ((crc >> 8) & 0xff) || + pload[pload.size() - 6] != ((crc >> 16) & 0xff) || + pload[pload.size() - 5] != ((crc >> 24) & 0xff)) { + return 0; + } + + try { + return new SNAP(&pload[0], payload_size); + } + catch (exception_base&) { + return 0; + } +} + +#ifdef TINS_HAVE_WPA2_DECRYPTION +// WPA2Decrypter + +using WPA2::SessionKeys; + +const HWAddress<6>& min(const HWAddress<6>& lhs, const HWAddress<6>& rhs) { + return lhs < rhs ? lhs : rhs; +} + +const HWAddress<6>& max(const HWAddress<6>& lhs, const HWAddress<6>& rhs) { + return lhs < rhs ? rhs : lhs; +} + HWAddress<6> get_bssid(const Dot11Data& dot11) { if (dot11.from_ds() && !dot11.to_ds()) { return dot11.addr3(); @@ -442,76 +551,12 @@ SNAP* SessionKeys::ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) con } } -RC4Key SessionKeys::generate_rc4_key(const Dot11Data& dot11, const RawPDU& raw) const { - const RawPDU::payload_type& pload = raw.payload(); - const uint8_t* tk = &ptk_[0] + 32; - Internals::byte_array<16> rc4_key; - uint16_t ppk[6]; - const Dot11::address_type addr = dot11.addr2(); - // Phase 1 - ppk[0] = join_bytes(pload[4], pload[5]); - ppk[1] = join_bytes(pload[6], pload[7]); - ppk[2] = join_bytes(addr[1], addr[0]); - ppk[3] = join_bytes(addr[3], addr[2]); - ppk[4] = join_bytes(addr[5], addr[4]); - - for (size_t i = 0; i < 4; ++i) { - ppk[0] += sbox(ppk[4] ^ join_bytes(tk[1], tk[0])); - ppk[1] += sbox(ppk[0] ^ join_bytes(tk[5], tk[4])); - ppk[2] += sbox(ppk[1] ^ join_bytes(tk[9], tk[8])); - ppk[3] += sbox(ppk[2] ^ join_bytes(tk[13], tk[12])); - ppk[4] += sbox(ppk[3] ^ join_bytes(tk[1], tk[0])) + 2*i; - ppk[0] += sbox(ppk[4] ^ join_bytes(tk[3], tk[2])); - ppk[1] += sbox(ppk[0] ^ join_bytes(tk[7], tk[6])); - ppk[2] += sbox(ppk[1] ^ join_bytes(tk[11], tk[10])); - ppk[3] += sbox(ppk[2] ^ join_bytes(tk[15], tk[14])); - ppk[4] += sbox(ppk[3] ^ join_bytes(tk[3], tk[2])) + 2*i + 1; - } - - // Phase 2, step 1 - ppk[5] = ppk[4] + join_bytes(pload[0], pload[2]); - - // Phase 2, step 2 - ppk[0] += sbox(ppk[5] ^ join_bytes(tk[1], tk[0])); - ppk[1] += sbox(ppk[0] ^ join_bytes(tk[3], tk[2])); - ppk[2] += sbox(ppk[1] ^ join_bytes(tk[5], tk[4])); - ppk[3] += sbox(ppk[2] ^ join_bytes(tk[7], tk[6])); - ppk[4] += sbox(ppk[3] ^ join_bytes(tk[9], tk[8])); - ppk[5] += sbox(ppk[4] ^ join_bytes(tk[11], tk[10])); - - ppk[0] += rotate(ppk[5] ^ join_bytes(tk[13], tk[12])); - ppk[1] += rotate(ppk[0] ^ join_bytes(tk[15], tk[14])); - ppk[2] += rotate(ppk[1]); - ppk[3] += rotate(ppk[2]); - ppk[4] += rotate(ppk[3]); - ppk[5] += rotate(ppk[4]); - - // Phase 2, step 3 - rc4_key[0] = upper_byte(join_bytes(pload[0], pload[2])); - rc4_key[1] = (rc4_key[0] | 0x20) & 0x7f; - rc4_key[2] = lower_byte(join_bytes(pload[0], pload[2])); - rc4_key[3] = lower_byte((ppk[5] ^ join_bytes(tk[1], tk[0])) >> 1); - rc4_key[4] = lower_byte(ppk[0]); - rc4_key[5] = upper_byte(ppk[0]); - rc4_key[6] = lower_byte(ppk[1]); - rc4_key[7] = upper_byte(ppk[1]); - rc4_key[8] = lower_byte(ppk[2]); - rc4_key[9] = upper_byte(ppk[2]); - rc4_key[10] = lower_byte(ppk[3]); - rc4_key[11] = upper_byte(ppk[3]); - rc4_key[12] = lower_byte(ppk[4]); - rc4_key[13] = upper_byte(ppk[4]); - rc4_key[14] = lower_byte(ppk[5]); - rc4_key[15] = upper_byte(ppk[5]); - return RC4Key(rc4_key.begin(), rc4_key.end()); -} - SNAP* SessionKeys::tkip_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) const { // at least 20 bytes for IV + crc + stuff if (raw.payload_size() <= 20) { return 0; } - Crypto::RC4Key key = generate_rc4_key(dot11, raw); + Crypto::RC4Key key = RC4Key::from_packet(dot11, raw, ptk_); RawPDU::payload_type& pload = raw.payload(); rc4(pload.begin() + 8, pload.end(), key, pload.begin()); From af325f00d9fc0454be4b3990dd32df24b4e09fe7 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 10:13:58 -0700 Subject: [PATCH 15/73] Move functions to parse /proc/net/routes into utils.cpp --- include/tins/internals.h | 4 ---- src/internals.cpp | 50 -------------------------------------- src/utils.cpp | 52 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 54 deletions(-) diff --git a/include/tins/internals.h b/include/tins/internals.h index f2d30f2..958780d 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -52,10 +52,6 @@ class ICMPExtensionsStructure; namespace Internals { -void skip_line(std::istream& input); -bool from_hex(const std::string& str, uint32_t& result); -bool from_hex(const std::string& str, std::string& result); - 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, diff --git a/src/internals.cpp b/src/internals.cpp index 7f9b384..4a70972 100644 --- a/src/internals.cpp +++ b/src/internals.cpp @@ -64,56 +64,6 @@ using Tins::Memory::InputMemoryStream; namespace Tins { namespace Internals { -bool from_hex(const string& str, uint32_t& result) { - size_t i = 0; - result = 0; - while (i < str.size()) { - uint8_t tmp; - if (str[i] >= 'A' && str[i] <= 'F') { - tmp = (str[i] - 'A' + 10); - } - else if (str[i] >= '0' && str[i] <= '9') { - tmp = (str[i] - '0'); - } - else { - return false; - } - result = (result << 4) | tmp; - i++; - } - return true; -} - -bool from_hex(const string& str, string& result) { - result = ""; - for (size_t i = 0; i < str.size(); i+= 2) { - uint8_t value = 0; - for (size_t j = i; j < i + 2 && j < str.size(); ++j) { - if (str[j] >= 'A' && str[j] <= 'F') { - value = (value << 4) | (str[j] - 'A' + 10); - } - else if (str[j] >= 'a' && str[j] <= 'f') { - value = (value << 4) | (str[j] - 'a' + 10); - } - else if (str[j] >= '0' && str[j] <= '9') { - value = (value << 4) | (str[j] - '0'); - } - else { - return false; - } - } - result.push_back(value); - } - return true; -} - -void skip_line(std::istream& input) { - int c = 0; - while (c != '\n' && input) { - c = input.get(); - } -} - Tins::PDU* pdu_from_flag(Constants::Ethernet::e flag, const uint8_t* buffer, uint32_t size, diff --git a/src/utils.cpp b/src/utils.cpp index 3a6e0b9..8645607 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -72,6 +72,7 @@ #include "detail/smart_ptr.h" using std::string; +using std::istream; using std::set; using std::ifstream; using std::vector; @@ -82,6 +83,57 @@ using Tins::Memory::InputMemoryStream; using Tins::Memory::OutputMemoryStream; /** \cond */ + +bool from_hex(const string& str, uint32_t& result) { + size_t i = 0; + result = 0; + while (i < str.size()) { + uint8_t tmp; + if (str[i] >= 'A' && str[i] <= 'F') { + tmp = (str[i] - 'A' + 10); + } + else if (str[i] >= '0' && str[i] <= '9') { + tmp = (str[i] - '0'); + } + else { + return false; + } + result = (result << 4) | tmp; + i++; + } + return true; +} + +bool from_hex(const string& str, string& result) { + result.clear(); + for (size_t i = 0; i < str.size(); i+= 2) { + uint8_t value = 0; + for (size_t j = i; j < i + 2 && j < str.size(); ++j) { + if (str[j] >= 'A' && str[j] <= 'F') { + value = (value << 4) | (str[j] - 'A' + 10); + } + else if (str[j] >= 'a' && str[j] <= 'f') { + value = (value << 4) | (str[j] - 'a' + 10); + } + else if (str[j] >= '0' && str[j] <= '9') { + value = (value << 4) | (str[j] - '0'); + } + else { + return false; + } + } + result.push_back(value); + } + return true; +} + +void skip_line(istream& input) { + int c = 0; + while (c != '\n' && input) { + c = input.get(); + } +} + struct InterfaceCollector { set ifaces; From ac6927867638bf4e542cf97a58114a661d8f4818 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 10:21:26 -0700 Subject: [PATCH 16/73] Move helpers for address types in internals.h to their own header --- include/tins/address_range.h | 2 +- include/tins/detail/address_helpers.h | 106 ++++++++++++++++++++++++++ include/tins/internals.h | 54 ------------- src/CMakeLists.txt | 1 + src/detail/address_helpers.cpp | 78 +++++++++++++++++++ src/internals.cpp | 36 --------- src/ip_address.cpp | 1 + 7 files changed, 187 insertions(+), 91 deletions(-) create mode 100644 include/tins/detail/address_helpers.h create mode 100644 src/detail/address_helpers.cpp diff --git a/include/tins/address_range.h b/include/tins/address_range.h index fb10cf6..89a753a 100644 --- a/include/tins/address_range.h +++ b/include/tins/address_range.h @@ -33,7 +33,7 @@ #include #include #include "endianness.h" -#include "internals.h" +#include "detail/address_helpers.h" namespace Tins { /** diff --git a/include/tins/detail/address_helpers.h b/include/tins/detail/address_helpers.h new file mode 100644 index 0000000..4a8f4be --- /dev/null +++ b/include/tins/detail/address_helpers.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_ADDRESS_HELPERS_H +#define TINS_ADDRESS_HELPERS_H + +#include "hw_address.h" + +/** + * \cond + */ +namespace Tins { + +class IPv4Address; +class IPv6Address; + +namespace Internals { + +template +bool increment_buffer(T& addr) { + typename T::iterator it = addr.end() - 1; + while (it >= addr.begin() && *it == 0xff) { + *it = 0; + --it; + } + // reached end + if (it < addr.begin()) { + return true; + } + (*it)++; + return false; +} + +template +bool decrement_buffer(T& addr) { + typename T::iterator it = addr.end() - 1; + while (it >= addr.begin() && *it == 0) { + *it = 0xff; + --it; + } + // reached end + if (it < addr.begin()) { + return true; + } + (*it)--; + return false; +} + +bool increment(IPv4Address& addr); +bool increment(IPv6Address& addr); +bool decrement(IPv4Address& addr); +bool decrement(IPv6Address& addr); +template +bool increment(HWAddress& addr) { + return increment_buffer(addr); +} +template +bool decrement(HWAddress& addr) { + return decrement_buffer(addr); +} + +IPv4Address last_address_from_mask(IPv4Address addr, IPv4Address mask); +IPv6Address last_address_from_mask(IPv6Address addr, const IPv6Address& mask); +template +HWAddress last_address_from_mask(HWAddress addr, const HWAddress& mask) { + typename HWAddress::iterator addr_iter = addr.begin(); + for (typename HWAddress::const_iterator it = mask.begin(); it != mask.end(); ++it, ++addr_iter) { + *addr_iter = *addr_iter | ~*it; + } + return addr; +} + +} // Internals +} // Tins + +/** + * \endcond + */ + +#endif // TINS_ADDRESS_HELPERS_H diff --git a/include/tins/internals.h b/include/tins/internals.h index 958780d..6540e1f 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -71,63 +71,9 @@ uint32_t get_padded_icmp_inner_pdu_size(const PDU* inner_pdu, uint32_t pad_align void try_parse_icmp_extensions(Memory::InputMemoryStream& stream, uint32_t payload_length, ICMPExtensionsStructure& extensions); -template -bool increment_buffer(T& addr) { - typename T::iterator it = addr.end() - 1; - while (it >= addr.begin() && *it == 0xff) { - *it = 0; - --it; - } - // reached end - if (it < addr.begin()) { - return true; - } - (*it)++; - return false; -} - -template -bool decrement_buffer(T& addr) { - typename T::iterator it = addr.end() - 1; - while (it >= addr.begin() && *it == 0) { - *it = 0xff; - --it; - } - // reached end - if (it < addr.begin()) { - return true; - } - (*it)--; - return false; -} - -bool increment(IPv4Address& addr); -bool increment(IPv6Address& addr); -bool decrement(IPv4Address& addr); -bool decrement(IPv6Address& addr); -template -bool increment(HWAddress& addr) { - return increment_buffer(addr); -} -template -bool decrement(HWAddress& addr) { - return decrement_buffer(addr); -} - // Compares sequence numbers as defined by RFC 1982. int seq_compare(uint32_t seq1, uint32_t seq2); -IPv4Address last_address_from_mask(IPv4Address addr, IPv4Address mask); -IPv6Address last_address_from_mask(IPv6Address addr, const IPv6Address& mask); -template -HWAddress last_address_from_mask(HWAddress addr, const HWAddress& mask) { - typename HWAddress::iterator addr_iter = addr.begin(); - for (typename HWAddress::const_iterator it = mask.begin(); it != mask.end(); ++it, ++addr_iter) { - *addr_iter = *addr_iter | ~*it; - } - return addr; -} - inline bool is_dot3(const uint8_t* ptr, size_t sz) { return (sz >= 13 && ptr[12] < 8); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04d069b..791aad7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ set(SOURCES stp.cpp pppoe.cpp crypto.cpp + detail/address_helpers.cpp dhcp.cpp dhcpv6.cpp dns.cpp diff --git a/src/detail/address_helpers.cpp b/src/detail/address_helpers.cpp new file mode 100644 index 0000000..2d58011 --- /dev/null +++ b/src/detail/address_helpers.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "ip_address.h" +#include "ipv6_address.h" +#include "endianness.h" +#include "detail/address_helpers.h" + +using Tins::IPv4Address; +using Tins::IPv6Address; + +namespace Tins { +namespace Internals { + +bool increment(IPv4Address &addr) { + uint32_t addr_int = Endian::be_to_host(addr); + bool reached_end = ++addr_int == 0xffffffff; + addr = IPv4Address(Endian::be_to_host(addr_int)); + return reached_end; +} + +bool increment(IPv6Address& addr) { + return increment_buffer(addr); +} + +bool decrement(IPv4Address& addr) { + uint32_t addr_int = Endian::be_to_host(addr); + bool reached_end = --addr_int == 0; + addr = IPv4Address(Endian::be_to_host(addr_int)); + return reached_end; +} + +bool decrement(IPv6Address& addr) { + return decrement_buffer(addr); +} + +IPv4Address last_address_from_mask(IPv4Address addr, IPv4Address mask) { + uint32_t addr_int = Endian::be_to_host(addr), + mask_int = Endian::be_to_host(mask); + return IPv4Address(Endian::host_to_be(addr_int | ~mask_int)); +} + +IPv6Address last_address_from_mask(IPv6Address addr, const IPv6Address& mask) { + IPv6Address::iterator addr_iter = addr.begin(); + for (IPv6Address::const_iterator it = mask.begin(); it != mask.end(); ++it, ++addr_iter) { + *addr_iter = *addr_iter | ~*it; + } + return addr; +} + +} // Internals +} // Tins diff --git a/src/internals.cpp b/src/internals.cpp index 4a70972..f4122c6 100644 --- a/src/internals.cpp +++ b/src/internals.cpp @@ -347,28 +347,6 @@ PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag) { }; } -bool increment(IPv4Address &addr) { - uint32_t addr_int = Endian::be_to_host(addr); - bool reached_end = ++addr_int == 0xffffffff; - addr = IPv4Address(Endian::be_to_host(addr_int)); - return reached_end; -} - -bool increment(IPv6Address& addr) { - return increment_buffer(addr); -} - -bool decrement(IPv4Address& addr) { - uint32_t addr_int = Endian::be_to_host(addr); - bool reached_end = --addr_int == 0; - addr = IPv4Address(Endian::be_to_host(addr_int)); - return reached_end; -} - -bool decrement(IPv6Address& addr) { - return decrement_buffer(addr); -} - int seq_compare(uint32_t seq1, uint32_t seq2) { // As defined by RFC 1982 - 2 ^ (SERIAL_BITS - 1) static const uint32_t seq_number_diff = 2147483648U; @@ -383,19 +361,5 @@ int seq_compare(uint32_t seq1, uint32_t seq2) { } } -IPv4Address last_address_from_mask(IPv4Address addr, IPv4Address mask) { - uint32_t addr_int = Endian::be_to_host(addr), - mask_int = Endian::be_to_host(mask); - return IPv4Address(Endian::host_to_be(addr_int | ~mask_int)); -} - -IPv6Address last_address_from_mask(IPv6Address addr, const IPv6Address& mask) { - IPv6Address::iterator addr_iter = addr.begin(); - for (IPv6Address::const_iterator it = mask.begin(); it != mask.end(); ++it, ++addr_iter) { - *addr_iter = *addr_iter | ~*it; - } - return addr; -} - } // namespace Internals } // namespace Tins diff --git a/src/ip_address.cpp b/src/ip_address.cpp index 659f736..740ab4c 100644 --- a/src/ip_address.cpp +++ b/src/ip_address.cpp @@ -39,6 +39,7 @@ #include "ip_address.h" #include "endianness.h" #include "address_range.h" +#include "exceptions.h" using std::string; using std::ostringstream; From c50c4c105c6db886a602ae71f388f9b5f4110deb Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 10:30:55 -0700 Subject: [PATCH 17/73] Add relative includes on detail headers --- include/tins/detail/address_helpers.h | 2 +- include/tins/detail/type_traits.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/tins/detail/address_helpers.h b/include/tins/detail/address_helpers.h index 4a8f4be..587bba8 100644 --- a/include/tins/detail/address_helpers.h +++ b/include/tins/detail/address_helpers.h @@ -30,7 +30,7 @@ #ifndef TINS_ADDRESS_HELPERS_H #define TINS_ADDRESS_HELPERS_H -#include "hw_address.h" +#include "../hw_address.h" /** * \cond diff --git a/include/tins/detail/type_traits.h b/include/tins/detail/type_traits.h index 23aebf8..f133d5c 100644 --- a/include/tins/detail/type_traits.h +++ b/include/tins/detail/type_traits.h @@ -31,7 +31,7 @@ #define TINS_TYPE_TRAITS_H #include -#include "cxxstd.h" +#include "../cxxstd.h" #if TINS_IS_CXX11 #include #endif From 6f32a1982a079803b88bf9967228e14a36562ca0 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 10:31:11 -0700 Subject: [PATCH 18/73] Remove useless stdexcept includes --- include/tins/ipv6.h | 1 - include/tins/ipv6_address.h | 1 - include/tins/packet_sender.h | 1 - include/tins/packet_writer.h | 1 - include/tins/sniffer.h | 1 - include/tins/tcp.h | 1 - 6 files changed, 6 deletions(-) diff --git a/include/tins/ipv6.h b/include/tins/ipv6.h index 727bd2b..95d3e30 100644 --- a/include/tins/ipv6.h +++ b/include/tins/ipv6.h @@ -31,7 +31,6 @@ #define TINS_IPV6_h #include -#include #include "macros.h" #include "pdu.h" #include "endianness.h" diff --git a/include/tins/ipv6_address.h b/include/tins/ipv6_address.h index 87ba039..fcec9b3 100644 --- a/include/tins/ipv6_address.h +++ b/include/tins/ipv6_address.h @@ -31,7 +31,6 @@ #define TINS_IPV6_ADDRESS #include -#include #include #include #include "cxxstd.h" diff --git a/include/tins/packet_sender.h b/include/tins/packet_sender.h index 130a9b2..eb6b09c 100644 --- a/include/tins/packet_sender.h +++ b/include/tins/packet_sender.h @@ -32,7 +32,6 @@ #include -#include #include #include #include diff --git a/include/tins/packet_writer.h b/include/tins/packet_writer.h index ef9f2c9..79b7b8e 100644 --- a/include/tins/packet_writer.h +++ b/include/tins/packet_writer.h @@ -32,7 +32,6 @@ #include "utils.h" #include -#include #include "macros.h" #include "cxxstd.h" diff --git a/include/tins/sniffer.h b/include/tins/sniffer.h index 2cd2ec0..d0c8f11 100644 --- a/include/tins/sniffer.h +++ b/include/tins/sniffer.h @@ -33,7 +33,6 @@ #include #include -#include #include #include "pdu.h" #include "packet.h" diff --git a/include/tins/tcp.h b/include/tins/tcp.h index 0f11fa4..4f762d6 100644 --- a/include/tins/tcp.h +++ b/include/tins/tcp.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include "pdu.h" #include "macros.h" From 110adc58dc76ec346329e7ff43bf27ccb00cd96c Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 10:53:21 -0700 Subject: [PATCH 19/73] Move ICMP extension helpers into their own file --- include/tins/detail/icmp_extension_helpers.h | 61 ++++++++++++++ include/tins/internals.h | 4 - src/CMakeLists.txt | 1 + src/detail/icmp_extension_helpers.cpp | 86 ++++++++++++++++++++ src/icmp.cpp | 2 +- src/icmpv6.cpp | 2 +- src/internals.cpp | 45 ---------- 7 files changed, 150 insertions(+), 51 deletions(-) create mode 100644 include/tins/detail/icmp_extension_helpers.h create mode 100644 src/detail/icmp_extension_helpers.cpp diff --git a/include/tins/detail/icmp_extension_helpers.h b/include/tins/detail/icmp_extension_helpers.h new file mode 100644 index 0000000..cfd6bd1 --- /dev/null +++ b/include/tins/detail/icmp_extension_helpers.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_ICMP_EXTENSION_HELPERS_H +#define TINS_ICMP_EXTENSION_HELPERS_H + +#include + +/** + * \cond + */ +namespace Tins { + +class PDU; +class ICMPExtensionsStructure; + +namespace Memory { +class InputMemoryStream; +} // Memory + +namespace Internals { + +uint32_t get_padded_icmp_inner_pdu_size(const PDU* inner_pdu, uint32_t pad_alignment); +void try_parse_icmp_extensions(Memory::InputMemoryStream& stream, uint32_t payload_length, + ICMPExtensionsStructure& extensions); + + +} // Internals +} // Tins + +/** + * \endcond + */ + +#endif // TINS_ICMP_EXTENSION_HELPERS_H diff --git a/include/tins/internals.h b/include/tins/internals.h index 6540e1f..caddac4 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -67,10 +67,6 @@ PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag); Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag); PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag); -uint32_t get_padded_icmp_inner_pdu_size(const PDU* inner_pdu, uint32_t pad_alignment); -void try_parse_icmp_extensions(Memory::InputMemoryStream& stream, - uint32_t payload_length, ICMPExtensionsStructure& extensions); - // Compares sequence numbers as defined by RFC 1982. int seq_compare(uint32_t seq1, uint32_t seq2); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 791aad7..f340fb6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,7 @@ set(SOURCES pppoe.cpp crypto.cpp detail/address_helpers.cpp + detail/icmp_extension_helpers.cpp dhcp.cpp dhcpv6.cpp dns.cpp diff --git a/src/detail/icmp_extension_helpers.cpp b/src/detail/icmp_extension_helpers.cpp new file mode 100644 index 0000000..a2eea40 --- /dev/null +++ b/src/detail/icmp_extension_helpers.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "detail/icmp_extension_helpers.h" +#include "memory_helpers.h" +#include "pdu.h" +#include "icmp_extension.h" + +using Tins::Memory::InputMemoryStream; + +namespace Tins { +namespace Internals { + +uint32_t get_padded_icmp_inner_pdu_size(const PDU* inner_pdu, uint32_t pad_alignment) { + // This gets the size of the next pdu, padded to the next 32 bit word boundary + if (inner_pdu) { + uint32_t inner_pdu_size = inner_pdu->size(); + uint32_t padding = inner_pdu_size % pad_alignment; + inner_pdu_size = padding ? (inner_pdu_size - padding + pad_alignment) : inner_pdu_size; + return inner_pdu_size; + } + else { + return 0; + } +} + +void try_parse_icmp_extensions(InputMemoryStream& stream, + uint32_t payload_length, + ICMPExtensionsStructure& extensions) { + if (!stream) { + return; + } + // Check if this is one of the types defined in RFC 4884 + const uint32_t minimum_payload = ICMPExtensionsStructure::MINIMUM_ICMP_PAYLOAD; + // Check if we actually have this amount of data and whether it's more than + // the minimum encapsulated packet size + const uint8_t* extensions_ptr; + uint32_t extensions_size; + if (stream.can_read(payload_length) && payload_length >= minimum_payload) { + extensions_ptr = stream.pointer() + payload_length; + extensions_size = stream.size() - payload_length; + } + else if (stream.can_read(minimum_payload)) { + // This packet might be non-rfc compliant. In that case the length + // field can contain garbage. + extensions_ptr = stream.pointer() + minimum_payload; + extensions_size = stream.size() - minimum_payload; + } + else { + // No more special cases, this doesn't have extensions + return; + } + if (ICMPExtensionsStructure::validate_extensions(extensions_ptr, extensions_size)) { + extensions = ICMPExtensionsStructure(extensions_ptr, extensions_size); + stream.size(stream.size() - extensions_size); + } +} + +} // Internals +} // Tins diff --git a/src/icmp.cpp b/src/icmp.cpp index 3404c77..419399f 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -36,8 +36,8 @@ #include "utils.h" #include "exceptions.h" #include "icmp.h" -#include "internals.h" #include "memory_helpers.h" +#include "detail/icmp_extension_helpers.h" using std::memset; using std::max; diff --git a/src/icmpv6.cpp b/src/icmpv6.cpp index 7426efd..d503eb6 100644 --- a/src/icmpv6.cpp +++ b/src/icmpv6.cpp @@ -36,7 +36,7 @@ #include "constants.h" #include "exceptions.h" #include "memory_helpers.h" -#include "internals.h" +#include "detail/icmp_extension_helpers.h" using std::memset; using std::vector; diff --git a/src/internals.cpp b/src/internals.cpp index f4122c6..740d9eb 100644 --- a/src/internals.cpp +++ b/src/internals.cpp @@ -279,51 +279,6 @@ Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag) { }; } -uint32_t get_padded_icmp_inner_pdu_size(const PDU* inner_pdu, uint32_t pad_alignment) { - // This gets the size of the next pdu, padded to the next 32 bit word boundary - if (inner_pdu) { - uint32_t inner_pdu_size = inner_pdu->size(); - uint32_t padding = inner_pdu_size % pad_alignment; - inner_pdu_size = padding ? (inner_pdu_size - padding + pad_alignment) : inner_pdu_size; - return inner_pdu_size; - } - else { - return 0; - } -} - -void try_parse_icmp_extensions(InputMemoryStream& stream, - uint32_t payload_length, - ICMPExtensionsStructure& extensions) { - if (!stream) { - return; - } - // Check if this is one of the types defined in RFC 4884 - const uint32_t minimum_payload = ICMPExtensionsStructure::MINIMUM_ICMP_PAYLOAD; - // Check if we actually have this amount of data and whether it's more than - // the minimum encapsulated packet size - const uint8_t* extensions_ptr; - uint32_t extensions_size; - if (stream.can_read(payload_length) && payload_length >= minimum_payload) { - extensions_ptr = stream.pointer() + payload_length; - extensions_size = stream.size() - payload_length; - } - else if (stream.can_read(minimum_payload)) { - // This packet might be non-rfc compliant. In that case the length - // field can contain garbage. - extensions_ptr = stream.pointer() + minimum_payload; - extensions_size = stream.size() - minimum_payload; - } - else { - // No more special cases, this doesn't have extensions - return; - } - if (ICMPExtensionsStructure::validate_extensions(extensions_ptr, extensions_size)) { - extensions = ICMPExtensionsStructure(extensions_ptr, extensions_size); - stream.size(stream.size() - extensions_size); - } -} - PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag) { switch(flag) { case Constants::IP::PROTO_IPIP: From 89202c5dd5bd1a44e356a0c6d68660d20ddd4a58 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 11:59:02 -0700 Subject: [PATCH 20/73] Move checksum utils into their own file --- include/tins/CMakeLists.txt | 1 + include/tins/utils.h | 58 +----------- include/tins/utils/CMakeLists.txt | 6 ++ include/tins/utils/checksum_utils.h | 106 ++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/icmp.cpp | 2 +- src/icmpv6.cpp | 2 +- src/ip.cpp | 2 +- src/radiotap.cpp | 1 + src/tcp.cpp | 2 +- src/udp.cpp | 2 +- src/utils.cpp | 84 ------------------ src/utils/checksum_utils.cpp | 131 ++++++++++++++++++++++++++++ 13 files changed, 252 insertions(+), 146 deletions(-) create mode 100644 include/tins/utils/CMakeLists.txt create mode 100644 include/tins/utils/checksum_utils.h create mode 100644 src/utils/checksum_utils.cpp diff --git a/include/tins/CMakeLists.txt b/include/tins/CMakeLists.txt index 1f55d3a..1b67728 100644 --- a/include/tins/CMakeLists.txt +++ b/include/tins/CMakeLists.txt @@ -7,3 +7,4 @@ INSTALL( ADD_SUBDIRECTORY(dot11) ADD_SUBDIRECTORY(tcp_ip) ADD_SUBDIRECTORY(detail) +ADD_SUBDIRECTORY(utils) diff --git a/include/tins/utils.h b/include/tins/utils.h index 0e9c341..e2a54e2 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -39,6 +39,7 @@ #include "ipv6_address.h" #include "pdu.h" #include "detail/type_traits.h" +#include "utils/checksum_utils.h" // Fix for Windows interface define on combaseapi.h #undef interface @@ -215,13 +216,6 @@ TINS_API std::vector route_entries(); */ TINS_API std::vector route6_entries(); -/** \brief Returns the 32 bit crc of the given buffer. - * - * \param data The input buffer. - * \param data_size The size of the input buffer. - */ -TINS_API uint32_t crc32(const uint8_t* data, uint32_t data_size); - /** * \brief Converts a channel number to its mhz representation. * \param channel The channel number. @@ -243,56 +237,6 @@ TINS_API uint16_t mhz_to_channel(uint16_t mhz); */ TINS_API std::string to_string(PDU::PDUType pduType); -/** - * \brief Does the 16 bits sum of all 2 bytes elements between start and end. - * - * This is the checksum used by IP, UDP and TCP. If there's and odd number of - * bytes, the last one is padded and added to the checksum. - * \param start The pointer to the start of the buffer. - * \param end The pointer to the end of the buffer(excluding the last element). - * \return Returns the checksum between start and end (non inclusive) - * in network endian - */ -TINS_API uint32_t do_checksum(const uint8_t* start, const uint8_t* end); - -/** - * \brief Computes the 16 bit sum of the input buffer. - * - * If there's and odd number of bytes in the buffer, the last one is padded and - * added to the checksum. - * \param start The pointer to the start of the buffer. - * \param end The pointer to the end of the buffer(excluding the last element). - * \return Returns the checksum between start and end (non inclusive) - * in network endian - */ -TINS_API uint16_t sum_range(const uint8_t* start, const uint8_t* end); - -/** \brief Performs the pseudo header checksum used in TCP and UDP PDUs. - * - * \param source_ip The source ip address. - * \param dest_ip The destination ip address. - * \param len The length to be included in the pseudo header. - * \param flag The flag to use in the protocol field of the pseudo header. - * \return The pseudo header checksum. - */ -TINS_API uint32_t pseudoheader_checksum(IPv4Address source_ip, - IPv4Address dest_ip, - uint16_t len, - uint16_t flag); - -/** \brief Performs the pseudo header checksum used in TCP and UDP PDUs. - * - * \param source_ip The source ip address. - * \param dest_ip The destination ip address. - * \param len The length to be included in the pseudo header. - * \param flag The flag to use in the protocol field of the pseudo header. - * \return The pseudo header checksum. - */ -TINS_API uint32_t pseudoheader_checksum(IPv6Address source_ip, - IPv6Address dest_ip, - uint16_t len, - uint16_t flag); - template struct is_pdu { template diff --git a/include/tins/utils/CMakeLists.txt b/include/tins/utils/CMakeLists.txt new file mode 100644 index 0000000..04ddc8b --- /dev/null +++ b/include/tins/utils/CMakeLists.txt @@ -0,0 +1,6 @@ +FILE(GLOB INCLUDE_FILES "*.h") +INSTALL( + FILES ${INCLUDE_FILES} + DESTINATION include/tins/utils + COMPONENT Headers +) diff --git a/include/tins/utils/checksum_utils.h b/include/tins/utils/checksum_utils.h new file mode 100644 index 0000000..1c4b407 --- /dev/null +++ b/include/tins/utils/checksum_utils.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_CHECKSUM_UTILS_H +#define TINS_CHECKSUM_UTILS_H + +#include +#include "../macros.h" + +namespace Tins { + +class IPv4Address; +class IPv6Address; + +namespace Utils { + +/** + * \brief Does the 16 bits sum of all 2 bytes elements between start and end. + * + * This is the checksum used by IP, UDP and TCP. If there's and odd number of + * bytes, the last one is padded and added to the checksum. + * \param start The pointer to the start of the buffer. + * \param end The pointer to the end of the buffer(excluding the last element). + * \return Returns the checksum between start and end (non inclusive) + * in network endian + */ +TINS_API uint32_t do_checksum(const uint8_t* start, const uint8_t* end); + +/** + * \brief Computes the 16 bit sum of the input buffer. + * + * If there's and odd number of bytes in the buffer, the last one is padded and + * added to the checksum. + * \param start The pointer to the start of the buffer. + * \param end The pointer to the end of the buffer(excluding the last element). + * \return Returns the checksum between start and end (non inclusive) + * in network endian + */ +TINS_API uint16_t sum_range(const uint8_t* start, const uint8_t* end); + +/** + * \brief Performs the pseudo header checksum used in TCP and UDP PDUs. + * + * \param source_ip The source ip address. + * \param dest_ip The destination ip address. + * \param len The length to be included in the pseudo header. + * \param flag The flag to use in the protocol field of the pseudo header. + * \return The pseudo header checksum. + */ +TINS_API uint32_t pseudoheader_checksum(IPv4Address source_ip, + IPv4Address dest_ip, + uint16_t len, + uint16_t flag); + +/** + * \brief Performs the pseudo header checksum used in TCP and UDP PDUs. + * + * \param source_ip The source ip address. + * \param dest_ip The destination ip address. + * \param len The length to be included in the pseudo header. + * \param flag The flag to use in the protocol field of the pseudo header. + * \return The pseudo header checksum. + */ +TINS_API uint32_t pseudoheader_checksum(IPv6Address source_ip, + IPv6Address dest_ip, + uint16_t len, + uint16_t flag); + +/** + * \brief Returns the 32 bit crc of the given buffer. + * + * \param data The input buffer. + * \param data_size The size of the input buffer. + */ +TINS_API uint32_t crc32(const uint8_t* data, uint32_t data_size); + +} // Utils +} // Tins + +#endif // TINS_CHECKSUM_UTILS_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f340fb6..07334c0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -72,6 +72,7 @@ set(SOURCES dot11/dot11_auth.cpp dot11/dot11_probe.cpp dot11/dot11_control.cpp + utils/checksum_utils.cpp ) SET(PCAP_DEPENDENT_SOURCES diff --git a/src/icmp.cpp b/src/icmp.cpp index 419399f..5b14f0c 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -33,11 +33,11 @@ #include #endif #include "rawpdu.h" -#include "utils.h" #include "exceptions.h" #include "icmp.h" #include "memory_helpers.h" #include "detail/icmp_extension_helpers.h" +#include "utils/checksum_utils.h" using std::memset; using std::max; diff --git a/src/icmpv6.cpp b/src/icmpv6.cpp index d503eb6..457ca46 100644 --- a/src/icmpv6.cpp +++ b/src/icmpv6.cpp @@ -32,11 +32,11 @@ #include "icmpv6.h" #include "ipv6.h" #include "rawpdu.h" -#include "utils.h" #include "constants.h" #include "exceptions.h" #include "memory_helpers.h" #include "detail/icmp_extension_helpers.h" +#include "utils/checksum_utils.h" using std::memset; using std::vector; diff --git a/src/ip.cpp b/src/ip.cpp index 3bcbdb3..6eb0c7a 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -39,7 +39,6 @@ #endif #include "ip.h" #include "rawpdu.h" -#include "utils.h" #include "packet_sender.h" #include "constants.h" #include "network_interface.h" @@ -47,6 +46,7 @@ #include "pdu_allocator.h" #include "memory_helpers.h" #include "internals.h" +#include "utils/checksum_utils.h" using std::list; using std::min; diff --git a/src/radiotap.cpp b/src/radiotap.cpp index 1477360..6198fa1 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -48,6 +48,7 @@ #include "packet_sender.h" #include "exceptions.h" #include "memory_helpers.h" +#include "utils/checksum_utils.h" using std::memcpy; diff --git a/src/tcp.cpp b/src/tcp.cpp index 6a7ffe2..fec72fa 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -34,10 +34,10 @@ #include "ipv6.h" #include "constants.h" #include "rawpdu.h" -#include "utils.h" #include "exceptions.h" #include "internals.h" #include "memory_helpers.h" +#include "utils/checksum_utils.h" using std::find_if; using std::min; diff --git a/src/udp.cpp b/src/udp.cpp index 74cd93d..fbec788 100644 --- a/src/udp.cpp +++ b/src/udp.cpp @@ -31,12 +31,12 @@ #include #include "udp.h" #include "constants.h" -#include "utils.h" #include "ip.h" #include "ipv6.h" #include "rawpdu.h" #include "exceptions.h" #include "memory_helpers.h" +#include "utils/checksum_utils.h" using Tins::Memory::InputMemoryStream; using Tins::Memory::OutputMemoryStream; diff --git a/src/utils.cpp b/src/utils.cpp index 8645607..f815e99 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -595,89 +595,5 @@ string to_string(PDU::PDUType pduType) { #undef ENUM_TEXT } -uint32_t do_checksum(const uint8_t* start, const uint8_t* end) { - return Endian::host_to_be(sum_range(start, end)); -} - -uint16_t sum_range(const uint8_t* start, const uint8_t* end) { - uint32_t checksum(0); - const uint8_t* last = end; - uint16_t buffer = 0; - uint16_t padding = 0; - const uint8_t* ptr = start; - - if (((end - start) & 1) == 1) { - last = end - 1; - padding = Endian::host_to_le(*(end - 1)); - } - - while (ptr < last) { - memcpy(&buffer, ptr, sizeof(uint16_t)); - checksum += buffer; - ptr += sizeof(uint16_t); - } - - checksum += padding; - while (checksum >> 16) { - checksum = (checksum & 0xffff) + (checksum >> 16); - } - return checksum; -} - -template -uint32_t generic_pseudoheader_checksum(const AddressType& source_ip, - const AddressType& dest_ip, - uint16_t len, - uint16_t flag) { - uint8_t buffer[buffer_size]; - OutputMemoryStream stream(buffer, sizeof(buffer)); - stream.write(source_ip); - stream.write(dest_ip); - stream.write(Endian::host_to_be(flag)); - stream.write(Endian::host_to_be(len)); - - InputMemoryStream input_stream(buffer, sizeof(buffer)); - uint32_t checksum = 0; - while (input_stream) { - checksum += input_stream.read(); - } - return checksum; -} - -uint32_t pseudoheader_checksum(IPv4Address source_ip, - IPv4Address dest_ip, - uint16_t len, - uint16_t flag) { - return generic_pseudoheader_checksum( - source_ip, dest_ip, len, flag - ); -} - -uint32_t pseudoheader_checksum(IPv6Address source_ip, - IPv6Address dest_ip, - uint16_t len, - uint16_t flag) { - return generic_pseudoheader_checksum( - source_ip, dest_ip, len, flag - ); -} - -uint32_t crc32(const uint8_t* data, uint32_t data_size) { - uint32_t i, crc = 0; - static uint32_t crc_table[] = { - 0x4DBDF21C, 0x500AE278, 0x76D3D2D4, 0x6B64C2B0, - 0x3B61B38C, 0x26D6A3E8, 0x000F9344, 0x1DB88320, - 0xA005713C, 0xBDB26158, 0x9B6B51F4, 0x86DC4190, - 0xD6D930AC, 0xCB6E20C8, 0xEDB71064, 0xF0000000 - }; - - for (i = 0; i < data_size; ++i) { - crc = (crc >> 4) ^ crc_table[(crc ^ data[i]) & 0x0F]; - crc = (crc >> 4) ^ crc_table[(crc ^ (data[i] >> 4)) & 0x0F]; - } - - return crc; -} - } // Utils } // Tins diff --git a/src/utils/checksum_utils.cpp b/src/utils/checksum_utils.cpp new file mode 100644 index 0000000..3038ec0 --- /dev/null +++ b/src/utils/checksum_utils.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "utils/checksum_utils.h" +#include +#include "ip_address.h" +#include "ipv6_address.h" +#include "endianness.h" +#include "memory_helpers.h" + +using std::memcpy; + +using Tins::Memory::InputMemoryStream; +using Tins::Memory::OutputMemoryStream; + +namespace Tins { +namespace Utils { + +uint32_t do_checksum(const uint8_t* start, const uint8_t* end) { + return Endian::host_to_be(sum_range(start, end)); +} + +uint16_t sum_range(const uint8_t* start, const uint8_t* end) { + uint32_t checksum(0); + const uint8_t* last = end; + uint16_t buffer = 0; + uint16_t padding = 0; + const uint8_t* ptr = start; + + if (((end - start) & 1) == 1) { + last = end - 1; + padding = Endian::host_to_le(*(end - 1)); + } + + while (ptr < last) { + memcpy(&buffer, ptr, sizeof(uint16_t)); + checksum += buffer; + ptr += sizeof(uint16_t); + } + + checksum += padding; + while (checksum >> 16) { + checksum = (checksum & 0xffff) + (checksum >> 16); + } + return checksum; +} + +template +uint32_t generic_pseudoheader_checksum(const AddressType& source_ip, + const AddressType& dest_ip, + uint16_t len, + uint16_t flag) { + uint8_t buffer[buffer_size]; + OutputMemoryStream stream(buffer, sizeof(buffer)); + stream.write(source_ip); + stream.write(dest_ip); + stream.write(Endian::host_to_be(flag)); + stream.write(Endian::host_to_be(len)); + + InputMemoryStream input_stream(buffer, sizeof(buffer)); + uint32_t checksum = 0; + while (input_stream) { + checksum += input_stream.read(); + } + return checksum; +} + +uint32_t pseudoheader_checksum(IPv4Address source_ip, + IPv4Address dest_ip, + uint16_t len, + uint16_t flag) { + return generic_pseudoheader_checksum( + source_ip, dest_ip, len, flag + ); +} + +uint32_t pseudoheader_checksum(IPv6Address source_ip, + IPv6Address dest_ip, + uint16_t len, + uint16_t flag) { + return generic_pseudoheader_checksum( + source_ip, dest_ip, len, flag + ); +} + +uint32_t crc32(const uint8_t* data, uint32_t data_size) { + uint32_t i, crc = 0; + static uint32_t crc_table[] = { + 0x4DBDF21C, 0x500AE278, 0x76D3D2D4, 0x6B64C2B0, + 0x3B61B38C, 0x26D6A3E8, 0x000F9344, 0x1DB88320, + 0xA005713C, 0xBDB26158, 0x9B6B51F4, 0x86DC4190, + 0xD6D930AC, 0xCB6E20C8, 0xEDB71064, 0xF0000000 + }; + + for (i = 0; i < data_size; ++i) { + crc = (crc >> 4) ^ crc_table[(crc ^ data[i]) & 0x0F]; + crc = (crc >> 4) ^ crc_table[(crc ^ (data[i] >> 4)) & 0x0F]; + } + + return crc; +} + + +} // Utils +} // Tins From 36fedf4f65dd5d411d199d92df18d18c94810acd Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 11:59:10 -0700 Subject: [PATCH 21/73] Remove useless includes for utils.h on tests --- tests/src/arp_test.cpp | 1 - tests/src/dns_test.cpp | 1 - tests/src/dot11/dot11_test.cpp | 1 - tests/src/ethernet_test.cpp | 1 - tests/src/icmp_test.cpp | 1 - tests/src/icmpv6_test.cpp | 1 - tests/src/ip_address_test.cpp | 1 - tests/src/ip_test.cpp | 1 - tests/src/ipv6_address_test.cpp | 1 - tests/src/ipv6_test.cpp | 1 - tests/src/network_interface_test.cpp | 1 - tests/src/rc4_eapol_test.cpp | 1 - tests/src/rsn_eapol_test.cpp | 1 - tests/src/snap_test.cpp | 1 - tests/src/tcp_ip_test.cpp | 1 - tests/src/tcp_stream_test.cpp | 1 - tests/src/tcp_test.cpp | 1 - 17 files changed, 17 deletions(-) diff --git a/tests/src/arp_test.cpp b/tests/src/arp_test.cpp index 036d8e4..09a25d9 100644 --- a/tests/src/arp_test.cpp +++ b/tests/src/arp_test.cpp @@ -4,7 +4,6 @@ #include #include #include "arp.h" -#include "utils.h" #include "ip_address.h" diff --git a/tests/src/dns_test.cpp b/tests/src/dns_test.cpp index d19daa5..55641a4 100644 --- a/tests/src/dns_test.cpp +++ b/tests/src/dns_test.cpp @@ -2,7 +2,6 @@ #include #include "dns.h" #include "ipv6_address.h" -#include "utils.h" using namespace Tins; diff --git a/tests/src/dot11/dot11_test.cpp b/tests/src/dot11/dot11_test.cpp index d1308c4..6fd9a25 100644 --- a/tests/src/dot11/dot11_test.cpp +++ b/tests/src/dot11/dot11_test.cpp @@ -4,7 +4,6 @@ #include #include "tests/dot11.h" -#include "utils.h" using namespace std; using namespace Tins; diff --git a/tests/src/ethernet_test.cpp b/tests/src/ethernet_test.cpp index 0307685..56267e8 100644 --- a/tests/src/ethernet_test.cpp +++ b/tests/src/ethernet_test.cpp @@ -1,7 +1,6 @@ #include #include #include "ethernetII.h" -#include "utils.h" #include "macros.h" #include "ipv6.h" #include "ip.h" diff --git a/tests/src/icmp_test.cpp b/tests/src/icmp_test.cpp index ba17f85..a49cdc8 100644 --- a/tests/src/icmp_test.cpp +++ b/tests/src/icmp_test.cpp @@ -5,7 +5,6 @@ #include "icmp.h" #include "ip.h" #include "ethernetII.h" -#include "utils.h" #include "mpls.h" #include "rawpdu.h" diff --git a/tests/src/icmpv6_test.cpp b/tests/src/icmpv6_test.cpp index 4d8f231..9305ac6 100644 --- a/tests/src/icmpv6_test.cpp +++ b/tests/src/icmpv6_test.cpp @@ -6,7 +6,6 @@ #include "ethernetII.h" #include "ip.h" #include "tcp.h" -#include "utils.h" #include "rawpdu.h" #include "hw_address.h" diff --git a/tests/src/ip_address_test.cpp b/tests/src/ip_address_test.cpp index f61208d..8bbc920 100644 --- a/tests/src/ip_address_test.cpp +++ b/tests/src/ip_address_test.cpp @@ -4,7 +4,6 @@ #include #include #include "ip_address.h" -#include "utils.h" using namespace Tins; diff --git a/tests/src/ip_test.cpp b/tests/src/ip_test.cpp index e2d6b8e..bbe4e75 100644 --- a/tests/src/ip_test.cpp +++ b/tests/src/ip_test.cpp @@ -9,7 +9,6 @@ #include "icmp_extension.h" #include "rawpdu.h" #include "ip_address.h" -#include "utils.h" #include "ethernetII.h" using namespace std; diff --git a/tests/src/ipv6_address_test.cpp b/tests/src/ipv6_address_test.cpp index c355abe..7556101 100644 --- a/tests/src/ipv6_address_test.cpp +++ b/tests/src/ipv6_address_test.cpp @@ -5,7 +5,6 @@ #include #include #include "ipv6_address.h" -#include "utils.h" using namespace Tins; diff --git a/tests/src/ipv6_test.cpp b/tests/src/ipv6_test.cpp index 5f0c283..72809b6 100644 --- a/tests/src/ipv6_test.cpp +++ b/tests/src/ipv6_test.cpp @@ -10,7 +10,6 @@ #include "rawpdu.h" #include "ethernetII.h" #include "ipv6_address.h" -#include "utils.h" using namespace std; using namespace Tins; diff --git a/tests/src/network_interface_test.cpp b/tests/src/network_interface_test.cpp index 346d668..c3c708d 100644 --- a/tests/src/network_interface_test.cpp +++ b/tests/src/network_interface_test.cpp @@ -2,7 +2,6 @@ #include #include #include "network_interface.h" -#include "utils.h" #include "macros.h" using namespace Tins; diff --git a/tests/src/rc4_eapol_test.cpp b/tests/src/rc4_eapol_test.cpp index 5d39554..7f6fabf 100644 --- a/tests/src/rc4_eapol_test.cpp +++ b/tests/src/rc4_eapol_test.cpp @@ -3,7 +3,6 @@ #include #include #include "eapol.h" -#include "utils.h" using namespace std; using namespace Tins; diff --git a/tests/src/rsn_eapol_test.cpp b/tests/src/rsn_eapol_test.cpp index 3339251..705492f 100644 --- a/tests/src/rsn_eapol_test.cpp +++ b/tests/src/rsn_eapol_test.cpp @@ -4,7 +4,6 @@ #include #include "eapol.h" #include "snap.h" -#include "utils.h" #include "ethernetII.h" #include "rsn_information.h" diff --git a/tests/src/snap_test.cpp b/tests/src/snap_test.cpp index a716cee..17e4d89 100644 --- a/tests/src/snap_test.cpp +++ b/tests/src/snap_test.cpp @@ -3,7 +3,6 @@ #include #include #include "snap.h" -#include "utils.h" using namespace std; using namespace Tins; diff --git a/tests/src/tcp_ip_test.cpp b/tests/src/tcp_ip_test.cpp index ae9f600..896b0a0 100644 --- a/tests/src/tcp_ip_test.cpp +++ b/tests/src/tcp_ip_test.cpp @@ -17,7 +17,6 @@ #include "ethernetII.h" #include "rawpdu.h" #include "packet.h" -#include "utils.h" #include "config.h" #ifdef TINS_HAVE_ACK_TRACKER #include "tcp_ip/ack_tracker.h" diff --git a/tests/src/tcp_stream_test.cpp b/tests/src/tcp_stream_test.cpp index 9df9459..9933acd 100644 --- a/tests/src/tcp_stream_test.cpp +++ b/tests/src/tcp_stream_test.cpp @@ -5,7 +5,6 @@ #include "tcp_stream.h" #include "tcp.h" #include "ethernetII.h" -#include "utils.h" using namespace Tins; diff --git a/tests/src/tcp_test.cpp b/tests/src/tcp_test.cpp index 4aef600..a7ed226 100644 --- a/tests/src/tcp_test.cpp +++ b/tests/src/tcp_test.cpp @@ -6,7 +6,6 @@ #include "tcp.h" #include "ip.h" #include "ethernetII.h" -#include "utils.h" using namespace std; using namespace Tins; From d061fced7e3aa4352f47aa68276e58c18054fba6 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 12:06:42 -0700 Subject: [PATCH 22/73] Move frequency (channel) utils into their own file --- include/tins/utils.h | 15 +------- include/tins/utils/frequency_utils.h | 56 ++++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/radiotap.cpp | 2 +- src/utils.cpp | 8 ---- src/utils/frequency_utils.cpp | 44 ++++++++++++++++++++++ 6 files changed, 103 insertions(+), 23 deletions(-) create mode 100644 include/tins/utils/frequency_utils.h create mode 100644 src/utils/frequency_utils.cpp diff --git a/include/tins/utils.h b/include/tins/utils.h index e2a54e2..f445af3 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -40,6 +40,7 @@ #include "pdu.h" #include "detail/type_traits.h" #include "utils/checksum_utils.h" +#include "utils/frequency_utils.h" // Fix for Windows interface define on combaseapi.h #undef interface @@ -216,20 +217,6 @@ TINS_API std::vector route_entries(); */ TINS_API std::vector route6_entries(); -/** - * \brief Converts a channel number to its mhz representation. - * \param channel The channel number. - * \return The channel's mhz representation. - */ -TINS_API uint16_t channel_to_mhz(uint16_t channel); - -/** - * \brief Converts mhz units to the appropriate channel number. - * \param mhz The mhz units to be converted. - * \return The channel number. - */ -TINS_API uint16_t mhz_to_channel(uint16_t mhz); - /** * \brief Converts a PDUType to a string. * \param pduType The PDUType to be converted. diff --git a/include/tins/utils/frequency_utils.h b/include/tins/utils/frequency_utils.h new file mode 100644 index 0000000..dfc34d5 --- /dev/null +++ b/include/tins/utils/frequency_utils.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_FREQUENCY_UTILS_H +#define TINS_FREQUENCY_UTILS_H + +#include +#include "../macros.h" + +namespace Tins { +namespace Utils { + +/** + * \brief Converts a channel number to its mhz representation. + * \param channel The channel number. + * \return The channel's mhz representation. + */ +TINS_API uint16_t channel_to_mhz(uint16_t channel); + +/** + * \brief Converts mhz units to the appropriate channel number. + * \param mhz The mhz units to be converted. + * \return The channel number. + */ +TINS_API uint16_t mhz_to_channel(uint16_t mhz); + +} // Utils +} // Tins + +#endif // TINS_FREQUENCY_UTILS_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 07334c0..6ba788f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,6 +73,7 @@ set(SOURCES dot11/dot11_probe.cpp dot11/dot11_control.cpp utils/checksum_utils.cpp + utils/frequency_utils.cpp ) SET(PCAP_DEPENDENT_SOURCES diff --git a/src/radiotap.cpp b/src/radiotap.cpp index 6198fa1..d6a7a04 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -44,11 +44,11 @@ #include #endif #include "dot11/dot11_base.h" -#include "utils.h" #include "packet_sender.h" #include "exceptions.h" #include "memory_helpers.h" #include "utils/checksum_utils.h" +#include "utils/frequency_utils.h" using std::memcpy; diff --git a/src/utils.cpp b/src/utils.cpp index f815e99..413d713 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -524,14 +524,6 @@ set network_interfaces() { return output; } #endif // _WIN32 - -uint16_t channel_to_mhz(uint16_t channel) { - return 2407 + (channel * 5); -} - -uint16_t mhz_to_channel(uint16_t mhz) { - return (mhz - 2407) / 5; -} string to_string(PDU::PDUType pduType) { #define ENUM_TEXT(p) case(PDU::p): return #p; diff --git a/src/utils/frequency_utils.cpp b/src/utils/frequency_utils.cpp new file mode 100644 index 0000000..9c27d06 --- /dev/null +++ b/src/utils/frequency_utils.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "utils/frequency_utils.h" + +namespace Tins { +namespace Utils { + +uint16_t channel_to_mhz(uint16_t channel) { + return 2407 + (channel * 5); +} + +uint16_t mhz_to_channel(uint16_t mhz) { + return (mhz - 2407) / 5; +} + +} // Utils +} // Tins From 714b8d9810f05d5203d38780006faba2fa92d595 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 12:07:06 -0700 Subject: [PATCH 23/73] Use checksum utils on crypto and icmp extension source files --- src/crypto.cpp | 2 +- src/icmp_extension.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crypto.cpp b/src/crypto.cpp index a3a9d9b..6cf076a 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -42,7 +42,7 @@ #include "dot11/dot11_data.h" #include "dot11/dot11_beacon.h" #include "exceptions.h" -#include "utils.h" +#include "utils/checksum_utils.h" #include "detail/type_traits.h" using std::string; diff --git a/src/icmp_extension.cpp b/src/icmp_extension.cpp index 095c127..13eeabb 100644 --- a/src/icmp_extension.cpp +++ b/src/icmp_extension.cpp @@ -31,9 +31,9 @@ #include #include "icmp_extension.h" #include "exceptions.h" -#include "utils.h" #include "memory_helpers.h" #include "mpls.h" +#include "utils/checksum_utils.h" using std::runtime_error; From 35e65d018cb8e3aead6d1a21494611368bb981c8 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 12:32:16 -0700 Subject: [PATCH 24/73] Move routing related functions into their own header file --- include/tins/utils.h | 103 +------ include/tins/utils/routing_utils.h | 148 ++++++++++ src/CMakeLists.txt | 1 + src/network_interface.cpp | 2 +- src/utils.cpp | 370 +------------------------ src/utils/routing_utils.cpp | 429 +++++++++++++++++++++++++++++ 6 files changed, 581 insertions(+), 472 deletions(-) create mode 100644 include/tins/utils/routing_utils.h create mode 100644 src/utils/routing_utils.cpp diff --git a/include/tins/utils.h b/include/tins/utils.h index f445af3..27d2128 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -32,8 +32,6 @@ #include "macros.h" #include -#include -#include #include #include "ip_address.h" #include "ipv6_address.h" @@ -41,6 +39,7 @@ #include "detail/type_traits.h" #include "utils/checksum_utils.h" #include "utils/frequency_utils.h" +#include "utils/routing_utils.h" // Fix for Windows interface define on combaseapi.h #undef interface @@ -63,66 +62,6 @@ class HWAddress; */ namespace Utils { -/** - * Struct that represents an entry the routing table - */ -struct RouteEntry { - /** - * This interface's name. - */ - std::string interface; - - /** - * This route entry's destination. - */ - IPv4Address destination; - - /** - * This route entry's gateway. - */ - IPv4Address gateway; - - /** - * This route entry's subnet mask. - */ - IPv4Address mask; - - /** - * This route entry's metric. - */ - int metric; -}; - -/** - * Struct that represents an entry the IPv6 routing table - */ -struct Route6Entry { - /** - * This interface's name. - */ - std::string interface; - - /** - * This route entry's destination. - */ - IPv6Address destination; - - /** - * This route entry's subnet mask. - */ - IPv6Address mask; - - /** - * This route entry's next hop. - */ - IPv6Address gateway; - - /** - * This route entry's metric. - */ - int metric; -}; - /** * \brief Resolves a domain name and returns its corresponding ip address. * @@ -173,14 +112,6 @@ TINS_API HWAddress<6> resolve_hwaddr(const NetworkInterface& iface, */ TINS_API HWAddress<6> resolve_hwaddr(IPv4Address ip, PacketSender& sender); -/** \brief List all network interfaces. - * - * Returns a set of strings, each of them representing the name - * of a network interface. These names can be used as the input - * interface for Utils::interface_ip, Utils::interface_hwaddr, etc. - */ -TINS_API std::set network_interfaces(); - /** * \brief Finds the gateway's IP address for the given IP * address. @@ -194,29 +125,6 @@ TINS_API std::set network_interfaces(); */ TINS_API bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr); - -/** - * \brief Retrieves entries in the routing table. - * - * \brief output ForwardIterator in which entries will be stored. - */ -template -void route_entries(ForwardIterator output); - -/** - * \brief Retrieves entries in the routing table. - * - * \return a vector which contains all of the route entries. - */ -TINS_API std::vector route_entries(); - -/** - * \brief Retrieves entries in the routing table. - * - * \return a vector which contains all of the route entries. - */ -TINS_API std::vector route6_entries(); - /** * \brief Converts a PDUType to a string. * \param pduType The PDUType to be converted. @@ -259,13 +167,4 @@ dereference_until_pdu(T& value) { } // Utils } // Tins -template -void Tins::Utils::route_entries(ForwardIterator output) { - std::vector entries = route_entries(); - for (size_t i = 0; i < entries.size(); ++i) { - *output = entries[i]; - ++output; - } -} - #endif // TINS_UTILS_H diff --git a/include/tins/utils/routing_utils.h b/include/tins/utils/routing_utils.h new file mode 100644 index 0000000..71a5863 --- /dev/null +++ b/include/tins/utils/routing_utils.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_ROUTING_UTILS_H +#define TINS_ROUTING_UTILS_H + +#include +#include +#include "../macros.h" +#include "../ip_address.h" +#include "../ipv6_address.h" + +// Fix for Windows interface define on combaseapi.h +#undef interface + +namespace Tins { +namespace Utils { + +/** + * Struct that represents an entry the routing table + */ +struct RouteEntry { + /** + * This interface's name. + */ + std::string interface; + + /** + * This route entry's destination. + */ + IPv4Address destination; + + /** + * This route entry's gateway. + */ + IPv4Address gateway; + + /** + * This route entry's subnet mask. + */ + IPv4Address mask; + + /** + * This route entry's metric. + */ + int metric; +}; + +/** + * Struct that represents an entry the IPv6 routing table + */ +struct Route6Entry { + /** + * This interface's name. + */ + std::string interface; + + /** + * This route entry's destination. + */ + IPv6Address destination; + + /** + * This route entry's subnet mask. + */ + IPv6Address mask; + + /** + * This route entry's next hop. + */ + IPv6Address gateway; + + /** + * This route entry's metric. + */ + int metric; +}; + +/** + * \brief Retrieves entries in the routing table. + * + * \brief output ForwardIterator in which entries will be stored. + */ +template +void route_entries(ForwardIterator output); + +/** + * \brief Retrieves entries in the routing table. + * + * \return a vector which contains all of the route entries. + */ +TINS_API std::vector route_entries(); + +/** + * \brief Retrieves entries in the routing table. + * + * \return a vector which contains all of the route entries. + */ +TINS_API std::vector route6_entries(); + +/** + * \brief List all network interfaces. + * + * Returns a set of strings, each of them representing the name + * of a network interface. These names can be used as the input + * interface for Utils::interface_ip, Utils::interface_hwaddr, etc. + */ +TINS_API std::set network_interfaces(); + +} // Utils +} // Tins + +template +void Tins::Utils::route_entries(ForwardIterator output) { + std::vector entries = route_entries(); + for (size_t i = 0; i < entries.size(); ++i) { + *output = entries[i]; + ++output; + } +} + +#endif // TINS_ROUTING_UTILS_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6ba788f..9e709e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -74,6 +74,7 @@ set(SOURCES dot11/dot11_control.cpp utils/checksum_utils.cpp utils/frequency_utils.cpp + utils/routing_utils.cpp ) SET(PCAP_DEPENDENT_SOURCES diff --git a/src/network_interface.cpp b/src/network_interface.cpp index 47c75cc..cd191be 100644 --- a/src/network_interface.cpp +++ b/src/network_interface.cpp @@ -31,7 +31,6 @@ #include #include #include "macros.h" -#include "utils.h" #ifndef _WIN32 #include #if defined(BSD) || defined(__FreeBSD_kernel__) @@ -52,6 +51,7 @@ #include "network_interface.h" #include "endianness.h" #include "exceptions.h" +#include "utils/routing_utils.h" using std::string; using std::wstring; diff --git a/src/utils.cpp b/src/utils.cpp index 413d713..9940c91 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -28,10 +28,7 @@ */ #include -#include -#include #include -#include #include "macros.h" #ifndef _WIN32 #if defined(BSD) || defined(__FreeBSD_kernel__) @@ -59,22 +56,19 @@ #undef interface #endif #include "utils.h" -#include "pdu.h" #include "arp.h" #include "ethernetII.h" -#include "endianness.h" #include "network_interface.h" #include "packet_sender.h" #include "cxxstd.h" #include "hw_address.h" #include "memory_helpers.h" -#include "internals.h" +#include "detail/smart_ptr.h" #include "detail/smart_ptr.h" using std::string; using std::istream; using std::set; -using std::ifstream; using std::vector; using std::back_inserter; using std::runtime_error; @@ -84,72 +78,6 @@ using Tins::Memory::OutputMemoryStream; /** \cond */ -bool from_hex(const string& str, uint32_t& result) { - size_t i = 0; - result = 0; - while (i < str.size()) { - uint8_t tmp; - if (str[i] >= 'A' && str[i] <= 'F') { - tmp = (str[i] - 'A' + 10); - } - else if (str[i] >= '0' && str[i] <= '9') { - tmp = (str[i] - '0'); - } - else { - return false; - } - result = (result << 4) | tmp; - i++; - } - return true; -} - -bool from_hex(const string& str, string& result) { - result.clear(); - for (size_t i = 0; i < str.size(); i+= 2) { - uint8_t value = 0; - for (size_t j = i; j < i + 2 && j < str.size(); ++j) { - if (str[j] >= 'A' && str[j] <= 'F') { - value = (value << 4) | (str[j] - 'A' + 10); - } - else if (str[j] >= 'a' && str[j] <= 'f') { - value = (value << 4) | (str[j] - 'a' + 10); - } - else if (str[j] >= '0' && str[j] <= '9') { - value = (value << 4) | (str[j] - '0'); - } - else { - return false; - } - } - result.push_back(value); - } - return true; -} - -void skip_line(istream& input) { - int c = 0; - while (c != '\n' && input) { - c = input.get(); - } -} - -struct InterfaceCollector { - set ifaces; - - #ifdef _WIN32 - bool operator() (PIP_ADAPTER_ADDRESSES addr) { - ifaces.insert(addr->AdapterName); - return false; - } - #else - bool operator() (struct ifaddrs* addr) { - ifaces.insert(addr->ifa_name); - return false; - } - #endif -}; - addrinfo* resolve_domain(const string& to_resolve, int family) { addrinfo* result, hints = addrinfo(); hints.ai_socktype = SOCK_STREAM; @@ -163,47 +91,6 @@ addrinfo* resolve_domain(const string& to_resolve, int family) { } } -#if defined(BSD) || defined(__FreeBSD_kernel__) -vector query_route_table(int family) { - int mib[6]; - vector buf; - size_t len; - - mib[0] = CTL_NET; - mib[1] = AF_ROUTE; - mib[2] = 0; - mib[3] = family; - mib[4] = NET_RT_DUMP; - mib[5] = 0; - if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { - throw runtime_error("sysctl failed"); - } - - buf.resize(len); - if (sysctl(mib, 6, &buf[0], &len, NULL, 0) < 0) { - throw runtime_error("sysctl failed"); - } - - return buf; -} - -void parse_header(struct rt_msghdr* rtm, vector& addrs) { - char* ptr = (char *)(rtm + 1); - // Iterate from RTA_DST (0) to RTA_NETMASK (2) - for (int i = 0; i < 3; ++i) { - sockaddr* sa = 0; - if ((rtm->rtm_addrs & (1 << i)) != 0) { - sa = (struct sockaddr *)ptr; - ptr += sa->sa_len; - if (sa->sa_family == 0) { - sa = 0; - } - } - addrs[i] = sa; - } -} -#endif - namespace Tins { /** \endcond */ @@ -256,230 +143,6 @@ HWAddress<6> resolve_hwaddr(IPv4Address ip, PacketSender& sender) { return resolve_hwaddr(sender.default_interface(), ip, sender); } -#if defined(BSD) || defined(__FreeBSD_kernel__) - -vector route_entries() { - vector output; - vector buffer = query_route_table(AF_INET); - char* next = &buffer[0], *end = &buffer[buffer.size()]; - rt_msghdr* rtm; - vector sa(32); - char iface_name[IF_NAMESIZE]; - while (next < end) { - rtm = (rt_msghdr*)next; - // Filter: - // * RTF_STATIC (only manually added routes) - if ((rtm->rtm_flags & (RTF_STATIC)) != 0) { - parse_header(rtm, sa); - if (sa[RTAX_DST] && sa[RTAX_GATEWAY] && if_indextoname(rtm->rtm_index, iface_name)) { - RouteEntry entry; - entry.destination = IPv4Address(((struct sockaddr_in *)sa[RTAX_DST])->sin_addr.s_addr); - entry.gateway = IPv4Address(((struct sockaddr_in *)sa[RTAX_GATEWAY])->sin_addr.s_addr); - if (sa[RTAX_NETMASK]) { - entry.mask = IPv4Address(((struct sockaddr_in *)sa[RTAX_NETMASK])->sin_addr.s_addr); - } - entry.interface = iface_name; - entry.metric = 0; - output.push_back(entry); - } - } - next += rtm->rtm_msglen; - } - return output; -} - -vector route6_entries() { - vector output; - vector buffer = query_route_table(AF_INET6); - char* next = &buffer[0], *end = &buffer[buffer.size()]; - rt_msghdr* rtm; - vector sa(9); - char iface_name[IF_NAMESIZE]; - while (next < end) { - rtm = (rt_msghdr*)next; - // Filter protocol-cloned entries - bool process_entry = true; - // These were removed in recent versions of FreeBSD - #if defined(RTF_WASCLONED) && defined(RTF_PRCLONING) - process_entry = (rtm->rtm_flags & RTF_WASCLONED) == 0 || - (rtm->rtm_flags & RTF_PRCLONING) == 0; - #endif - if (process_entry) { - parse_header(rtm, sa); - if (sa[RTAX_DST] && sa[RTAX_GATEWAY] && if_indextoname(rtm->rtm_index, iface_name)) { - Route6Entry entry; - entry.destination = IPv6Address(((struct sockaddr_in6 *)sa[RTAX_DST])->sin6_addr.s6_addr); - entry.gateway = IPv6Address(((struct sockaddr_in6 *)sa[RTAX_GATEWAY])->sin6_addr.s6_addr); - int prefix_length = 0; - if (sa[RTAX_NETMASK]) { - struct sockaddr_in6 *sin = (struct sockaddr_in6 *)sa[RTAX_NETMASK]; - for (size_t i = 0; i < 16; ++i) { - uint8_t this_byte = sin->sin6_addr.s6_addr[i]; - // Stop when we find a zero byte - if (this_byte == 0) { - break; - } - switch (this_byte) { - case 0xff: - prefix_length += 8; - break; - case 0xfe: - prefix_length += 7; - break; - case 0xfc: - prefix_length += 6; - break; - case 0xf8: - prefix_length += 5; - break; - case 0xf0: - prefix_length += 4; - break; - case 0xe0: - prefix_length += 3; - break; - case 0xc0: - prefix_length += 2; - break; - case 0x80: - prefix_length += 1; - break; - default: - break; - } - } - } - entry.mask = IPv6Address::from_prefix_length(prefix_length); - entry.interface = iface_name; - entry.metric = 0; - output.push_back(entry); - } - } - next += rtm->rtm_msglen; - } - return output; -} - -#elif defined(_WIN32) - -vector route_entries() { - vector output; - MIB_IPFORWARDTABLE* table; - ULONG size = 0; - GetIpForwardTable(0, &size, 0); - vector buffer(size); - table = (MIB_IPFORWARDTABLE*)&buffer[0]; - GetIpForwardTable(table, &size, 0); - - for (DWORD i = 0; i < table->dwNumEntries; i++) { - MIB_IPFORWARDROW* row = &table->table[i]; - if (row->dwForwardType == MIB_IPROUTE_TYPE_INDIRECT || - row->dwForwardType == MIB_IPROUTE_TYPE_DIRECT) { - RouteEntry entry; - entry.interface = NetworkInterface::from_index(row->dwForwardIfIndex).name(); - entry.destination = IPv4Address(row->dwForwardDest); - entry.mask = IPv4Address(row->dwForwardMask); - entry.gateway = IPv4Address(row->dwForwardNextHop); - entry.metric = row->dwForwardMetric1; - output.push_back(entry); - } - } - return output; -} - -vector route6_entries() { - vector output; - MIB_IPFORWARD_TABLE2* table; - GetIpForwardTable2(AF_INET6, &table); - for (ULONG i = 0; i < table->NumEntries; i++) { - MIB_IPFORWARD_ROW2* row = &table->Table[i]; - if (true) { - try { - Route6Entry entry; - entry.interface = NetworkInterface::from_index(row->InterfaceIndex).name(); - entry.destination = IPv6Address(row->DestinationPrefix.Prefix.Ipv6.sin6_addr.s6_addr); - entry.mask = IPv6Address::from_prefix_length(row->DestinationPrefix.PrefixLength); - entry.gateway = IPv6Address(row->NextHop.Ipv6.sin6_addr.s6_addr); - entry.metric = row->Metric; - output.push_back(entry); - } - catch (invalid_interface&) { - - } - } - } - FreeMibTable(table); - return output; -} - -#else // GNU/LINUX - -vector route_entries() { - using namespace Tins::Internals; - vector output; - ifstream input("/proc/net/route"); - string destination, mask, metric, gw; - uint32_t dummy; - skip_line(input); - RouteEntry entry; - while (input >> entry.interface >> destination >> gw) { - for (unsigned i(0); i < 4; ++i) { - input >> metric; - } - input >> mask; - from_hex(destination, dummy); - entry.destination = IPv4Address(dummy); - from_hex(mask, dummy); - entry.mask = IPv4Address(dummy); - from_hex(gw, dummy); - entry.gateway = IPv4Address(dummy); - from_hex(metric, dummy); - entry.metric = dummy; - skip_line(input); - output.push_back(entry); - } - return output; -} - -vector route6_entries() { - using namespace Tins::Internals; - vector output; - ifstream input("/proc/net/ipv6_route"); - string destination, mask_length, metric, next_hop, dummy, flags; - Route6Entry entry; - while (input >> destination >> mask_length) { - string temporary; - uint32_t temporary_int; - for (unsigned i(0); i < 2; ++i) { - input >> dummy; - } - input >> next_hop; - input >> metric; - for (unsigned i(0); i < 2; ++i) { - input >> dummy; - } - input >> flags >> entry.interface; - from_hex(destination, temporary); - entry.destination = IPv6Address((const uint8_t*)&temporary[0]); - from_hex(mask_length, temporary_int); - entry.mask = IPv6Address::from_prefix_length(temporary_int); - from_hex(next_hop, temporary); - entry.gateway = IPv6Address((const uint8_t*)&temporary[0]); - from_hex(metric, temporary_int); - entry.metric = temporary_int; - // Process flags - from_hex(flags, temporary_int); - // Skip: - // * 0x01000000 -> cache entries - if ((temporary_int & 0x01000000) == 0) { - output.push_back(entry); - } - } - return output; -} - -#endif - bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr) { typedef vector entries_type; entries_type entries; @@ -493,37 +156,6 @@ bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr) { } return false; } - -#ifdef _WIN32 -set network_interfaces() { - set output; - ULONG size; - ::GetAdaptersAddresses(AF_INET, 0, 0, 0, &size); - std::vector buffer(size); - if (::GetAdaptersAddresses(AF_INET, 0, 0, (IP_ADAPTER_ADDRESSES *)&buffer[0], &size) == ERROR_SUCCESS) { - PIP_ADAPTER_ADDRESSES iface = (IP_ADAPTER_ADDRESSES *)&buffer[0]; - while (iface) { - output.insert(iface->AdapterName); - iface = iface->Next; - } - } - return output; -} -#else -set network_interfaces() { - set output; - struct ifaddrs* ifaddrs = 0; - struct ifaddrs* if_it = 0; - getifaddrs(&ifaddrs); - for (if_it = ifaddrs; if_it; if_it = if_it->ifa_next) { - output.insert(if_it->ifa_name); - } - if (ifaddrs) { - freeifaddrs(ifaddrs); - } - return output; -} -#endif // _WIN32 string to_string(PDU::PDUType pduType) { #define ENUM_TEXT(p) case(PDU::p): return #p; diff --git a/src/utils/routing_utils.cpp b/src/utils/routing_utils.cpp new file mode 100644 index 0000000..31fca0d --- /dev/null +++ b/src/utils/routing_utils.cpp @@ -0,0 +1,429 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "utils/routing_utils.h" +#ifndef _WIN32 + #if defined(BSD) || defined(__FreeBSD_kernel__) + #include + #include + #include + #include + #include + #include + #include + #else + #include + #endif + #include + #include + #include + #ifdef __ANDROID_API__ + #include + #include + #endif +#else + #include + #include + #include + #undef interface +#endif +#include +#include +#include "network_interface.h" + +using std::vector; +using std::string; +using std::set; +using std::ifstream; +using std::istream; + +namespace Tins { +namespace Utils { + +struct InterfaceCollector { + set ifaces; + + #ifdef _WIN32 + bool operator() (PIP_ADAPTER_ADDRESSES addr) { + ifaces.insert(addr->AdapterName); + return false; + } + #else + bool operator() (struct ifaddrs* addr) { + ifaces.insert(addr->ifa_name); + return false; + } + #endif +}; + +bool from_hex(const string& str, uint32_t& result) { + size_t i = 0; + result = 0; + while (i < str.size()) { + uint8_t tmp; + if (str[i] >= 'A' && str[i] <= 'F') { + tmp = (str[i] - 'A' + 10); + } + else if (str[i] >= '0' && str[i] <= '9') { + tmp = (str[i] - '0'); + } + else { + return false; + } + result = (result << 4) | tmp; + i++; + } + return true; +} + +bool from_hex(const string& str, string& result) { + result.clear(); + for (size_t i = 0; i < str.size(); i+= 2) { + uint8_t value = 0; + for (size_t j = i; j < i + 2 && j < str.size(); ++j) { + if (str[j] >= 'A' && str[j] <= 'F') { + value = (value << 4) | (str[j] - 'A' + 10); + } + else if (str[j] >= 'a' && str[j] <= 'f') { + value = (value << 4) | (str[j] - 'a' + 10); + } + else if (str[j] >= '0' && str[j] <= '9') { + value = (value << 4) | (str[j] - '0'); + } + else { + return false; + } + } + result.push_back(value); + } + return true; +} + +void skip_line(istream& input) { + int c = 0; + while (c != '\n' && input) { + c = input.get(); + } +} + +#if defined(BSD) || defined(__FreeBSD_kernel__) +vector query_route_table(int family) { + int mib[6]; + vector buf; + size_t len; + + mib[0] = CTL_NET; + mib[1] = AF_ROUTE; + mib[2] = 0; + mib[3] = family; + mib[4] = NET_RT_DUMP; + mib[5] = 0; + if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { + throw runtime_error("sysctl failed"); + } + + buf.resize(len); + if (sysctl(mib, 6, &buf[0], &len, NULL, 0) < 0) { + throw runtime_error("sysctl failed"); + } + + return buf; +} + +void parse_header(struct rt_msghdr* rtm, vector& addrs) { + char* ptr = (char *)(rtm + 1); + // Iterate from RTA_DST (0) to RTA_NETMASK (2) + for (int i = 0; i < 3; ++i) { + sockaddr* sa = 0; + if ((rtm->rtm_addrs & (1 << i)) != 0) { + sa = (struct sockaddr *)ptr; + ptr += sa->sa_len; + if (sa->sa_family == 0) { + sa = 0; + } + } + addrs[i] = sa; + } +} + +vector route_entries() { + vector output; + vector buffer = query_route_table(AF_INET); + char* next = &buffer[0], *end = &buffer[buffer.size()]; + rt_msghdr* rtm; + vector sa(32); + char iface_name[IF_NAMESIZE]; + while (next < end) { + rtm = (rt_msghdr*)next; + // Filter: + // * RTF_STATIC (only manually added routes) + if ((rtm->rtm_flags & (RTF_STATIC)) != 0) { + parse_header(rtm, sa); + if (sa[RTAX_DST] && sa[RTAX_GATEWAY] && if_indextoname(rtm->rtm_index, iface_name)) { + RouteEntry entry; + entry.destination = IPv4Address(((struct sockaddr_in *)sa[RTAX_DST])->sin_addr.s_addr); + entry.gateway = IPv4Address(((struct sockaddr_in *)sa[RTAX_GATEWAY])->sin_addr.s_addr); + if (sa[RTAX_NETMASK]) { + entry.mask = IPv4Address(((struct sockaddr_in *)sa[RTAX_NETMASK])->sin_addr.s_addr); + } + entry.interface = iface_name; + entry.metric = 0; + output.push_back(entry); + } + } + next += rtm->rtm_msglen; + } + return output; +} + +vector route6_entries() { + vector output; + vector buffer = query_route_table(AF_INET6); + char* next = &buffer[0], *end = &buffer[buffer.size()]; + rt_msghdr* rtm; + vector sa(9); + char iface_name[IF_NAMESIZE]; + while (next < end) { + rtm = (rt_msghdr*)next; + // Filter protocol-cloned entries + bool process_entry = true; + // These were removed in recent versions of FreeBSD + #if defined(RTF_WASCLONED) && defined(RTF_PRCLONING) + process_entry = (rtm->rtm_flags & RTF_WASCLONED) == 0 || + (rtm->rtm_flags & RTF_PRCLONING) == 0; + #endif + if (process_entry) { + parse_header(rtm, sa); + if (sa[RTAX_DST] && sa[RTAX_GATEWAY] && if_indextoname(rtm->rtm_index, iface_name)) { + Route6Entry entry; + entry.destination = IPv6Address(((struct sockaddr_in6 *)sa[RTAX_DST])->sin6_addr.s6_addr); + entry.gateway = IPv6Address(((struct sockaddr_in6 *)sa[RTAX_GATEWAY])->sin6_addr.s6_addr); + int prefix_length = 0; + if (sa[RTAX_NETMASK]) { + struct sockaddr_in6 *sin = (struct sockaddr_in6 *)sa[RTAX_NETMASK]; + for (size_t i = 0; i < 16; ++i) { + uint8_t this_byte = sin->sin6_addr.s6_addr[i]; + // Stop when we find a zero byte + if (this_byte == 0) { + break; + } + switch (this_byte) { + case 0xff: + prefix_length += 8; + break; + case 0xfe: + prefix_length += 7; + break; + case 0xfc: + prefix_length += 6; + break; + case 0xf8: + prefix_length += 5; + break; + case 0xf0: + prefix_length += 4; + break; + case 0xe0: + prefix_length += 3; + break; + case 0xc0: + prefix_length += 2; + break; + case 0x80: + prefix_length += 1; + break; + default: + break; + } + } + } + entry.mask = IPv6Address::from_prefix_length(prefix_length); + entry.interface = iface_name; + entry.metric = 0; + output.push_back(entry); + } + } + next += rtm->rtm_msglen; + } + return output; +} + +#elif defined(_WIN32) + +vector route_entries() { + vector output; + MIB_IPFORWARDTABLE* table; + ULONG size = 0; + GetIpForwardTable(0, &size, 0); + vector buffer(size); + table = (MIB_IPFORWARDTABLE*)&buffer[0]; + GetIpForwardTable(table, &size, 0); + + for (DWORD i = 0; i < table->dwNumEntries; i++) { + MIB_IPFORWARDROW* row = &table->table[i]; + if (row->dwForwardType == MIB_IPROUTE_TYPE_INDIRECT || + row->dwForwardType == MIB_IPROUTE_TYPE_DIRECT) { + RouteEntry entry; + entry.interface = NetworkInterface::from_index(row->dwForwardIfIndex).name(); + entry.destination = IPv4Address(row->dwForwardDest); + entry.mask = IPv4Address(row->dwForwardMask); + entry.gateway = IPv4Address(row->dwForwardNextHop); + entry.metric = row->dwForwardMetric1; + output.push_back(entry); + } + } + return output; +} + +vector route6_entries() { + vector output; + MIB_IPFORWARD_TABLE2* table; + GetIpForwardTable2(AF_INET6, &table); + for (ULONG i = 0; i < table->NumEntries; i++) { + MIB_IPFORWARD_ROW2* row = &table->Table[i]; + if (true) { + try { + Route6Entry entry; + entry.interface = NetworkInterface::from_index(row->InterfaceIndex).name(); + entry.destination = IPv6Address(row->DestinationPrefix.Prefix.Ipv6.sin6_addr.s6_addr); + entry.mask = IPv6Address::from_prefix_length(row->DestinationPrefix.PrefixLength); + entry.gateway = IPv6Address(row->NextHop.Ipv6.sin6_addr.s6_addr); + entry.metric = row->Metric; + output.push_back(entry); + } + catch (invalid_interface&) { + + } + } + } + FreeMibTable(table); + return output; +} + +#else // GNU/LINUX + +vector route_entries() { + using namespace Tins::Internals; + vector output; + ifstream input("/proc/net/route"); + string destination, mask, metric, gw; + uint32_t dummy; + skip_line(input); + RouteEntry entry; + while (input >> entry.interface >> destination >> gw) { + for (unsigned i(0); i < 4; ++i) { + input >> metric; + } + input >> mask; + from_hex(destination, dummy); + entry.destination = IPv4Address(dummy); + from_hex(mask, dummy); + entry.mask = IPv4Address(dummy); + from_hex(gw, dummy); + entry.gateway = IPv4Address(dummy); + from_hex(metric, dummy); + entry.metric = dummy; + skip_line(input); + output.push_back(entry); + } + return output; +} + +vector route6_entries() { + using namespace Tins::Internals; + vector output; + ifstream input("/proc/net/ipv6_route"); + string destination, mask_length, metric, next_hop, dummy, flags; + Route6Entry entry; + while (input >> destination >> mask_length) { + string temporary; + uint32_t temporary_int; + for (unsigned i(0); i < 2; ++i) { + input >> dummy; + } + input >> next_hop; + input >> metric; + for (unsigned i(0); i < 2; ++i) { + input >> dummy; + } + input >> flags >> entry.interface; + from_hex(destination, temporary); + entry.destination = IPv6Address((const uint8_t*)&temporary[0]); + from_hex(mask_length, temporary_int); + entry.mask = IPv6Address::from_prefix_length(temporary_int); + from_hex(next_hop, temporary); + entry.gateway = IPv6Address((const uint8_t*)&temporary[0]); + from_hex(metric, temporary_int); + entry.metric = temporary_int; + // Process flags + from_hex(flags, temporary_int); + // Skip: + // * 0x01000000 -> cache entries + if ((temporary_int & 0x01000000) == 0) { + output.push_back(entry); + } + } + return output; +} + +#endif + +#ifdef _WIN32 +set network_interfaces() { + set output; + ULONG size; + ::GetAdaptersAddresses(AF_INET, 0, 0, 0, &size); + vector buffer(size); + if (::GetAdaptersAddresses(AF_INET, 0, 0, (IP_ADAPTER_ADDRESSES *)&buffer[0], &size) == ERROR_SUCCESS) { + PIP_ADAPTER_ADDRESSES iface = (IP_ADAPTER_ADDRESSES *)&buffer[0]; + while (iface) { + output.insert(iface->AdapterName); + iface = iface->Next; + } + } + return output; +} +#else +set network_interfaces() { + set output; + struct ifaddrs* ifaddrs = 0; + struct ifaddrs* if_it = 0; + getifaddrs(&ifaddrs); + for (if_it = ifaddrs; if_it; if_it = if_it->ifa_next) { + output.insert(if_it->ifa_name); + } + if (ifaddrs) { + freeifaddrs(ifaddrs); + } + return output; +} +#endif // _WIN32 + +} // Utils +} // Tins From 4e4f7a239073f7f338d5fe5023d3671230c21581 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 13:12:39 -0700 Subject: [PATCH 25/73] Move Utils::gateway_from_ip into routing utils files --- include/tins/utils.h | 13 ------------- include/tins/utils/routing_utils.h | 13 +++++++++++++ src/utils.cpp | 14 -------------- src/utils/routing_utils.cpp | 13 +++++++++++++ 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/include/tins/utils.h b/include/tins/utils.h index 27d2128..d4665cb 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -112,19 +112,6 @@ TINS_API HWAddress<6> resolve_hwaddr(const NetworkInterface& iface, */ TINS_API HWAddress<6> resolve_hwaddr(IPv4Address ip, PacketSender& sender); -/** - * \brief Finds the gateway's IP address for the given IP - * address. - * - * \param ip The IP address for which the default gateway will - * be searched. - * \param gw_addr This parameter will contain the gateway's IP - * address in case it is found. - * - * \return bool indicating whether the lookup was successfull. - */ -TINS_API bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr); - /** * \brief Converts a PDUType to a string. * \param pduType The PDUType to be converted. diff --git a/include/tins/utils/routing_utils.h b/include/tins/utils/routing_utils.h index 71a5863..a162841 100644 --- a/include/tins/utils/routing_utils.h +++ b/include/tins/utils/routing_utils.h @@ -133,6 +133,19 @@ TINS_API std::vector route6_entries(); */ TINS_API std::set network_interfaces(); +/** + * \brief Finds the gateway's IP address for the given IP + * address. + * + * \param ip The IP address for which the default gateway will + * be searched. + * \param gw_addr This parameter will contain the gateway's IP + * address in case it is found. + * + * \return bool indicating whether the lookup was successfull. + */ +TINS_API bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr); + } // Utils } // Tins diff --git a/src/utils.cpp b/src/utils.cpp index 9940c91..8d91f8b 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -142,20 +142,6 @@ HWAddress<6> resolve_hwaddr(const NetworkInterface& iface, HWAddress<6> resolve_hwaddr(IPv4Address ip, PacketSender& sender) { return resolve_hwaddr(sender.default_interface(), ip, sender); } - -bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr) { - typedef vector entries_type; - entries_type entries; - uint32_t ip_int = ip; - route_entries(back_inserter(entries)); - for (entries_type::const_iterator it(entries.begin()); it != entries.end(); ++it) { - if ((ip_int & it->mask) == it->destination) { - gw_addr = it->gateway; - return true; - } - } - return false; -} string to_string(PDU::PDUType pduType) { #define ENUM_TEXT(p) case(PDU::p): return #p; diff --git a/src/utils/routing_utils.cpp b/src/utils/routing_utils.cpp index 31fca0d..c2d3229 100644 --- a/src/utils/routing_utils.cpp +++ b/src/utils/routing_utils.cpp @@ -425,5 +425,18 @@ set network_interfaces() { } #endif // _WIN32 +bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr) { + typedef vector entries_type; + entries_type entries = route_entries(); + uint32_t ip_int = ip; + for (entries_type::const_iterator it(entries.begin()); it != entries.end(); ++it) { + if ((ip_int & it->mask) == it->destination) { + gw_addr = it->gateway; + return true; + } + } + return false; +} + } // Utils } // Tins From e556f4147f01dd2daa359c708b815ab3baebb9fe Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 13:21:13 -0700 Subject: [PATCH 26/73] Move resolution utils into their own file --- include/tins/utils.h | 51 +---------- include/tins/utils/resolve_utils.h | 100 ++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/utils.cpp | 64 -------------- src/utils/resolve_utils.cpp | 133 +++++++++++++++++++++++++++++ 5 files changed, 235 insertions(+), 114 deletions(-) create mode 100644 include/tins/utils/resolve_utils.h create mode 100644 src/utils/resolve_utils.cpp diff --git a/include/tins/utils.h b/include/tins/utils.h index d4665cb..249ec8c 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -40,6 +40,7 @@ #include "utils/checksum_utils.h" #include "utils/frequency_utils.h" #include "utils/routing_utils.h" +#include "utils/resolve_utils.h" // Fix for Windows interface define on combaseapi.h #undef interface @@ -62,56 +63,6 @@ class HWAddress; */ namespace Utils { -/** - * \brief Resolves a domain name and returns its corresponding ip address. - * - * If an ip address is given, its integer representation is returned. - * Otherwise, the domain name is resolved and its ip address is returned. - * - * \param to_resolve The domain name/ip address to resolve. - */ -TINS_API IPv4Address resolve_domain(const std::string& to_resolve); - -/** - * \brief Resolves a domain name and returns its corresponding ip address. - * - * If an ip address is given, its integer representation is returned. - * Otherwise, the domain name is resolved and its ip address is returned. - * - * \param to_resolve The domain name/ip address to resolve. - */ -TINS_API IPv6Address resolve_domain6(const std::string& to_resolve); - -/** - * \brief Resolves the hardware address for a given ip. - * - * If the address can't be resolved, a std::runtime_error - * exception is thrown. - * - * \param iface The interface in which the packet will be sent. - * \param ip The ip to resolve, in integer format. - * \param sender The sender to use to send and receive the ARP requests. - * \return HWAddress<6> containing the resolved hardware address. - */ -TINS_API HWAddress<6> resolve_hwaddr(const NetworkInterface& iface, - IPv4Address ip, - PacketSender& sender); - -/** - * \brief Resolves the hardware address for a given ip. - * - * If the address can't be resolved, a std::runtime_error - * exception is thrown. - * - * This method sends and receives the packet through - * PacketSender::default_interface. - * - * \param ip The ip to resolve, in integer format. - * \param sender The sender to use to send and receive the ARP requests. - * \return HWAddress<6> containing the resolved hardware address. - */ -TINS_API HWAddress<6> resolve_hwaddr(IPv4Address ip, PacketSender& sender); - /** * \brief Converts a PDUType to a string. * \param pduType The PDUType to be converted. diff --git a/include/tins/utils/resolve_utils.h b/include/tins/utils/resolve_utils.h new file mode 100644 index 0000000..b3c45d8 --- /dev/null +++ b/include/tins/utils/resolve_utils.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_RESOLVE_UTILS_H +#define TINS_RESOLVE_UTILS_H + +#include +#include "../macros.h" + +namespace Tins { + +class PacketSender; +class NetworkInterface; +class IPv4Address; +class IPv6Address; +template +class HWAddress; + +namespace Utils { + +/** + * \brief Resolves a domain name and returns its corresponding ip address. + * + * If an ip address is given, its integer representation is returned. + * Otherwise, the domain name is resolved and its ip address is returned. + * + * \param to_resolve The domain name/ip address to resolve. + */ +TINS_API IPv4Address resolve_domain(const std::string& to_resolve); + +/** + * \brief Resolves a domain name and returns its corresponding ip address. + * + * If an ip address is given, its integer representation is returned. + * Otherwise, the domain name is resolved and its ip address is returned. + * + * \param to_resolve The domain name/ip address to resolve. + */ +TINS_API IPv6Address resolve_domain6(const std::string& to_resolve); + +/** + * \brief Resolves the hardware address for a given ip. + * + * If the address can't be resolved, a std::runtime_error + * exception is thrown. + * + * \param iface The interface in which the packet will be sent. + * \param ip The ip to resolve, in integer format. + * \param sender The sender to use to send and receive the ARP requests. + * \return HWAddress<6> containing the resolved hardware address. + */ +TINS_API HWAddress<6> resolve_hwaddr(const NetworkInterface& iface, + IPv4Address ip, + PacketSender& sender); + +/** + * \brief Resolves the hardware address for a given ip. + * + * If the address can't be resolved, a std::runtime_error + * exception is thrown. + * + * This method sends and receives the packet through + * PacketSender::default_interface. + * + * \param ip The ip to resolve, in integer format. + * \param sender The sender to use to send and receive the ARP requests. + * \return HWAddress<6> containing the resolved hardware address. + */ +TINS_API HWAddress<6> resolve_hwaddr(IPv4Address ip, PacketSender& sender); + +} // Utils +} // Tins + +#endif // TINS_RESOLVE_UTILS_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e709e5..6279a2f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -75,6 +75,7 @@ set(SOURCES utils/checksum_utils.cpp utils/frequency_utils.cpp utils/routing_utils.cpp + utils/resolve_utils.cpp ) SET(PCAP_DEPENDENT_SOURCES diff --git a/src/utils.cpp b/src/utils.cpp index 8d91f8b..d5f9300 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -76,72 +76,8 @@ using std::runtime_error; using Tins::Memory::InputMemoryStream; using Tins::Memory::OutputMemoryStream; -/** \cond */ - -addrinfo* resolve_domain(const string& to_resolve, int family) { - addrinfo* result, hints = addrinfo(); - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - hints.ai_family = family; - if (!getaddrinfo(to_resolve.c_str(), 0, &hints, &result)) { - return result; - } - else { - throw runtime_error("Could not resolve address"); - } -} - namespace Tins { - -/** \endcond */ namespace Utils { - -IPv4Address resolve_domain(const string& to_resolve) { - addrinfo* result = ::resolve_domain(to_resolve, AF_INET); - IPv4Address addr(((sockaddr_in*)result->ai_addr)->sin_addr.s_addr); - freeaddrinfo(result); - return addr; -} - -IPv6Address resolve_domain6(const string& to_resolve) { - addrinfo* result = ::resolve_domain(to_resolve, AF_INET6); - IPv6Address addr((const uint8_t*)&((sockaddr_in6*)result->ai_addr)->sin6_addr); - freeaddrinfo(result); - return addr; -} - -HWAddress<6> resolve_hwaddr(const NetworkInterface& iface, - IPv4Address ip, - PacketSender& sender) { - NetworkInterface::Info info(iface.addresses()); - #ifdef _WIN32 - // On Windows, use SendARP - IPAddr source; - IPAddr dest; - ULONG hw_address[2]; - ULONG address_length = 6; - source = static_cast(info.ip_addr); - dest = static_cast(ip); - if (SendARP(dest, source, &hw_address, &address_length) == NO_ERROR && address_length == 6) { - return HWAddress<6>((const uint8_t*)hw_address); - } - #else - // On other platforms, just do the ARP resolution ourselves - EthernetII packet = ARP::make_arp_request(ip, info.ip_addr, info.hw_addr); - Internals::smart_ptr::type response(sender.send_recv(packet, iface)); - if (response.get()) { - const ARP* arp_resp = response->find_pdu(); - if (arp_resp) { - return arp_resp->sender_hw_addr(); - } - } - #endif - throw runtime_error("Could not resolve hardware address"); -} - -HWAddress<6> resolve_hwaddr(IPv4Address ip, PacketSender& sender) { - return resolve_hwaddr(sender.default_interface(), ip, sender); -} string to_string(PDU::PDUType pduType) { #define ENUM_TEXT(p) case(PDU::p): return #p; diff --git a/src/utils/resolve_utils.cpp b/src/utils/resolve_utils.cpp new file mode 100644 index 0000000..05c6747 --- /dev/null +++ b/src/utils/resolve_utils.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "utils/resolve_utils.h" + #ifndef _WIN32 + #if defined(BSD) || defined(__FreeBSD_kernel__) + #include + #include + #else + #include + #endif + #include + #include + #include + #ifdef __ANDROID_API__ + #include + #include + #endif +#else + #include + #include + #include + #undef interface +#endif +#include +#include "ip_address.h" +#include "ipv6_address.h" +#include "hw_address.h" +#include "ethernetII.h" +#include "arp.h" +#include "packet_sender.h" +#include "network_interface.h" +#include "detail/smart_ptr.h" + +using std::string; +using std::runtime_error; + +/** \cond */ + +addrinfo* resolve_domain(const string& to_resolve, int family) { + addrinfo* result, hints = addrinfo(); + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + hints.ai_family = family; + if (!getaddrinfo(to_resolve.c_str(), 0, &hints, &result)) { + return result; + } + else { + throw runtime_error("Could not resolve address"); + } +} + +/** \endcond */ + +namespace Tins { +namespace Utils { + +IPv4Address resolve_domain(const string& to_resolve) { + addrinfo* result = ::resolve_domain(to_resolve, AF_INET); + IPv4Address addr(((sockaddr_in*)result->ai_addr)->sin_addr.s_addr); + freeaddrinfo(result); + return addr; +} + +IPv6Address resolve_domain6(const string& to_resolve) { + addrinfo* result = ::resolve_domain(to_resolve, AF_INET6); + IPv6Address addr((const uint8_t*)&((sockaddr_in6*)result->ai_addr)->sin6_addr); + freeaddrinfo(result); + return addr; +} + +HWAddress<6> resolve_hwaddr(const NetworkInterface& iface, + IPv4Address ip, + PacketSender& sender) { + NetworkInterface::Info info(iface.addresses()); + #ifdef _WIN32 + // On Windows, use SendARP + IPAddr source; + IPAddr dest; + ULONG hw_address[2]; + ULONG address_length = 6; + source = static_cast(info.ip_addr); + dest = static_cast(ip); + if (SendARP(dest, source, &hw_address, &address_length) == NO_ERROR && address_length == 6) { + return HWAddress<6>((const uint8_t*)hw_address); + } + #else + // On other platforms, just do the ARP resolution ourselves + EthernetII packet = ARP::make_arp_request(ip, info.ip_addr, info.hw_addr); + Internals::smart_ptr::type response(sender.send_recv(packet, iface)); + if (response.get()) { + const ARP* arp_resp = response->find_pdu(); + if (arp_resp) { + return arp_resp->sender_hw_addr(); + } + } + #endif + throw runtime_error("Could not resolve hardware address"); +} + +HWAddress<6> resolve_hwaddr(IPv4Address ip, PacketSender& sender) { + return resolve_hwaddr(sender.default_interface(), ip, sender); +} + + +} // Utils +} // Tins From 3d4f9285c92a3c86ee7d977b34ce5f3adb318086 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 13:29:33 -0700 Subject: [PATCH 27/73] Move PDU utils into their own file --- include/tins/packet_writer.h | 2 +- include/tins/tcp_stream.h | 2 +- include/tins/utils.h | 59 +----------------- include/tins/utils/pdu_utils.h | 83 ++++++++++++++++++++++++++ src/CMakeLists.txt | 2 +- src/{utils.cpp => utils/pdu_utils.cpp} | 49 +-------------- 6 files changed, 90 insertions(+), 107 deletions(-) create mode 100644 include/tins/utils/pdu_utils.h rename src/{utils.cpp => utils/pdu_utils.cpp} (74%) diff --git a/include/tins/packet_writer.h b/include/tins/packet_writer.h index 79b7b8e..07fa53e 100644 --- a/include/tins/packet_writer.h +++ b/include/tins/packet_writer.h @@ -30,10 +30,10 @@ #ifndef TINS_PACKET_WRITER_H #define TINS_PACKET_WRITER_H -#include "utils.h" #include #include "macros.h" #include "cxxstd.h" +#include "utils/pdu_utils.h" #ifdef TINS_HAVE_PCAP #include diff --git a/include/tins/tcp_stream.h b/include/tins/tcp_stream.h index 0952176..eb0a838 100644 --- a/include/tins/tcp_stream.h +++ b/include/tins/tcp_stream.h @@ -38,9 +38,9 @@ #include #include "macros.h" #include "tcp.h" -#include "utils.h" #include "ip.h" #include "ip_address.h" +#include "utils/pdu_utils.h" #ifdef TINS_HAVE_PCAP diff --git a/include/tins/utils.h b/include/tins/utils.h index 249ec8c..ea13730 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -30,30 +30,14 @@ #ifndef TINS_UTILS_H #define TINS_UTILS_H -#include "macros.h" -#include -#include -#include "ip_address.h" -#include "ipv6_address.h" -#include "pdu.h" -#include "detail/type_traits.h" #include "utils/checksum_utils.h" #include "utils/frequency_utils.h" #include "utils/routing_utils.h" #include "utils/resolve_utils.h" - -// Fix for Windows interface define on combaseapi.h -#undef interface - +#include "utils/pdu_utils.h" + namespace Tins { -class NetworkInterface; -class PacketSender; -class PDU; -class IPv6Address; -template -class HWAddress; - /** * \brief Network utils namespace. * @@ -63,45 +47,6 @@ class HWAddress; */ namespace Utils { -/** - * \brief Converts a PDUType to a string. - * \param pduType The PDUType to be converted. - * \return A string representation, for example "DOT11_QOS_DATA". - */ -TINS_API std::string to_string(PDU::PDUType pduType); - -template -struct is_pdu { - template - static char test(typename U::PDUType*); - - template - static long test(...); - - static const bool value = sizeof(test(0)) == 1; -}; - -/** - * Returns the argument. - */ -inline PDU& dereference_until_pdu(PDU& pdu) { - return pdu; -} - -/** - * \brief Dereferences the parameter until a PDU is found. - * - * This function dereferences the parameter until a PDU object - * is found. When it's found, it is returned. - * - * \param value The parameter to be dereferenced. - */ -template -inline typename Internals::enable_if::value, PDU&>::type -dereference_until_pdu(T& value) { - return dereference_until_pdu(*value); -} - } // Utils } // Tins diff --git a/include/tins/utils/pdu_utils.h b/include/tins/utils/pdu_utils.h new file mode 100644 index 0000000..2e91217 --- /dev/null +++ b/include/tins/utils/pdu_utils.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_PDU_UTILS_H +#define TINS_PDU_UTILS_H + +#include "../macros.h" +#include "../pdu.h" +#include "../detail/type_traits.h" + +namespace Tins { +namespace Utils { + +/** + * \brief Converts a PDUType to a string. + * \param pduType The PDUType to be converted. + * \return A string representation, for example "DOT11_QOS_DATA". + */ +TINS_API std::string to_string(PDU::PDUType pduType); + +template +struct is_pdu { + template + static char test(typename U::PDUType*); + + template + static long test(...); + + static const bool value = sizeof(test(0)) == 1; +}; + +/** + * Returns the argument. + */ +inline PDU& dereference_until_pdu(PDU& pdu) { + return pdu; +} + +/** + * \brief Dereferences the parameter until a PDU is found. + * + * This function dereferences the parameter until a PDU object + * is found. When it's found, it is returned. + * + * \param value The parameter to be dereferenced. + */ +template +inline typename Internals::enable_if::value, PDU&>::type +dereference_until_pdu(T& value) { + return dereference_until_pdu(*value); +} + +} // Utils +} // Tins + + +#endif // TINS_PDU_UTILS_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6279a2f..b4f1730 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,7 +63,6 @@ set(SOURCES tcp_ip/stream_identifier.cpp timestamp.cpp udp.cpp - utils.cpp dot11/dot11_base.cpp dot11/dot11_data.cpp dot11/dot11_mgmt.cpp @@ -76,6 +75,7 @@ set(SOURCES utils/frequency_utils.cpp utils/routing_utils.cpp utils/resolve_utils.cpp + utils/pdu_utils.cpp ) SET(PCAP_DEPENDENT_SOURCES diff --git a/src/utils.cpp b/src/utils/pdu_utils.cpp similarity index 74% rename from src/utils.cpp rename to src/utils/pdu_utils.cpp index d5f9300..a268539 100644 --- a/src/utils.cpp +++ b/src/utils/pdu_utils.cpp @@ -27,58 +27,13 @@ * */ -#include -#include -#include "macros.h" -#ifndef _WIN32 - #if defined(BSD) || defined(__FreeBSD_kernel__) - #include - #include - #include - #include - #include - #include - #include - #else - #include - #endif - #include - #include - #include - #ifdef __ANDROID_API__ - #include - #include - #endif -#else - #include - #include - #include - #undef interface -#endif -#include "utils.h" -#include "arp.h" -#include "ethernetII.h" -#include "network_interface.h" -#include "packet_sender.h" -#include "cxxstd.h" -#include "hw_address.h" -#include "memory_helpers.h" -#include "detail/smart_ptr.h" -#include "detail/smart_ptr.h" +#include "utils/pdu_utils.h" using std::string; -using std::istream; -using std::set; -using std::vector; -using std::back_inserter; -using std::runtime_error; - -using Tins::Memory::InputMemoryStream; -using Tins::Memory::OutputMemoryStream; namespace Tins { namespace Utils { - + string to_string(PDU::PDUType pduType) { #define ENUM_TEXT(p) case(PDU::p): return #p; switch (pduType){ From 3e7188edf775f530c3e48be7b9109fae9150bc88 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 13:49:50 -0700 Subject: [PATCH 28/73] Move internals' PDU helpers into their own files --- include/tins/detail/pdu_helpers.h | 66 +++++++ include/tins/detail/type_traits.h | 1 + include/tins/internals.h | 32 +--- src/CMakeLists.txt | 1 + src/detail/pdu_helpers.cpp | 298 ++++++++++++++++++++++++++++++ src/dhcp.cpp | 1 - src/dot1q.cpp | 2 +- src/ethernetII.cpp | 3 +- src/internals.cpp | 270 --------------------------- src/ip.cpp | 3 +- src/ip_reassembler.cpp | 2 +- src/ipsec.cpp | 2 +- src/ipv6.cpp | 3 +- src/pktap.cpp | 2 +- src/sll.cpp | 2 +- src/snap.cpp | 2 +- src/tcp.cpp | 1 - 17 files changed, 382 insertions(+), 309 deletions(-) create mode 100644 include/tins/detail/pdu_helpers.h create mode 100644 src/detail/pdu_helpers.cpp diff --git a/include/tins/detail/pdu_helpers.h b/include/tins/detail/pdu_helpers.h new file mode 100644 index 0000000..77cc767 --- /dev/null +++ b/include/tins/detail/pdu_helpers.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_PDU_HELPERS_H +#define TINS_PDU_HELPERS_H + +#include "../constants.h" +#include "../config.h" +#include "../pdu.h" + +/** + * \cond + */ + +namespace Tins { +namespace Internals { + +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); +PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag); +Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag); +PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag); + +} // Internals +} // Tins + +/** + * \endcond + */ + +#endif // TINS_PDU_HELPERS_H diff --git a/include/tins/detail/type_traits.h b/include/tins/detail/type_traits.h index f133d5c..99fbc4b 100644 --- a/include/tins/detail/type_traits.h +++ b/include/tins/detail/type_traits.h @@ -34,6 +34,7 @@ #include "../cxxstd.h" #if TINS_IS_CXX11 #include + #include #endif namespace Tins { diff --git a/include/tins/internals.h b/include/tins/internals.h index caddac4..d6697af 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -30,43 +30,19 @@ #ifndef TINS_INTERNALS_H #define TINS_INTERNALS_H -#include #include -#include "constants.h" -#include "pdu.h" -#include "hw_address.h" -#include "macros.h" #include "detail/type_traits.h" +#include "detail/address_helpers.h" +#include "detail/icmp_extension_helpers.h" +#include "detail/smart_ptr.h" +#include "detail/pdu_helpers.h" /** * \cond */ namespace Tins { -namespace Memory { - -class InputMemoryStream; -} // Memory -class IPv4Address; -class IPv6Address; -class ICMPExtensionsStructure; - namespace Internals { -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); -PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag); -Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag); -PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag); - // Compares sequence numbers as defined by RFC 1982. int seq_compare(uint32_t seq1, uint32_t seq2); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b4f1730..58e4920 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ set(SOURCES crypto.cpp detail/address_helpers.cpp detail/icmp_extension_helpers.cpp + detail/pdu_helpers.cpp dhcp.cpp dhcpv6.cpp dns.cpp diff --git a/src/detail/pdu_helpers.cpp b/src/detail/pdu_helpers.cpp new file mode 100644 index 0000000..ea15ee5 --- /dev/null +++ b/src/detail/pdu_helpers.cpp @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "detail/pdu_helpers.h" +#ifdef TINS_HAVE_PCAP + #include +#endif // TINS_HAVE_PCAP +#include "ip.h" +#include "ethernetII.h" +#include "ieee802_3.h" +#include "radiotap.h" +#include "dot11/dot11_base.h" +#include "ipv6.h" +#include "tcp.h" +#include "udp.h" +#include "ipsec.h" +#include "icmp.h" +#include "loopback.h" +#include "sll.h" +#include "ppi.h" +#include "icmpv6.h" +#include "mpls.h" +#include "arp.h" +#include "eapol.h" +#include "rawpdu.h" +#include "dot1q.h" +#include "pppoe.h" +#include "pdu_allocator.h" + +namespace Tins { +namespace Internals { + +Tins::PDU* pdu_from_flag(Constants::Ethernet::e flag, + const uint8_t* buffer, + uint32_t size, + bool rawpdu_on_no_match) { + switch (flag) { + case Tins::Constants::Ethernet::IP: + return new IP(buffer, size); + case Constants::Ethernet::IPV6: + return new IPv6(buffer, size); + case Tins::Constants::Ethernet::ARP: + return new ARP(buffer, size); + case Tins::Constants::Ethernet::PPPOED: + case Tins::Constants::Ethernet::PPPOES: + return new PPPoE(buffer, size); + case Tins::Constants::Ethernet::EAPOL: + return EAPOL::from_bytes(buffer, size); + case Tins::Constants::Ethernet::VLAN: + case Tins::Constants::Ethernet::QINQ: + case Tins::Constants::Ethernet::OLD_QINQ: + return new Dot1Q(buffer, size); + case Tins::Constants::Ethernet::MPLS: + return new MPLS(buffer, size); + default: + { + PDU* pdu = Internals::allocate( + static_cast(flag), + buffer, + size + ); + if (pdu) { + return pdu; + } + } + return rawpdu_on_no_match ? new RawPDU(buffer, size) : 0; + }; +} + +Tins::PDU* pdu_from_flag(Constants::IP::e flag, + const uint8_t* buffer, + uint32_t size, + bool rawpdu_on_no_match) { + switch (flag) { + case Constants::IP::PROTO_IPIP: + return new Tins::IP(buffer, size); + case Constants::IP::PROTO_TCP: + return new Tins::TCP(buffer, size); + case Constants::IP::PROTO_UDP: + return new Tins::UDP(buffer, size); + case Constants::IP::PROTO_ICMP: + return new Tins::ICMP(buffer, size); + case Constants::IP::PROTO_ICMPV6: + return new Tins::ICMPv6(buffer, size); + case Constants::IP::PROTO_IPV6: + return new Tins::IPv6(buffer, size); + case Constants::IP::PROTO_AH: + return new Tins::IPSecAH(buffer, size); + case Constants::IP::PROTO_ESP: + return new Tins::IPSecESP(buffer, size); + default: + break; + } + if (rawpdu_on_no_match) { + return new Tins::RawPDU(buffer, size); + } + return 0; +} + +#ifdef TINS_HAVE_PCAP +PDU* pdu_from_dlt_flag(int flag, + const uint8_t* buffer, + uint32_t size, + bool rawpdu_on_no_match) { + switch (flag) { + case DLT_EN10MB: + return new EthernetII(buffer, size); + + #ifdef TINS_HAVE_DOT11 + case DLT_IEEE802_11_RADIO: + return new RadioTap(buffer, size); + case DLT_IEEE802_11: + return Dot11::from_bytes(buffer, size); + #else // TINS_HAVE_DOT11 + case DLT_IEEE802_11_RADIO: + case DLT_IEEE802_11: + throw protocol_disabled(); + #endif // TINS_HAVE_DOT11 + + case DLT_NULL: + return new Loopback(buffer, size); + case DLT_LINUX_SLL: + return new SLL(buffer, size); + case DLT_PPI: + return new PPI(buffer, size); + default: + 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) { + case Tins::PDU::ETHERNET_II: + return new Tins::EthernetII(buffer, size); + case Tins::PDU::IP: + return new Tins::IP(buffer, size); + case Tins::PDU::IPv6: + return new Tins::IPv6(buffer, size); + case Tins::PDU::ARP: + return new Tins::ARP(buffer, size); + case Tins::PDU::IEEE802_3: + return new Tins::IEEE802_3(buffer, size); + case Tins::PDU::PPPOE: + return new Tins::PPPoE(buffer, size); + #ifdef TINS_HAVE_DOT11 + case Tins::PDU::RADIOTAP: + return new Tins::RadioTap(buffer, size); + case Tins::PDU::DOT11: + case Tins::PDU::DOT11_ACK: + case Tins::PDU::DOT11_ASSOC_REQ: + case Tins::PDU::DOT11_ASSOC_RESP: + case Tins::PDU::DOT11_AUTH: + case Tins::PDU::DOT11_BEACON: + case Tins::PDU::DOT11_BLOCK_ACK: + case Tins::PDU::DOT11_BLOCK_ACK_REQ: + case Tins::PDU::DOT11_CF_END: + case Tins::PDU::DOT11_DATA: + case Tins::PDU::DOT11_CONTROL: + case Tins::PDU::DOT11_DEAUTH: + case Tins::PDU::DOT11_DIASSOC: + case Tins::PDU::DOT11_END_CF_ACK: + case Tins::PDU::DOT11_MANAGEMENT: + case Tins::PDU::DOT11_PROBE_REQ: + case Tins::PDU::DOT11_PROBE_RESP: + case Tins::PDU::DOT11_PS_POLL: + case Tins::PDU::DOT11_REASSOC_REQ: + case Tins::PDU::DOT11_REASSOC_RESP: + case Tins::PDU::DOT11_RTS: + case Tins::PDU::DOT11_QOS_DATA: + return Tins::Dot11::from_bytes(buffer, size); + #endif // TINS_HAVE_DOT11 + default: + return 0; + }; +} + +Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag) { + switch (flag) { + case PDU::IP: + return Constants::Ethernet::IP; + case PDU::IPv6: + return Constants::Ethernet::IPV6; + case PDU::ARP: + return Constants::Ethernet::ARP; + case PDU::DOT1Q: + return Constants::Ethernet::VLAN; + case PDU::PPPOE: + return Constants::Ethernet::PPPOED; + case PDU::MPLS: + return Constants::Ethernet::MPLS; + case PDU::RSNEAPOL: + case PDU::RC4EAPOL: + return Constants::Ethernet::EAPOL; + default: + if (Internals::pdu_type_registered(flag)) { + return static_cast( + Internals::pdu_type_to_id(flag) + ); + } + return Constants::Ethernet::UNKNOWN; + } +} + +PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag) { + switch (flag) { + case Constants::Ethernet::IP: + return PDU::IP; + case Constants::Ethernet::IPV6: + return PDU::IPv6; + case Constants::Ethernet::ARP: + return PDU::ARP; + case Constants::Ethernet::VLAN: + return PDU::DOT1Q; + case Constants::Ethernet::PPPOED: + return PDU::PPPOE; + //case PDU::RSNEAPOL + //case PDU::RC4EAPOL: + // return Constants::Ethernet::EAPOL; + default: + return PDU::UNKNOWN; + } +} + +Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag) { + switch(flag) { + case PDU::IP: + return Constants::IP::PROTO_IPIP; + case PDU::IPv6: + return Constants::IP::PROTO_IPV6; + case PDU::TCP: + return Constants::IP::PROTO_TCP; + case PDU::UDP: + return Constants::IP::PROTO_UDP; + case PDU::ICMP: + return Constants::IP::PROTO_ICMP; + case PDU::ICMPv6: + return Constants::IP::PROTO_ICMPV6; + case PDU::IPSEC_AH: + return Constants::IP::PROTO_AH; + case PDU::IPSEC_ESP: + return Constants::IP::PROTO_ESP; + default: + return static_cast(0xff); + }; +} + +PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag) { + switch(flag) { + case Constants::IP::PROTO_IPIP: + return PDU::IP; + case Constants::IP::PROTO_IPV6: + return PDU::IPv6; + case Constants::IP::PROTO_TCP: + return PDU::TCP; + case Constants::IP::PROTO_UDP: + return PDU::UDP; + case Constants::IP::PROTO_ICMP: + return PDU::ICMP; + case Constants::IP::PROTO_ICMPV6: + return PDU::ICMPv6; + case Constants::IP::PROTO_AH: + return PDU::IPSEC_AH; + case Constants::IP::PROTO_ESP: + return PDU::IPSEC_ESP; + default: + return PDU::UNKNOWN; + }; +} + +} // Internals +} // Tins \ No newline at end of file diff --git a/src/dhcp.cpp b/src/dhcp.cpp index 46dd78f..051e303 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -33,7 +33,6 @@ #include "endianness.h" #include "dhcp.h" #include "ethernetII.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" diff --git a/src/dot1q.cpp b/src/dot1q.cpp index 5fca01c..f3f5fed 100644 --- a/src/dot1q.cpp +++ b/src/dot1q.cpp @@ -30,9 +30,9 @@ #include #include #include "dot1q.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using Tins::Memory::InputMemoryStream; using Tins::Memory::OutputMemoryStream; diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index df85505..8dcdbaa 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -39,8 +39,8 @@ #include #include #endif -#include "config.h" #include "ethernetII.h" +#include "config.h" #include "packet_sender.h" #include "rawpdu.h" #include "pppoe.h" @@ -51,6 +51,7 @@ #include "internals.h" #include "exceptions.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using std::equal; diff --git a/src/internals.cpp b/src/internals.cpp index 740d9eb..78c63fb 100644 --- a/src/internals.cpp +++ b/src/internals.cpp @@ -28,280 +28,10 @@ */ #include "internals.h" -#ifdef TINS_HAVE_PCAP - #include -#endif // TINS_HAVE_PCAP -#include "ip.h" -#include "ethernetII.h" -#include "ieee802_3.h" -#include "radiotap.h" -#include "dot11/dot11_base.h" -#include "ipv6.h" -#include "tcp.h" -#include "udp.h" -#include "ipsec.h" -#include "icmp.h" -#include "loopback.h" -#include "sll.h" -#include "ppi.h" -#include "icmpv6.h" -#include "mpls.h" -#include "arp.h" -#include "eapol.h" -#include "rawpdu.h" -#include "dot1q.h" -#include "pppoe.h" -#include "exceptions.h" -#include "ip_address.h" -#include "ipv6_address.h" -#include "pdu_allocator.h" -#include "memory_helpers.h" - -using std::string; - -using Tins::Memory::InputMemoryStream; namespace Tins { namespace Internals { -Tins::PDU* pdu_from_flag(Constants::Ethernet::e flag, - const uint8_t* buffer, - uint32_t size, - bool rawpdu_on_no_match) { - switch (flag) { - case Tins::Constants::Ethernet::IP: - return new IP(buffer, size); - case Constants::Ethernet::IPV6: - return new IPv6(buffer, size); - case Tins::Constants::Ethernet::ARP: - return new ARP(buffer, size); - case Tins::Constants::Ethernet::PPPOED: - case Tins::Constants::Ethernet::PPPOES: - return new PPPoE(buffer, size); - case Tins::Constants::Ethernet::EAPOL: - return EAPOL::from_bytes(buffer, size); - case Tins::Constants::Ethernet::VLAN: - case Tins::Constants::Ethernet::QINQ: - case Tins::Constants::Ethernet::OLD_QINQ: - return new Dot1Q(buffer, size); - case Tins::Constants::Ethernet::MPLS: - return new MPLS(buffer, size); - default: - { - PDU* pdu = Internals::allocate( - static_cast(flag), - buffer, - size - ); - if (pdu) { - return pdu; - } - } - return rawpdu_on_no_match ? new RawPDU(buffer, size) : 0; - }; -} - -Tins::PDU* pdu_from_flag(Constants::IP::e flag, - const uint8_t* buffer, - uint32_t size, - bool rawpdu_on_no_match) { - switch (flag) { - case Constants::IP::PROTO_IPIP: - return new Tins::IP(buffer, size); - case Constants::IP::PROTO_TCP: - return new Tins::TCP(buffer, size); - case Constants::IP::PROTO_UDP: - return new Tins::UDP(buffer, size); - case Constants::IP::PROTO_ICMP: - return new Tins::ICMP(buffer, size); - case Constants::IP::PROTO_ICMPV6: - return new Tins::ICMPv6(buffer, size); - case Constants::IP::PROTO_IPV6: - return new Tins::IPv6(buffer, size); - case Constants::IP::PROTO_AH: - return new Tins::IPSecAH(buffer, size); - case Constants::IP::PROTO_ESP: - return new Tins::IPSecESP(buffer, size); - default: - break; - } - if (rawpdu_on_no_match) { - return new Tins::RawPDU(buffer, size); - } - return 0; -} - -#ifdef TINS_HAVE_PCAP -PDU* pdu_from_dlt_flag(int flag, - const uint8_t* buffer, - uint32_t size, - bool rawpdu_on_no_match) { - switch (flag) { - case DLT_EN10MB: - return new EthernetII(buffer, size); - - #ifdef TINS_HAVE_DOT11 - case DLT_IEEE802_11_RADIO: - return new RadioTap(buffer, size); - case DLT_IEEE802_11: - return Dot11::from_bytes(buffer, size); - #else // TINS_HAVE_DOT11 - case DLT_IEEE802_11_RADIO: - case DLT_IEEE802_11: - throw protocol_disabled(); - #endif // TINS_HAVE_DOT11 - - case DLT_NULL: - return new Loopback(buffer, size); - case DLT_LINUX_SLL: - return new SLL(buffer, size); - case DLT_PPI: - return new PPI(buffer, size); - default: - 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) { - case Tins::PDU::ETHERNET_II: - return new Tins::EthernetII(buffer, size); - case Tins::PDU::IP: - return new Tins::IP(buffer, size); - case Tins::PDU::IPv6: - return new Tins::IPv6(buffer, size); - case Tins::PDU::ARP: - return new Tins::ARP(buffer, size); - case Tins::PDU::IEEE802_3: - return new Tins::IEEE802_3(buffer, size); - case Tins::PDU::PPPOE: - return new Tins::PPPoE(buffer, size); - #ifdef TINS_HAVE_DOT11 - case Tins::PDU::RADIOTAP: - return new Tins::RadioTap(buffer, size); - case Tins::PDU::DOT11: - case Tins::PDU::DOT11_ACK: - case Tins::PDU::DOT11_ASSOC_REQ: - case Tins::PDU::DOT11_ASSOC_RESP: - case Tins::PDU::DOT11_AUTH: - case Tins::PDU::DOT11_BEACON: - case Tins::PDU::DOT11_BLOCK_ACK: - case Tins::PDU::DOT11_BLOCK_ACK_REQ: - case Tins::PDU::DOT11_CF_END: - case Tins::PDU::DOT11_DATA: - case Tins::PDU::DOT11_CONTROL: - case Tins::PDU::DOT11_DEAUTH: - case Tins::PDU::DOT11_DIASSOC: - case Tins::PDU::DOT11_END_CF_ACK: - case Tins::PDU::DOT11_MANAGEMENT: - case Tins::PDU::DOT11_PROBE_REQ: - case Tins::PDU::DOT11_PROBE_RESP: - case Tins::PDU::DOT11_PS_POLL: - case Tins::PDU::DOT11_REASSOC_REQ: - case Tins::PDU::DOT11_REASSOC_RESP: - case Tins::PDU::DOT11_RTS: - case Tins::PDU::DOT11_QOS_DATA: - return Tins::Dot11::from_bytes(buffer, size); - #endif // TINS_HAVE_DOT11 - default: - return 0; - }; -} - -Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag) { - switch (flag) { - case PDU::IP: - return Constants::Ethernet::IP; - case PDU::IPv6: - return Constants::Ethernet::IPV6; - case PDU::ARP: - return Constants::Ethernet::ARP; - case PDU::DOT1Q: - return Constants::Ethernet::VLAN; - case PDU::PPPOE: - return Constants::Ethernet::PPPOED; - case PDU::MPLS: - return Constants::Ethernet::MPLS; - case PDU::RSNEAPOL: - case PDU::RC4EAPOL: - return Constants::Ethernet::EAPOL; - default: - if (Internals::pdu_type_registered(flag)) { - return static_cast( - Internals::pdu_type_to_id(flag) - ); - } - return Constants::Ethernet::UNKNOWN; - } -} - -PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag) { - switch (flag) { - case Constants::Ethernet::IP: - return PDU::IP; - case Constants::Ethernet::IPV6: - return PDU::IPv6; - case Constants::Ethernet::ARP: - return PDU::ARP; - case Constants::Ethernet::VLAN: - return PDU::DOT1Q; - case Constants::Ethernet::PPPOED: - return PDU::PPPOE; - //case PDU::RSNEAPOL - //case PDU::RC4EAPOL: - // return Constants::Ethernet::EAPOL; - default: - return PDU::UNKNOWN; - } -} - -Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag) { - switch(flag) { - case PDU::IP: - return Constants::IP::PROTO_IPIP; - case PDU::IPv6: - return Constants::IP::PROTO_IPV6; - case PDU::TCP: - return Constants::IP::PROTO_TCP; - case PDU::UDP: - return Constants::IP::PROTO_UDP; - case PDU::ICMP: - return Constants::IP::PROTO_ICMP; - case PDU::ICMPv6: - return Constants::IP::PROTO_ICMPV6; - case PDU::IPSEC_AH: - return Constants::IP::PROTO_AH; - case PDU::IPSEC_ESP: - return Constants::IP::PROTO_ESP; - default: - return static_cast(0xff); - }; -} - -PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag) { - switch(flag) { - case Constants::IP::PROTO_IPIP: - return PDU::IP; - case Constants::IP::PROTO_IPV6: - return PDU::IPv6; - case Constants::IP::PROTO_TCP: - return PDU::TCP; - case Constants::IP::PROTO_UDP: - return PDU::UDP; - case Constants::IP::PROTO_ICMP: - return PDU::ICMP; - case Constants::IP::PROTO_ICMPV6: - return PDU::ICMPv6; - case Constants::IP::PROTO_AH: - return PDU::IPSEC_AH; - case Constants::IP::PROTO_ESP: - return PDU::IPSEC_ESP; - default: - return PDU::UNKNOWN; - }; -} - int seq_compare(uint32_t seq1, uint32_t seq2) { // As defined by RFC 1982 - 2 ^ (SERIAL_BITS - 1) static const uint32_t seq_number_diff = 2147483648U; diff --git a/src/ip.cpp b/src/ip.cpp index 6eb0c7a..cd892fd 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -45,8 +45,9 @@ #include "exceptions.h" #include "pdu_allocator.h" #include "memory_helpers.h" -#include "internals.h" #include "utils/checksum_utils.h" +#include "detail/pdu_helpers.h" +#include "pdu_allocator.h" using std::list; using std::min; diff --git a/src/ip_reassembler.cpp b/src/ip_reassembler.cpp index 61c9578..12b4aeb 100644 --- a/src/ip_reassembler.cpp +++ b/src/ip_reassembler.cpp @@ -30,8 +30,8 @@ #include "ip.h" #include "rawpdu.h" #include "constants.h" -#include "internals.h" #include "ip_reassembler.h" +#include "detail/pdu_helpers.h" using std::make_pair; diff --git a/src/ipsec.cpp b/src/ipsec.cpp index 688053b..e925c2e 100644 --- a/src/ipsec.cpp +++ b/src/ipsec.cpp @@ -29,9 +29,9 @@ #include #include "ipsec.h" -#include "internals.h" #include "rawpdu.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using std::memcpy; using std::copy; diff --git a/src/ipv6.cpp b/src/ipv6.cpp index ba766a0..00e3f57 100644 --- a/src/ipv6.cpp +++ b/src/ipv6.cpp @@ -41,8 +41,9 @@ #include "rawpdu.h" #include "exceptions.h" #include "pdu_allocator.h" -#include "internals.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" +#include "pdu_allocator.h" using std::copy; diff --git a/src/pktap.cpp b/src/pktap.cpp index 60df8a6..7bb6f24 100644 --- a/src/pktap.cpp +++ b/src/pktap.cpp @@ -31,9 +31,9 @@ #include #include "exceptions.h" #include "pktap.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using Tins::Memory::InputMemoryStream; diff --git a/src/sll.cpp b/src/sll.cpp index 289b6fd..c21d062 100644 --- a/src/sll.cpp +++ b/src/sll.cpp @@ -30,9 +30,9 @@ #include #include #include "sll.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using Tins::Memory::InputMemoryStream; using Tins::Memory::OutputMemoryStream; diff --git a/src/snap.cpp b/src/snap.cpp index 33010f1..f27545d 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -38,9 +38,9 @@ #include "arp.h" #include "ip.h" #include "eapol.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using Tins::Memory::InputMemoryStream; using Tins::Memory::OutputMemoryStream; diff --git a/src/tcp.cpp b/src/tcp.cpp index fec72fa..37a0572 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -35,7 +35,6 @@ #include "constants.h" #include "rawpdu.h" #include "exceptions.h" -#include "internals.h" #include "memory_helpers.h" #include "utils/checksum_utils.h" From be48947ead73f97fbe4de3478deafe7b0ca991a4 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 16:46:28 -0700 Subject: [PATCH 29/73] Move is_dot3 into details/pdu_helpers.h --- include/tins/detail/pdu_helpers.h | 4 ++++ include/tins/internals.h | 4 ---- src/ethernetII.cpp | 1 - src/packet_sender.cpp | 2 +- src/ppi.cpp | 2 +- src/sniffer.cpp | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/tins/detail/pdu_helpers.h b/include/tins/detail/pdu_helpers.h index 77cc767..83d9b67 100644 --- a/include/tins/detail/pdu_helpers.h +++ b/include/tins/detail/pdu_helpers.h @@ -56,6 +56,10 @@ PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag); Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag); PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag); +inline bool is_dot3(const uint8_t* ptr, size_t sz) { + return (sz >= 13 && ptr[12] < 8); +} + } // Internals } // Tins diff --git a/include/tins/internals.h b/include/tins/internals.h index d6697af..9de7866 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -46,10 +46,6 @@ namespace Internals { // Compares sequence numbers as defined by RFC 1982. int seq_compare(uint32_t seq1, uint32_t seq2); -inline bool is_dot3(const uint8_t* ptr, size_t sz) { - return (sz >= 13 && ptr[12] < 8); -} - } // namespace Internals } // namespace Tins /** diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index 8dcdbaa..c0704c4 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -48,7 +48,6 @@ #include "ipv6.h" #include "arp.h" #include "constants.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" #include "detail/pdu_helpers.h" diff --git a/src/packet_sender.cpp b/src/packet_sender.cpp index e95bdd2..b9a57f8 100644 --- a/src/packet_sender.cpp +++ b/src/packet_sender.cpp @@ -64,8 +64,8 @@ #include "dot11/dot11_base.h" #include "radiotap.h" #include "ieee802_3.h" -#include "internals.h" #include "cxxstd.h" +#include "detail/pdu_helpers.h" #if TINS_IS_CXX11 #include #endif // TINS_IS_CXX11 diff --git a/src/ppi.cpp b/src/ppi.cpp index 51bd00f..effc049 100644 --- a/src/ppi.cpp +++ b/src/ppi.cpp @@ -37,9 +37,9 @@ #include "loopback.h" #include "sll.h" #include "ppi.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using Tins::Memory::InputMemoryStream; diff --git a/src/sniffer.cpp b/src/sniffer.cpp index 2b95872..c2b3c71 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -45,7 +45,7 @@ #include "pktap.h" #include "sll.h" #include "ppi.h" -#include "internals.h" +#include "detail/pdu_helpers.h" using std::string; using std::runtime_error; From 815889bd22c76affc331920cf70a1fc3d5e52e99 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 16:52:59 -0700 Subject: [PATCH 30/73] Move seq_compare into its own header file --- include/tins/detail/sequence_number_helpers.h | 49 +++++++++++++++++++ include/tins/internals.h | 17 +------ src/CMakeLists.txt | 2 +- .../sequence_number_helpers.cpp} | 6 +-- src/tcp_ip/ack_tracker.cpp | 2 +- src/tcp_ip/data_tracker.cpp | 2 +- src/tcp_ip/flow.cpp | 2 +- 7 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 include/tins/detail/sequence_number_helpers.h rename src/{internals.cpp => detail/sequence_number_helpers.cpp} (96%) diff --git a/include/tins/detail/sequence_number_helpers.h b/include/tins/detail/sequence_number_helpers.h new file mode 100644 index 0000000..04af18d --- /dev/null +++ b/include/tins/detail/sequence_number_helpers.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_SEQUENCE_NUMBER_HELPERS_H +#define TINS_SEQUENCE_NUMBER_HELPERS_H + +#include +/** + * \cond + */ +namespace Tins { +namespace Internals { + +// Compares sequence numbers as defined by RFC 1982. +int seq_compare(uint32_t seq1, uint32_t seq2); + +} // namespace Internals +} // namespace Tins +/** + * \endcond + */ + +#endif // TINS_SEQUENCE_NUMBER_HELPERS_H diff --git a/include/tins/internals.h b/include/tins/internals.h index 9de7866..e44d30c 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -30,26 +30,11 @@ #ifndef TINS_INTERNALS_H #define TINS_INTERNALS_H -#include #include "detail/type_traits.h" #include "detail/address_helpers.h" #include "detail/icmp_extension_helpers.h" #include "detail/smart_ptr.h" #include "detail/pdu_helpers.h" - -/** - * \cond - */ -namespace Tins { -namespace Internals { - -// Compares sequence numbers as defined by RFC 1982. -int seq_compare(uint32_t seq1, uint32_t seq2); - -} // namespace Internals -} // namespace Tins -/** - * \endcond - */ +#include "detail/sequence_number_helpers.h" #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 58e4920..9fff026 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ set(SOURCES detail/address_helpers.cpp detail/icmp_extension_helpers.cpp detail/pdu_helpers.cpp + detail/sequence_number_helpers.cpp dhcp.cpp dhcpv6.cpp dns.cpp @@ -35,7 +36,6 @@ set(SOURCES icmp_extension.cpp icmp.cpp icmpv6.cpp - internals.cpp ip_reassembler.cpp ip.cpp ip_address.cpp diff --git a/src/internals.cpp b/src/detail/sequence_number_helpers.cpp similarity index 96% rename from src/internals.cpp rename to src/detail/sequence_number_helpers.cpp index 78c63fb..7c8acec 100644 --- a/src/internals.cpp +++ b/src/detail/sequence_number_helpers.cpp @@ -27,7 +27,7 @@ * */ -#include "internals.h" +#include "detail/sequence_number_helpers.h" namespace Tins { namespace Internals { @@ -46,5 +46,5 @@ int seq_compare(uint32_t seq1, uint32_t seq2) { } } -} // namespace Internals -} // namespace Tins +} // Internals +} // Tins diff --git a/src/tcp_ip/ack_tracker.cpp b/src/tcp_ip/ack_tracker.cpp index 101a28e..a4129d2 100644 --- a/src/tcp_ip/ack_tracker.cpp +++ b/src/tcp_ip/ack_tracker.cpp @@ -33,7 +33,7 @@ #include #include "tcp.h" -#include "internals.h" +#include "detail/sequence_number_helpers.h" using std::vector; using std::numeric_limits; diff --git a/src/tcp_ip/data_tracker.cpp b/src/tcp_ip/data_tracker.cpp index 9256de2..0987513 100644 --- a/src/tcp_ip/data_tracker.cpp +++ b/src/tcp_ip/data_tracker.cpp @@ -31,7 +31,7 @@ #ifdef TINS_HAVE_TCPIP -#include "internals.h" +#include "detail/sequence_number_helpers.h" using std::move; diff --git a/src/tcp_ip/flow.cpp b/src/tcp_ip/flow.cpp index 0742d56..64e09db 100644 --- a/src/tcp_ip/flow.cpp +++ b/src/tcp_ip/flow.cpp @@ -40,7 +40,7 @@ #include "ip.h" #include "ipv6.h" #include "rawpdu.h" -#include "internals.h" +#include "detail/sequence_number_helpers.h" #include "exceptions.h" #include "memory_helpers.h" From 86da3818ffa8c6830e69613c5b0c0ab53f14f49c Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 17:34:02 -0700 Subject: [PATCH 31/73] Remove useless includes --- include/tins/packet.h | 5 +++-- include/tins/tcp_ip/flow.h | 3 --- include/tins/tcp_stream.h | 1 - src/arp.cpp | 4 +--- src/dhcp.cpp | 5 ++--- src/dns.cpp | 1 - src/dot11/dot11_base.cpp | 9 +++------ src/eapol.cpp | 1 - src/ethernetII.cpp | 4 ---- src/hw_address.cpp | 29 +++++++++++++++++++++++++++++ src/ip_reassembler.cpp | 1 - src/ipv6.cpp | 1 - src/packet_sender.cpp | 1 - src/pdu.cpp | 1 - src/snap.cpp | 3 --- src/sniffer.cpp | 2 -- src/stp.cpp | 5 +---- src/tcp_ip/flow.cpp | 4 ---- src/tcp_ip/stream.cpp | 6 ------ src/tcp_ip/stream_follower.cpp | 7 ------- src/tcp_ip/stream_identifier.cpp | 8 ++++---- 21 files changed, 43 insertions(+), 58 deletions(-) diff --git a/include/tins/packet.h b/include/tins/packet.h index b96a2f1..01fc862 100644 --- a/include/tins/packet.h +++ b/include/tins/packet.h @@ -30,7 +30,6 @@ #ifndef TINS_PACKET_H #define TINS_PACKET_H -#include #include "cxxstd.h" #include "pdu.h" #include "timestamp.h" @@ -234,7 +233,9 @@ public: */ Packet& operator=(Packet &&rhs) TINS_NOEXCEPT { if (this != &rhs) { - std::swap(pdu_, rhs.pdu_); + PDU* tmp = std::move(pdu_); + pdu_ = std::move(rhs.pdu_); + rhs.pdu_ = std::move(tmp); ts_ = rhs.timestamp(); } return* this; diff --git a/include/tins/tcp_ip/flow.h b/include/tins/tcp_ip/flow.h index d157e13..9d250c3 100644 --- a/include/tins/tcp_ip/flow.h +++ b/include/tins/tcp_ip/flow.h @@ -34,12 +34,9 @@ #ifdef TINS_HAVE_TCPIP -#include #include -#include #include #include -#include "../hw_address.h" #include "../macros.h" #include "ack_tracker.h" #include "data_tracker.h" diff --git a/include/tins/tcp_stream.h b/include/tins/tcp_stream.h index eb0a838..eff9fcc 100644 --- a/include/tins/tcp_stream.h +++ b/include/tins/tcp_stream.h @@ -32,7 +32,6 @@ #include #include -#include #include #include #include diff --git a/src/arp.cpp b/src/arp.cpp index 80d11d8..f415d47 100644 --- a/src/arp.cpp +++ b/src/arp.cpp @@ -30,11 +30,9 @@ #include #include #include "arp.h" -#include "ip.h" #include "ethernetII.h" #include "rawpdu.h" #include "constants.h" -#include "network_interface.h" #include "exceptions.h" #include "memory_helpers.h" @@ -58,7 +56,7 @@ ARP::ARP(ipaddress_type target_ip, hw_addr_format((uint16_t)Constants::ARP::ETHER); prot_addr_format((uint16_t)Constants::Ethernet::IP); hw_addr_length(Tins::EthernetII::address_type::address_size); - prot_addr_length(Tins::IP::address_type::address_size); + prot_addr_length(4 /* IP address size */); sender_ip_addr(sender_ip); target_ip_addr(target_ip); sender_hw_addr(sender_hw); diff --git a/src/dhcp.cpp b/src/dhcp.cpp index 051e303..0ab03ef 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -32,7 +32,6 @@ #include #include "endianness.h" #include "dhcp.h" -#include "ethernetII.h" #include "exceptions.h" #include "memory_helpers.h" @@ -58,8 +57,8 @@ PDU::metadata DHCP::extract_metadata(const uint8_t* /*buffer*/, uint32_t total_s DHCP::DHCP() : size_(sizeof(uint32_t)) { opcode(BOOTREQUEST); - htype(1); //ethernet - hlen(EthernetII::address_type::address_size); + htype(1); // ethernet + hlen(6); // MAC address length } DHCP::DHCP(const uint8_t* buffer, uint32_t total_sz) diff --git a/src/dns.cpp b/src/dns.cpp index 1ccea4c..2ddc72c 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -36,7 +36,6 @@ #include "ip_address.h" #include "ipv6_address.h" #include "exceptions.h" -#include "rawpdu.h" #include "endianness.h" #include "memory_helpers.h" diff --git a/src/dot11/dot11_base.cpp b/src/dot11/dot11_base.cpp index 0417064..af359de 100644 --- a/src/dot11/dot11_base.cpp +++ b/src/dot11/dot11_base.cpp @@ -32,9 +32,7 @@ #ifdef TINS_HAVE_DOT11 #include -#include #include -#include #include "macros.h" #include "exceptions.h" @@ -49,12 +47,11 @@ #include #endif #include "dot11.h" -#include "rawpdu.h" -#include "rsn_information.h" #include "packet_sender.h" -#include "snap.h" #include "memory_helpers.h" +using std::list; + using Tins::Memory::InputMemoryStream; using Tins::Memory::OutputMemoryStream; @@ -218,7 +215,7 @@ void Dot11::write_serialization(uint8_t* buffer, uint32_t total_sz) { stream.write(header_); write_ext_header(stream); write_fixed_parameters(stream); - for (std::list