mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Remove inclusion of algorithm almost everywhere
This commit is contained in:
@@ -410,7 +410,7 @@ public:
|
||||
* \return The stored options.
|
||||
*/
|
||||
const options_type& options() const {
|
||||
return ip_options_;
|
||||
return options_;
|
||||
}
|
||||
|
||||
/* Setters */
|
||||
@@ -525,7 +525,7 @@ public:
|
||||
*/
|
||||
void add_option(option &&opt) {
|
||||
internal_add_option(opt);
|
||||
ip_options_.push_back(std::move(opt));
|
||||
options_.push_back(std::move(opt));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -538,8 +538,8 @@ public:
|
||||
*/
|
||||
template<typename... Args>
|
||||
void add_option(Args&&... args) {
|
||||
ip_options_.emplace_back(std::forward<Args>(args)...);
|
||||
internal_add_option(ip_options_.back());
|
||||
options_.emplace_back(std::forward<Args>(args)...);
|
||||
internal_add_option(options_.back());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -770,7 +770,7 @@ private:
|
||||
|
||||
ip_header header_;
|
||||
uint16_t options_size_, padded_options_size_;
|
||||
options_type ip_options_;
|
||||
options_type options_;
|
||||
};
|
||||
|
||||
} // Tins
|
||||
|
||||
@@ -537,22 +537,36 @@ private:
|
||||
};
|
||||
|
||||
namespace Internals {
|
||||
/*
|
||||
* \cond
|
||||
*/
|
||||
template <typename Option>
|
||||
struct option_type_equality_comparator {
|
||||
option_type_equality_comparator(typename Option::option_type type) : type(type) { }
|
||||
/*
|
||||
* \cond
|
||||
*/
|
||||
|
||||
bool operator()(const Option& opt) const {
|
||||
return opt.option() == type;
|
||||
template <typename Option, typename Container>
|
||||
typename Container::iterator find_option(Container& cont, typename Option::option_type type) {
|
||||
typename Container::iterator iter;
|
||||
for (iter = cont.begin(); iter != cont.end(); ++iter) {
|
||||
if (iter->option() == type) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
|
||||
typename Option::option_type type;
|
||||
};
|
||||
/*
|
||||
* \endcond
|
||||
*/
|
||||
template <typename Option, typename Container>
|
||||
typename Container::const_iterator find_option_const(const Container& cont,
|
||||
typename Option::option_type type) {
|
||||
typename Container::const_iterator iter;
|
||||
for (iter = cont.begin(); iter != cont.end(); ++iter) {
|
||||
if (iter->option() == type) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
|
||||
/*
|
||||
* \endcond
|
||||
*/
|
||||
} // Internals
|
||||
|
||||
} // namespace Tins
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "arp.h"
|
||||
#include "ethernetII.h"
|
||||
#include "rawpdu.h"
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "endianness.h"
|
||||
#include "dhcp.h"
|
||||
#include "exceptions.h"
|
||||
@@ -39,7 +38,6 @@ using std::string;
|
||||
using std::vector;
|
||||
using std::list;
|
||||
using std::runtime_error;
|
||||
using std::find_if;
|
||||
|
||||
using Tins::Memory::InputMemoryStream;
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
@@ -113,13 +111,11 @@ const DHCP::option* DHCP::search_option(OptionTypes opt) const {
|
||||
}
|
||||
|
||||
DHCP::options_type::const_iterator DHCP::search_option_iterator(OptionTypes opt) const {
|
||||
Internals::option_type_equality_comparator<option> comparator(opt);
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
return Internals::find_option_const<option>(options_, opt);
|
||||
}
|
||||
|
||||
DHCP::options_type::iterator DHCP::search_option_iterator(OptionTypes opt) {
|
||||
Internals::option_type_equality_comparator<option> comparator(opt);
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
return Internals::find_option<option>(options_, opt);
|
||||
}
|
||||
|
||||
void DHCP::type(Flags type) {
|
||||
|
||||
@@ -28,13 +28,10 @@
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "dhcpv6.h"
|
||||
#include "exceptions.h"
|
||||
#include "memory_helpers.h"
|
||||
|
||||
using std::find_if;
|
||||
using std::copy;
|
||||
using std::vector;
|
||||
using std::runtime_error;
|
||||
using std::memcpy;
|
||||
@@ -105,13 +102,11 @@ const DHCPv6::option* DHCPv6::search_option(OptionTypes type) const {
|
||||
}
|
||||
|
||||
DHCPv6::options_type::const_iterator DHCPv6::search_option_iterator(OptionTypes type) const {
|
||||
Internals::option_type_equality_comparator<option> comparator(type);
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
return Internals::find_option_const<option>(options_, type);
|
||||
}
|
||||
|
||||
DHCPv6::options_type::iterator DHCPv6::search_option_iterator(OptionTypes type) {
|
||||
Internals::option_type_equality_comparator<option> comparator(type);
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
return Internals::find_option<option>(options_, type);
|
||||
}
|
||||
|
||||
void DHCPv6::write_option(const option& opt, OutputMemoryStream& stream) const {
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#ifdef TINS_HAVE_DOT11
|
||||
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "macros.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
@@ -126,13 +125,11 @@ const Dot11::option* Dot11::search_option(OptionTypes type) const {
|
||||
}
|
||||
|
||||
Dot11::options_type::const_iterator Dot11::search_option_iterator(OptionTypes type) const {
|
||||
Internals::option_type_equality_comparator<option> comparator(static_cast<uint8_t>(type));
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
return Internals::find_option_const<option>(options_, type);
|
||||
}
|
||||
|
||||
Dot11::options_type::iterator Dot11::search_option_iterator(OptionTypes type) {
|
||||
Internals::option_type_equality_comparator<option> comparator(static_cast<uint8_t>(type));
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
return Internals::find_option<option>(options_, type);
|
||||
}
|
||||
|
||||
void Dot11::protocol(small_uint<2> new_proto) {
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "dot11/dot11_control.h"
|
||||
#ifdef TINS_HAVE_DOT11
|
||||
|
||||
#include <algorithm>
|
||||
#include "memory_helpers.h"
|
||||
|
||||
using std::copy;
|
||||
@@ -234,7 +233,7 @@ void Dot11BlockAck::fragment_number(small_uint<4> frag) {
|
||||
}
|
||||
|
||||
void Dot11BlockAck::bitmap(const uint8_t* bit) {
|
||||
copy(bit, bit + bitmap_size, bitmap_);
|
||||
memcpy(bitmap_, bit, bitmap_size);
|
||||
}
|
||||
|
||||
void Dot11BlockAck::write_ext_header(OutputMemoryStream& stream) {
|
||||
|
||||
12
src/dot3.cpp
12
src/dot3.cpp
@@ -29,7 +29,6 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include "macros.h"
|
||||
#ifndef _WIN32
|
||||
#if defined(BSD) || defined(__FreeBSD_kernel__)
|
||||
@@ -78,11 +77,11 @@ Dot3::Dot3(const uint8_t* buffer, uint32_t total_sz) {
|
||||
}
|
||||
|
||||
void Dot3::dst_addr(const address_type& address) {
|
||||
copy(address.begin(), address.end(), header_.dst_mac);
|
||||
address.copy(header_.dst_mac);
|
||||
}
|
||||
|
||||
void Dot3::src_addr(const address_type& address) {
|
||||
copy(address.begin(), address.end(), header_.src_mac);
|
||||
address.copy(header_.src_mac);
|
||||
}
|
||||
|
||||
void Dot3::length(uint16_t value) {
|
||||
@@ -121,11 +120,10 @@ bool Dot3::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
||||
if (total_sz < sizeof(header_)) {
|
||||
return false;
|
||||
}
|
||||
const size_t addr_sz = address_type::address_size;
|
||||
const dot3_header* eth_ptr = (const dot3_header*)ptr;
|
||||
if (equal(header_.src_mac, header_.src_mac + addr_sz, eth_ptr->dst_mac)) {
|
||||
if (equal(header_.src_mac, header_.src_mac + addr_sz, eth_ptr->dst_mac) ||
|
||||
dst_addr() == BROADCAST) {
|
||||
if (address_type(header_.src_mac) == address_type(eth_ptr->dst_mac)) {
|
||||
if (address_type(header_.src_mac) == address_type(eth_ptr->dst_mac) ||
|
||||
dst_addr() == BROADCAST) {
|
||||
ptr += sizeof(dot3_header);
|
||||
total_sz -= sizeof(dot3_header);
|
||||
return inner_pdu() ? inner_pdu()->matches_response(ptr, total_sz) : true;
|
||||
|
||||
@@ -29,14 +29,11 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include "eapol.h"
|
||||
#include "exceptions.h"
|
||||
#include "rawpdu.h"
|
||||
#include "memory_helpers.h"
|
||||
|
||||
using std::copy;
|
||||
using std::min;
|
||||
using std::memset;
|
||||
using std::memcpy;
|
||||
|
||||
@@ -51,7 +48,8 @@ PDU::metadata EAPOL::extract_metadata(const uint8_t *buffer, uint32_t total_sz)
|
||||
}
|
||||
const eapol_header* header = (const eapol_header*)buffer;
|
||||
uint32_t advertised_size = Endian::be_to_host<uint16_t>(header->length) + 4;
|
||||
return metadata(min(total_sz, advertised_size), pdu_flag, PDU::UNKNOWN);
|
||||
const uint32_t actual_size = (total_sz < advertised_size) ? total_sz : advertised_size;
|
||||
return metadata(actual_size, pdu_flag, PDU::UNKNOWN);
|
||||
}
|
||||
|
||||
EAPOL::EAPOL(uint8_t packet_type, EAPOLTYPE type)
|
||||
@@ -73,10 +71,8 @@ EAPOL* EAPOL::from_bytes(const uint8_t* buffer, uint32_t total_sz) {
|
||||
const eapol_header* ptr = (const eapol_header*)buffer;
|
||||
uint32_t data_len = Endian::be_to_host<uint16_t>(ptr->length);
|
||||
// at least 4 for fields always present
|
||||
total_sz = min(
|
||||
total_sz,
|
||||
data_len + 4
|
||||
);
|
||||
data_len += 4;
|
||||
total_sz = (total_sz < data_len) ? total_sz : data_len;
|
||||
switch(ptr->type) {
|
||||
case RC4:
|
||||
return new Tins::RC4EAPOL(buffer, total_sz);
|
||||
@@ -142,7 +138,7 @@ void RC4EAPOL::replay_counter(uint64_t value) {
|
||||
}
|
||||
|
||||
void RC4EAPOL::key_iv(const uint8_t* ptr) {
|
||||
copy(ptr, ptr + sizeof(header_.key_iv), header_.key_iv);
|
||||
memcpy(header_.key_iv, ptr, sizeof(header_.key_iv));
|
||||
}
|
||||
|
||||
void RC4EAPOL::key_flag(small_uint<1> flag) {
|
||||
@@ -195,15 +191,15 @@ RSNEAPOL::RSNEAPOL(const uint8_t* buffer, uint32_t total_sz)
|
||||
}
|
||||
|
||||
void RSNEAPOL::nonce(const uint8_t* ptr) {
|
||||
copy(ptr, ptr + nonce_size, header_.nonce);
|
||||
memcpy(header_.nonce, ptr, nonce_size);
|
||||
}
|
||||
|
||||
void RSNEAPOL::rsc(const uint8_t* ptr) {
|
||||
copy(ptr, ptr + rsc_size, header_.rsc);
|
||||
memcpy(header_.rsc, ptr, rsc_size);
|
||||
}
|
||||
|
||||
void RSNEAPOL::id(const uint8_t* ptr) {
|
||||
copy(ptr, ptr + id_size, header_.id);
|
||||
memcpy(header_.id, ptr, id_size);
|
||||
}
|
||||
|
||||
void RSNEAPOL::replay_counter(uint64_t new_replay_counter) {
|
||||
@@ -211,7 +207,7 @@ void RSNEAPOL::replay_counter(uint64_t new_replay_counter) {
|
||||
}
|
||||
|
||||
void RSNEAPOL::mic(const uint8_t* ptr) {
|
||||
copy(ptr, ptr + mic_size, header_.mic);
|
||||
memcpy(header_.mic, ptr, mic_size);
|
||||
}
|
||||
|
||||
void RSNEAPOL::wpa_length(uint16_t length) {
|
||||
@@ -219,7 +215,7 @@ void RSNEAPOL::wpa_length(uint16_t length) {
|
||||
}
|
||||
|
||||
void RSNEAPOL::key_iv(const uint8_t* ptr) {
|
||||
copy(ptr, ptr + sizeof(header_.key_iv), header_.key_iv);
|
||||
memcpy(header_.key_iv, ptr, sizeof(header_.key_iv));
|
||||
}
|
||||
|
||||
void RSNEAPOL::key_length(uint16_t length) {
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "macros.h"
|
||||
#ifndef _WIN32
|
||||
#if defined(BSD) || defined(__FreeBSD_kernel__)
|
||||
@@ -48,8 +47,6 @@
|
||||
#include "memory_helpers.h"
|
||||
#include "detail/pdu_helpers.h"
|
||||
|
||||
using std::equal;
|
||||
|
||||
using Tins::Memory::InputMemoryStream;
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
|
||||
@@ -144,10 +141,9 @@ bool EthernetII::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
||||
if (total_sz < sizeof(header_)) {
|
||||
return false;
|
||||
}
|
||||
const size_t addr_sz = address_type::address_size;
|
||||
const ethernet_header* eth_ptr = (const ethernet_header*)ptr;
|
||||
if (equal(header_.src_mac, header_.src_mac + addr_sz, eth_ptr->dst_mac)) {
|
||||
if (equal(header_.src_mac, header_.src_mac + addr_sz, eth_ptr->dst_mac) ||
|
||||
if (address_type(header_.src_mac) == address_type(eth_ptr->dst_mac)) {
|
||||
if (address_type(header_.src_mac) == address_type(eth_ptr->dst_mac) ||
|
||||
!dst_addr().is_unicast()) {
|
||||
return inner_pdu() ?
|
||||
inner_pdu()->matches_response(ptr + sizeof(header_), total_sz - sizeof(header_)) :
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include "icmp_extension.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "icmpv6.h"
|
||||
#include "ipv6.h"
|
||||
#include "rawpdu.h"
|
||||
@@ -41,7 +40,6 @@
|
||||
using std::memset;
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::max;
|
||||
|
||||
using Tins::Memory::InputMemoryStream;
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
@@ -258,7 +256,8 @@ uint32_t ICMPv6::trailer_size() const {
|
||||
// If the next pdu size is lower than 128 bytes, then padding = 128 - pdu size
|
||||
// If the next pdu size is greater than 128 bytes,
|
||||
// then padding = pdu size padded to next 32 bit boundary - pdu size
|
||||
const uint32_t upper_bound = max(get_adjusted_inner_pdu_size(), 128U);
|
||||
const uint32_t upper_bound = (get_adjusted_inner_pdu_size() > 128U) ?
|
||||
get_adjusted_inner_pdu_size() : 128U;
|
||||
output += upper_bound - inner_pdu()->size();
|
||||
}
|
||||
}
|
||||
@@ -291,7 +290,9 @@ void ICMPv6::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||
uint32_t length_value = get_adjusted_inner_pdu_size();
|
||||
// If the next pdu size is greater than 128, we are forced to set the length field
|
||||
if (length() != 0 || length_value > 128) {
|
||||
length_value = length_value ? max(length_value, 128U) : 0;
|
||||
if (length_value > 0) {
|
||||
length_value = (length_value > 128U) ? length_value : 128U;
|
||||
}
|
||||
// This field uses 64 bit words as the unit
|
||||
header_.rfc4884.length = length_value / sizeof(uint64_t);
|
||||
}
|
||||
@@ -437,13 +438,11 @@ const ICMPv6::option* ICMPv6::search_option(OptionTypes type) const {
|
||||
}
|
||||
|
||||
ICMPv6::options_type::const_iterator ICMPv6::search_option_iterator(OptionTypes type) const {
|
||||
Internals::option_type_equality_comparator<option> comparator(type);
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
return Internals::find_option_const<option>(options_, type);
|
||||
}
|
||||
|
||||
ICMPv6::options_type::iterator ICMPv6::search_option_iterator(OptionTypes type) {
|
||||
Internals::option_type_equality_comparator<option> comparator(type);
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
return Internals::find_option<option>(options_, type);
|
||||
}
|
||||
|
||||
// ********************************************************************
|
||||
|
||||
30
src/ip.cpp
30
src/ip.cpp
@@ -29,7 +29,6 @@
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#ifndef _WIN32
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -50,7 +49,6 @@
|
||||
#include "pdu_allocator.h"
|
||||
|
||||
using std::list;
|
||||
using std::min;
|
||||
using std::memcmp;
|
||||
using std::vector;
|
||||
|
||||
@@ -104,13 +102,13 @@ IP::IP(const uint8_t* buffer, uint32_t total_sz)
|
||||
if (stream.pointer() + data_size > options_end) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
ip_options_.push_back(
|
||||
options_.push_back(
|
||||
option(opt_type, stream.pointer(), stream.pointer() + data_size)
|
||||
);
|
||||
stream.skip(data_size);
|
||||
}
|
||||
else {
|
||||
ip_options_.push_back(option(opt_type));
|
||||
options_.push_back(option(opt_type));
|
||||
}
|
||||
options_size_ += option_size;
|
||||
}
|
||||
@@ -123,7 +121,7 @@ IP::IP(const uint8_t* buffer, uint32_t total_sz)
|
||||
break;
|
||||
}
|
||||
else {
|
||||
ip_options_.push_back(option(opt_type));
|
||||
options_.push_back(option(opt_type));
|
||||
options_size_++;
|
||||
}
|
||||
}
|
||||
@@ -133,7 +131,8 @@ IP::IP(const uint8_t* buffer, uint32_t total_sz)
|
||||
// since this is the case when using TCP segmentation offload
|
||||
if (tot_len() != 0) {
|
||||
const uint32_t advertised_length = (uint32_t)tot_len() - head_len() * sizeof(uint32_t);
|
||||
total_sz = min(static_cast<uint32_t>(stream.size()), advertised_length);
|
||||
const uint32_t stream_size = static_cast<uint32_t>(stream.size());
|
||||
total_sz = (stream_size < advertised_length) ? stream_size : advertised_length;
|
||||
}
|
||||
else {
|
||||
total_sz = stream.size();
|
||||
@@ -325,7 +324,7 @@ uint16_t IP::stream_identifier() const {
|
||||
|
||||
void IP::add_option(const option& opt) {
|
||||
internal_add_option(opt);
|
||||
ip_options_.push_back(opt);
|
||||
options_.push_back(opt);
|
||||
}
|
||||
|
||||
void IP::update_padded_options_size() {
|
||||
@@ -340,28 +339,26 @@ void IP::internal_add_option(const option& opt) {
|
||||
|
||||
bool IP::remove_option(option_identifier id) {
|
||||
options_type::iterator iter = search_option_iterator(id);
|
||||
if (iter == ip_options_.end()) {
|
||||
if (iter == options_.end()) {
|
||||
return false;
|
||||
}
|
||||
options_size_ -= static_cast<uint16_t>(1 + iter->data_size());
|
||||
ip_options_.erase(iter);
|
||||
options_.erase(iter);
|
||||
update_padded_options_size();
|
||||
return true;
|
||||
}
|
||||
|
||||
const IP::option* IP::search_option(option_identifier id) const {
|
||||
options_type::const_iterator iter = search_option_iterator(id);
|
||||
return (iter != ip_options_.end()) ? &*iter : 0;
|
||||
return (iter != options_.end()) ? &*iter : 0;
|
||||
}
|
||||
|
||||
IP::options_type::const_iterator IP::search_option_iterator(option_identifier id) const {
|
||||
Internals::option_type_equality_comparator<option> comparator(id);
|
||||
return find_if(ip_options_.begin(), ip_options_.end(), comparator);
|
||||
return Internals::find_option_const<option>(options_, id);
|
||||
}
|
||||
|
||||
IP::options_type::iterator IP::search_option_iterator(option_identifier id) {
|
||||
Internals::option_type_equality_comparator<option> comparator(id);
|
||||
return find_if(ip_options_.begin(), ip_options_.end(), comparator);
|
||||
return Internals::find_option<option>(options_, id);
|
||||
}
|
||||
|
||||
void IP::write_option(const option& opt, OutputMemoryStream& stream) {
|
||||
@@ -461,7 +458,7 @@ void IP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||
// Restore the fragment offset field in case we flipped it
|
||||
header_.frag_off = original_frag_off;
|
||||
|
||||
for (options_type::const_iterator it = ip_options_.begin(); it != ip_options_.end(); ++it) {
|
||||
for (options_type::const_iterator it = options_.begin(); it != options_.end(); ++it) {
|
||||
write_option(*it, stream);
|
||||
}
|
||||
// Add option padding
|
||||
@@ -499,7 +496,8 @@ bool IP::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
||||
if ((header_.saddr == ip_ptr->daddr &&
|
||||
(header_.daddr == ip_ptr->saddr || dst_addr().is_broadcast())) ||
|
||||
(dst_addr().is_broadcast() && header_.saddr == 0)) {
|
||||
uint32_t sz = min<uint32_t>(header_size(), total_sz);
|
||||
|
||||
uint32_t sz = (header_size() < total_sz) ? header_size() : total_sz;
|
||||
return inner_pdu() ? inner_pdu()->matches_response(ptr + sz, total_sz - sz) : true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#else
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
#include <algorithm>
|
||||
#include "ipv6.h"
|
||||
#include "constants.h"
|
||||
#include "packet_sender.h"
|
||||
@@ -272,7 +271,7 @@ void IPv6::send(PacketSender& sender, const NetworkInterface &) {
|
||||
PacketSender::SocketType type = PacketSender::IPV6_SOCKET;
|
||||
link_addr.sin6_family = AF_INET6;
|
||||
link_addr.sin6_port = 0;
|
||||
copy(header_.dst_addr, header_.dst_addr + address_type::address_size, (uint8_t*)&link_addr.sin6_addr);
|
||||
memcpy((uint8_t*)&link_addr.sin6_addr, header_.dst_addr, address_type::address_size);
|
||||
if (inner_pdu() && inner_pdu()->pdu_type() == PDU::ICMP) {
|
||||
type = PacketSender::ICMP_SOCKET;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include <ws2tcpip.h>
|
||||
#include <mstcpip.h>
|
||||
#endif
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
@@ -45,7 +44,8 @@
|
||||
#include "address_range.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
using std::fill;
|
||||
using std::memset;
|
||||
using std::memcpy;
|
||||
using std::string;
|
||||
using std::ostream;
|
||||
|
||||
@@ -67,7 +67,7 @@ IPv6Address IPv6Address::from_prefix_length(uint32_t prefix_length) {
|
||||
}
|
||||
|
||||
IPv6Address::IPv6Address() {
|
||||
fill(address_, address_ + address_size, 0);
|
||||
memset(address_, 0, address_size);
|
||||
}
|
||||
|
||||
IPv6Address::IPv6Address(const char* addr) {
|
||||
@@ -75,7 +75,7 @@ IPv6Address::IPv6Address(const char* addr) {
|
||||
}
|
||||
|
||||
IPv6Address::IPv6Address(const_iterator ptr) {
|
||||
std::copy(ptr, ptr + address_size, address_);
|
||||
memcpy(address_, ptr, address_size);
|
||||
}
|
||||
|
||||
IPv6Address::IPv6Address(const std::string& addr) {
|
||||
|
||||
@@ -54,7 +54,6 @@
|
||||
#endif
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <algorithm>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
// PDUs required by PacketSender::send(PDU&, NetworkInterface)
|
||||
@@ -71,7 +70,6 @@
|
||||
|
||||
using std::string;
|
||||
using std::ostringstream;
|
||||
using std::max;
|
||||
using std::make_pair;
|
||||
using std::vector;
|
||||
using std::runtime_error;
|
||||
@@ -457,7 +455,7 @@ PDU* PacketSender::recv_match_loop(const vector<int>& sockets,
|
||||
int max_fd = 0;
|
||||
for (vector<int>::const_iterator it = sockets.begin(); it != sockets.end(); ++it) {
|
||||
FD_SET(*it, &readfds);
|
||||
max_fd = max(max_fd, *it);
|
||||
max_fd = (max_fd > *it) ? max_fd : *it;
|
||||
}
|
||||
if ((read = select(max_fd + 1, &readfds, 0, 0, &timeout)) == -1) {
|
||||
return 0;
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <pcap.h>
|
||||
#include "dot11/dot11_base.h"
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include "rawpdu.h"
|
||||
#include "memory_helpers.h"
|
||||
|
||||
|
||||
12
src/tcp.cpp
12
src/tcp.cpp
@@ -28,7 +28,6 @@
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "tcp.h"
|
||||
#include "ip.h"
|
||||
#include "ipv6.h"
|
||||
@@ -38,8 +37,6 @@
|
||||
#include "memory_helpers.h"
|
||||
#include "utils/checksum_utils.h"
|
||||
|
||||
using std::find_if;
|
||||
using std::min;
|
||||
using std::vector;
|
||||
using std::pair;
|
||||
|
||||
@@ -345,13 +342,11 @@ const TCP::option* TCP::search_option(OptionTypes type) const {
|
||||
}
|
||||
|
||||
TCP::options_type::const_iterator TCP::search_option_iterator(OptionTypes type) const {
|
||||
Internals::option_type_equality_comparator<option> comparator(type);
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
return Internals::find_option_const<option>(options_, type);
|
||||
}
|
||||
|
||||
TCP::options_type::iterator TCP::search_option_iterator(OptionTypes type) {
|
||||
Internals::option_type_equality_comparator<option> comparator(type);
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
return Internals::find_option<option>(options_, type);
|
||||
}
|
||||
|
||||
/* options */
|
||||
@@ -408,7 +403,8 @@ bool TCP::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
||||
}
|
||||
const tcp_header* tcp_ptr = (const tcp_header*)ptr;
|
||||
if (tcp_ptr->sport == header_.dport && tcp_ptr->dport == header_.sport) {
|
||||
uint32_t sz = min<uint32_t>(total_sz, tcp_ptr->doff * sizeof(uint32_t));
|
||||
const uint32_t data_offset = tcp_ptr->doff * sizeof(uint32_t);
|
||||
uint32_t sz = (total_sz < data_offset) ? total_sz : data_offset;
|
||||
return inner_pdu() ? inner_pdu()->matches_response(ptr + sz, total_sz - sz) : true;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user