1
0
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:
Matias Fontanini
2016-01-24 14:13:34 -08:00
parent d7df3a449e
commit 0cf3dd3342
13 changed files with 36 additions and 30 deletions

View File

@@ -16,6 +16,7 @@ IF(MSVC)
# Disable VC secure checks, since these are not really issues.
ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS=1")
ADD_DEFINITIONS("-D_SCL_SECURE_NO_WARNINGS=1")
ADD_DEFINITIONS("-DNOGDI=1")
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
ENDIF()

View File

@@ -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) {

View File

@@ -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)) {

View File

@@ -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) {

View File

@@ -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());
}

View File

@@ -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"

View File

@@ -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:
/**

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -31,6 +31,7 @@
#include <vector>
#include <cstring>
#include "macros.h"
#include "utils.h"
#ifndef _WIN32
#include <netinet/in.h>
#if defined(BSD) || defined(__FreeBSD_kernel__)
@@ -45,9 +46,9 @@
#else
#include <winsock2.h>
#include <iphlpapi.h>
#undef interface
#endif
#include "network_interface.h"
#include "utils.h"
#include "endianness.h"
#include "exceptions.h"

View File

@@ -32,7 +32,7 @@
#include <memory>
#include <cstring>
#include <fstream>
#include "utils.h"
#include "macros.h"
#ifndef _WIN32
#if defined(BSD) || defined(__FreeBSD_kernel__)
#include <sys/socket.h>
@@ -58,6 +58,7 @@
#include <ws2tcpip.h>
#undef interface
#endif
#include "utils.h"
#include "pdu.h"
#include "arp.h"
#include "ethernetII.h"