From 7589a0a1084eafe92cdf67a0f146e41cd77a411a Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 14 May 2017 10:33:04 -0700 Subject: [PATCH] Rename IPv6::add_ext_header to IPv6::add_header (deprecate former) --- include/tins/ipv6.h | 35 ++++++++++++++++++++++++++++++++++- src/ipv6.cpp | 6 +++++- tests/src/ipv6_test.cpp | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/include/tins/ipv6.h b/include/tins/ipv6.h index 82bf37b..e3a33bd 100644 --- a/include/tins/ipv6.h +++ b/include/tins/ipv6.h @@ -31,6 +31,7 @@ #define TINS_IPV6_h #include "macros.h" +#include "cxxstd.h" #include "pdu.h" #include "endianness.h" #include "small_uint.h" @@ -302,10 +303,42 @@ public: /** * Adds an extension header. * + * \deprecated Use IPv6::add_header * \param header The extension header to be added. */ - void add_ext_header(const ext_header& header); + TINS_DEPRECATED(void add_ext_header(const ext_header& header)); + /** + * Adds an extension header + * + * \deprecated Use IPv6::add_header + * \param header The extension header to be added. + */ + void add_header(const ext_header& header); + + #if TINS_IS_CXX11 + + /** + * Adds an extension header by moving it + * + * \param header The extension header to be added. + */ + void add_header(ext_header&& header) { + ext_headers_.emplace_back(std::move(header)); + } + + /** + * Adds an extension header by using the provided parameters + * + * \param header The extension header to be added. + */ + template + void add_header(Args&&... args) { + ext_headers_.emplace_back(std::forward(args)...); + } + + #endif // TINS_IS_CXX11 + /** * \brief Searchs for an extension header that matchs the given * flag. diff --git a/src/ipv6.cpp b/src/ipv6.cpp index 31144b2..281433b 100644 --- a/src/ipv6.cpp +++ b/src/ipv6.cpp @@ -97,7 +97,7 @@ IPv6::IPv6(const uint8_t* buffer, uint32_t total_sz) { } // Add a header using the current header type (e.g. what we saw as the next // header type in the previous) - add_ext_header(ext_header(current_header, payload_size, stream.pointer())); + add_header(ext_header(current_header, payload_size, stream.pointer())); if (actual_payload_length == 0u && current_header == HOP_BY_HOP) { // could be a jumbogram, look for Jumbo Payload Option InputMemoryStream options(stream.pointer(), payload_size); @@ -305,6 +305,10 @@ void IPv6::send(PacketSender& sender, const NetworkInterface &) { #endif void IPv6::add_ext_header(const ext_header& header) { + add_header(header); +} + +void IPv6::add_header(const ext_header& header) { ext_headers_.push_back(header); } diff --git a/tests/src/ipv6_test.cpp b/tests/src/ipv6_test.cpp index 8c7549e..e8017cd 100644 --- a/tests/src/ipv6_test.cpp +++ b/tests/src/ipv6_test.cpp @@ -349,7 +349,7 @@ TEST_F(IPv6Test, OptionAddition) { EthernetII pkt(routing_header, sizeof(routing_header)); IPv6& ipv6 = pkt.rfind_pdu(); // Add a dummy header - ipv6.add_ext_header(IPv6::ext_header(IPv6::AUTHENTICATION)); + ipv6.add_header(IPv6::ext_header(IPv6::AUTHENTICATION)); const IPv6::headers_type& headers = ipv6.headers();