libtins
4.5
Toggle main menu visibility
Loading...
Searching...
No Matches
include
tins
utils
pdu_utils.h
1
/*
2
* Copyright (c) 2017, Matias Fontanini
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are
7
* met:
8
*
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above
12
* copyright notice, this list of conditions and the following disclaimer
13
* in the documentation and/or other materials provided with the
14
* distribution.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
*
28
*/
29
30
#ifndef TINS_PDU_UTILS_H
31
#define TINS_PDU_UTILS_H
32
33
#include <tins/macros.h>
34
#include <tins/pdu.h>
35
#include <tins/detail/type_traits.h>
36
37
namespace
Tins
{
38
namespace
Utils
{
39
45
TINS_API std::string
to_string
(
PDU::PDUType
pduType);
46
47
template
<
typename
T>
48
struct
is_pdu
{
49
template
<
typename
U>
50
static
char
test(
typename
U::PDUType*);
51
52
template
<
typename
U>
53
static
long
test(...);
54
55
static
const
bool
value =
sizeof
(test<T>(0)) == 1;
56
};
57
61
inline
PDU
&
dereference_until_pdu
(
PDU
& pdu) {
62
return
pdu;
63
}
64
73
template
<
typename
T>
74
inline
typename
Internals::enable_if<!is_pdu<T>::value,
PDU
&>::type
75
dereference_until_pdu
(T& value) {
76
return
dereference_until_pdu
(*value);
77
}
78
79
}
// Utils
80
}
// Tins
81
82
83
#endif
// TINS_PDU_UTILS_H
Tins::PDU
Base class for protocol data units.
Definition
pdu.h:107
Tins::PDU::PDUType
PDUType
Enum which identifies each type of PDU.
Definition
pdu.h:127
Tins::Utils
Network utils namespace.
Definition
utils.h:50
Tins::Utils::to_string
TINS_API std::string to_string(PDU::PDUType pduType)
Converts a PDUType to a string.
Definition
pdu_utils.cpp:37
Tins::Utils::dereference_until_pdu
PDU & dereference_until_pdu(PDU &pdu)
Definition
pdu_utils.h:61
Tins
The Tins namespace.
Definition
address_range.h:38
Tins::Utils::is_pdu
Definition
pdu_utils.h:48
Generated on
for libtins by
1.17.0