From 0f2bc4505938310bc2e99735b31d8b88e62903dd Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Tue, 23 Apr 2013 13:04:57 -0300 Subject: [PATCH] Moved definitions inside TINS_IS_CXX11 into header files. --- include/dhcp.h | 5 ++++- include/dns_record.h | 15 +++++++++++++-- include/dot11.h | 5 ++++- include/icmpv6.h | 5 ++++- include/ip.h | 5 ++++- include/packet_sender.h | 22 ++++++++++++++++++++-- include/packet_writer.h | 12 ++++++++++-- include/pdu.h | 11 +++++++++-- include/pppoe.h | 5 ++++- include/sniffer.h | 16 ++++++++++++++-- include/tcp.h | 5 ++++- src/dhcp.cpp | 7 ------- src/dns_record.cpp | 18 ------------------ src/dot11.cpp | 7 ------- src/icmpv6.cpp | 7 ------- src/ip.cpp | 7 ------- src/packet_sender.cpp | 27 --------------------------- src/packet_writer.cpp | 14 -------------- src/pdu.cpp | 13 ------------- src/pppoe.cpp | 7 ------- src/sniffer.cpp | 18 ------------------ src/tcp.cpp | 7 ------- 22 files changed, 90 insertions(+), 148 deletions(-) diff --git a/include/dhcp.h b/include/dhcp.h index 00032d2..370f9a7 100644 --- a/include/dhcp.h +++ b/include/dhcp.h @@ -185,7 +185,10 @@ namespace Tins { * * \param opt The option to be added. */ - void add_option(option &&opt); + void add_option(option &&opt) { + internal_add_option(opt); + _options.push_back(std::move(opt)); + } #endif /** diff --git a/include/dns_record.h b/include/dns_record.h index f64aea5..a42896d 100644 --- a/include/dns_record.h +++ b/include/dns_record.h @@ -108,12 +108,23 @@ public: /** * Move constructor. */ - DNSResourceRecord(DNSResourceRecord &&rhs) noexcept; + DNSResourceRecord(DNSResourceRecord &&rhs) noexcept + : info_(rhs.info_), data(std::move(rhs.data)), impl(0) { + std::swap(impl, rhs.impl); + } /** * Move assignment operator. */ - DNSResourceRecord& operator=(DNSResourceRecord &&rhs) noexcept; + DNSResourceRecord& operator=(DNSResourceRecord &&rhs) noexcept + { + info_ = rhs.info_; + data = std::move(rhs.data); + delete impl; + impl = 0; + std::swap(impl, rhs.impl); + return *this; + } #endif // TINS_IS_CXX11 /** diff --git a/include/dot11.h b/include/dot11.h index d72bdf1..8cdeb46 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -395,7 +395,10 @@ namespace Tins { * * \param opt The option to be added. */ - void add_option(option &&opt); + void add_option(option &&opt) { + internal_add_option(opt); + _options.push_back(std::move(opt)); + } #endif /** diff --git a/include/icmpv6.h b/include/icmpv6.h index 4e4e293..55faa07 100644 --- a/include/icmpv6.h +++ b/include/icmpv6.h @@ -751,7 +751,10 @@ public: * * \param option The option to be added. */ - void add_option(option &&option); + void add_option(option &&option) { + internal_add_option(option); + _options.push_back(std::move(option)); + } #endif /** diff --git a/include/ip.h b/include/ip.h index 4a173ac..ca967a2 100644 --- a/include/ip.h +++ b/include/ip.h @@ -424,7 +424,10 @@ namespace Tins { * * \param opt The option to be added. */ - void add_option(option &&opt); + void add_option(option &&opt) { + internal_add_option(opt); + _ip_options.push_back(std::move(opt)); + } #endif /** diff --git a/include/packet_sender.h b/include/packet_sender.h index 773dac1..df2cb6e 100644 --- a/include/packet_sender.h +++ b/include/packet_sender.h @@ -86,13 +86,31 @@ namespace Tins { * \brief Move constructor. * \param rhs The sender to be moved. */ - PacketSender(PacketSender &&rhs); + PacketSender(PacketSender &&rhs) noexcept { + *this = std::move(rhs); + } /** * \brief Move assignment operator. * \param rhs The sender to be moved. */ - PacketSender& operator=(PacketSender &&rhs); + PacketSender& operator=(PacketSender &&rhs) noexcept { + _sockets = std::move(rhs._sockets); + rhs._sockets = std::vector(SOCKETS_END, INVALID_RAW_SOCKET); + #ifndef WIN32 + #if defined(BSD) || defined(__FreeBSD_kernel__) + _ether_socket = std::move(rhs._ether_socket); + #else + _ether_socket = rhs._ether_socket; + rhs._ether_socket = INVALID_RAW_SOCKET; + #endif + #endif + _types = rhs._types; // no move + _timeout = rhs._timeout; + _timeout_usec = rhs._timeout_usec; + default_iface = rhs.default_iface; + return *this; + } #endif /** diff --git a/include/packet_writer.h b/include/packet_writer.h index b015a90..25ed2fa 100644 --- a/include/packet_writer.h +++ b/include/packet_writer.h @@ -75,7 +75,9 @@ public: * * \param rhs The PacketWriter to be moved. */ - PacketWriter(PacketWriter &&rhs) noexcept; + PacketWriter(PacketWriter &&rhs) noexcept { + *this = std::move(rhs); + } /** * \brief Move assignment operator. @@ -85,7 +87,13 @@ public: * * \param rhs The PacketWriter to be moved. */ - PacketWriter& operator=(PacketWriter &&rhs) noexcept; + PacketWriter& operator=(PacketWriter &&rhs) noexcept { + handle = 0; + dumper = 0; + std::swap(handle, rhs.handle); + std::swap(dumper, rhs.dumper); + return *this; + } #endif /** diff --git a/include/pdu.h b/include/pdu.h index 21ab87f..d16d4b2 100644 --- a/include/pdu.h +++ b/include/pdu.h @@ -135,14 +135,21 @@ namespace Tins { * * \param rhs The PDU to be moved. */ - PDU(PDU &&rhs) noexcept; + PDU(PDU &&rhs) noexcept + : _inner_pdu(0) + { + std::swap(_inner_pdu, rhs._inner_pdu); + } /** * \brief Move assignment operator. * * \param rhs The PDU to be moved. */ - PDU& operator=(PDU &&rhs) noexcept; + PDU& operator=(PDU &&rhs) noexcept { + std::swap(_inner_pdu, rhs._inner_pdu); + return *this; + } #endif /** diff --git a/include/pppoe.h b/include/pppoe.h index 780daac..97bead2 100644 --- a/include/pppoe.h +++ b/include/pppoe.h @@ -233,7 +233,10 @@ public: * * \param option The option to be added. */ - void add_tag(tag &&option); + void add_tag(tag &&option) { + _tags_size += option.data_size() + sizeof(uint16_t) * 2; + _tags.push_back(std::move(option)); + } #endif // Option setters diff --git a/include/sniffer.h b/include/sniffer.h index 240eaa0..cb6dbc9 100644 --- a/include/sniffer.h +++ b/include/sniffer.h @@ -64,13 +64,25 @@ namespace Tins { * \brief Move constructor. * This constructor is available only in C++11. */ - BaseSniffer(BaseSniffer &&rhs) noexcept; + BaseSniffer(BaseSniffer &&rhs) noexcept + { + *this = std::move(rhs); + } /** * \brief Move assignment operator. * This opeartor is available only in C++11. */ - BaseSniffer& operator=(BaseSniffer &&rhs) noexcept; + BaseSniffer& operator=(BaseSniffer &&rhs) noexcept + { + handle = 0; + mask = rhs.mask; + iface_type = rhs.iface_type; + actual_filter.bf_insns = 0; + std::swap(handle, rhs.handle); + std::swap(actual_filter, rhs.actual_filter); + return *this; + } #endif /** diff --git a/include/tcp.h b/include/tcp.h index ea0a87c..07b1550 100644 --- a/include/tcp.h +++ b/include/tcp.h @@ -368,7 +368,10 @@ namespace Tins { * * \param option The option to be added. */ - void add_option(option &&opt); + void add_option(option &&opt) { + internal_add_option(opt); + _options.push_back(std::move(opt)); + } #endif /** diff --git a/src/dhcp.cpp b/src/dhcp.cpp index c184ec4..0322814 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -82,13 +82,6 @@ void DHCP::add_option(const option &opt) { _options.push_back(opt); } -#if TINS_IS_CXX11 -void DHCP::add_option(option &&opt) { - internal_add_option(opt); - _options.push_back(std::move(opt)); -} -#endif - void DHCP::internal_add_option(const option &opt) { _size += opt.data_size() + (sizeof(uint8_t) << 1); } diff --git a/src/dns_record.cpp b/src/dns_record.cpp index 0fd9a3b..f92c700 100644 --- a/src/dns_record.cpp +++ b/src/dns_record.cpp @@ -107,24 +107,6 @@ DNSResourceRecord& DNSResourceRecord::operator=(const DNSResourceRecord &rhs) return *this; } -#if TINS_IS_CXX11 - DNSResourceRecord::DNSResourceRecord(DNSResourceRecord &&rhs) noexcept - : info_(rhs.info_), data(std::move(rhs.data)), impl(0) { - std::swap(impl, rhs.impl); - } - - DNSResourceRecord& DNSResourceRecord::operator=(DNSResourceRecord &&rhs) - noexcept - { - info_ = rhs.info_; - data = std::move(rhs.data); - delete impl; - impl = 0; - std::swap(impl, rhs.impl); - return *this; - } -#endif - DNSResourceRecord::~DNSResourceRecord() { delete impl; } diff --git a/src/dot11.cpp b/src/dot11.cpp index 35eb84e..f4742bd 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -104,13 +104,6 @@ void Dot11::add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t *val) _options_size += opt_size; } -#if TINS_IS_CXX11 -void Dot11::add_option(option &&opt) { - internal_add_option(opt); - _options.push_back(std::move(opt)); -} -#endif - void Dot11::internal_add_option(const option &opt) { _options_size += opt.data_size() + sizeof(uint8_t) * 2; } diff --git a/src/icmpv6.cpp b/src/icmpv6.cpp index 362f327..dc12c81 100644 --- a/src/icmpv6.cpp +++ b/src/icmpv6.cpp @@ -251,13 +251,6 @@ void ICMPv6::add_option(const option &option) { _options.push_back(option); } -#if TINS_IS_CXX11 -void ICMPv6::add_option(option &&option) { - internal_add_option(option); - _options.push_back(std::move(option)); -} -#endif - void ICMPv6::internal_add_option(const option &option) { _options_size += option.data_size() + sizeof(uint8_t) * 2; } diff --git a/src/ip.cpp b/src/ip.cpp index 62798e7..31d4544 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -293,13 +293,6 @@ uint16_t IP::stream_identifier() const { return Endian::be_to_host(*(const uint16_t*)option->data_ptr()); } -#if TINS_IS_CXX11 -void IP::add_option(option &&opt) { - internal_add_option(opt); - _ip_options.push_back(std::move(opt)); -} -#endif - void IP::add_option(const option &opt) { internal_add_option(opt); _ip_options.push_back(opt); diff --git a/src/packet_sender.cpp b/src/packet_sender.cpp index 07197ee..b6a41b5 100644 --- a/src/packet_sender.cpp +++ b/src/packet_sender.cpp @@ -97,33 +97,6 @@ PacketSender::PacketSender(const NetworkInterface &iface, uint32_t recv_timeout, _types[ICMP_SOCKET] = IPPROTO_ICMP; } -#if TINS_IS_CXX11 -PacketSender::PacketSender(PacketSender &&rhs) -{ - *this = std::move(rhs); -} - -PacketSender& PacketSender::operator=(PacketSender &&rhs) -{ - _sockets = std::move(rhs._sockets); - rhs._sockets = std::vector(SOCKETS_END, INVALID_RAW_SOCKET); - #ifndef WIN32 - #if defined(BSD) || defined(__FreeBSD_kernel__) - _ether_socket = std::move(rhs._ether_socket); - #else - _ether_socket = rhs._ether_socket; - rhs._ether_socket = INVALID_RAW_SOCKET; - #endif - #endif - _types = rhs._types; // no move - _timeout = rhs._timeout; - _timeout_usec = rhs._timeout_usec; - default_iface = rhs.default_iface; - return *this; - -} -#endif - PacketSender::~PacketSender() { for(unsigned i(0); i < _sockets.size(); ++i) { if(_sockets[i] != INVALID_RAW_SOCKET) diff --git a/src/packet_writer.cpp b/src/packet_writer.cpp index daa5595..bd84898 100644 --- a/src/packet_writer.cpp +++ b/src/packet_writer.cpp @@ -47,20 +47,6 @@ PacketWriter::PacketWriter(const std::string &file_name, LinkType lt) { } } -#if TINS_IS_CXX11 -PacketWriter::PacketWriter(PacketWriter &&rhs) noexcept { - *this = std::move(rhs); -} - -PacketWriter& PacketWriter::operator=(PacketWriter &&rhs) noexcept { - handle = 0; - dumper = 0; - std::swap(handle, rhs.handle); - std::swap(dumper, rhs.dumper); - return *this; -} -#endif - PacketWriter::~PacketWriter() { if(dumper && handle) { pcap_dump_close(dumper); diff --git a/src/pdu.cpp b/src/pdu.cpp index 81c8bd8..d7273eb 100644 --- a/src/pdu.cpp +++ b/src/pdu.cpp @@ -40,19 +40,6 @@ PDU::PDU(PDU *next_pdu) : _inner_pdu(next_pdu) { } -#if TINS_IS_CXX11 -PDU::PDU(PDU &&rhs) noexcept -: _inner_pdu(0) -{ - std::swap(_inner_pdu, rhs._inner_pdu); -} - -PDU& PDU::operator=(PDU &&rhs) noexcept { - std::swap(_inner_pdu, rhs._inner_pdu); - return *this; -} -#endif - PDU::PDU(const PDU &other) : _inner_pdu(0) { copy_inner_pdu(other); } diff --git a/src/pppoe.cpp b/src/pppoe.cpp index 6aee175..42033ce 100644 --- a/src/pppoe.cpp +++ b/src/pppoe.cpp @@ -131,13 +131,6 @@ void PPPoE::add_tag(const tag &option) { _tags.push_back(option); } -#if TINS_IS_CXX11 -void PPPoE::add_tag(tag &&option) { - _tags_size += option.data_size() + sizeof(uint16_t) * 2; - _tags.push_back(std::move(option)); -} -#endif - // *********************** Setters ************************* void PPPoE::end_of_list() { diff --git a/src/sniffer.cpp b/src/sniffer.cpp index 7e0502b..f23eb3c 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -39,24 +39,6 @@ BaseSniffer::BaseSniffer() : handle(0), mask(0) { actual_filter.bf_insns = 0; } - -#if TINS_IS_CXX11 -BaseSniffer::BaseSniffer(BaseSniffer &&rhs) noexcept -{ - *this = std::move(rhs); -} - -BaseSniffer& BaseSniffer::operator=(BaseSniffer &&rhs) noexcept -{ - handle = 0; - mask = rhs.mask; - iface_type = rhs.iface_type; - actual_filter.bf_insns = 0; - std::swap(handle, rhs.handle); - std::swap(actual_filter, rhs.actual_filter); - return *this; -} -#endif BaseSniffer::~BaseSniffer() { if(actual_filter.bf_insns) diff --git a/src/tcp.cpp b/src/tcp.cpp index b6f4351..2cda887 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -349,13 +349,6 @@ uint8_t *TCP::write_option(const option &opt, uint8_t *buffer) { } } -#if TINS_IS_CXX11 -void TCP::add_option(option &&opt) { - internal_add_option(opt); - _options.push_back(std::move(opt)); -} -#endif - void TCP::internal_add_option(const option &opt) { uint8_t padding;