1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Modified some protocols' internal type names.

This commit is contained in:
Matias Fontanini
2013-04-09 15:40:58 -03:00
parent 20054e6c73
commit ae1e1c2ce2
22 changed files with 356 additions and 319 deletions

View File

@@ -67,7 +67,7 @@ namespace Tins {
/**
* \brief DHCP options enum.
*/
enum Options {
enum OptionTypes {
PAD,
SUBNET_MASK,
TIME_OFFSET,
@@ -140,15 +140,19 @@ namespace Tins {
END = 255
};
TINS_DEPRECATED(typedef OptionTypes Options);
/**
* The DHCP option type.
*/
typedef PDUOption<uint8_t> dhcp_option;
typedef PDUOption<uint8_t> option;
TINS_DEPRECATED(typedef option dhcp_option);
/**
* The type used to store the DHCP options.
*/
typedef std::list<dhcp_option> options_type;
typedef std::list<option> options_type;
/**
* \brief Creates an instance of DHCP.
@@ -169,9 +173,9 @@ namespace Tins {
/**
* \brief Adds a new option to this DHCP PDU.
* \param option The option to be added.
* \param opt The option to be added.
*/
void add_option(const dhcp_option &option);
void add_option(const option &opt);
#if TINS_IS_CXX11
/**
@@ -179,9 +183,9 @@ namespace Tins {
*
* The option is move-constructed.
*
* \param option The option to be added.
* \param opt The option to be added.
*/
void add_option(dhcp_option &&option);
void add_option(option &&opt);
#endif
/**
@@ -189,7 +193,7 @@ namespace Tins {
* \param opt_flag The flag to be searched.
* \return A pointer to the option, or 0 if it was not found.
*/
const dhcp_option *search_option(Options opt) const;
const option *search_option(OptionTypes opt) const;
/**
* \brief Adds a type option the the option list.
@@ -413,18 +417,18 @@ namespace Tins {
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
template<class T>
T generic_search(Options opt, type2type<T>) const {
const dhcp_option *option = search_option(opt);
T generic_search(OptionTypes opt, type2type<T>) const {
const option *option = search_option(opt);
if(option && option->data_size() == sizeof(T))
return *(const T*)option->data_ptr();
else
throw option_not_found();
}
void internal_add_option(const dhcp_option &option);
std::list<ipaddress_type> generic_search(Options opt, type2type<std::list<ipaddress_type> >) const;
std::string generic_search(Options opt, type2type<std::string>) const;
ipaddress_type generic_search(Options opt, type2type<ipaddress_type>) const;
void internal_add_option(const option &opt);
std::list<ipaddress_type> generic_search(OptionTypes opt, type2type<std::list<ipaddress_type> >) const;
std::string generic_search(OptionTypes opt, type2type<std::string>) const;
ipaddress_type generic_search(OptionTypes opt, type2type<ipaddress_type>) const;
serialization_type serialize_list(const std::list<ipaddress_type> &ip_list);

View File

@@ -46,7 +46,9 @@ public:
/**
* Represents a DHCPv6 option.
*/
typedef PDUOption<uint16_t> dhcpv6_option;
typedef PDUOption<uint16_t> option;
TINS_DEPRECATED(typedef option dhcpv6_option);
/**
* The message types.
@@ -74,7 +76,7 @@ public:
/**
* The DHCPv6 options.
*/
enum Option {
enum OptionTypes {
CLIENTID = 1,
SERVERID,
IA_NA,
@@ -151,10 +153,12 @@ public:
KRB_KDC
};
TINS_DEPRECATED(typedef OptionTypes Option);
/**
* The type used to store the DHCPv6 options.
*/
typedef std::list<dhcpv6_option> options_type;
typedef std::list<option> options_type;
/**
* The type used to store IP addresses.
@@ -366,7 +370,7 @@ public:
/**
* The type used to store the Option Request option.
*/
typedef std::vector<Option> option_request_type;
typedef std::vector<OptionTypes> option_request_type;
/**
* The type used to store the Relay Message option.
@@ -779,9 +783,9 @@ public:
* The option is added after the last option in the option
* fields.
*
* \param option The option to be added
* \param opt The option to be added
*/
void add_option(const dhcpv6_option &option);
void add_option(const option &opt);
/**
* \brief Searchs for an option that matchs the given flag.
@@ -792,7 +796,7 @@ public:
*
* \param id The option identifier to be searched.
*/
const dhcpv6_option *search_option(Option id) const;
const option *search_option(OptionTypes id) const;
// PDU stuff
@@ -826,11 +830,11 @@ public:
}
private:
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *);
uint8_t* write_option(const dhcpv6_option &option, uint8_t* buffer) const;
uint8_t* write_option(const option &option, uint8_t* buffer) const;
template<template <typename> class Functor>
const dhcpv6_option *safe_search_option(Option opt, uint32_t size) const {
const dhcpv6_option *option = search_option(opt);
const option *safe_search_option(OptionTypes opt, uint32_t size) const {
const option *option = search_option(opt);
if(!option || Functor<uint32_t>()(option->data_size(), size))
throw option_not_found();
return option;

View File

@@ -77,7 +77,7 @@ namespace Tins {
/**
* \brief Enum for the different types of tagged options.
*/
enum TaggedOption {
enum OptionTypes {
SSID,
SUPPORTED_RATES,
FH_SET,
@@ -113,6 +113,8 @@ namespace Tins {
EXT_SUPPORTED_RATES = 50
};
TINS_DEPRECATED(typedef OptionTypes TaggedOption);
/**
* \brief Enum for the different subtypes of 802.11 management frames.
*
@@ -169,7 +171,9 @@ namespace Tins {
/**
* \brief IEEE 802.11 options struct.
*/
typedef PDUOption<uint8_t> dot11_option;
typedef PDUOption<uint8_t> option;
TINS_DEPRECATED(typedef option dot11_option);
/**
* \brief Constructor for creating an 802.11 PDU
@@ -395,7 +399,13 @@ namespace Tins {
* \brief Adds a new option to this Dot11 PDU.
* \param opt The option to be added.
*/
void add_tagged_option(const dot11_option &opt);
TINS_DEPRECATED(void add_tagged_option(const option &opt));
/**
* \brief Adds a new option to this Dot11 PDU.
* \param opt The option to be added.
*/
void add_option(const option &opt);
#if TINS_IS_CXX11
/**
@@ -405,7 +415,7 @@ namespace Tins {
*
* \param opt The option to be added.
*/
void add_tagged_option(dot11_option &&opt);
void add_option(option &&opt);
#endif
/**
@@ -416,7 +426,7 @@ namespace Tins {
* \param opt The option identifier.
* \return The option found, or 0 if no such option has been set.
*/
const dot11_option *search_option(TaggedOption opt) const;
const option *search_option(OptionTypes opt) const;
/**
* \brief Getter for the PDU's type.
@@ -457,7 +467,7 @@ namespace Tins {
virtual uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz) { return 0; }
virtual uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { return 0; }
void parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz);
void add_tagged_option(TaggedOption opt, uint8_t len, const uint8_t *val);
void add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t *val);
protected:
/**
* Struct that represents the 802.11 header
@@ -499,14 +509,14 @@ namespace Tins {
private:
Dot11(const ieee80211_header *header_ptr);
void internal_add_option(const dot11_option &opt);
void internal_add_option(const option &opt);
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
ieee80211_header _header;
NetworkInterface _iface;
uint32_t _options_size;
std::list<dot11_option> _options;
std::list<option> _options;
};
/**
@@ -1487,7 +1497,7 @@ namespace Tins {
}
private:
static uint8_t *serialize_rates(const rates_type &rates);
static rates_type deserialize_rates(const dot11_option *option);
static rates_type deserialize_rates(const option *option);
ExtendedHeader _ext_header;
address_type _addr4;

View File

@@ -84,7 +84,7 @@ public:
/**
* The types of ICMPv6 options.
*/
enum Options {
enum OptionTypes {
SOURCE_ADDRESS = 1,
TARGET_ADDRESS,
PREFIX_INFO,
@@ -122,6 +122,8 @@ public:
CARD_REPLY
};
TINS_DEPRECATED(typedef OptionTypes Options);
/**
* The type used to store addresses.
*/
@@ -135,12 +137,14 @@ public:
/**
* The type used to represent ICMPv6 options.
*/
typedef PDUOption<uint8_t> icmpv6_option;
typedef PDUOption<uint8_t> option;
TINS_DEPRECATED(typedef option icmpv6_option);
/**
* The type used to store options.
*/
typedef std::list<icmpv6_option> options_type;
typedef std::list<option> options_type;
/**
* \brief The type used to store the new home agent information
@@ -737,7 +741,7 @@ public:
*
* \param option The option to be added
*/
void add_option(const icmpv6_option &option);
void add_option(const option &option);
#if TINS_IS_CXX11
/**
@@ -747,7 +751,7 @@ public:
*
* \param option The option to be added.
*/
void add_option(icmpv6_option &&option);
void add_option(option &&option);
#endif
/**
@@ -776,7 +780,7 @@ public:
*
* \param id The option identifier to be searched.
*/
const icmpv6_option *search_option(Options id) const;
const option *search_option(OptionTypes id) const;
/**
* \sa PDU::clone
@@ -1202,17 +1206,17 @@ private:
};
} TINS_END_PACK;
void internal_add_option(const icmpv6_option &option);
void internal_add_option(const option &option);
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
bool has_options() const;
uint8_t *write_option(const icmpv6_option &opt, uint8_t *buffer);
uint8_t *write_option(const option &opt, uint8_t *buffer);
void parse_options(const uint8_t *&buffer, uint32_t &total_sz);
void add_addr_list(uint8_t type, const addr_list_type &value);
addr_list_type search_addr_list(Options type) const;
addr_list_type search_addr_list(OptionTypes type) const;
template<template <typename> class Functor>
const icmpv6_option *safe_search_option(Options opt, uint32_t size) const {
const icmpv6_option *option = search_option(opt);
const option *safe_search_option(OptionTypes opt, uint32_t size) const {
const option *option = search_option(opt);
if(!option || Functor<uint32_t>()(option->data_size(), size))
throw option_not_found();
return option;

View File

@@ -169,7 +169,9 @@ namespace Tins {
/**
* The IP options type.
*/
typedef PDUOption<option_identifier> ip_option;
typedef PDUOption<option_identifier> option;
TINS_DEPRECATED(typedef option ip_option);
/**
* The type of the security option.
@@ -218,7 +220,7 @@ namespace Tins {
/**
* The type used to store IP options.
*/
typedef std::list<ip_option> options_type;
typedef std::list<option> options_type;
/**
* \brief Constructor for building the IP PDU.
@@ -415,9 +417,9 @@ namespace Tins {
* The option is added after the last option in the option
* fields.
*
* \param option The option to be added
* \param opt The option to be added
*/
void add_option(const ip_option &option);
void add_option(const option &opt);
#if TINS_IS_CXX11
/**
@@ -425,9 +427,9 @@ namespace Tins {
*
* The option is move-constructed.
*
* \param option The option to be added.
* \param opt The option to be added.
*/
void add_option(ip_option &&option);
void add_option(option &&opt);
#endif
/**
@@ -439,7 +441,7 @@ namespace Tins {
*
* \param id The option identifier to be searched.
*/
const ip_option *search_option(option_identifier id) const;
const option *search_option(option_identifier id) const;
// Option setters
@@ -635,10 +637,10 @@ namespace Tins {
} TINS_END_PACK;
void prepare_for_serialize(const PDU *parent);
void internal_add_option(const ip_option &option);
void internal_add_option(const option &option);
void init_ip_fields();
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
uint8_t* write_option(const ip_option &opt, uint8_t* buffer);
uint8_t* write_option(const option &opt, uint8_t* buffer);
void add_route_option(option_identifier id, const generic_route_option_type &data);
generic_route_option_type search_route_option(option_identifier id) const;

View File

@@ -60,12 +60,14 @@ public:
/**
* The type used to represent IPv6 extension headers.
*/
typedef PDUOption<uint8_t> ipv6_ext_header;
typedef PDUOption<uint8_t> ext_header;
TINS_DEPRECATED(typedef ext_header ipv6_ext_header);
/**
* The type used to store the extension headers.
*/
typedef std::list<ipv6_ext_header> headers_type;
typedef std::list<ext_header> headers_type;
/**
* The values used to identify extension headers.
@@ -291,7 +293,7 @@ public:
*
* \param header The extension header to be added.
*/
void add_ext_header(const ipv6_ext_header &header);
void add_ext_header(const ext_header &header);
/**
* \brief Searchs for an extension header that matchs the given
@@ -303,11 +305,11 @@ public:
*
* \param id The header identifier to be searched.
*/
const ipv6_ext_header *search_header(ExtensionHeader id) const;
const ext_header *search_header(ExtensionHeader id) const;
private:
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
void set_last_next_header(uint8_t value);
static uint8_t *write_header(const ipv6_ext_header &header, uint8_t *buffer);
static uint8_t *write_header(const ext_header &header, uint8_t *buffer);
static bool is_extension_header(uint8_t header_id);
TINS_BEGIN_PACK

View File

@@ -45,7 +45,7 @@ public:
/**
* The tag types enum.
*/
enum tag_identifiers {
enum TagTypes {
END_OF_LIST = 0,
SERVICE_NAME = 0x101,
#if TINS_IS_LITTLE_ENDIAN
@@ -72,12 +72,12 @@ public:
/**
* The type used to store a TLV option.
*/
typedef PDUOption<tag_identifiers> pppoe_tag;
typedef PDUOption<TagTypes> tag;
/**
* The type used to store the options.
*/
typedef std::list<pppoe_tag> tags_type;
typedef std::list<tag> tags_type;
/**
* The type used to store the Vendor-Specific tag's value.
@@ -175,7 +175,7 @@ public:
return new PPPoE(*this);
}
const pppoe_tag *search_tag(tag_identifiers identifier) const;
const tag *search_tag(TagTypes identifier) const;
/**
* \brief Getter for the PDU's type.
@@ -220,7 +220,7 @@ public:
*
* \param option The option to be added.
*/
void add_tag(const pppoe_tag &option);
void add_tag(const tag &option);
#if TINS_IS_CXX11
/**
@@ -230,7 +230,7 @@ public:
*
* \param option The option to be added.
*/
void add_tag(pppoe_tag &&option);
void add_tag(tag &&option);
#endif
// Option setters
@@ -380,9 +380,9 @@ private:
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *);
template<typename T>
void add_tag_iterable(tag_identifiers id, const T &data) {
void add_tag_iterable(TagTypes id, const T &data) {
add_tag(
pppoe_tag(
tag(
id,
data.begin(),
data.end()
@@ -391,16 +391,16 @@ private:
}
template<typename T>
T retrieve_tag_iterable(tag_identifiers id) const {
const pppoe_tag *tag = search_tag(id);
T retrieve_tag_iterable(TagTypes id) const {
const tag *tag = search_tag(id);
if(!tag)
throw option_not_found();
return T(tag->data_ptr(), tag->data_ptr() + tag->data_size());
}
template<template <typename> class Functor>
const pppoe_tag *safe_search_tag(tag_identifiers opt, uint32_t size) const {
const pppoe_tag *option = search_tag(opt);
const tag *safe_search_tag(TagTypes opt, uint32_t size) const {
const tag *option = search_tag(opt);
if(!option || Functor<uint32_t>()(option->data_size(), size))
throw option_not_found();
return option;

View File

@@ -79,8 +79,7 @@ namespace Tins {
*
* This enum identifies valid options supported by TCP PDU.
*/
enum Option {
enum OptionTypes {
EOL = 0,
NOP = 1,
MSS = 2,
@@ -91,6 +90,8 @@ namespace Tins {
ALTCHK = 14
};
TINS_DEPRECATED(typedef OptionTypes Option);
/**
* \brief Alternate checksum enum.
*/
@@ -100,12 +101,17 @@ namespace Tins {
CHK_16FLETCHER
};
typedef PDUOption<uint8_t> tcp_option;
/**
* The type used to store TCP options.
*/
typedef PDUOption<uint8_t> option;
TINS_DEPRECATED(typedef option tcp_option);
/**
* The type used to store the options.
*/
typedef std::list<tcp_option> options_type;
typedef std::list<option> options_type;
/**
* The type used to store the sack option.
@@ -357,20 +363,20 @@ namespace Tins {
* \brief Adds a TCP option.
*
* \deprecated This function is deprecated. The overloads taking
* tcp_option should be used.
* a TCP::option should be used.
*
* \param option The option type flag to be set.
* \param length The length of this option(optional).
* \param data Pointer to this option's data(optional).
*/
TINS_DEPRECATED(void add_option(Option option, uint8_t length = 0, const uint8_t *data = 0));
TINS_DEPRECATED(void add_option(OptionTypes opt, uint8_t length = 0, const uint8_t *data = 0));
/**
* \brief Adds a TCP option.
*
* \param option The option to be added.
*/
void add_option(const tcp_option &option);
void add_option(const option &opt);
#if TINS_IS_CXX11
/**
@@ -380,7 +386,7 @@ namespace Tins {
*
* \param option The option to be added.
*/
void add_option(tcp_option &&option);
void add_option(option &&opt);
#endif
/**
@@ -414,7 +420,7 @@ namespace Tins {
* \param opt_flag The flag to be searched.
* \return A pointer to the option, or 0 if it was not found.
*/
const tcp_option *search_option(Option opt) const;
const option *search_option(OptionTypes opt) const;
/**
* \sa PDU::clone
@@ -462,17 +468,17 @@ namespace Tins {
static const uint16_t DEFAULT_WINDOW;
template<class T>
T generic_search(Option opt) const {
const tcp_option *option = search_option(opt);
T generic_search(OptionTypes opt) const {
const option *option = search_option(opt);
if(option && option->data_size() == sizeof(T))
return *(const T*)(&option->data_ptr()[0]);
throw option_not_found();
}
void internal_add_option(const tcp_option &option);
void internal_add_option(const option &option);
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
uint8_t *write_option(const tcp_option &opt, uint8_t *buffer);
uint8_t *write_option(const option &opt, uint8_t *buffer);
tcphdr _tcp;
uint16_t _options_size, _total_options_size;

View File

@@ -68,29 +68,29 @@ DHCP::DHCP(const uint8_t *buffer, uint32_t total_sz)
}
if(total_sz < args[1])
throw std::runtime_error("Not enough size for a DHCP header in the buffer.");
add_option(dhcp_option((Options)args[0], args[1], buffer));
add_option(option((OptionTypes)args[0], args[1], buffer));
buffer += args[1];
total_sz -= args[1];
}
}
void DHCP::add_option(const dhcp_option &option) {
internal_add_option(option);
_options.push_back(option);
void DHCP::add_option(const option &opt) {
internal_add_option(opt);
_options.push_back(opt);
}
#if TINS_IS_CXX11
void DHCP::add_option(dhcp_option &&option) {
internal_add_option(option);
_options.push_back(std::move(option));
void DHCP::add_option(option &&opt) {
internal_add_option(opt);
_options.push_back(std::move(opt));
}
#endif
void DHCP::internal_add_option(const dhcp_option &option) {
_size += option.data_size() + (sizeof(uint8_t) << 1);
void DHCP::internal_add_option(const option &opt) {
_size += opt.data_size() + (sizeof(uint8_t) << 1);
}
const DHCP::dhcp_option *DHCP::search_option(Options opt) const {
const DHCP::option *DHCP::search_option(OptionTypes opt) const {
for(options_type::const_iterator it = _options.begin(); it != _options.end(); ++it) {
if(it->option() == opt)
return &(*it);
@@ -100,11 +100,11 @@ const DHCP::dhcp_option *DHCP::search_option(Options opt) const {
void DHCP::type(Flags type) {
uint8_t int_type = type;
add_option(dhcp_option(DHCP_MESSAGE_TYPE, sizeof(uint8_t), &int_type));
add_option(option(DHCP_MESSAGE_TYPE, sizeof(uint8_t), &int_type));
}
void DHCP::end() {
add_option(dhcp_option(DHCP_MESSAGE_TYPE));
add_option(option(DHCP_MESSAGE_TYPE));
}
uint8_t DHCP::type() const {
@@ -113,7 +113,7 @@ uint8_t DHCP::type() const {
void DHCP::server_identifier(ipaddress_type ip) {
uint32_t ip_int = ip;
add_option(dhcp_option(DHCP_SERVER_IDENTIFIER, sizeof(uint32_t), (const uint8_t*)&ip_int));
add_option(option(DHCP_SERVER_IDENTIFIER, sizeof(uint32_t), (const uint8_t*)&ip_int));
}
DHCP::ipaddress_type DHCP::server_identifier() const {
@@ -122,7 +122,7 @@ DHCP::ipaddress_type DHCP::server_identifier() const {
void DHCP::lease_time(uint32_t time) {
time = Endian::host_to_be(time);
add_option(dhcp_option(DHCP_LEASE_TIME, sizeof(uint32_t), (const uint8_t*)&time));
add_option(option(DHCP_LEASE_TIME, sizeof(uint32_t), (const uint8_t*)&time));
}
uint32_t DHCP::lease_time() const {
@@ -131,7 +131,7 @@ uint32_t DHCP::lease_time() const {
void DHCP::renewal_time(uint32_t time) {
time = Endian::host_to_be(time);
add_option(dhcp_option(DHCP_RENEWAL_TIME, sizeof(uint32_t), (const uint8_t*)&time));
add_option(option(DHCP_RENEWAL_TIME, sizeof(uint32_t), (const uint8_t*)&time));
}
uint32_t DHCP::renewal_time() const {
@@ -140,7 +140,7 @@ uint32_t DHCP::renewal_time() const {
void DHCP::subnet_mask(ipaddress_type mask) {
uint32_t mask_int = mask;
add_option(dhcp_option(SUBNET_MASK, sizeof(uint32_t), (const uint8_t*)&mask_int));
add_option(option(SUBNET_MASK, sizeof(uint32_t), (const uint8_t*)&mask_int));
}
DHCP::ipaddress_type DHCP::subnet_mask() const {
@@ -149,7 +149,7 @@ DHCP::ipaddress_type DHCP::subnet_mask() const {
void DHCP::routers(const list<ipaddress_type> &routers) {
serialization_type buffer = serialize_list(routers);
add_option(dhcp_option(ROUTERS, buffer.begin(), buffer.end()));
add_option(option(ROUTERS, buffer.begin(), buffer.end()));
}
std::list<DHCP::ipaddress_type> DHCP::routers() const {
@@ -158,7 +158,7 @@ std::list<DHCP::ipaddress_type> DHCP::routers() const {
void DHCP::domain_name_servers(const list<ipaddress_type> &dns) {
serialization_type buffer = serialize_list(dns);
add_option(dhcp_option(DOMAIN_NAME_SERVERS, buffer.begin(), buffer.end()));
add_option(option(DOMAIN_NAME_SERVERS, buffer.begin(), buffer.end()));
}
std::list<DHCP::ipaddress_type> DHCP::domain_name_servers() const {
@@ -167,7 +167,7 @@ std::list<DHCP::ipaddress_type> DHCP::domain_name_servers() const {
void DHCP::broadcast(ipaddress_type addr) {
uint32_t int_addr = addr;
add_option(dhcp_option(BROADCAST_ADDRESS, sizeof(uint32_t), (uint8_t*)&int_addr));
add_option(option(BROADCAST_ADDRESS, sizeof(uint32_t), (uint8_t*)&int_addr));
}
DHCP::ipaddress_type DHCP::broadcast() const {
@@ -176,7 +176,7 @@ DHCP::ipaddress_type DHCP::broadcast() const {
void DHCP::requested_ip(ipaddress_type addr) {
uint32_t int_addr = addr;
add_option(dhcp_option(DHCP_REQUESTED_ADDRESS, sizeof(uint32_t), (uint8_t*)&int_addr));
add_option(option(DHCP_REQUESTED_ADDRESS, sizeof(uint32_t), (uint8_t*)&int_addr));
}
DHCP::ipaddress_type DHCP::requested_ip() const {
@@ -184,7 +184,7 @@ DHCP::ipaddress_type DHCP::requested_ip() const {
}
void DHCP::domain_name(const string &name) {
add_option(dhcp_option(DOMAIN_NAME, name.size(), (const uint8_t*)name.c_str()));
add_option(option(DOMAIN_NAME, name.size(), (const uint8_t*)name.c_str()));
}
std::string DHCP::domain_name() const {
@@ -193,7 +193,7 @@ std::string DHCP::domain_name() const {
void DHCP::rebind_time(uint32_t time) {
time = Endian::host_to_be(time);
add_option(dhcp_option(DHCP_REBINDING_TIME, sizeof(uint32_t), (uint8_t*)&time));
add_option(option(DHCP_REBINDING_TIME, sizeof(uint32_t), (uint8_t*)&time));
}
uint32_t DHCP::rebind_time() const {
@@ -230,12 +230,12 @@ void DHCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *pa
BootP::write_serialization(buffer, total_sz, parent);
}
std::list<DHCP::ipaddress_type> DHCP::generic_search(Options opt, type2type<std::list<ipaddress_type> >) const {
const dhcp_option *option = search_option(opt);
if(!option)
std::list<DHCP::ipaddress_type> DHCP::generic_search(OptionTypes opt_type, type2type<std::list<ipaddress_type> >) const {
const option *opt = search_option(opt_type);
if(!opt)
throw option_not_found();
const uint32_t *ptr = (const uint32_t*)option->data_ptr();
uint32_t len = option->data_size();
const uint32_t *ptr = (const uint32_t*)opt->data_ptr();
uint32_t len = opt->data_size();
if((len % sizeof(uint32_t)) != 0)
throw option_not_found();
std::list<ipaddress_type> container;
@@ -246,14 +246,14 @@ std::list<DHCP::ipaddress_type> DHCP::generic_search(Options opt, type2type<std:
return container;
}
std::string DHCP::generic_search(Options opt, type2type<std::string>) const {
const dhcp_option *option = search_option(opt);
if(!option)
std::string DHCP::generic_search(OptionTypes opt_type, type2type<std::string>) const {
const option *opt = search_option(opt_type);
if(!opt)
throw option_not_found();
return string(option->data_ptr(), option->data_ptr() + option->data_size());
return string(opt->data_ptr(), opt->data_ptr() + opt->data_size());
}
DHCP::ipaddress_type DHCP::generic_search(Options opt, type2type<ipaddress_type>) const {
DHCP::ipaddress_type DHCP::generic_search(OptionTypes opt, type2type<ipaddress_type>) const {
return ipaddress_type(generic_search(opt, type2type<uint32_t>()));
}
}

View File

@@ -64,7 +64,7 @@ DHCPv6::DHCPv6(const uint8_t *buffer, uint32_t total_sz)
if(total_sz < sizeof(uint16_t) * 2)
throw std::runtime_error(opt_err_msg);
const uint16_t option = Endian::be_to_host(*(const uint16_t*)buffer);
const uint16_t opt = Endian::be_to_host(*(const uint16_t*)buffer);
const uint16_t data_size = Endian::be_to_host(
*(const uint16_t*)(buffer + sizeof(uint16_t))
);
@@ -72,18 +72,18 @@ DHCPv6::DHCPv6(const uint8_t *buffer, uint32_t total_sz)
throw std::runtime_error(opt_err_msg);
buffer += sizeof(uint16_t) * 2;
add_option(
dhcpv6_option(option, buffer, buffer + data_size)
option(opt, buffer, buffer + data_size)
);
buffer += data_size;
total_sz -= sizeof(uint16_t) * 2 + data_size;
}
}
void DHCPv6::add_option(const dhcpv6_option &option) {
options_.push_back(option);
void DHCPv6::add_option(const option &opt) {
options_.push_back(opt);
}
const DHCPv6::dhcpv6_option *DHCPv6::search_option(Option id) const {
const DHCPv6::option *DHCPv6::search_option(OptionTypes id) const {
for(options_type::const_iterator it = options_.begin(); it != options_.end(); ++it) {
if(it->option() == static_cast<uint16_t>(id))
return &*it;
@@ -91,12 +91,12 @@ const DHCPv6::dhcpv6_option *DHCPv6::search_option(Option id) const {
return 0;
}
uint8_t* DHCPv6::write_option(const dhcpv6_option &option, uint8_t* buffer) const {
*(uint16_t*)buffer = Endian::host_to_be(option.option());
*(uint16_t*)&buffer[sizeof(uint16_t)] = Endian::host_to_be<uint16_t>(option.length_field());
uint8_t* DHCPv6::write_option(const option &opt, uint8_t* buffer) const {
*(uint16_t*)buffer = Endian::host_to_be(opt.option());
*(uint16_t*)&buffer[sizeof(uint16_t)] = Endian::host_to_be<uint16_t>(opt.length_field());
return std::copy(
option.data_ptr(),
option.data_ptr() + option.data_size(),
opt.data_ptr(),
opt.data_ptr() + opt.data_size(),
buffer + sizeof(uint16_t) * 2
);
}
@@ -158,7 +158,7 @@ void DHCPv6::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *
// ********************************************************************
DHCPv6::ia_na_type DHCPv6::ia_na() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
IA_NA, sizeof(uint32_t) * 3
);
const uint8_t *ptr = opt->data_ptr() + sizeof(uint32_t) * 3;
@@ -172,7 +172,7 @@ DHCPv6::ia_na_type DHCPv6::ia_na() const {
}
DHCPv6::ia_ta_type DHCPv6::ia_ta() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
IA_TA, sizeof(uint32_t)
);
const uint8_t *ptr = opt->data_ptr() + sizeof(uint32_t);
@@ -184,7 +184,7 @@ DHCPv6::ia_ta_type DHCPv6::ia_ta() const {
}
DHCPv6::ia_address_type DHCPv6::ia_address() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
IA_ADDR, sizeof(uint32_t) * 2 + ipaddress_type::address_size
);
const uint8_t *ptr = opt->data_ptr() + sizeof(uint32_t) * 2 + ipaddress_type::address_size;
@@ -198,7 +198,7 @@ DHCPv6::ia_address_type DHCPv6::ia_address() const {
}
DHCPv6::option_request_type DHCPv6::option_request() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
OPTION_REQUEST, 2
);
const uint16_t *ptr = (const uint16_t*)opt->data_ptr(),
@@ -206,21 +206,21 @@ DHCPv6::option_request_type DHCPv6::option_request() const {
option_request_type output;
while(ptr < end) {
output.push_back(
static_cast<Option>(Endian::be_to_host(*ptr++))
static_cast<OptionTypes>(Endian::be_to_host(*ptr++))
);
}
return output;
}
uint8_t DHCPv6::preference() const {
const dhcpv6_option *opt = safe_search_option<std::not_equal_to>(
const option *opt = safe_search_option<std::not_equal_to>(
PREFERENCE, 1
);
return *opt->data_ptr();
}
uint16_t DHCPv6::elapsed_time() const {
const dhcpv6_option *opt = safe_search_option<std::not_equal_to>(
const option *opt = safe_search_option<std::not_equal_to>(
ELAPSED_TIME, 2
);
return Endian::be_to_host(
@@ -229,7 +229,7 @@ uint16_t DHCPv6::elapsed_time() const {
}
DHCPv6::relay_msg_type DHCPv6::relay_message() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
RELAY_MSG, 1
);
return relay_msg_type(
@@ -239,7 +239,7 @@ DHCPv6::relay_msg_type DHCPv6::relay_message() const {
}
DHCPv6::authentication_type DHCPv6::authentication() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
AUTH, sizeof(uint8_t) * 3 + sizeof(uint64_t)
);
const uint8_t *ptr = opt->data_ptr();
@@ -256,14 +256,14 @@ DHCPv6::authentication_type DHCPv6::authentication() const {
}
DHCPv6::ipaddress_type DHCPv6::server_unicast() const {
const dhcpv6_option *opt = safe_search_option<std::not_equal_to>(
const option *opt = safe_search_option<std::not_equal_to>(
UNICAST, ipaddress_type::address_size
);
return ipaddress_type(opt->data_ptr());
}
DHCPv6::status_code_type DHCPv6::status_code() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
STATUS_CODE, sizeof(uint16_t)
);
status_code_type output;
@@ -280,7 +280,7 @@ bool DHCPv6::has_rapid_commit() const {
}
DHCPv6::user_class_type DHCPv6::user_class() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
USER_CLASS, sizeof(uint16_t)
);
return option2class_option_data<user_class_type>(
@@ -289,7 +289,7 @@ DHCPv6::user_class_type DHCPv6::user_class() const {
}
DHCPv6::vendor_class_type DHCPv6::vendor_class() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
VENDOR_CLASS, sizeof(uint32_t)
);
typedef vendor_class_type::class_data_type data_type;
@@ -306,7 +306,7 @@ DHCPv6::vendor_class_type DHCPv6::vendor_class() const {
}
DHCPv6::vendor_info_type DHCPv6::vendor_info() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
VENDOR_OPTS, sizeof(uint32_t)
);
vendor_info_type output;
@@ -321,7 +321,7 @@ DHCPv6::vendor_info_type DHCPv6::vendor_info() const {
}
DHCPv6::interface_id_type DHCPv6::interface_id() const {
const dhcpv6_option *opt = safe_search_option<std::equal_to>(
const option *opt = safe_search_option<std::equal_to>(
INTERFACE_ID, 0
);
return interface_id_type(
@@ -341,7 +341,7 @@ bool DHCPv6::has_reconfigure_accept() const {
}
DHCPv6::duid_type DHCPv6::client_id() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
CLIENTID, sizeof(uint16_t) + 1
);
return duid_type(
@@ -354,7 +354,7 @@ DHCPv6::duid_type DHCPv6::client_id() const {
}
DHCPv6::duid_type DHCPv6::server_id() const {
const dhcpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
SERVERID, sizeof(uint16_t) + 1
);
return duid_type(
@@ -382,7 +382,7 @@ void DHCPv6::ia_na(const ia_na_type &value) {
buffer.begin() + sizeof(uint32_t) * 3
);
add_option(
dhcpv6_option(IA_NA, buffer.begin(), buffer.end())
option(IA_NA, buffer.begin(), buffer.end())
);
}
@@ -396,7 +396,7 @@ void DHCPv6::ia_ta(const ia_ta_type &value) {
buffer.begin() + sizeof(uint32_t)
);
add_option(
dhcpv6_option(IA_TA, buffer.begin(), buffer.end())
option(IA_TA, buffer.begin(), buffer.end())
);
}
@@ -414,7 +414,7 @@ void DHCPv6::ia_address(const ia_address_type &value) {
buffer.begin() + sizeof(uint32_t) * 2 + ipaddress_type::address_size
);
add_option(
dhcpv6_option(IA_ADDR, buffer.begin(), buffer.end())
option(IA_ADDR, buffer.begin(), buffer.end())
);
}
@@ -426,26 +426,26 @@ void DHCPv6::option_request(const option_request_type &value) {
for(iterator it = value.begin(); it != value.end(); ++it, index += 2)
*(uint16_t*)&buffer[index] = Endian::host_to_be<uint16_t>(*it);
add_option(
dhcpv6_option(OPTION_REQUEST, buffer.begin(), buffer.end())
option(OPTION_REQUEST, buffer.begin(), buffer.end())
);
}
void DHCPv6::preference(uint8_t value) {
add_option(
dhcpv6_option(PREFERENCE, 1, &value)
option(PREFERENCE, 1, &value)
);
}
void DHCPv6::elapsed_time(uint16_t value) {
value = Endian::host_to_be(value);
add_option(
dhcpv6_option(ELAPSED_TIME, 2, (const uint8_t*)&value)
option(ELAPSED_TIME, 2, (const uint8_t*)&value)
);
}
void DHCPv6::relay_message(const relay_msg_type &value) {
add_option(
dhcpv6_option(RELAY_MSG, value.begin(), value.end())
option(RELAY_MSG, value.begin(), value.end())
);
}
@@ -463,13 +463,13 @@ void DHCPv6::authentication(const authentication_type &value) {
buffer.begin() + sizeof(uint8_t) * 3 + sizeof(uint64_t)
);
add_option(
dhcpv6_option(AUTH, buffer.begin(), buffer.end())
option(AUTH, buffer.begin(), buffer.end())
);
}
void DHCPv6::server_unicast(const ipaddress_type &value) {
add_option(
dhcpv6_option(UNICAST, value.begin(), value.end())
option(UNICAST, value.begin(), value.end())
);
}
@@ -482,7 +482,7 @@ void DHCPv6::status_code(const status_code_type &value) {
buffer.begin() + sizeof(uint16_t)
);
add_option(
dhcpv6_option(STATUS_CODE, buffer.begin(), buffer.end())
option(STATUS_CODE, buffer.begin(), buffer.end())
);
}
@@ -498,7 +498,7 @@ void DHCPv6::user_class(const user_class_type &value) {
std::vector<uint8_t> buffer;
class_option_data2option(value.begin(), value.end(), buffer);
add_option(
dhcpv6_option(USER_CLASS, buffer.begin(), buffer.end())
option(USER_CLASS, buffer.begin(), buffer.end())
);
}
@@ -514,7 +514,7 @@ void DHCPv6::vendor_class(const vendor_class_type &value) {
sizeof(uint32_t)
);
add_option(
dhcpv6_option(VENDOR_CLASS, buffer.begin(), buffer.end())
option(VENDOR_CLASS, buffer.begin(), buffer.end())
);
}
@@ -527,19 +527,19 @@ void DHCPv6::vendor_info(const vendor_info_type &value) {
buffer.begin() + sizeof(uint32_t)
);
add_option(
dhcpv6_option(VENDOR_OPTS, buffer.begin(), buffer.end())
option(VENDOR_OPTS, buffer.begin(), buffer.end())
);
}
void DHCPv6::interface_id(const interface_id_type &value) {
add_option(
dhcpv6_option(INTERFACE_ID, value.begin(), value.end())
option(INTERFACE_ID, value.begin(), value.end())
);
}
void DHCPv6::reconfigure_msg(uint8_t value) {
add_option(
dhcpv6_option(RECONF_MSG, 1, &value)
option(RECONF_MSG, 1, &value)
);
}
@@ -634,7 +634,7 @@ void DHCPv6::client_id(const duid_type &value) {
buffer.begin() + sizeof(uint16_t)
);
add_option(
dhcpv6_option(CLIENTID, buffer.begin(), buffer.end())
option(CLIENTID, buffer.begin(), buffer.end())
);
}
@@ -647,7 +647,7 @@ void DHCPv6::server_id(const duid_type &value) {
buffer.begin() + sizeof(uint16_t)
);
add_option(
dhcpv6_option(SERVERID, buffer.begin(), buffer.end())
option(SERVERID, buffer.begin(), buffer.end())
);
}

View File

@@ -90,37 +90,42 @@ void Dot11::parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz) {
if(length > total_sz) {
throw std::runtime_error("Malformed option encountered");
}
add_tagged_option((TaggedOption)opcode, length, buffer);
add_tagged_option((OptionTypes)opcode, length, buffer);
buffer += length;
total_sz -= length;
}
}
}
void Dot11::add_tagged_option(TaggedOption opt, uint8_t len, const uint8_t *val) {
void Dot11::add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t *val) {
uint32_t opt_size = len + sizeof(uint8_t) * 2;
_options.push_back(dot11_option((uint8_t)opt, len, val));
_options.push_back(option((uint8_t)opt, len, val));
_options_size += opt_size;
}
#if TINS_IS_CXX11
void Dot11::add_tagged_option(dot11_option &&opt) {
void Dot11::add_option(option &&opt) {
internal_add_option(opt);
_options.push_back(std::move(opt));
}
#endif
void Dot11::internal_add_option(const dot11_option &opt) {
void Dot11::internal_add_option(const option &opt) {
_options_size += opt.data_size() + sizeof(uint8_t) * 2;
}
void Dot11::add_tagged_option(const dot11_option &opt) {
void Dot11::add_option(const option &opt) {
internal_add_option(opt);
_options.push_back(opt);
}
const Dot11::dot11_option *Dot11::search_option(TaggedOption opt) const {
for(std::list<dot11_option>::const_iterator it = _options.begin(); it != _options.end(); ++it)
void Dot11::add_tagged_option(const option &opt) {
internal_add_option(opt);
_options.push_back(opt);
}
const Dot11::option *Dot11::search_option(OptionTypes opt) const {
for(std::list<option>::const_iterator it = _options.begin(); it != _options.end(); ++it)
if(it->option() == (uint8_t)opt)
return &(*it);
return 0;
@@ -219,7 +224,7 @@ void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *p
uint32_t child_len = write_fixed_parameters(buffer, total_sz - _options_size);
buffer += child_len;
assert(total_sz >= child_len + _options_size);
for(std::list<dot11_option>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
for(std::list<option>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
*(buffer++) = it->option();
*(buffer++) = it->length_field();
std::copy(it->data_ptr(), it->data_ptr() + it->data_size(), buffer);
@@ -377,9 +382,9 @@ uint8_t *Dot11ManagementFrame::serialize_rates(const rates_type &rates) {
return buffer;
}
Dot11ManagementFrame::rates_type Dot11ManagementFrame::deserialize_rates(const dot11_option *option) {
Dot11ManagementFrame::rates_type Dot11ManagementFrame::deserialize_rates(const option *opt) {
rates_type output;
const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size();
const uint8_t *ptr = opt->data_ptr(), *end = ptr + opt->data_size();
while(ptr != end) {
output.push_back(float(*(ptr++) & 0x7f) / 2);
}
@@ -609,49 +614,49 @@ void Dot11ManagementFrame::challenge_text(const std::string &text) {
// Getters
RSNInformation Dot11ManagementFrame::rsn_information() {
const Dot11::dot11_option *option = search_option(RSN);
const Dot11::option *option = search_option(RSN);
if(!option || option->data_size() < (sizeof(uint16_t) << 1) + sizeof(uint32_t))
throw std::runtime_error("RSN information not set");
return RSNInformation(option->data_ptr(), option->data_size());
}
string Dot11ManagementFrame::ssid() const {
const Dot11::dot11_option *option = search_option(SSID);
const Dot11::option *option = search_option(SSID);
if(!option || option->data_size() == 0)
throw std::runtime_error("SSID not set");
return string((const char*)option->data_ptr(), option->data_size());
}
Dot11ManagementFrame::rates_type Dot11ManagementFrame::supported_rates() const {
const Dot11::dot11_option *option = search_option(SUPPORTED_RATES);
const Dot11::option *option = search_option(SUPPORTED_RATES);
if(!option || option->data_size() == 0)
throw std::runtime_error("Supported rates not set");
return deserialize_rates(option);
}
Dot11ManagementFrame::rates_type Dot11ManagementFrame::extended_supported_rates() const {
const Dot11::dot11_option *option = search_option(EXT_SUPPORTED_RATES);
const Dot11::option *option = search_option(EXT_SUPPORTED_RATES);
if(!option || option->data_size() == 0)
throw std::runtime_error("Extended supported rates not set");
return deserialize_rates(option);
}
uint8_t Dot11ManagementFrame::qos_capability() const {
const Dot11::dot11_option *option = search_option(QOS_CAPABILITY);
const Dot11::option *option = search_option(QOS_CAPABILITY);
if(!option || option->data_size() != 1)
throw std::runtime_error("QOS capability not set");
return *option->data_ptr();
}
std::pair<uint8_t, uint8_t> Dot11ManagementFrame::power_capability() const {
const Dot11::dot11_option *option = search_option(POWER_CAPABILITY);
const Dot11::option *option = search_option(POWER_CAPABILITY);
if(!option || option->data_size() != 2)
throw std::runtime_error("Power capability not set");
return std::make_pair(*option->data_ptr(), *(option->data_ptr() + 1));
}
Dot11ManagementFrame::channels_type Dot11ManagementFrame::supported_channels() const {
const Dot11::dot11_option *option = search_option(SUPPORTED_CHANNELS);
const Dot11::option *option = search_option(SUPPORTED_CHANNELS);
// We need a multiple of two
if(!option || ((option->data_size() & 0x1) == 1))
throw std::runtime_error("Supported channels not set");
@@ -665,7 +670,7 @@ Dot11ManagementFrame::channels_type Dot11ManagementFrame::supported_channels() c
}
Dot11ManagementFrame::request_info_type Dot11ManagementFrame::request_information() const {
const Dot11::dot11_option *option = search_option(REQUEST_INFORMATION);
const Dot11::option *option = search_option(REQUEST_INFORMATION);
if(!option || option->data_size() == 0)
throw std::runtime_error("Request information not set");
request_info_type output;
@@ -675,7 +680,7 @@ Dot11ManagementFrame::request_info_type Dot11ManagementFrame::request_informatio
}
Dot11ManagementFrame::fh_params_set Dot11ManagementFrame::fh_parameter_set() const {
const Dot11::dot11_option *option = search_option(FH_SET);
const Dot11::option *option = search_option(FH_SET);
if(!option || option->data_size() != sizeof(fh_params_set))
throw std::runtime_error("FH parameters set not set");
fh_params_set output = *reinterpret_cast<const fh_params_set*>(option->data_ptr());
@@ -687,21 +692,21 @@ Dot11ManagementFrame::fh_params_set Dot11ManagementFrame::fh_parameter_set() con
}
uint8_t Dot11ManagementFrame::ds_parameter_set() const {
const Dot11::dot11_option *option = search_option(DS_SET);
const Dot11::option *option = search_option(DS_SET);
if(!option || option->data_size() != sizeof(uint8_t))
throw std::runtime_error("DS parameters set not set");
return *option->data_ptr();
}
uint16_t Dot11ManagementFrame::ibss_parameter_set() const {
const Dot11::dot11_option *option = search_option(IBSS_SET);
const Dot11::option *option = search_option(IBSS_SET);
if(!option || option->data_size() != sizeof(uint16_t))
throw std::runtime_error("IBSS parameters set not set");
return Endian::le_to_host(*reinterpret_cast<const uint16_t*>(option->data_ptr()));
}
Dot11ManagementFrame::ibss_dfs_params Dot11ManagementFrame::ibss_dfs() const {
const Dot11::dot11_option *option = search_option(IBSS_DFS);
const Dot11::option *option = search_option(IBSS_DFS);
if(!option || option->data_size() < ibss_dfs_params::minimum_size)
throw std::runtime_error("IBSS DFS set not set");
ibss_dfs_params output;
@@ -719,7 +724,7 @@ Dot11ManagementFrame::ibss_dfs_params Dot11ManagementFrame::ibss_dfs() const {
}
Dot11ManagementFrame::country_params Dot11ManagementFrame::country() const {
const Dot11::dot11_option *option = search_option(COUNTRY);
const Dot11::option *option = search_option(COUNTRY);
if(!option || option->data_size() < country_params::minimum_size)
throw std::runtime_error("Country option not set");
country_params output;
@@ -737,7 +742,7 @@ Dot11ManagementFrame::country_params Dot11ManagementFrame::country() const {
}
std::pair<uint8_t, uint8_t> Dot11ManagementFrame::fh_parameters() const {
const Dot11::dot11_option *option = search_option(HOPPING_PATTERN_PARAMS);
const Dot11::option *option = search_option(HOPPING_PATTERN_PARAMS);
if(!option || option->data_size() != sizeof(uint8_t) * 2)
throw std::runtime_error("FH parameters option not set");
const uint8_t *ptr = option->data_ptr();
@@ -746,7 +751,7 @@ std::pair<uint8_t, uint8_t> Dot11ManagementFrame::fh_parameters() const {
}
Dot11ManagementFrame::fh_pattern_type Dot11ManagementFrame::fh_pattern_table() const {
const Dot11::dot11_option *option = search_option(HOPPING_PATTERN_TABLE);
const Dot11::option *option = search_option(HOPPING_PATTERN_TABLE);
if(!option || option->data_size() < fh_pattern_type::minimum_size)
throw std::runtime_error("FH pattern option not set");
fh_pattern_type output;
@@ -762,14 +767,14 @@ Dot11ManagementFrame::fh_pattern_type Dot11ManagementFrame::fh_pattern_table() c
}
uint8_t Dot11ManagementFrame::power_constraint() const {
const Dot11::dot11_option *option = search_option(POWER_CONSTRAINT);
const Dot11::option *option = search_option(POWER_CONSTRAINT);
if(!option || option->data_size() != 1)
throw std::runtime_error("Power constraint option not set");
return *option->data_ptr();
}
Dot11ManagementFrame::channel_switch_type Dot11ManagementFrame::channel_switch() const {
const Dot11::dot11_option *option = search_option(CHANNEL_SWITCH);
const Dot11::option *option = search_option(CHANNEL_SWITCH);
if(!option || option->data_size() != sizeof(uint8_t) * 3)
throw std::runtime_error("Channel switch option not set");
const uint8_t *ptr = option->data_ptr();
@@ -781,7 +786,7 @@ Dot11ManagementFrame::channel_switch_type Dot11ManagementFrame::channel_switch()
}
Dot11ManagementFrame::quiet_type Dot11ManagementFrame::quiet() const {
const Dot11::dot11_option *option = search_option(QUIET);
const Dot11::option *option = search_option(QUIET);
if(!option || option->data_size() != (sizeof(uint8_t) * 2 + sizeof(uint16_t) * 2))
throw std::runtime_error("Quiet option not set");
const uint8_t *ptr = option->data_ptr();
@@ -796,7 +801,7 @@ Dot11ManagementFrame::quiet_type Dot11ManagementFrame::quiet() const {
}
std::pair<uint8_t, uint8_t> Dot11ManagementFrame::tpc_report() const {
const Dot11::dot11_option *option = search_option(TPC_REPORT);
const Dot11::option *option = search_option(TPC_REPORT);
if(!option || option->data_size() != sizeof(uint8_t) * 2)
throw std::runtime_error("TPC Report option not set");
const uint8_t *ptr = option->data_ptr();
@@ -805,14 +810,14 @@ std::pair<uint8_t, uint8_t> Dot11ManagementFrame::tpc_report() const {
}
uint8_t Dot11ManagementFrame::erp_information() const {
const Dot11::dot11_option *option = search_option(ERP_INFORMATION);
const Dot11::option *option = search_option(ERP_INFORMATION);
if(!option || option->data_size() != sizeof(uint8_t))
throw std::runtime_error("ERP Information option not set");
return *option->data_ptr();
}
Dot11ManagementFrame::bss_load_type Dot11ManagementFrame::bss_load() const {
const Dot11::dot11_option *option = search_option(BSS_LOAD);
const Dot11::option *option = search_option(BSS_LOAD);
if(!option || option->data_size() != sizeof(uint8_t) + 2 * sizeof(uint16_t))
throw std::runtime_error("BSS Load option not set");
bss_load_type output;
@@ -825,7 +830,7 @@ Dot11ManagementFrame::bss_load_type Dot11ManagementFrame::bss_load() const {
}
Dot11ManagementFrame::tim_type Dot11ManagementFrame::tim() const {
const Dot11::dot11_option *option = search_option(TIM);
const Dot11::option *option = search_option(TIM);
if(!option || option->data_size() < 4 * sizeof(uint8_t))
throw std::runtime_error("TIM option not set");
const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size();
@@ -840,7 +845,7 @@ Dot11ManagementFrame::tim_type Dot11ManagementFrame::tim() const {
}
std::string Dot11ManagementFrame::challenge_text() const {
const Dot11::dot11_option *option = search_option(CHALLENGE_TEXT);
const Dot11::option *option = search_option(CHALLENGE_TEXT);
if(!option || option->data_size() == 0)
throw std::runtime_error("Challenge text option not set");
return std::string(option->data_ptr(), option->data_ptr() + option->data_size());

View File

@@ -87,7 +87,7 @@ void ICMPv6::parse_options(const uint8_t *&buffer, uint32_t &total_sz) {
if(total_sz < 8 || (static_cast<uint32_t>(buffer[1]) * 8) > total_sz || buffer[1] < 1)
throw std::runtime_error("Not enough size for options");
// size(option) = option_size - identifier_size - length_identifier_size
add_option(icmpv6_option(buffer[0], static_cast<uint32_t>(buffer[1]) * 8 - sizeof(uint8_t) * 2, buffer + 2));
add_option(option(buffer[0], static_cast<uint32_t>(buffer[1]) * 8 - sizeof(uint8_t) * 2, buffer + 2));
total_sz -= buffer[1] * 8;
buffer += buffer[1] * 8;
}
@@ -236,29 +236,29 @@ bool ICMPv6::has_options() const {
type() == ROUTER_ADVERT;
}
void ICMPv6::add_option(const icmpv6_option &option) {
void ICMPv6::add_option(const option &option) {
internal_add_option(option);
_options.push_back(option);
}
#if TINS_IS_CXX11
void ICMPv6::add_option(icmpv6_option &&option) {
void ICMPv6::add_option(option &&option) {
internal_add_option(option);
_options.push_back(std::move(option));
}
#endif
void ICMPv6::internal_add_option(const icmpv6_option &option) {
void ICMPv6::internal_add_option(const option &option) {
_options_size += option.data_size() + sizeof(uint8_t) * 2;
}
uint8_t *ICMPv6::write_option(const icmpv6_option &opt, uint8_t *buffer) {
uint8_t *ICMPv6::write_option(const option &opt, uint8_t *buffer) {
*buffer++ = opt.option();
*buffer++ = (opt.length_field() + sizeof(uint8_t) * 2) / 8;
return std::copy(opt.data_ptr(), opt.data_ptr() + opt.data_size(), buffer);
}
const ICMPv6::icmpv6_option *ICMPv6::search_option(Options id) const {
const ICMPv6::option *ICMPv6::search_option(OptionTypes id) const {
for(options_type::const_iterator it = _options.begin(); it != _options.end(); ++it) {
if(it->option() == id)
return &*it;
@@ -271,11 +271,11 @@ const ICMPv6::icmpv6_option *ICMPv6::search_option(Options id) const {
// ********************************************************************
void ICMPv6::source_link_layer_addr(const hwaddress_type &addr) {
add_option(icmpv6_option(SOURCE_ADDRESS, addr.begin(), addr.end()));
add_option(option(SOURCE_ADDRESS, addr.begin(), addr.end()));
}
void ICMPv6::target_link_layer_addr(const hwaddress_type &addr) {
add_option(icmpv6_option(TARGET_ADDRESS, addr.begin(), addr.end()));
add_option(option(TARGET_ADDRESS, addr.begin(), addr.end()));
}
void ICMPv6::prefix_info(prefix_info_type info) {
@@ -287,7 +287,7 @@ void ICMPv6::prefix_info(prefix_info_type info) {
*(uint32_t*)(buffer + 2 + sizeof(uint32_t) * 2) = 0;
info.prefix.copy(buffer + 2 + sizeof(uint32_t) * 3);
add_option(
icmpv6_option(PREFIX_INFO, buffer, buffer + sizeof(buffer))
option(PREFIX_INFO, buffer, buffer + sizeof(buffer))
);
}
@@ -299,32 +299,32 @@ void ICMPv6::redirect_header(PDU::serialization_type data) {
if(padding == 8)
padding = 0;
data.insert(data.end(), padding, 0);
add_option(icmpv6_option(REDIRECT_HEADER, data.begin(), data.end()));
add_option(option(REDIRECT_HEADER, data.begin(), data.end()));
}
void ICMPv6::mtu(uint32_t value) {
uint8_t buffer[sizeof(uint16_t) + sizeof(uint32_t)] = {0};
*((uint32_t*)(buffer + sizeof(uint16_t))) = Endian::host_to_be(value);
add_option(icmpv6_option(MTU, sizeof(buffer), buffer));
add_option(option(MTU, sizeof(buffer), buffer));
}
void ICMPv6::shortcut_limit(uint8_t value) {
uint8_t buffer[sizeof(uint16_t) + sizeof(uint32_t)] = {0};
buffer[0] = value;
add_option(icmpv6_option(NBMA_SHORT_LIMIT, sizeof(buffer), buffer));
add_option(option(NBMA_SHORT_LIMIT, sizeof(buffer), buffer));
}
void ICMPv6::new_advert_interval(uint32_t value) {
uint8_t buffer[sizeof(uint16_t) + sizeof(uint32_t)] = {0};
*((uint32_t*)(buffer + sizeof(uint16_t))) = Endian::host_to_be(value);
add_option(icmpv6_option(ADVERT_INTERVAL, sizeof(buffer), buffer));
add_option(option(ADVERT_INTERVAL, sizeof(buffer), buffer));
}
void ICMPv6::new_home_agent_info(const new_ha_info_type &value) {
uint8_t buffer[sizeof(uint16_t) + sizeof(uint32_t)] = {0};
*((uint16_t*)(buffer + sizeof(uint16_t))) = Endian::host_to_be(value.first);
*((uint16_t*)(buffer + sizeof(uint16_t) * 2)) = Endian::host_to_be(value.second);
add_option(icmpv6_option(HOME_AGENT_INFO, sizeof(buffer), buffer));
add_option(option(HOME_AGENT_INFO, sizeof(buffer), buffer));
}
void ICMPv6::source_addr_list(const addr_list_type &value) {
@@ -341,7 +341,7 @@ void ICMPv6::add_addr_list(uint8_t type, const addr_list_type &value) {
buffer.insert(buffer.end(), 6, 0);
for(addr_list_type::const_iterator it(value.begin()); it != value.end(); ++it)
buffer.insert(buffer.end(), it->begin(), it->end());
add_option(icmpv6_option(type, buffer.begin(), buffer.end()));
add_option(option(type, buffer.begin(), buffer.end()));
}
void ICMPv6::rsa_signature(const rsa_sign_type &value) {
@@ -355,18 +355,18 @@ void ICMPv6::rsa_signature(const rsa_sign_type &value) {
buffer.insert(buffer.end(), value.key_hash, value.key_hash + sizeof(value.key_hash));
buffer.insert(buffer.end(), value.signature.begin(), value.signature.end());
buffer.insert(buffer.end(), padding, 0);
add_option(icmpv6_option(RSA_SIGN, buffer.begin(), buffer.end()));
add_option(option(RSA_SIGN, buffer.begin(), buffer.end()));
}
void ICMPv6::timestamp(uint64_t value) {
std::vector<uint8_t> buffer(6 + sizeof(uint64_t));
buffer.insert(buffer.begin(), 6, 0);
*((uint64_t*)&buffer[6]) = Endian::host_to_be(value);
add_option(icmpv6_option(TIMESTAMP, buffer.begin(), buffer.end()));
add_option(option(TIMESTAMP, buffer.begin(), buffer.end()));
}
void ICMPv6::nonce(const nonce_type &value) {
add_option(icmpv6_option(NONCE, value.begin(), value.end()));
add_option(option(NONCE, value.begin(), value.end()));
}
void ICMPv6::ip_prefix(const ip_prefix_type &value) {
@@ -377,7 +377,7 @@ void ICMPv6::ip_prefix(const ip_prefix_type &value) {
// reserved
buffer.insert(buffer.end(), sizeof(uint32_t), 0);
buffer.insert(buffer.end(), value.address.begin(), value.address.end());
add_option(icmpv6_option(IP_PREFIX, buffer.begin(), buffer.end()));
add_option(option(IP_PREFIX, buffer.begin(), buffer.end()));
}
void ICMPv6::link_layer_addr(lladdr_type value) {
@@ -386,14 +386,14 @@ void ICMPv6::link_layer_addr(lladdr_type value) {
if(padding == 8)
padding = 0;
value.address.insert(value.address.end(), padding, 0);
add_option(icmpv6_option(LINK_ADDRESS, value.address.begin(), value.address.end()));
add_option(option(LINK_ADDRESS, value.address.begin(), value.address.end()));
}
void ICMPv6::naack(const naack_type &value) {
uint8_t buffer[6];
buffer[0] = value.first;
buffer[1] = value.second;
add_option(icmpv6_option(NAACK, buffer, buffer + sizeof(buffer)));
add_option(option(NAACK, buffer, buffer + sizeof(buffer)));
}
void ICMPv6::map(const map_type &value) {
@@ -402,7 +402,7 @@ void ICMPv6::map(const map_type &value) {
buffer[1] = value.r << 7;
*(uint32_t*)(buffer + 2) = Endian::host_to_be(value.valid_lifetime);
value.address.copy(buffer + 2 + sizeof(uint32_t));
add_option(icmpv6_option(MAP, buffer, buffer + sizeof(buffer)));
add_option(option(MAP, buffer, buffer + sizeof(buffer)));
}
void ICMPv6::route_info(const route_info_type &value) {
@@ -419,7 +419,7 @@ void ICMPv6::route_info(const route_info_type &value) {
padding,
0
);
add_option(icmpv6_option(ROUTE_INFO, buffer.begin(), buffer.end()));
add_option(option(ROUTE_INFO, buffer.begin(), buffer.end()));
}
void ICMPv6::recursive_dns_servers(const recursive_dns_type &value) {
@@ -433,7 +433,7 @@ void ICMPv6::recursive_dns_servers(const recursive_dns_type &value) {
typedef recursive_dns_type::servers_type::const_iterator iterator;
for(iterator it = value.servers.begin(); it != value.servers.end(); ++it)
out = it->copy(out);
add_option(icmpv6_option(RECURSIVE_DNS_SERV, buffer.begin(), buffer.end()));
add_option(option(RECURSIVE_DNS_SERV, buffer.begin(), buffer.end()));
}
void ICMPv6::handover_key_request(const handover_key_req_type &value) {
@@ -449,7 +449,7 @@ void ICMPv6::handover_key_request(const handover_key_req_type &value) {
buffer.end(),
0
);
add_option(icmpv6_option(HANDOVER_KEY_REQ, buffer.begin(), buffer.end()));
add_option(option(HANDOVER_KEY_REQ, buffer.begin(), buffer.end()));
}
void ICMPv6::handover_key_reply(const handover_key_reply_type &value) {
@@ -467,7 +467,7 @@ void ICMPv6::handover_key_reply(const handover_key_reply_type &value) {
buffer.end(),
0
);
add_option(icmpv6_option(HANDOVER_KEY_REPLY, buffer.begin(), buffer.end()));
add_option(option(HANDOVER_KEY_REPLY, buffer.begin(), buffer.end()));
}
void ICMPv6::handover_assist_info(const handover_assist_info_type &value) {
@@ -484,7 +484,7 @@ void ICMPv6::handover_assist_info(const handover_assist_info_type &value) {
padding,
0
);
add_option(icmpv6_option(HANDOVER_ASSIST_INFO, buffer.begin(), buffer.end()));
add_option(option(HANDOVER_ASSIST_INFO, buffer.begin(), buffer.end()));
}
void ICMPv6::mobile_node_identifier(const mobile_node_id_type &value) {
@@ -501,7 +501,7 @@ void ICMPv6::mobile_node_identifier(const mobile_node_id_type &value) {
padding,
0
);
add_option(icmpv6_option(MOBILE_NODE_ID, buffer.begin(), buffer.end()));
add_option(option(MOBILE_NODE_ID, buffer.begin(), buffer.end()));
}
void ICMPv6::dns_search_list(const dns_search_list_type &value) {
@@ -525,7 +525,7 @@ void ICMPv6::dns_search_list(const dns_search_list_type &value) {
if(padding == 8)
padding = 0;
buffer.insert(buffer.end(), padding, 0);
add_option(icmpv6_option(DNS_SEARCH_LIST, buffer.begin(), buffer.end()));
add_option(option(DNS_SEARCH_LIST, buffer.begin(), buffer.end()));
}
// ********************************************************************
@@ -533,21 +533,21 @@ void ICMPv6::dns_search_list(const dns_search_list_type &value) {
// ********************************************************************
ICMPv6::hwaddress_type ICMPv6::source_link_layer_addr() const {
const icmpv6_option *opt = search_option(SOURCE_ADDRESS);
const option *opt = search_option(SOURCE_ADDRESS);
if(!opt || opt->data_size() != hwaddress_type::address_size)
throw option_not_found();
return hwaddress_type(opt->data_ptr());
}
ICMPv6::hwaddress_type ICMPv6::target_link_layer_addr() const {
const icmpv6_option *opt = search_option(TARGET_ADDRESS);
const option *opt = search_option(TARGET_ADDRESS);
if(!opt || opt->data_size() != hwaddress_type::address_size)
throw option_not_found();
return hwaddress_type(opt->data_ptr());
}
ICMPv6::prefix_info_type ICMPv6::prefix_info() const {
const icmpv6_option *opt = search_option(PREFIX_INFO);
const option *opt = search_option(PREFIX_INFO);
if(!opt || opt->data_size() != 2 + sizeof(uint32_t) * 3 + ipaddress_type::address_size)
throw option_not_found();
const uint8_t *ptr = opt->data_ptr();
@@ -563,7 +563,7 @@ ICMPv6::prefix_info_type ICMPv6::prefix_info() const {
}
PDU::serialization_type ICMPv6::redirect_header() const {
const icmpv6_option *opt = search_option(REDIRECT_HEADER);
const option *opt = search_option(REDIRECT_HEADER);
if(!opt || opt->data_size() < 6)
throw option_not_found();
const uint8_t *ptr = opt->data_ptr() + 6;
@@ -571,28 +571,28 @@ PDU::serialization_type ICMPv6::redirect_header() const {
}
uint32_t ICMPv6::mtu() const {
const icmpv6_option *opt = search_option(MTU);
const option *opt = search_option(MTU);
if(!opt || opt->data_size() != sizeof(uint16_t) + sizeof(uint32_t))
throw option_not_found();
return Endian::be_to_host(*(const uint32_t*)(opt->data_ptr() + sizeof(uint16_t)));
}
uint8_t ICMPv6::shortcut_limit() const {
const icmpv6_option *opt = search_option(NBMA_SHORT_LIMIT);
const option *opt = search_option(NBMA_SHORT_LIMIT);
if(!opt || opt->data_size() != sizeof(uint16_t) + sizeof(uint32_t))
throw option_not_found();
return *opt->data_ptr();
}
uint32_t ICMPv6::new_advert_interval() const {
const icmpv6_option *opt = search_option(ADVERT_INTERVAL);
const option *opt = search_option(ADVERT_INTERVAL);
if(!opt || opt->data_size() != sizeof(uint16_t) + sizeof(uint32_t))
throw option_not_found();
return Endian::be_to_host(*(const uint32_t*)(opt->data_ptr() + sizeof(uint16_t)));
}
ICMPv6::new_ha_info_type ICMPv6::new_home_agent_info() const {
const icmpv6_option *opt = search_option(HOME_AGENT_INFO);
const option *opt = search_option(HOME_AGENT_INFO);
if(!opt || opt->data_size() != sizeof(uint16_t) + sizeof(uint32_t))
throw option_not_found();
return std::make_pair(
@@ -609,8 +609,8 @@ ICMPv6::addr_list_type ICMPv6::target_addr_list() const {
return search_addr_list(T_ADDRESS_LIST);
}
ICMPv6::addr_list_type ICMPv6::search_addr_list(Options type) const {
const icmpv6_option *opt = search_option(type);
ICMPv6::addr_list_type ICMPv6::search_addr_list(OptionTypes type) const {
const option *opt = search_option(type);
if(!opt || opt->data_size() < 6 + ipaddress_type::address_size)
throw option_not_found();
addr_list_type output;
@@ -625,7 +625,7 @@ ICMPv6::addr_list_type ICMPv6::search_addr_list(Options type) const {
}
ICMPv6::rsa_sign_type ICMPv6::rsa_signature() const {
const icmpv6_option *opt = search_option(RSA_SIGN);
const option *opt = search_option(RSA_SIGN);
// 2 bytes reserved + at least 1 byte signature.
// 16 == sizeof(rsa_sign_type::key_hash), removed the sizeof
// expression since gcc 4.2 doesn't like it
@@ -640,21 +640,21 @@ ICMPv6::rsa_sign_type ICMPv6::rsa_signature() const {
}
uint64_t ICMPv6::timestamp() const {
const icmpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
TIMESTAMP, 6 + sizeof(uint64_t)
);
return Endian::be_to_host(*(uint64_t*)(opt->data_ptr() + 6));
}
ICMPv6::nonce_type ICMPv6::nonce() const {
const icmpv6_option *opt = safe_search_option<std::equal_to>(
const option *opt = safe_search_option<std::equal_to>(
NONCE, 0
);
return nonce_type(opt->data_ptr(), opt->data_ptr() + opt->data_size());
}
ICMPv6::ip_prefix_type ICMPv6::ip_prefix() const {
const icmpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
IP_PREFIX, 2
);
const uint8_t *ptr = opt->data_ptr();
@@ -669,7 +669,7 @@ ICMPv6::ip_prefix_type ICMPv6::ip_prefix() const {
ICMPv6::lladdr_type ICMPv6::link_layer_addr() const {
// at least the option_code and 1 byte from the link layer address
const icmpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
LINK_ADDRESS, 2
);
const uint8_t *ptr = opt->data_ptr();
@@ -679,7 +679,7 @@ ICMPv6::lladdr_type ICMPv6::link_layer_addr() const {
}
ICMPv6::naack_type ICMPv6::naack() const {
const icmpv6_option *opt = safe_search_option<std::not_equal_to>(
const option *opt = safe_search_option<std::not_equal_to>(
NAACK, 6
);
const uint8_t *ptr = opt->data_ptr();
@@ -687,7 +687,7 @@ ICMPv6::naack_type ICMPv6::naack() const {
}
ICMPv6::map_type ICMPv6::map() const {
const icmpv6_option *opt = safe_search_option<std::not_equal_to>(
const option *opt = safe_search_option<std::not_equal_to>(
MAP, 2 + sizeof(uint32_t) + ipaddress_type::address_size
);
const uint8_t *ptr = opt->data_ptr();
@@ -702,7 +702,7 @@ ICMPv6::map_type ICMPv6::map() const {
}
ICMPv6::route_info_type ICMPv6::route_info() const {
const icmpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
ROUTE_INFO, 2 + sizeof(uint32_t)
);
const uint8_t *ptr = opt->data_ptr();
@@ -716,7 +716,7 @@ ICMPv6::route_info_type ICMPv6::route_info() const {
}
ICMPv6::recursive_dns_type ICMPv6::recursive_dns_servers() const {
const icmpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
RECURSIVE_DNS_SERV, 2 + sizeof(uint32_t) + ipaddress_type::address_size
);
const uint8_t *ptr = opt->data_ptr() + 2, *end = opt->data_ptr() + opt->data_size();
@@ -733,7 +733,7 @@ ICMPv6::recursive_dns_type ICMPv6::recursive_dns_servers() const {
}
ICMPv6::handover_key_req_type ICMPv6::handover_key_request() const {
const icmpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
HANDOVER_KEY_REQ, 2 + sizeof(uint32_t)
);
const uint8_t *ptr = opt->data_ptr() + 1, *end = opt->data_ptr() + opt->data_size();
@@ -747,7 +747,7 @@ ICMPv6::handover_key_req_type ICMPv6::handover_key_request() const {
}
ICMPv6::handover_key_reply_type ICMPv6::handover_key_reply() const {
const icmpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
HANDOVER_KEY_REPLY, 2 + sizeof(uint32_t)
);
const uint8_t *ptr = opt->data_ptr() + 1, *end = opt->data_ptr() + opt->data_size();
@@ -763,7 +763,7 @@ ICMPv6::handover_key_reply_type ICMPv6::handover_key_reply() const {
}
ICMPv6::handover_assist_info_type ICMPv6::handover_assist_info() const {
const icmpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
HANDOVER_ASSIST_INFO, 2
);
const uint8_t *ptr = opt->data_ptr(), *end = ptr + opt->data_size();
@@ -776,7 +776,7 @@ ICMPv6::handover_assist_info_type ICMPv6::handover_assist_info() const {
}
ICMPv6::mobile_node_id_type ICMPv6::mobile_node_identifier() const {
const icmpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
MOBILE_NODE_ID, 2
);
const uint8_t *ptr = opt->data_ptr(), *end = ptr + opt->data_size();
@@ -789,7 +789,7 @@ ICMPv6::mobile_node_id_type ICMPv6::mobile_node_identifier() const {
}
ICMPv6::dns_search_list_type ICMPv6::dns_search_list() const {
const icmpv6_option *opt = safe_search_option<std::less>(
const option *opt = safe_search_option<std::less>(
DNS_SEARCH_LIST, 2 + sizeof(uint32_t)
);
const uint8_t *ptr = opt->data_ptr(), *end = ptr + opt->data_size();

View File

@@ -98,15 +98,15 @@ IP::IP(const uint8_t *buffer, uint32_t total_sz)
ptr_buffer++;
if(buffer - ptr_buffer < data_size)
throw std::runtime_error(msg);
_ip_options.push_back(ip_option(opt_type, ptr_buffer, ptr_buffer + data_size));
_ip_options.push_back(option(opt_type, ptr_buffer, ptr_buffer + data_size));
}
else
_ip_options.push_back(ip_option(opt_type));
_ip_options.push_back(option(opt_type));
ptr_buffer += _ip_options.back().data_size() + 1;
}
else {
_ip_options.push_back(ip_option(opt_type));
_ip_options.push_back(option(opt_type));
break;
}
_options_size += _ip_options.back().data_size() + 2;
@@ -213,7 +213,7 @@ void IP::security(const security_type &data) {
array[6] = ((value >> 16) & 0xff);
add_option(
ip_option(
option(
130,
sizeof(array),
array
@@ -224,7 +224,7 @@ void IP::security(const security_type &data) {
void IP::stream_identifier(uint16_t stream_id) {
stream_id = Endian::host_to_be(stream_id);
add_option(
ip_option(
option(
136,
sizeof(uint16_t),
(const uint8_t*)&stream_id
@@ -246,7 +246,7 @@ void IP::add_route_option(option_identifier id, const generic_route_option_type
opt_data[1 + i * 4 + 3] = (ip >> 24) & 0xff;
}
add_option(
ip_option(
option(
id,
opt_data.size(),
&opt_data[0]
@@ -255,7 +255,7 @@ void IP::add_route_option(option_identifier id, const generic_route_option_type
}
IP::generic_route_option_type IP::search_route_option(option_identifier id) const {
const ip_option *option = search_option(id);
const option *option = search_option(id);
if(!option || option->data_size() < 1 + sizeof(uint32_t) ||
((option->data_size() - 1) % sizeof(uint32_t)) != 0)
throw option_not_found();
@@ -269,7 +269,7 @@ IP::generic_route_option_type IP::search_route_option(option_identifier id) cons
}
IP::security_type IP::security() const {
const ip_option *option = search_option(130);
const option *option = search_option(130);
if(!option || option->data_size() < 9)
throw option_not_found();
security_type output;
@@ -285,39 +285,39 @@ IP::security_type IP::security() const {
}
uint16_t IP::stream_identifier() const {
const ip_option *option = search_option(136);
const option *option = search_option(136);
if(!option || option->data_size() != sizeof(uint16_t))
throw option_not_found();
return Endian::be_to_host(*(const uint16_t*)option->data_ptr());
}
#if TINS_IS_CXX11
void IP::add_option(ip_option &&option) {
internal_add_option(option);
_ip_options.push_back(std::move(option));
void IP::add_option(option &&opt) {
internal_add_option(opt);
_ip_options.push_back(std::move(opt));
}
#endif
void IP::add_option(const ip_option &option) {
internal_add_option(option);
_ip_options.push_back(option);
void IP::add_option(const option &opt) {
internal_add_option(opt);
_ip_options.push_back(opt);
}
void IP::internal_add_option(const ip_option &option) {
_options_size += 1 + option.data_size();
void IP::internal_add_option(const option &opt) {
_options_size += 1 + opt.data_size();
uint8_t padding = _options_size % 4;
_padded_options_size = padding ? (_options_size - padding + 4) : _options_size;
}
const IP::ip_option *IP::search_option(option_identifier id) const {
for(std::list<ip_option>::const_iterator it = _ip_options.begin(); it != _ip_options.end(); ++it) {
const IP::option *IP::search_option(option_identifier id) const {
for(options_type::const_iterator it = _ip_options.begin(); it != _ip_options.end(); ++it) {
if(it->option() == id)
return &(*it);
}
return 0;
}
uint8_t* IP::write_option(const ip_option &opt, uint8_t* buffer) {
uint8_t* IP::write_option(const option &opt, uint8_t* buffer) {
option_identifier opt_type = opt.option();
memcpy(buffer, &opt_type, 1);
buffer++;
@@ -411,7 +411,7 @@ void IP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU* pare
memcpy(buffer, &_ip, sizeof(_ip));
uint8_t* ptr_buffer = buffer + sizeof(_ip);
for(list<ip_option>::iterator it = _ip_options.begin(); it != _ip_options.end(); ++it)
for(options_type::iterator it = _ip_options.begin(); it != _ip_options.end(); ++it)
ptr_buffer = write_option(*it, ptr_buffer);
memset(buffer + sizeof(_ip) + _options_size, 0, _padded_options_size - _options_size);

View File

@@ -77,7 +77,7 @@ IPv6::IPv6(const uint8_t *buffer, uint32_t total_sz)
throw header_size_error();
// minus one, from the size field
add_ext_header(
ipv6_ext_header(buffer[0], size - sizeof(uint8_t)*2, buffer + 2)
ext_header(buffer[0], size - sizeof(uint8_t)*2, buffer + 2)
);
current_header = buffer[0];
buffer += size;
@@ -238,12 +238,12 @@ void IPv6::send(PacketSender &sender) {
}
#endif
void IPv6::add_ext_header(const ipv6_ext_header &header) {
void IPv6::add_ext_header(const ext_header &header) {
ext_headers.push_back(header);
headers_size += header.data_size() + sizeof(uint8_t) * 2;
}
const IPv6::ipv6_ext_header *IPv6::search_header(ExtensionHeader id) const {
const IPv6::ext_header *IPv6::search_header(ExtensionHeader id) const {
uint8_t current_header = _header.next_header;
headers_type::const_iterator it = ext_headers.begin();
while(it != ext_headers.end() && current_header != id) {
@@ -262,7 +262,7 @@ void IPv6::set_last_next_header(uint8_t value) {
ext_headers.back().option(value);
}
uint8_t *IPv6::write_header(const ipv6_ext_header &header, uint8_t *buffer) {
uint8_t *IPv6::write_header(const ext_header &header, uint8_t *buffer) {
*buffer++ = header.option();
*buffer++ = (header.length_field() > 8) ? (header.length_field() - 8) : 0;
return std::copy(header.data_ptr(), header.data_ptr() + header.data_size(), buffer);

View File

@@ -62,8 +62,8 @@ PPPoE::PPPoE(const uint8_t *buffer, uint32_t total_sz)
if(Endian::be_to_host(opt_len) > total_sz)
throw std::runtime_error(err_msg);
add_tag(
pppoe_tag(
static_cast<tag_identifiers>(opt_type),
tag(
static_cast<TagTypes>(opt_type),
Endian::be_to_host(opt_len),
buffer
)
@@ -73,7 +73,7 @@ PPPoE::PPPoE(const uint8_t *buffer, uint32_t total_sz)
}
}
const PPPoE::pppoe_tag *PPPoE::search_tag(tag_identifiers identifier) const {
const PPPoE::tag *PPPoE::search_tag(TagTypes identifier) const {
for(tags_type::const_iterator it = _tags.begin(); it != _tags.end(); ++it) {
if(it->option() == identifier)
return &*it;
@@ -126,13 +126,13 @@ void PPPoE::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *)
}
}
void PPPoE::add_tag(const pppoe_tag &option) {
void PPPoE::add_tag(const tag &option) {
_tags_size += option.data_size() + sizeof(uint16_t) * 2;
_tags.push_back(option);
}
#if TINS_IS_CXX11
void PPPoE::add_tag(pppoe_tag &&option) {
void PPPoE::add_tag(tag &&option) {
_tags_size += option.data_size() + sizeof(uint16_t) * 2;
_tags.push_back(std::move(option));
}
@@ -171,7 +171,7 @@ void PPPoE::vendor_specific(const vendor_spec_type &value) {
buffer.begin() + sizeof(uint32_t)
);
add_tag(
pppoe_tag(
tag(
VENDOR_SPECIFIC,
buffer.begin(),
buffer.end()
@@ -214,7 +214,7 @@ byte_array PPPoE::ac_cookie() const {
}
PPPoE::vendor_spec_type PPPoE::vendor_specific() const {
const pppoe_tag *tag = safe_search_tag<std::less>(
const tag *tag = safe_search_tag<std::less>(
VENDOR_SPECIFIC, sizeof(uint32_t)
);
vendor_spec_type output;

View File

@@ -80,13 +80,13 @@ TCP::TCP(const uint8_t *buffer, uint32_t total_sz)
if(header_end - index < args[1])
throw std::runtime_error("Not enough size for a TCP header in the buffer.");
if(args[1])
add_option(tcp_option((Option)args[0], buffer + index, buffer + index + args[1]));
add_option(option((OptionTypes)args[0], buffer + index, buffer + index + args[1]));
else
add_option(tcp_option((Option)args[0], args[1], 0));
add_option(option((OptionTypes)args[0], args[1], 0));
index += args[1];
}
else
add_option(tcp_option((Option)args[0], 0));
add_option(option((OptionTypes)args[0], 0));
}
buffer += index;
total_sz -= index;
@@ -129,7 +129,7 @@ void TCP::data_offset(small_uint<4> new_doff) {
void TCP::mss(uint16_t value) {
value = Endian::host_to_be(value);
add_option(tcp_option(MSS, 2, (uint8_t*)&value));
add_option(option(MSS, 2, (uint8_t*)&value));
}
uint16_t TCP::mss() const {
@@ -137,7 +137,7 @@ uint16_t TCP::mss() const {
}
void TCP::winscale(uint8_t value) {
add_option(tcp_option(WSCALE, 1, &value));
add_option(option(WSCALE, 1, &value));
}
uint8_t TCP::winscale() const {
@@ -145,7 +145,7 @@ uint8_t TCP::winscale() const {
}
void TCP::sack_permitted() {
add_option(tcp_option(SACK_OK, 0));
add_option(option(SACK_OK, 0));
}
bool TCP::has_sack_permitted() const {
@@ -161,7 +161,7 @@ void TCP::sack(const sack_type &edges) {
*(ptr++) = Endian::host_to_be(*it);
}
add_option(
tcp_option(
option(
SACK,
(uint8_t)(sizeof(uint32_t) * edges.size()),
(const uint8_t*)value
@@ -171,7 +171,7 @@ void TCP::sack(const sack_type &edges) {
}
TCP::sack_type TCP::sack() const {
const tcp_option *option = search_option(SACK);
const option *option = search_option(SACK);
if(!option || (option->data_size() % sizeof(uint32_t)) != 0)
throw option_not_found();
const uint32_t *ptr = (const uint32_t*)option->data_ptr();
@@ -186,11 +186,11 @@ TCP::sack_type TCP::sack() const {
void TCP::timestamp(uint32_t value, uint32_t reply) {
uint64_t buffer = (uint64_t(value) << 32) | reply;
buffer = Endian::host_to_be(buffer);
add_option(tcp_option(TSOPT, 8, (uint8_t*)&buffer));
add_option(option(TSOPT, 8, (uint8_t*)&buffer));
}
std::pair<uint32_t, uint32_t> TCP::timestamp() const {
const tcp_option *option = search_option(TSOPT);
const option *option = search_option(TSOPT);
if(!option || option->data_size() != (sizeof(uint32_t) << 1))
throw option_not_found();
uint64_t buffer = *(const uint64_t*)option->data_ptr();
@@ -200,7 +200,7 @@ std::pair<uint32_t, uint32_t> TCP::timestamp() const {
void TCP::altchecksum(AltChecksums value) {
uint8_t int_value = value;
add_option(tcp_option(ALTCHK, 1, &int_value));
add_option(option(ALTCHK, 1, &int_value));
}
TCP::AltChecksums TCP::altchecksum() const {
@@ -268,13 +268,13 @@ void TCP::set_flag(Flags tcp_flag, small_uint<1> value) {
};
}
void TCP::add_option(Option option, uint8_t length, const uint8_t *data) {
add_option(tcp_option(option, data, data + length));
void TCP::add_option(OptionTypes opt, uint8_t length, const uint8_t *data) {
add_option(option(opt, data, data + length));
}
void TCP::add_option(const tcp_option &option) {
_options.push_back(option);
internal_add_option(option);
void TCP::add_option(const option &opt) {
_options.push_back(opt);
internal_add_option(opt);
}
uint32_t TCP::header_size() const {
@@ -329,7 +329,7 @@ void TCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *par
_tcp.check = 0;
}
const TCP::tcp_option *TCP::search_option(Option opt) const {
const TCP::option *TCP::search_option(OptionTypes opt) const {
for(options_type::const_iterator it = _options.begin(); it != _options.end(); ++it) {
if(it->option() == opt)
return &(*it);
@@ -337,9 +337,9 @@ const TCP::tcp_option *TCP::search_option(Option opt) const {
return 0;
}
/* tcp_options */
/* options */
uint8_t *TCP::write_option(const tcp_option &opt, uint8_t *buffer) {
uint8_t *TCP::write_option(const option &opt, uint8_t *buffer) {
if(opt.option() == 0 || opt.option() == 1) {
*buffer = opt.option();
return buffer + 1;
@@ -354,21 +354,21 @@ uint8_t *TCP::write_option(const tcp_option &opt, uint8_t *buffer) {
}
#if TINS_IS_CXX11
void TCP::add_option(tcp_option &&option) {
internal_add_option(option);
_options.push_back(std::move(option));
void TCP::add_option(option &&opt) {
internal_add_option(opt);
_options.push_back(std::move(opt));
}
#endif
void TCP::internal_add_option(const tcp_option &option) {
void TCP::internal_add_option(const option &opt) {
uint8_t padding;
_options_size += sizeof(uint8_t);
// SACK_OK contains length but not data....
if(option.data_size() || option.option() == SACK_OK)
if(opt.data_size() || opt.option() == SACK_OK)
_options_size += sizeof(uint8_t);
_options_size += option.data_size();
_options_size += opt.data_size();
padding = _options_size & 3;
_total_options_size = (padding) ? _options_size - padding + 4 : _options_size;

View File

@@ -21,7 +21,7 @@ public:
static const IPv4Address addr;
void test_equals(const DHCP &dhcp1, const DHCP &dhcp2);
void test_option(const DHCP &dhcp, DHCP::Options opt, uint32_t len = 0, uint8_t *value = 0);
void test_option(const DHCP &dhcp, DHCP::OptionTypes opt, uint32_t len = 0, uint8_t *value = 0);
};
const BootP::chaddr_type DHCPTest::chaddr("16:ab:54:12:fa:ca:56:7f:1b:65:11:fa:da:ab:19:18");
@@ -167,8 +167,8 @@ TEST_F(DHCPTest, File) {
EXPECT_TRUE(memcmp(dhcp.file(), file, 128) == 0);
}
void DHCPTest::test_option(const DHCP &dhcp, DHCP::Options opt, uint32_t len, uint8_t *value) {
const DHCP::dhcp_option *option = dhcp.search_option(opt);
void DHCPTest::test_option(const DHCP &dhcp, DHCP::OptionTypes opt, uint32_t len, uint8_t *value) {
const DHCP::option *option = dhcp.search_option(opt);
ASSERT_TRUE(option != 0);
EXPECT_EQ(option->option(), opt);
ASSERT_EQ(option->data_size(), len);

View File

@@ -151,8 +151,8 @@ TEST_F(Dot11Test, Addr1) {
TEST_F(Dot11Test, AddTaggedOption) {
Dot11 dot11;
dot11.add_tagged_option(Dot11::dot11_option(Dot11::SSID, hwaddr.begin(), hwaddr.end()));
const Dot11::dot11_option *option;
dot11.add_option(Dot11::option(Dot11::SSID, hwaddr.begin(), hwaddr.end()));
const Dot11::option *option;
ASSERT_TRUE((option = dot11.search_option(Dot11::SSID)));
EXPECT_EQ(option->data_size(), hwaddr.size());
EXPECT_EQ(option->option(), Dot11::SSID);

View File

@@ -72,7 +72,7 @@ TEST_F(ICMPv6Test, ConstructorFromBuffer2) {
EXPECT_EQ(icmp.router_lifetime(), 1800);
EXPECT_EQ(icmp.reachable_time(), 30000);
EXPECT_EQ(icmp.retransmit_timer(), 1000);
const ICMPv6::icmpv6_option *opt = icmp.search_option(ICMPv6::SOURCE_ADDRESS);
const ICMPv6::option *opt = icmp.search_option(ICMPv6::SOURCE_ADDRESS);
ASSERT_TRUE(opt);
EXPECT_EQ(opt->data_size(), 6);
EXPECT_EQ(HWAddress<6>(opt->data_ptr()), "00:60:97:07:69:ea");

View File

@@ -196,11 +196,11 @@ TEST_F(IPTest, AddOption) {
IP ip;
const uint8_t data[] = { 0x15, 0x17, 0x94, 0x66, 0xff };
IP::option_identifier id(IP::SEC, IP::CONTROL, 1);
ip.add_option(IP::ip_option(id, data, data + sizeof(data)));
const IP::ip_option *option;
ASSERT_TRUE((option = ip.search_option(id)));
ASSERT_EQ(option->data_size(), sizeof(data));
EXPECT_TRUE(memcmp(option->data_ptr(), data, sizeof(data)) == 0);
ip.add_option(IP::option(id, data, data + sizeof(data)));
const IP::option *opt;
ASSERT_TRUE((opt = ip.search_option(id)));
ASSERT_EQ(opt->data_size(), sizeof(data));
EXPECT_TRUE(memcmp(opt->data_ptr(), data, sizeof(data)) == 0);
}
void IPTest::test_equals(const IP &ip1, const IP &ip2) {

View File

@@ -45,7 +45,7 @@ void IPv6Test::test_equals(IPv6 &ip1, IPv6 &ip2) {
EXPECT_EQ(ip1.src_addr(), ip2.src_addr());
EXPECT_EQ(bool(ip1.search_header(IPv6::HOP_BY_HOP)), bool(ip2.search_header(IPv6::HOP_BY_HOP)));
const IPv6::ipv6_ext_header *header1 = ip1.search_header(IPv6::HOP_BY_HOP),
const IPv6::ext_header *header1 = ip1.search_header(IPv6::HOP_BY_HOP),
*header2 = ip2.search_header(IPv6::HOP_BY_HOP);
if(header1 && header2) {
EXPECT_EQ(header1->data_size(), header2->data_size());
@@ -109,7 +109,7 @@ TEST_F(IPv6Test, ConstructorFromBuffer2) {
EXPECT_EQ(pdu->checksum(), 0x74fe);
EXPECT_EQ(pdu->checksum(), 0x74fe);
const IPv6::ipv6_ext_header *header = ipv6.search_header(IPv6::HOP_BY_HOP);
const IPv6::ext_header *header = ipv6.search_header(IPv6::HOP_BY_HOP);
ASSERT_TRUE(header);
EXPECT_EQ(header->data_size(), 6);
}

View File

@@ -163,13 +163,13 @@ TEST_F(PPPoETest, SpoofedOptions) {
PPPoE pdu;
uint8_t a[] = { 1,2,3,4,5,6 };
pdu.add_tag(
PPPoE::pppoe_tag(PPPoE::VENDOR_SPECIFIC, 65000, a, a + sizeof(a))
PPPoE::tag(PPPoE::VENDOR_SPECIFIC, 65000, a, a + sizeof(a))
);
pdu.add_tag(
PPPoE::pppoe_tag(PPPoE::VENDOR_SPECIFIC, 65000, a, a + sizeof(a))
PPPoE::tag(PPPoE::VENDOR_SPECIFIC, 65000, a, a + sizeof(a))
);
pdu.add_tag(
PPPoE::pppoe_tag(PPPoE::VENDOR_SPECIFIC, 65000, a, a + sizeof(a))
PPPoE::tag(PPPoE::VENDOR_SPECIFIC, 65000, a, a + sizeof(a))
);
// probably we'd expect it to crash if it's not working, valgrind plx
EXPECT_EQ(3, pdu.tags().size());