mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Move utils.h implementations to utils.cpp
This commit is contained in:
@@ -503,7 +503,7 @@ private:
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
|
||||
template<class T>
|
||||
template <typename T>
|
||||
T search_and_convert(OptionTypes opt) const {
|
||||
const option* option = search_option(opt);
|
||||
if (!option) {
|
||||
|
||||
@@ -887,7 +887,7 @@ private:
|
||||
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
||||
options_type::iterator search_option_iterator(OptionTypes type);
|
||||
|
||||
template<template <typename> class Functor>
|
||||
template <template <typename> class Functor>
|
||||
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)) {
|
||||
|
||||
@@ -288,7 +288,7 @@ public:
|
||||
* \param end A forward iterator pointing to the end of the
|
||||
* sequence used to initialize signature.
|
||||
*/
|
||||
template<typename RAIterator, typename ForwardIterator>
|
||||
template <typename RAIterator, typename ForwardIterator>
|
||||
rsa_sign_type(RAIterator hash, ForwardIterator start, ForwardIterator end)
|
||||
: signature(start, end) {
|
||||
std::copy(hash, hash + sizeof(key_hash), key_hash);
|
||||
@@ -306,7 +306,7 @@ public:
|
||||
* key_hash member.
|
||||
* \param sign The signature to be set.
|
||||
*/
|
||||
template<typename RAIterator>
|
||||
template <typename RAIterator>
|
||||
rsa_sign_type(RAIterator hash, const signature_type& sign)
|
||||
: signature(sign) {
|
||||
std::copy(hash, hash + sizeof(key_hash), key_hash);
|
||||
@@ -1555,7 +1555,7 @@ private:
|
||||
uint32_t get_adjusted_inner_pdu_size() const;
|
||||
uint8_t get_option_padding(uint32_t data_size);
|
||||
|
||||
template<template <typename> class Functor>
|
||||
template <template <typename> class Functor>
|
||||
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)) {
|
||||
@@ -1564,7 +1564,7 @@ private:
|
||||
return option;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
T search_and_convert(OptionTypes type) const {
|
||||
const option* opt = search_option(type);
|
||||
if (!opt) {
|
||||
|
||||
@@ -220,10 +220,10 @@ struct is_unsigned_integral<uint64_t> {
|
||||
#if TINS_IS_CXX11 && !defined(_MSC_VER)
|
||||
|
||||
// Template metaprogramming trait to determine if a functor can accept another parameter as an argument
|
||||
template <class T, class P, class=void>
|
||||
template <typename T, typename P, typename=void>
|
||||
struct accepts_type : std::false_type { };
|
||||
|
||||
template <class T, class P>
|
||||
template <typename T, typename P>
|
||||
struct accepts_type<T, P,
|
||||
typename std::enable_if<
|
||||
std::is_same< decltype( std::declval<T>()(std::declval<P>()) ), bool>::value
|
||||
@@ -231,17 +231,17 @@ struct accepts_type<T, P,
|
||||
> : std::true_type { };
|
||||
|
||||
// use enable_if to invoke the Packet&& version of the sniff_loop handler if possible - otherwise fail to old behavior
|
||||
template <class Functor, class Packet>
|
||||
template <typename Functor, typename Packet>
|
||||
bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if<accepts_type<Functor, Packet>::value, bool>::type* = 0) {
|
||||
return f(std::move(p));
|
||||
}
|
||||
|
||||
template <class Functor, class Packet>
|
||||
template <typename Functor, typename Packet>
|
||||
bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if<!accepts_type<Functor, Packet>::value && accepts_type<Functor, Packet&>::value, bool>::type* = 0) {
|
||||
return f(p);
|
||||
}
|
||||
|
||||
template <class Functor, class Packet>
|
||||
template <typename Functor, typename Packet>
|
||||
bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if<!accepts_type<Functor, Packet>::value && !accepts_type<Functor, Packet&>::value, bool>::type* = 0) {
|
||||
return f(*p.pdu());
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@
|
||||
#ifndef TINS_PACKET_WRITER_H
|
||||
#define TINS_PACKET_WRITER_H
|
||||
|
||||
#include "utils.h"
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <pcap.h>
|
||||
#include "data_link_type.h"
|
||||
#include "utils.h"
|
||||
#include "macros.h"
|
||||
#include "cxxstd.h"
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Tins {
|
||||
* serialized, such as performing checksums, iterate and copy options,
|
||||
* etc.
|
||||
*/
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
class PDUCacher : public PDU {
|
||||
public:
|
||||
/**
|
||||
|
||||
@@ -48,11 +48,11 @@ namespace Tins {
|
||||
/**
|
||||
* \cond
|
||||
*/
|
||||
template<typename OptionType, class PDUType>
|
||||
template <typename OptionType, typename PDUType>
|
||||
class PDUOption;
|
||||
|
||||
namespace Internals {
|
||||
template<typename T, typename X, typename PDUType>
|
||||
template <typename T, typename X, typename PDUType>
|
||||
T convert_to_integral(const PDUOption<X, PDUType> & opt) {
|
||||
if (opt.data_size() != sizeof(T)) {
|
||||
throw malformed_option();
|
||||
@@ -67,17 +67,17 @@ namespace Internals {
|
||||
return data;
|
||||
}
|
||||
|
||||
template<typename T, typename = void>
|
||||
template <typename T, typename = void>
|
||||
struct converter {
|
||||
template<typename X, typename PDUType>
|
||||
template <typename X, typename PDUType>
|
||||
static T convert(const PDUOption<X, PDUType>& opt) {
|
||||
return T::from_option(opt);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
template <>
|
||||
struct converter<uint8_t> {
|
||||
template<typename X, typename PDUType>
|
||||
template <typename X, typename PDUType>
|
||||
static uint8_t convert(const PDUOption<X, PDUType>& opt) {
|
||||
if (opt.data_size() != 1) {
|
||||
throw malformed_option();
|
||||
@@ -316,7 +316,7 @@ namespace Internals {
|
||||
* The OptionType template parameter indicates the type that will be
|
||||
* used to store this option's identifier.
|
||||
*/
|
||||
template<typename OptionType, class PDUType>
|
||||
template <typename OptionType, typename PDUType>
|
||||
class PDUOption {
|
||||
private:
|
||||
static const int small_buffer_size = 8;
|
||||
|
||||
@@ -181,7 +181,7 @@ public:
|
||||
* \param function The callback handler object which should process packets.
|
||||
* \param max_packets The maximum amount of packets to sniff. 0 == infinite.
|
||||
*/
|
||||
template<class Functor>
|
||||
template <typename Functor>
|
||||
void sniff_loop(Functor function, uint32_t max_packets = 0);
|
||||
|
||||
/**
|
||||
@@ -378,7 +378,7 @@ public:
|
||||
FileSniffer(const std::string& file_name, const std::string& filter = "");
|
||||
};
|
||||
|
||||
template<class T>
|
||||
template <typename T>
|
||||
class HandlerProxy {
|
||||
public:
|
||||
typedef T* ptr_type;
|
||||
@@ -395,7 +395,7 @@ private:
|
||||
fun_type fun_;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
template <typename T>
|
||||
HandlerProxy<T> make_sniffer_handler(T* ptr,
|
||||
typename HandlerProxy<T>::fun_type function) {
|
||||
return HandlerProxy<T>(ptr, function);
|
||||
@@ -599,7 +599,7 @@ protected:
|
||||
bool immediate_mode_;
|
||||
};
|
||||
|
||||
template<class Functor>
|
||||
template <typename Functor>
|
||||
void Tins::BaseSniffer::sniff_loop(Functor function, uint32_t max_packets) {
|
||||
for(iterator it = begin(); it != end(); ++it) {
|
||||
try {
|
||||
|
||||
@@ -482,7 +482,7 @@ public:
|
||||
* \param args The arguments to be used in the option's
|
||||
* constructor.
|
||||
*/
|
||||
template<typename... Args>
|
||||
template <typename... Args>
|
||||
void add_option(Args&&... args) {
|
||||
options_.emplace_back(std::forward<Args>(args)...);
|
||||
internal_add_option(options_.back());
|
||||
@@ -592,7 +592,7 @@ private:
|
||||
|
||||
static const uint16_t DEFAULT_WINDOW;
|
||||
|
||||
template<class T>
|
||||
template <typename T>
|
||||
T generic_search(OptionTypes opt_type) const {
|
||||
const option* opt = search_option(opt_type);
|
||||
if (!opt) {
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
#include "ip_address.h"
|
||||
#include "internals.h"
|
||||
|
||||
// Fix for Windows interface define on combaseapi.h
|
||||
#undef interface
|
||||
|
||||
namespace Tins {
|
||||
|
||||
class NetworkInterface;
|
||||
@@ -163,7 +166,7 @@ TINS_API bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr);
|
||||
*
|
||||
* \brief output ForwardIterator in which entries will be stored.
|
||||
*/
|
||||
template<class ForwardIterator>
|
||||
template<typename ForwardIterator>
|
||||
void route_entries(ForwardIterator output);
|
||||
|
||||
/**
|
||||
@@ -286,7 +289,7 @@ dereference_until_pdu(T& value) {
|
||||
} // Utils
|
||||
} // Tins
|
||||
|
||||
template<class ForwardIterator>
|
||||
template<typename ForwardIterator>
|
||||
void Tins::Utils::route_entries(ForwardIterator output) {
|
||||
std::vector<RouteEntry> entries = route_entries();
|
||||
for (size_t i = 0; i < entries.size(); ++i) {
|
||||
|
||||
Reference in New Issue
Block a user