diff --git a/include/ip.h b/include/ip.h index 5d55935..9dda366 100644 --- a/include/ip.h +++ b/include/ip.h @@ -426,6 +426,20 @@ namespace Tins { internal_add_option(opt); _ip_options.push_back(std::move(opt)); } + + /** + * \brief Adds an IP option. + * + * The option is constructed from the provided parameters. + * + * \param args The arguments to be used in the option's + * constructor. + */ + template + void add_option(Args&&... args) { + _ip_options.emplace_back(std::forward(args)...); + internal_add_option(_ip_options.back()); + } #endif /** diff --git a/include/tcp.h b/include/tcp.h index 05e56b4..43c3c76 100644 --- a/include/tcp.h +++ b/include/tcp.h @@ -409,6 +409,20 @@ namespace Tins { internal_add_option(opt); _options.push_back(std::move(opt)); } + + /** + * \brief Adds a TCP option using the provided arguments. + * + * The option is constructed from the provided parameters. + * + * \param args The arguments to be used in the option's + * constructor. + */ + template + void add_option(Args&&... args) { + _options.emplace_back(std::forward(args)...); + internal_add_option(_options.back()); + } #endif /** diff --git a/src/tcp.cpp b/src/tcp.cpp index 96913c9..7eb24c0 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -67,7 +67,11 @@ TCP::TCP(const uint8_t *buffer, uint32_t total_sz) while(buffer < header_end) { if(*buffer <= NOP) { + #if TINS_IS_CXX11 + add_option((OptionTypes)*buffer, 0); + #else add_option(option((OptionTypes)*buffer, 0)); + #endif // TINS_IS_CXX11 ++buffer; } else { @@ -77,7 +81,11 @@ TCP::TCP(const uint8_t *buffer, uint32_t total_sz) const uint8_t *data_start = buffer + 2; if(data_start + len > header_end) throw malformed_packet(); + #if TINS_IS_CXX11 + add_option((OptionTypes)*buffer, data_start, data_start + len); + #else add_option(option((OptionTypes)*buffer, data_start, data_start + len)); + #endif // TINS_IS_CXX11 buffer = data_start + len; } }