diff --git a/include/tins/dhcpv6.h b/include/tins/dhcpv6.h index 9af14a6..af010ac 100644 --- a/include/tins/dhcpv6.h +++ b/include/tins/dhcpv6.h @@ -917,54 +917,8 @@ private: uint32_t options_size_; ipaddress_type link_addr_, peer_addr_; options_type options_; -}; +}; -namespace Internals { - -template -void class_option_data2option(InputIterator start, - InputIterator end, - std::vector& buffer, - size_t start_index = 0) { - size_t index = start_index; - uint16_t uint16_t_buffer; - while (start != end) { - buffer.resize(buffer.size() + sizeof(uint16_t) + start->size()); - uint16_t_buffer = Endian::host_to_be(static_cast(start->size())); - std::memcpy(&buffer[index], &uint16_t_buffer, sizeof(uint16_t)); - index += sizeof(uint16_t); - std::copy(start->begin(), start->end(), buffer.begin() + index); - index += start->size(); - - start++; - } -} - -template -OutputType option2class_option_data(const uint8_t* ptr, uint32_t total_sz) { - typedef typename OutputType::value_type value_type; - OutputType output; - size_t index = 0; - while (index + 2 < total_sz) { - uint16_t size; - std::memcpy(&size, ptr + index, sizeof(uint16_t)); - size = Endian::be_to_host(size); - index += sizeof(uint16_t); - if (index + size > total_sz) { - throw option_not_found(); - } - output.push_back( - value_type(ptr + index, ptr + index + size) - ); - index += size; - } - if (index != total_sz) { - throw malformed_option(); - } - return output; -} - -} // Internals } // Tins #endif // TINS_DHCPV6_H diff --git a/include/tins/snap.h b/include/tins/snap.h index 3035254..41efafa 100644 --- a/include/tins/snap.h +++ b/include/tins/snap.h @@ -30,7 +30,6 @@ #ifndef TINS_SNAP_H #define TINS_SNAP_H - #include #include "pdu.h" #include "macros.h" diff --git a/src/bootp.cpp b/src/bootp.cpp index 8ba8e57..2543bf2 100644 --- a/src/bootp.cpp +++ b/src/bootp.cpp @@ -27,7 +27,6 @@ * */ -#include #include #include "bootp.h" #include "exceptions.h" diff --git a/src/dhcp.cpp b/src/dhcp.cpp index 2a86289..142f4a7 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -27,7 +27,6 @@ * */ -#include #include #include "endianness.h" #include "dhcp.h" diff --git a/src/dhcpv6.cpp b/src/dhcpv6.cpp index a4271c7..6d6285e 100644 --- a/src/dhcpv6.cpp +++ b/src/dhcpv6.cpp @@ -42,6 +42,55 @@ using Tins::Memory::OutputMemoryStream; namespace Tins { +namespace Internals { + +template +void class_option_data2option(InputIterator start, + InputIterator end, + vector& buffer, + size_t start_index = 0) { + size_t index = start_index; + uint16_t uint16_t_buffer; + while (start != end) { + buffer.resize(buffer.size() + sizeof(uint16_t) + start->size()); + uint16_t_buffer = Endian::host_to_be(static_cast(start->size())); + memcpy(&buffer[index], &uint16_t_buffer, sizeof(uint16_t)); + index += sizeof(uint16_t); + if (!start->empty()) { + memcpy(&*buffer.begin() + index, &*start->begin(), start->size()); + } + index += start->size(); + + start++; + } +} + +template +OutputType option2class_option_data(const uint8_t* ptr, uint32_t total_sz) { + typedef typename OutputType::value_type value_type; + OutputType output; + size_t index = 0; + while (index + 2 < total_sz) { + uint16_t size; + memcpy(&size, ptr + index, sizeof(uint16_t)); + size = Endian::be_to_host(size); + index += sizeof(uint16_t); + if (index + size > total_sz) { + throw option_not_found(); + } + output.push_back( + value_type(ptr + index, ptr + index + size) + ); + index += size; + } + if (index != total_sz) { + throw malformed_option(); + } + return output; +} + +} // Internals + PDU::metadata DHCPv6::extract_metadata(const uint8_t* /*buffer*/, uint32_t total_sz) { if (TINS_UNLIKELY(total_sz < 2)) { throw malformed_packet(); diff --git a/src/dns.cpp b/src/dns.cpp index 2ddc72c..f700ef2 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -28,9 +28,6 @@ */ #include -#include -#include -#include #include #include "dns.h" #include "ip_address.h" @@ -40,7 +37,6 @@ #include "memory_helpers.h" using std::string; -using std::copy; using std::memcpy; using std::list; using std::make_pair; @@ -372,7 +368,7 @@ uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const { if (current_out_ptr != out_ptr) { *current_out_ptr++ = '.'; } - copy(ptr, ptr + size, current_out_ptr); + memcpy(current_out_ptr, ptr, size); current_out_ptr += size; ptr += size; } diff --git a/src/dot1q.cpp b/src/dot1q.cpp index f3f5fed..fde47a0 100644 --- a/src/dot1q.cpp +++ b/src/dot1q.cpp @@ -27,7 +27,6 @@ * */ -#include #include #include "dot1q.h" #include "exceptions.h" diff --git a/src/dot3.cpp b/src/dot3.cpp index 5a8311e..686893f 100644 --- a/src/dot3.cpp +++ b/src/dot3.cpp @@ -28,7 +28,6 @@ */ #include -#include #include "macros.h" #ifndef _WIN32 #if defined(BSD) || defined(__FreeBSD_kernel__) diff --git a/src/eapol.cpp b/src/eapol.cpp index 4751db2..af6d0e6 100644 --- a/src/eapol.cpp +++ b/src/eapol.cpp @@ -28,7 +28,6 @@ */ #include -#include #include "eapol.h" #include "exceptions.h" #include "rawpdu.h" diff --git a/src/hw_address.cpp b/src/hw_address.cpp index 397a394..08bb42d 100644 --- a/src/hw_address.cpp +++ b/src/hw_address.cpp @@ -29,9 +29,9 @@ #include #include -#include #include #include "hw_address.h" +#include "exceptions.h" using std::string; using std::ostream; diff --git a/src/icmp.cpp b/src/icmp.cpp index 6496c60..11c9878 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -27,7 +27,6 @@ * */ -#include #include #ifndef _WIN32 #include diff --git a/src/ip.cpp b/src/ip.cpp index e5c17cb..b970eb5 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -27,7 +27,6 @@ * */ -#include #include #ifndef _WIN32 #include diff --git a/src/ip_address.cpp b/src/ip_address.cpp index 015311a..d6d1c95 100644 --- a/src/ip_address.cpp +++ b/src/ip_address.cpp @@ -37,7 +37,6 @@ // std::hash #include #endif // TINS_IS_CXX11 -#include #include #include #include "ip_address.h" diff --git a/src/llc.cpp b/src/llc.cpp index 371aa01..2391053 100644 --- a/src/llc.cpp +++ b/src/llc.cpp @@ -27,7 +27,6 @@ * */ -#include #include #include "llc.h" #include "stp.h" diff --git a/src/loopback.cpp b/src/loopback.cpp index 20899cf..9246505 100644 --- a/src/loopback.cpp +++ b/src/loopback.cpp @@ -37,7 +37,6 @@ #else #include #endif -#include #include #include "loopback.h" #include "packet_sender.h" diff --git a/src/offline_packet_filter.cpp b/src/offline_packet_filter.cpp index 74710b0..7cd39b2 100644 --- a/src/offline_packet_filter.cpp +++ b/src/offline_packet_filter.cpp @@ -27,7 +27,6 @@ * */ -#include #include #include "offline_packet_filter.h" #include "pdu.h" diff --git a/src/packet_writer.cpp b/src/packet_writer.cpp index 5e74b9e..b33d9b1 100644 --- a/src/packet_writer.cpp +++ b/src/packet_writer.cpp @@ -30,7 +30,6 @@ #ifndef _WIN32 #include #endif -#include #include #include "packet_writer.h" #include "packet.h" diff --git a/src/pktap.cpp b/src/pktap.cpp index 7bb6f24..c58b8a5 100644 --- a/src/pktap.cpp +++ b/src/pktap.cpp @@ -27,7 +27,6 @@ * */ -#include #include #include "exceptions.h" #include "pktap.h" diff --git a/src/radiotap.cpp b/src/radiotap.cpp index d6a7a04..8902c0f 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -32,7 +32,6 @@ #ifdef TINS_HAVE_DOT11 #include -#include #include "macros.h" #ifndef _WIN32 #if defined(BSD) || defined(__FreeBSD_kernel__) diff --git a/src/rsn_information.cpp b/src/rsn_information.cpp index 9ab4408..f88d9cb 100644 --- a/src/rsn_information.cpp +++ b/src/rsn_information.cpp @@ -31,7 +31,6 @@ #ifdef TINS_HAVE_DOT11 #include -#include #include "exceptions.h" #include "pdu.h" #include "pdu_option.h" diff --git a/src/sll.cpp b/src/sll.cpp index c21d062..ec7f6a8 100644 --- a/src/sll.cpp +++ b/src/sll.cpp @@ -27,7 +27,6 @@ * */ -#include #include #include "sll.h" #include "exceptions.h" diff --git a/src/snap.cpp b/src/snap.cpp index ebb5c4d..644ea6f 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -28,7 +28,6 @@ */ #include -#include #ifndef _WIN32 #include #include diff --git a/src/udp.cpp b/src/udp.cpp index fbec788..ed0ffb4 100644 --- a/src/udp.cpp +++ b/src/udp.cpp @@ -27,7 +27,6 @@ * */ -#include #include #include "udp.h" #include "constants.h" diff --git a/src/utils/resolve_utils.cpp b/src/utils/resolve_utils.cpp index 05c6747..5039c0c 100644 --- a/src/utils/resolve_utils.cpp +++ b/src/utils/resolve_utils.cpp @@ -48,7 +48,7 @@ #include #undef interface #endif -#include +#include "exceptions.h" #include "ip_address.h" #include "ipv6_address.h" #include "hw_address.h" diff --git a/src/utils/routing_utils.cpp b/src/utils/routing_utils.cpp index 57980ac..f16b9bd 100644 --- a/src/utils/routing_utils.cpp +++ b/src/utils/routing_utils.cpp @@ -55,7 +55,6 @@ #endif #include #include -#include #include "network_interface.h" #include "exceptions.h"