From 6dec68128d8542986448208d4416df4c4f4216e3 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Mon, 17 Aug 2015 15:19:03 -0700 Subject: [PATCH] Add remove_option member to IP, TCP, Dot11, ICMPv6, DHCP and DHCPv6 --- include/tins/dhcp.h | 13 ++++++++ include/tins/dhcpv6.h | 19 +++++++++-- include/tins/dot11/dot11_base.h | 17 ++++++++-- include/tins/icmpv6.h | 17 ++++++++-- include/tins/ip.h | 19 +++++++++-- include/tins/pdu_option.h | 20 +++++++++++ include/tins/tcp.h | 22 +++++++++--- src/dhcp.cpp | 30 ++++++++++++++--- src/dhcpv6.cpp | 33 ++++++++++++++---- src/dot11/dot11_base.cpp | 29 +++++++++++++--- src/icmpv6.cpp | 30 +++++++++++++---- src/ip.cpp | 36 ++++++++++++++++---- src/tcp.cpp | 59 ++++++++++++++++++++++++--------- tests/src/dhcp.cpp | 13 +++++++- tests/src/dhcpv6.cpp | 14 ++++++++ tests/src/dot11/beacon.cpp | 15 ++++++++- tests/src/icmpv6.cpp | 17 ++++++++++ tests/src/ip.cpp | 23 +++++++++++++ tests/src/tcp.cpp | 19 +++++++++++ 19 files changed, 386 insertions(+), 59 deletions(-) diff --git a/include/tins/dhcp.h b/include/tins/dhcp.h index 41aedd9..6fb7b50 100644 --- a/include/tins/dhcp.h +++ b/include/tins/dhcp.h @@ -210,6 +210,17 @@ namespace Tins { _options.push_back(std::move(opt)); } #endif + + /** + * \brief Removes a DHCP option. + * + * If there are multiple options of the given type, only the first one + * will be removed. + * + * \param type The type of the option to be removed. + * \return true if the option was removed, false otherwise. + */ + bool remove_option(OptionTypes type); /** * \brief Searchs for an option that matchs the given flag. @@ -501,6 +512,8 @@ namespace Tins { void internal_add_option(const option &opt); serialization_type serialize_list(const std::vector &ip_list); + options_type::const_iterator search_option_iterator(OptionTypes opt) const; + options_type::iterator search_option_iterator(OptionTypes opt); options_type _options; uint32_t _size; diff --git a/include/tins/dhcpv6.h b/include/tins/dhcpv6.h index 027b9b6..0226ace 100644 --- a/include/tins/dhcpv6.h +++ b/include/tins/dhcpv6.h @@ -816,15 +816,26 @@ public: void add_option(const option &opt); /** - * \brief Searchs for an option that matchs the given flag. + * \brief Removes a DHCPv6 option. + * + * If there are multiple options of the given type, only the first one + * will be removed. + * + * \param type The type of the option to be removed. + * \return true if the option was removed, false otherwise. + */ + bool remove_option(OptionTypes type); + + /** + * \brief Searchs for an option that matchs the given type. * * If the option is not found, a null pointer is returned. * Deleting the returned pointer will result in undefined * behaviour. * - * \param id The option identifier to be searched. + * \param type The option identifier to be searched. */ - const option *search_option(OptionTypes id) const; + const option *search_option(OptionTypes type) const; // PDU stuff @@ -859,6 +870,8 @@ public: private: void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *); uint8_t* write_option(const option &option, uint8_t* buffer) const; + options_type::const_iterator search_option_iterator(OptionTypes type) const; + options_type::iterator search_option_iterator(OptionTypes type); template